diff --git a/client/src/main/java/client/renderer/entity/RenderItem.java b/client/src/main/java/client/renderer/entity/RenderItem.java index aa287fe6..7042cd02 100755 --- a/client/src/main/java/client/renderer/entity/RenderItem.java +++ b/client/src/main/java/client/renderer/entity/RenderItem.java @@ -136,12 +136,7 @@ public class RenderItem } private void renderBuiltin(ItemStack stack) { - if(stack.getItem().getBlock() instanceof BlockChest chest) { - this.state = chest.getState().withProperty(BlockChest.FACING, Facing.SOUTH); - TileEntityRenderer.instance.renderItem(this.chest, 0.0D, 0.0D, 0.0D, 0.0F); - this.state = null; - } - else if(stack.getItem().getBlock() instanceof BlockStandingSign sign) { + if(stack.getItem().getBlock() instanceof BlockStandingSign sign) { this.state = sign.getState().withProperty(BlockStandingSign.ROTATION, 8); TileEntityRenderer.instance.renderItem(this.sign, 0.0D, 0.0D, 0.0D, 0.0F); this.state = null; diff --git a/client/src/main/java/client/renderer/model/ModelChest.java b/client/src/main/java/client/renderer/model/ModelChest.java deleted file mode 100755 index bfb5ffee..00000000 --- a/client/src/main/java/client/renderer/model/ModelChest.java +++ /dev/null @@ -1,42 +0,0 @@ -package client.renderer.model; - -public class ModelChest extends ModelBase -{ - /** The chest lid in the chest's model. */ - public ModelRenderer chestLid = (new ModelRenderer(this, 0, 0)).setTextureSize(64, 64); - - /** The model of the bottom of the chest. */ - public ModelRenderer chestBelow; - - /** The chest's knob in the chest model. */ - public ModelRenderer chestKnob; - - public ModelChest() - { - this.chestLid.addBox(0.0F, -5.0F, -14.0F, 14, 5, 14, 0.0F); - this.chestLid.rotationPointX = 1.0F; - this.chestLid.rotationPointY = 7.0F; - this.chestLid.rotationPointZ = 15.0F; - this.chestKnob = (new ModelRenderer(this, 0, 0)).setTextureSize(64, 64); - this.chestKnob.addBox(-1.0F, -2.0F, -15.0F, 2, 4, 1, 0.0F); - this.chestKnob.rotationPointX = 8.0F; - this.chestKnob.rotationPointY = 7.0F; - this.chestKnob.rotationPointZ = 15.0F; - this.chestBelow = (new ModelRenderer(this, 0, 19)).setTextureSize(64, 64); - this.chestBelow.addBox(0.0F, 0.0F, 0.0F, 14, 10, 14, 0.0F); - this.chestBelow.rotationPointX = 1.0F; - this.chestBelow.rotationPointY = 6.0F; - this.chestBelow.rotationPointZ = 1.0F; - } - - /** - * This method renders out all parts of the chest model. - */ - public void renderAll() - { - this.chestKnob.rotateAngleX = this.chestLid.rotateAngleX; - this.chestLid.render(0.0625F); - this.chestKnob.render(0.0625F); - this.chestBelow.render(0.0625F); - } -} diff --git a/client/src/main/java/client/renderer/tileentity/ChestRenderer.java b/client/src/main/java/client/renderer/tileentity/ChestRenderer.java deleted file mode 100755 index 07e2d841..00000000 --- a/client/src/main/java/client/renderer/tileentity/ChestRenderer.java +++ /dev/null @@ -1,105 +0,0 @@ -package client.renderer.tileentity; - -import org.lwjgl.opengl.GL11; - -import client.renderer.GlState; -import client.renderer.model.ModelChest; -import common.block.tech.BlockChest; -import common.init.BlockRegistry; -import common.init.Blocks; -import common.tileentity.TileEntityChest; -import common.world.State; - - -public class ChestRenderer extends TileRenderer -{ - private final ModelChest model = new ModelChest(); - - public ChestRenderer(TileEntityRenderer renderer) { - super(renderer); - } - - public void renderTileEntityAt(TileEntityChest te, double x, double y, double z, float partialTicks, int destroyStage) - { - GlState.enableDepth(); - GlState.depthFunc(GL11.GL_LEQUAL); - GlState.depthMask(true); - int i = 0; - BlockChest block = Blocks.chest; - - if (te.hasWorldObj()) - { - State state = te.getBlockState(); - if(state.getBlock() instanceof BlockChest chest) { - i = state.getValue(BlockChest.FACING).getIndex(); - block = chest; - } - } - - if (destroyStage >= 0) - { - this.bindTexture(DESTROY_STAGES[destroyStage]); - GL11.glMatrixMode(GL11.GL_TEXTURE); - GL11.glPushMatrix(); - GL11.glScalef(4.0F, 4.0F, 1.0F); - GL11.glTranslatef(0.0625F, 0.0625F, 0.0625F); - GL11.glMatrixMode(GL11.GL_MODELVIEW); - } - else - { - this.bindTexture("textures/blocks/" + BlockRegistry.getName(block) + ".png"); - } - - GL11.glPushMatrix(); - GlState.enableRescaleNormal(); - - if (destroyStage < 0) - { - GlState.color(1.0F, 1.0F, 1.0F, 1.0F); - } - - GL11.glTranslatef((float)x, (float)y + 1.0F, (float)z + 1.0F); - GL11.glScalef(1.0F, -1.0F, -1.0F); - GL11.glTranslatef(0.5F, 0.5F, 0.5F); - int j = 0; - - if (i == 2) - { - j = 180; - } - - if (i == 3) - { - j = 0; - } - - if (i == 4) - { - j = 90; - } - - if (i == 5) - { - j = -90; - } - - GL11.glRotatef((float)j, 0.0F, 1.0F, 0.0F); - GL11.glTranslatef(-0.5F, -0.5F, -0.5F); - float f = te.prevLidAngle + (te.lidAngle - te.prevLidAngle) * partialTicks; - - f = 1.0F - f; - f = 1.0F - f * f * f; - this.model.chestLid.rotateAngleX = -(f * (float)Math.PI / 2.0F); - this.model.renderAll(); - GlState.disableRescaleNormal(); - GL11.glPopMatrix(); - GlState.color(1.0F, 1.0F, 1.0F, 1.0F); - - if (destroyStage >= 0) - { - GL11.glMatrixMode(GL11.GL_TEXTURE); - GL11.glPopMatrix(); - GL11.glMatrixMode(GL11.GL_MODELVIEW); - } - } -} diff --git a/client/src/main/java/client/renderer/tileentity/TileEntityRenderer.java b/client/src/main/java/client/renderer/tileentity/TileEntityRenderer.java index 7a5e8832..03e41255 100755 --- a/client/src/main/java/client/renderer/tileentity/TileEntityRenderer.java +++ b/client/src/main/java/client/renderer/tileentity/TileEntityRenderer.java @@ -32,7 +32,6 @@ public class TileEntityRenderer { private TileEntityRenderer() { this.renderers.put(TileEntitySign.class, new SignRenderer(this)); this.renderers.put(TileEntityDisplay.class, new DisplayRenderer(this)); - this.renderers.put(TileEntityChest.class, new ChestRenderer(this)); } private TileRenderer getRenderer(Class clazz) { diff --git a/client/src/main/java/client/world/WorldClient.java b/client/src/main/java/client/world/WorldClient.java index cecb5d72..045dee5e 100755 --- a/client/src/main/java/client/world/WorldClient.java +++ b/client/src/main/java/client/world/WorldClient.java @@ -664,8 +664,10 @@ public class WorldClient extends AWorldClient case 2016: TileEntity te = this.getTileEntity(blockPosIn); - if(te instanceof TileEntityChest chest) + if(te instanceof TileEntityChest chest) { chest.setUsing(data); + this.markBlockForUpdate(blockPosIn); + } } } diff --git a/client/src/main/resources/textures/blocks/chest.png b/client/src/main/resources/textures/blocks/chest.png deleted file mode 100755 index 2e3d7fde..00000000 Binary files a/client/src/main/resources/textures/blocks/chest.png and /dev/null differ diff --git a/client/src/main/resources/textures/blocks/chest_front.png b/client/src/main/resources/textures/blocks/chest_front.png new file mode 100755 index 00000000..d6ad16cd Binary files /dev/null and b/client/src/main/resources/textures/blocks/chest_front.png differ diff --git a/client/src/main/resources/textures/blocks/chest_handle.png b/client/src/main/resources/textures/blocks/chest_handle.png new file mode 100755 index 00000000..0096cda9 Binary files /dev/null and b/client/src/main/resources/textures/blocks/chest_handle.png differ diff --git a/client/src/main/resources/textures/blocks/chest_inner.png b/client/src/main/resources/textures/blocks/chest_inner.png new file mode 100755 index 00000000..2b840b7b Binary files /dev/null and b/client/src/main/resources/textures/blocks/chest_inner.png differ diff --git a/client/src/main/resources/textures/blocks/chest_side.png b/client/src/main/resources/textures/blocks/chest_side.png new file mode 100755 index 00000000..4d4ad692 Binary files /dev/null and b/client/src/main/resources/textures/blocks/chest_side.png differ diff --git a/client/src/main/resources/textures/blocks/chest_top.png b/client/src/main/resources/textures/blocks/chest_top.png new file mode 100755 index 00000000..daf9cd16 Binary files /dev/null and b/client/src/main/resources/textures/blocks/chest_top.png differ diff --git a/client/src/main/resources/textures/blocks/large_chest.png b/client/src/main/resources/textures/blocks/large_chest.png deleted file mode 100755 index 3aef1901..00000000 Binary files a/client/src/main/resources/textures/blocks/large_chest.png and /dev/null differ diff --git a/common/src/main/java/common/block/tech/BlockChest.java b/common/src/main/java/common/block/tech/BlockChest.java index e2b4a6f0..24d9e2c3 100755 --- a/common/src/main/java/common/block/tech/BlockChest.java +++ b/common/src/main/java/common/block/tech/BlockChest.java @@ -20,8 +20,12 @@ import common.inventory.InventoryHelper; import common.item.CheatTab; import common.item.ItemStack; import common.item.tool.ItemKey; +import common.model.Model; +import common.model.ModelProvider; +import common.model.ModelRotation; import common.packet.SPacketSoundEffect; import common.properties.Property; +import common.properties.PropertyBool; import common.tileentity.TileEntity; import common.tileentity.TileEntityChest; import common.util.BlockPos; @@ -31,9 +35,11 @@ import common.vars.Vars; import common.world.State; import common.world.World; import common.world.AWorldServer; +import common.world.IWorldAccess; public class BlockChest extends Block implements ITileEntityProvider, Rotatable { + public static final PropertyBool OPEN = PropertyBool.create("open"); private static final Map CHESTS = Maps.newHashMap(); private final int width; @@ -46,7 +52,7 @@ public class BlockChest extends Block implements ITileEntityProvider, Rotatable public BlockChest(int width, int height) { super(Material.WOOD); - this.setDefaultState(this.getBaseState().withProperty(FACING, Facing.NORTH)); + this.setDefaultState(this.getBaseState().withProperty(FACING, Facing.NORTH).withProperty(OPEN, false)); this.width = width; this.height = height; this.setTab(CheatTab.TECHNOLOGY); @@ -74,11 +80,6 @@ public class BlockChest extends Block implements ITileEntityProvider, Rotatable return false; } - public int getRenderType() - { - return 2; - } - public State getPlacedState(World worldIn, BlockPos pos, Facing facing, float hitX, float hitY, float hitZ, EntityLiving placer) { return this.getState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()); @@ -230,15 +231,65 @@ public class BlockChest extends Block implements ITileEntityProvider, Rotatable protected Property[] getProperties() { - return new Property[] {FACING}; + return new Property[] {FACING, OPEN}; } + + protected Property[] getUnsavedProperties() + { + return new Property[] {OPEN}; + } + + public State getState(State state, IWorldAccess world, BlockPos pos) { + TileEntity te = world.getTileEntity(pos); + if(te instanceof TileEntityChest chest) + return state.withProperty(OPEN, chest.numPlayersUsing > 0); + return state; + } public boolean isXrayVisible() { return true; } - - public String getFallbackTexture() { - return "oak_planks"; + + public Model getModel(ModelProvider provider, String name, State state) { + return !state.getValue(OPEN) ? + provider.getModel(name + "_top") + .add(1, 0, 1, 15, 14, 15) + .d().noCull() + .u().noCull() + .n(name + "_front").noCull() + .s(name + "_side").noCull() + .w(name + "_side").noCull() + .e(name + "_side").noCull() + .add(7, 7, 0, 9, 11, 1) + .d(name + "_handle").uv(7, 8, 9, 9).noCull() + .u(name + "_handle").uv(7, 5, 9, 6).noCull() + .n(name + "_handle").noCull() + .w(name + "_handle").uv(8, 5, 9, 9).noCull() + .e(name + "_handle").uv(7, 5, 8, 9).noCull() + .rotate(ModelRotation.getNorthRot(state.getValue(FACING))) : + provider.getModel(name + "_top") + .add(1, 0, 1, 15, 10, 15) + .d().noCull() + .u(name + "_inner").noCull() + .n(name + "_front").noCull() + .s(name + "_side").noCull() + .w(name + "_side").noCull() + .e(name + "_side").noCull() + .add(1, 9, 15, 15, 23, 20) + .d(name + "_side").uv(1, 2, 15, 7).noCull() + .u(name + "_front").uv(1, 2, 15, 7).rot(180).noCull() + .n(name + "_inner").uv(1, 1, 15, 15).noCull() + .s().uv(1, 1, 15, 15).noCull() + .w(name + "_side").uv(1, 2, 15, 7).rot(90).noCull() + .e(name + "_side").uv(1, 2, 15, 7).rot(270).noCull() + .add(7, 23, 13, 9, 24, 17) + .n(name + "_handle").uv(7, 8, 9, 9).noCull() + .s(name + "_handle").uv(7, 5, 9, 6).rot(180).noCull() + .u(name + "_handle").uv(7, 5, 9, 9).rot(180).noCull() + .d(name + "_handle").uv(9, 5, 7, 9).noCull() + .w(name + "_handle").uv(8, 5, 9, 9).rot(90).noCull() + .e(name + "_handle").uv(7, 5, 8, 9).rot(270).noCull() + .rotate(ModelRotation.getNorthRot(state.getValue(FACING))); } } diff --git a/common/src/main/java/common/tileentity/TileEntityChest.java b/common/src/main/java/common/tileentity/TileEntityChest.java index 8dcceeac..43ca126d 100755 --- a/common/src/main/java/common/tileentity/TileEntityChest.java +++ b/common/src/main/java/common/tileentity/TileEntityChest.java @@ -18,8 +18,7 @@ public class TileEntityChest extends TileEntity implements ITickable, IInventory private ItemStack[] chestContents; private String code; - public float lidAngle; - public float prevLidAngle; + public boolean wasOpen; public int numPlayersUsing; private int ticksSinceSync; private String customName; @@ -216,49 +215,11 @@ public class TileEntityChest extends TileEntity implements ITickable, IInventory } } - this.prevLidAngle = this.lidAngle; - float f1 = 0.1F; - - if (this.numPlayersUsing > 0 && this.lidAngle == 0.0F) + if ((this.numPlayersUsing <= 0 && this.wasOpen) || (this.numPlayersUsing > 0 && !this.wasOpen)) { - double d1 = (double)i + 0.5D; - double d2 = (double)k + 0.5D; - - this.worldObj.playSound(SoundEvent.CHESTOPEN, d1, (double)j + 0.5D, d2, 0.5F); - } - - if (this.numPlayersUsing == 0 && this.lidAngle > 0.0F || this.numPlayersUsing > 0 && this.lidAngle < 1.0F) - { - float f2 = this.lidAngle; - - if (this.numPlayersUsing > 0) - { - this.lidAngle += f1; - } - else - { - this.lidAngle -= f1; - } - - if (this.lidAngle > 1.0F) - { - this.lidAngle = 1.0F; - } - - float f3 = 0.5F; - - if (this.lidAngle < f3 && f2 >= f3) - { - double d3 = (double)i + 0.5D; - double d0 = (double)k + 0.5D; - - this.worldObj.playSound(SoundEvent.CHESTCLOSED, d3, (double)j + 0.5D, d0, 0.5F); - } - - if (this.lidAngle < 0.0F) - { - this.lidAngle = 0.0F; - } + double d3 = (double)i + 0.5D; + double d0 = (double)k + 0.5D; + this.worldObj.playSound((this.wasOpen = this.numPlayersUsing > 0) ? SoundEvent.CHESTOPEN : SoundEvent.CHESTCLOSED, d3, (double)j + 0.5D, d0, 0.5F); } }