diff --git a/src/main/java/appeng/block/grindstone/BlockCrank.java b/src/main/java/appeng/block/grindstone/BlockCrank.java index 08e1f5f2..8fe305db 100644 --- a/src/main/java/appeng/block/grindstone/BlockCrank.java +++ b/src/main/java/appeng/block/grindstone/BlockCrank.java @@ -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; + } + } diff --git a/src/main/java/appeng/block/grindstone/CrankRendering.java b/src/main/java/appeng/block/grindstone/CrankRendering.java new file mode 100644 index 00000000..c7b2dd0a --- /dev/null +++ b/src/main/java/appeng/block/grindstone/CrankRendering.java @@ -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() ); + } +} diff --git a/src/main/java/appeng/client/render/model/pipeline/DoubleFacingQuadRotator.java b/src/main/java/appeng/client/render/model/pipeline/DoubleFacingQuadRotator.java index 1d942762..0aa797be 100644 --- a/src/main/java/appeng/client/render/model/pipeline/DoubleFacingQuadRotator.java +++ b/src/main/java/appeng/client/render/model/pipeline/DoubleFacingQuadRotator.java @@ -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 rotated = new ArrayList<>(); for( QuadVertexData data : elements ) diff --git a/src/main/java/appeng/client/render/tesr/CrankTESR.java b/src/main/java/appeng/client/render/tesr/CrankTESR.java new file mode 100644 index 00000000..3a997e1a --- /dev/null +++ b/src/main/java/appeng/client/render/tesr/CrankTESR.java @@ -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 . + */ + +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 +{ + + @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(); + } + +} diff --git a/src/main/java/appeng/core/api/definitions/ApiBlocks.java b/src/main/java/appeng/core/api/definitions/ApiBlocks.java index ddbd56f3..5cd4c5b1 100644 --- a/src/main/java/appeng/core/api/definitions/ApiBlocks.java +++ b/src/main/java/appeng/core/api/definitions/ApiBlocks.java @@ -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(); diff --git a/src/main/resources/assets/appliedenergistics2/blockstates/crank.json b/src/main/resources/assets/appliedenergistics2/blockstates/crank.json new file mode 100644 index 00000000..bf57ebba --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/blockstates/crank.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "appliedenergistics2:crank" } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/appliedenergistics2/models/block/crank.json b/src/main/resources/assets/appliedenergistics2/models/block/crank.json new file mode 100644 index 00000000..3f586fce --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/models/block/crank.json @@ -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" } + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/appliedenergistics2/textures/blocks/crank.png b/src/main/resources/assets/appliedenergistics2/textures/blocks/crank.png new file mode 100644 index 00000000..f6e63cc9 Binary files /dev/null and b/src/main/resources/assets/appliedenergistics2/textures/blocks/crank.png differ