Implemented crank TESR.
Fixed crash bug in model rotator if state wasn't set.
This commit is contained in:
parent
f0ee7939a2
commit
77dff3ab32
|
@ -28,6 +28,7 @@ import net.minecraft.entity.EntityLivingBase;
|
|||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumBlockRenderType;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -127,6 +128,12 @@ public class BlockCrank extends AEBaseTileBlock
|
|||
return te instanceof ICrankable && ( (ICrankable) te ).canCrankAttach( offset.getOpposite() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumBlockRenderType getRenderType( IBlockState state )
|
||||
{
|
||||
return EnumBlockRenderType.ENTITYBLOCK_ANIMATED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void neighborChanged( final IBlockState state, final World world, final BlockPos pos, final Block neighborBlock )
|
||||
{
|
||||
|
@ -150,4 +157,11 @@ public class BlockCrank extends AEBaseTileBlock
|
|||
{
|
||||
return this.findCrankable( world, pos ) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFullCube( IBlockState state )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package appeng.block.grindstone;
|
||||
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import appeng.bootstrap.BlockRenderingCustomizer;
|
||||
import appeng.bootstrap.IBlockRendering;
|
||||
import appeng.bootstrap.IItemRendering;
|
||||
import appeng.client.render.tesr.CrankTESR;
|
||||
|
||||
|
||||
public class CrankRendering extends BlockRenderingCustomizer
|
||||
{
|
||||
|
||||
@Override
|
||||
@SideOnly( Side.CLIENT )
|
||||
public void customize( IBlockRendering rendering, IItemRendering itemRendering )
|
||||
{
|
||||
rendering.tesr( new CrankTESR() );
|
||||
}
|
||||
}
|
|
@ -4,7 +4,6 @@ package appeng.client.render.model.pipeline;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.vecmath.Vector3f;
|
||||
import javax.vecmath.Vector4f;
|
||||
|
||||
|
@ -29,8 +28,16 @@ public class DoubleFacingQuadRotator implements BakingPipelineElement<QuadVertex
|
|||
{
|
||||
IExtendedBlockState extState = (IExtendedBlockState) state;
|
||||
|
||||
final EnumFacing forward = extState.getValue( AEBaseTileBlock.FORWARD );
|
||||
final EnumFacing up = extState.getValue( AEBaseTileBlock.UP );
|
||||
EnumFacing forward = extState.getValue( AEBaseTileBlock.FORWARD );
|
||||
if( forward == null )
|
||||
{
|
||||
forward = EnumFacing.NORTH;
|
||||
}
|
||||
EnumFacing up = extState.getValue( AEBaseTileBlock.UP );
|
||||
if( up == null )
|
||||
{
|
||||
up = EnumFacing.UP;
|
||||
}
|
||||
final FacingToRotation f2r = FacingToRotation.get( forward, up );
|
||||
List<QuadVertexData> rotated = new ArrayList<>();
|
||||
for( QuadVertexData data : elements )
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.client.render.tesr;
|
||||
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.BlockRendererDispatcher;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.VertexBuffer;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import appeng.client.render.FacingToRotation;
|
||||
import appeng.tile.grindstone.TileCrank;
|
||||
|
||||
|
||||
/**
|
||||
* This FastTESR only handles the animated model of the turning crank. When the crank is at rest, it is rendered using a normal model.
|
||||
*/
|
||||
@SideOnly( Side.CLIENT )
|
||||
public class CrankTESR extends TileEntitySpecialRenderer<TileCrank>
|
||||
{
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt( TileCrank te, double x, double y, double z, float partialTicks, int destroyStage )
|
||||
{
|
||||
// Most of this is blatantly copied from FastTESR
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
this.bindTexture( TextureMap.LOCATION_BLOCKS_TEXTURE );
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GlStateManager.blendFunc( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA );
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.disableCull();
|
||||
|
||||
if( Minecraft.isAmbientOcclusionEnabled() )
|
||||
{
|
||||
GlStateManager.shadeModel( GL11.GL_SMOOTH );
|
||||
}
|
||||
else
|
||||
{
|
||||
GlStateManager.shadeModel( GL11.GL_FLAT );
|
||||
}
|
||||
|
||||
IBlockState blockState = te.getWorld().getBlockState( te.getPos() );
|
||||
|
||||
BlockRendererDispatcher dispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher();
|
||||
IBakedModel model = dispatcher.getModelForState( blockState );
|
||||
|
||||
VertexBuffer buffer = tessellator.getBuffer();
|
||||
buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.BLOCK );
|
||||
|
||||
// The translation ensures the vertex buffer positions are relative to 0,0,0 instead of the block pos
|
||||
// This makes the translations that follow much easier
|
||||
buffer.setTranslation( -te.getPos().getX(), -te.getPos().getY(), -te.getPos().getZ() );
|
||||
dispatcher.getBlockModelRenderer().renderModel( te.getWorld(), model, blockState, te.getPos(), buffer, false );
|
||||
buffer.setTranslation( 0, 0, 0 );
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate( x, y, z );
|
||||
|
||||
// Apply GL transformations relative to the center of the block: 1) TE rotation and 2) crank rotation
|
||||
GlStateManager.translate( 0.5, 0.5, 0.5 );
|
||||
FacingToRotation.get( te.getForward(), te.getUp() ).glRotateCurrentMat();
|
||||
GlStateManager.rotate( te.getVisibleRotation(), 0, 1, 0 );
|
||||
GlStateManager.translate( -0.5, -0.5, -0.5 );
|
||||
|
||||
tessellator.draw();
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
}
|
||||
|
||||
}
|
|
@ -39,6 +39,7 @@ import appeng.block.crafting.BlockMolecularAssembler;
|
|||
import appeng.block.crafting.ItemCraftingStorage;
|
||||
import appeng.block.grindstone.BlockCrank;
|
||||
import appeng.block.grindstone.BlockGrinder;
|
||||
import appeng.block.grindstone.CrankRendering;
|
||||
import appeng.block.misc.BlockCellWorkbench;
|
||||
import appeng.block.misc.BlockCharger;
|
||||
import appeng.block.misc.BlockCondenser;
|
||||
|
@ -246,7 +247,7 @@ public final class ApiBlocks implements IBlocks
|
|||
this.grindstone = registry.block( "grindstone", BlockGrinder::new ).features( AEFeature.GrindStone ).build();
|
||||
this.crank = registry.block( "crank", BlockCrank::new )
|
||||
.features( AEFeature.GrindStone )
|
||||
.useCustomItemModel()
|
||||
.rendering( new CrankRendering() )
|
||||
.build();
|
||||
this.inscriber = registry.block( "inscriber", BlockInscriber::new ).features( AEFeature.Inscriber ).build();
|
||||
this.wirelessAccessPoint = registry.block( "wireless_access_point", BlockWireless::new ).features( AEFeature.WirelessAccessTerminal ).build();
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"variants": {
|
||||
"normal": { "model": "appliedenergistics2:crank" }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"parent": "block/block",
|
||||
"textures": {
|
||||
"wood": "appliedenergistics2:blocks/crank",
|
||||
"particle": "appliedenergistics2:blocks/crank"
|
||||
},
|
||||
"elements": [
|
||||
{
|
||||
"name": "Crank Shaft",
|
||||
"from": [ 7.2, 0.0, 7.2 ],
|
||||
"to": [ 8.8, 9.6, 8.8 ],
|
||||
"faces": {
|
||||
"north": { "texture": "#wood" },
|
||||
"east": { "texture": "#wood" },
|
||||
"south": { "texture": "#wood" },
|
||||
"west": { "texture": "#wood" },
|
||||
"up": { "texture": "#wood" },
|
||||
"down": { "texture": "#wood" }
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Crank Handle",
|
||||
"from": [ 8.8, 8.0, 7.2 ],
|
||||
"to": [ 13.6, 9.6, 8.8 ],
|
||||
"faces": {
|
||||
"north": { "texture": "#wood" },
|
||||
"east": { "texture": "#wood" },
|
||||
"south": { "texture": "#wood" },
|
||||
"west": { "texture": "#wood" },
|
||||
"up": { "texture": "#wood" },
|
||||
"down": { "texture": "#wood" }
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 398 B |
Loading…
Reference in New Issue