diff --git a/src/main/java/com/hbm/blocks/machine/MachinePress.java b/src/main/java/com/hbm/blocks/machine/MachinePress.java index 197933d8b..a28d22172 100644 --- a/src/main/java/com/hbm/blocks/machine/MachinePress.java +++ b/src/main/java/com/hbm/blocks/machine/MachinePress.java @@ -2,7 +2,6 @@ package com.hbm.blocks.machine; import java.util.Random; -import com.hbm.blocks.ModBlocks; import com.hbm.main.MainRegistry; import com.hbm.tileentity.machine.TileEntityMachinePress; import cpw.mods.fml.common.network.internal.FMLNetworkHandler; @@ -11,7 +10,6 @@ import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -19,18 +17,12 @@ import net.minecraft.world.World; public class MachinePress extends BlockContainer { - private final Random field_149933_a = new Random(); + private final Random field_149933_a = new Random(); private static boolean keepInventory; public MachinePress(Material p_i45386_1_) { super(p_i45386_1_); } - - @Override - public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_) - { - return Item.getItemFromBlock(ModBlocks.machine_press); - } @Override public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) { @@ -53,67 +45,56 @@ public class MachinePress extends BlockContainer { } @Override - public void breakBlock(World p_149749_1_, int p_149749_2_, int p_149749_3_, int p_149749_4_, Block p_149749_5_, int p_149749_6_) - { - if (!keepInventory) - { - TileEntityMachinePress tileentityfurnace = (TileEntityMachinePress)p_149749_1_.getTileEntity(p_149749_2_, p_149749_3_, p_149749_4_); + public void breakBlock(World p_149749_1_, int p_149749_2_, int p_149749_3_, int p_149749_4_, Block p_149749_5_, int p_149749_6_) { + if(!keepInventory) { + TileEntityMachinePress tileentityfurnace = (TileEntityMachinePress) p_149749_1_.getTileEntity(p_149749_2_, p_149749_3_, p_149749_4_); - if (tileentityfurnace != null) - { - for (int i1 = 0; i1 < tileentityfurnace.getSizeInventory(); ++i1) - { - ItemStack itemstack = tileentityfurnace.getStackInSlot(i1); + if(tileentityfurnace != null) { + for(int i1 = 0; i1 < tileentityfurnace.getSizeInventory(); ++i1) { + ItemStack itemstack = tileentityfurnace.getStackInSlot(i1); - if (itemstack != null) - { - float f = this.field_149933_a.nextFloat() * 0.8F + 0.1F; - float f1 = this.field_149933_a.nextFloat() * 0.8F + 0.1F; - float f2 = this.field_149933_a.nextFloat() * 0.8F + 0.1F; + if(itemstack != null) { + float f = this.field_149933_a.nextFloat() * 0.8F + 0.1F; + float f1 = this.field_149933_a.nextFloat() * 0.8F + 0.1F; + float f2 = this.field_149933_a.nextFloat() * 0.8F + 0.1F; - while (itemstack.stackSize > 0) - { - int j1 = this.field_149933_a.nextInt(21) + 10; + while(itemstack.stackSize > 0) { + int j1 = this.field_149933_a.nextInt(21) + 10; - if (j1 > itemstack.stackSize) - { - j1 = itemstack.stackSize; - } + if(j1 > itemstack.stackSize) { + j1 = itemstack.stackSize; + } - itemstack.stackSize -= j1; - EntityItem entityitem = new EntityItem(p_149749_1_, p_149749_2_ + f, p_149749_3_ + f1, p_149749_4_ + f2, new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage())); + itemstack.stackSize -= j1; + EntityItem entityitem = new EntityItem(p_149749_1_, p_149749_2_ + f, p_149749_3_ + f1, p_149749_4_ + f2, new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage())); - if (itemstack.hasTagCompound()) - { - entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy()); - } + if(itemstack.hasTagCompound()) { + entityitem.getEntityItem().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy()); + } - float f3 = 0.05F; - entityitem.motionX = (float)this.field_149933_a.nextGaussian() * f3; - entityitem.motionY = (float)this.field_149933_a.nextGaussian() * f3 + 0.2F; - entityitem.motionZ = (float)this.field_149933_a.nextGaussian() * f3; - p_149749_1_.spawnEntityInWorld(entityitem); - } - } - } + float f3 = 0.05F; + entityitem.motionX = (float) this.field_149933_a.nextGaussian() * f3; + entityitem.motionY = (float) this.field_149933_a.nextGaussian() * f3 + 0.2F; + entityitem.motionZ = (float) this.field_149933_a.nextGaussian() * f3; + p_149749_1_.spawnEntityInWorld(entityitem); + } + } + } - p_149749_1_.func_147453_f(p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_); - } - } + p_149749_1_.func_147453_f(p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_); + } + } - super.breakBlock(p_149749_1_, p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_, p_149749_6_); - } + super.breakBlock(p_149749_1_, p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_, p_149749_6_); + } @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { - if(world.isRemote) - { + if(world.isRemote) { return true; - } else if(!player.isSneaking()) - { + } else if(!player.isSneaking()) { TileEntityMachinePress entity = (TileEntityMachinePress) world.getTileEntity(x, y, z); - if(entity != null) - { + if(entity != null) { FMLNetworkHandler.openGui(player, MainRegistry.instance, 0, world, x, y, z); } return true; @@ -121,5 +102,4 @@ public class MachinePress extends BlockContainer { return false; } } - } diff --git a/src/main/java/com/hbm/inventory/container/ContainerMachinePress.java b/src/main/java/com/hbm/inventory/container/ContainerMachinePress.java index db5db00ff..b6a0a208c 100644 --- a/src/main/java/com/hbm/inventory/container/ContainerMachinePress.java +++ b/src/main/java/com/hbm/inventory/container/ContainerMachinePress.java @@ -6,7 +6,6 @@ import com.hbm.tileentity.machine.TileEntityMachinePress; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; -import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; @@ -14,18 +13,7 @@ public class ContainerMachinePress extends Container { private TileEntityMachinePress press; - private int power; - private int progress; - private int burnTime; - private int maxBurn; - public ContainerMachinePress(InventoryPlayer invPlayer, TileEntityMachinePress tedf) { - - power = 0; - progress = 0; - burnTime = 0; - maxBurn = 0; - press = tedf; // Coal @@ -80,50 +68,4 @@ public class ContainerMachinePress extends Container { public boolean canInteractWith(EntityPlayer player) { return press.isUseableByPlayer(player); } - - @Override - public void detectAndSendChanges() { - super.detectAndSendChanges(); - - for(int i = 0; i < this.crafters.size(); i++) { - ICrafting par1 = (ICrafting) this.crafters.get(i); - - if(this.power != this.press.power) { - par1.sendProgressBarUpdate(this, 0, this.press.power); - } - - if(this.progress != this.press.progress) { - par1.sendProgressBarUpdate(this, 1, this.press.progress); - } - - if(this.burnTime != this.press.burnTime) { - par1.sendProgressBarUpdate(this, 2, this.press.burnTime); - } - - if(this.maxBurn != this.press.maxBurn) { - par1.sendProgressBarUpdate(this, 3, this.press.maxBurn); - } - } - - this.power = this.press.power; - this.progress = this.press.progress; - this.burnTime = this.press.burnTime; - this.maxBurn = this.press.maxBurn; - } - - @Override - public void updateProgressBar(int i, int j) { - if(i == 0) { - press.power = j; - } - if(i == 1) { - press.progress = j; - } - if(i == 2) { - press.burnTime = j; - } - if(i == 3) { - press.maxBurn = j; - } - } } diff --git a/src/main/java/com/hbm/inventory/gui/GUIMachinePress.java b/src/main/java/com/hbm/inventory/gui/GUIMachinePress.java index efb77f14b..19d1e30fb 100644 --- a/src/main/java/com/hbm/inventory/gui/GUIMachinePress.java +++ b/src/main/java/com/hbm/inventory/gui/GUIMachinePress.java @@ -7,27 +7,34 @@ import com.hbm.lib.RefStrings; import com.hbm.tileentity.machine.TileEntityMachinePress; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.util.ResourceLocation; -public class GUIMachinePress extends GuiContainer { +public class GUIMachinePress extends GuiInfoContainer { private static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/gui_press.png"); - private TileEntityMachinePress assembler; + private TileEntityMachinePress press; public GUIMachinePress(InventoryPlayer invPlayer, TileEntityMachinePress tedf) { super(new ContainerMachinePress(invPlayer, tedf)); - assembler = tedf; + press = tedf; this.xSize = 176; this.ySize = 166; } + + @Override + public void drawScreen(int mouseX, int mouseY, float f) { + super.drawScreen(mouseX, mouseY, f); + + this.drawCustomInfoStat(mouseX, mouseY, guiLeft + 25, guiTop + 16, 18, 18, mouseX, mouseY, (press.speed * 100 / press.maxSpeed) + "%"); + this.drawCustomInfoStat(mouseX, mouseY, guiLeft + 25, guiTop + 34, 18, 18, mouseX, mouseY, (press.burnTime / 200) + " operations left"); + } @Override protected void drawGuiContainerForegroundLayer( int i, int j) { - String name = this.assembler.hasCustomInventoryName() ? this.assembler.getInventoryName() : I18n.format(this.assembler.getInventoryName()); + String name = this.press.hasCustomInventoryName() ? this.press.getInventoryName() : I18n.format(this.press.getInventoryName()); this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6, 4210752); this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 2, 4210752); @@ -39,13 +46,14 @@ public class GUIMachinePress extends GuiContainer { Minecraft.getMinecraft().getTextureManager().bindTexture(texture); drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); - int i = assembler.getPowerScaled(12); + int i = press.speed * 12 / press.maxSpeed; drawTexturedModalRect(guiLeft + 25, guiTop + 16, 176, 14 + 18 * i, 18, 18); - int l = assembler.getBurnScaled(13); - this.drawTexturedModalRect(guiLeft + 27, guiTop + 49 - l, 176, 13 - l, 13, l); + if(press.burnTime >= 20) { + this.drawTexturedModalRect(guiLeft + 27, guiTop + 36, 176, 0, 14, 14); + } - int k = assembler.getProgressScaled(16); - this.drawTexturedModalRect(guiLeft + 79, guiTop + 35, 194, 0, 18, k); + int k = (int) (press.renderPress * 16 / press.maxPress); + this.drawTexturedModalRect(guiLeft + 79, guiTop + 35, 194, 0, 18, k); } } diff --git a/src/main/java/com/hbm/packet/PacketDispatcher.java b/src/main/java/com/hbm/packet/PacketDispatcher.java index f55f1916c..3d94f2d10 100644 --- a/src/main/java/com/hbm/packet/PacketDispatcher.java +++ b/src/main/java/com/hbm/packet/PacketDispatcher.java @@ -15,10 +15,6 @@ public class PacketDispatcher { { int i = 0; - //Packet sent for every connected electricity pole, for wire rendering - //wrapper.registerMessage(TEPylonSenderPacket.Handler.class, TEPylonSenderPacket.class, i++, Side.CLIENT); - //Resets connection list in client-sided pole rendering - //wrapper.registerMessage(TEPylonDestructorPacket.Handler.class, TEPylonDestructorPacket.class, i++, Side.CLIENT); //Machine type for marker rendering wrapper.registerMessage(TEStructurePacket.Handler.class, TEStructurePacket.class, i++, Side.CLIENT); //Mining drill rotation for rendering @@ -35,10 +31,6 @@ public class PacketDispatcher { wrapper.registerMessage(LoopedSoundPacket.Handler.class, LoopedSoundPacket.class, i++, Side.CLIENT); //Signals server to consume items and create template wrapper.registerMessage(ItemFolderPacket.Handler.class, ItemFolderPacket.class, i++, Side.SERVER); - //Turbofan spin for rendering - wrapper.registerMessage(TETurbofanPacket.Handler.class, TETurbofanPacket.class, i++, Side.CLIENT); - //Press item for rendering - wrapper.registerMessage(TEPressPacket.Handler.class, TEPressPacket.class, i++, Side.CLIENT); //Electricity gauge for GUI rendering wrapper.registerMessage(AuxElectricityPacket.Handler.class, AuxElectricityPacket.class, i++, Side.CLIENT); //Universal package for machine gauges and states diff --git a/src/main/java/com/hbm/packet/TEPressPacket.java b/src/main/java/com/hbm/packet/TEPressPacket.java deleted file mode 100644 index 79dc45f2c..000000000 --- a/src/main/java/com/hbm/packet/TEPressPacket.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.hbm.packet; - -import com.hbm.tileentity.machine.TileEntityMachineEPress; -import com.hbm.tileentity.machine.TileEntityMachinePress; -import cpw.mods.fml.common.network.simpleimpl.IMessage; -import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; -import io.netty.buffer.ByteBuf; -import net.minecraft.client.Minecraft; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; - -public class TEPressPacket implements IMessage { - - int x; - int y; - int z; - int item; - int meta; - int progress; - - public TEPressPacket() - { - - } - - public TEPressPacket(int x, int y, int z, ItemStack stack, int progress) - { - this.x = x; - this.y = y; - this.z = z; - this.item = 0; - this.meta = 0; - if(stack != null) { - this.item = Item.getIdFromItem(stack.getItem()); - this.meta = stack.getItemDamage(); - } - this.progress = progress; - } - - @Override - public void fromBytes(ByteBuf buf) { - x = buf.readInt(); - y = buf.readInt(); - z = buf.readInt(); - item = buf.readInt(); - meta = buf.readInt(); - progress = buf.readInt(); - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeInt(x); - buf.writeInt(y); - buf.writeInt(z); - buf.writeInt(item); - buf.writeInt(meta); - buf.writeInt(progress); - } - - public static class Handler implements IMessageHandler { - - @Override - public IMessage onMessage(TEPressPacket m, MessageContext ctx) { - TileEntity te = Minecraft.getMinecraft().theWorld.getTileEntity(m.x, m.y, m.z); - - if (te != null && te instanceof TileEntityMachinePress) { - - TileEntityMachinePress gen = (TileEntityMachinePress) te; - gen.item = m.item; - gen.meta = m.meta; - gen.progress = m.progress; - } - if (te != null && te instanceof TileEntityMachineEPress) { - - TileEntityMachineEPress gen = (TileEntityMachineEPress) te; - gen.item = m.item; - gen.meta = m.meta; - gen.progress = m.progress; - } - return null; - } - } -} diff --git a/src/main/java/com/hbm/packet/TETurbofanPacket.java b/src/main/java/com/hbm/packet/TETurbofanPacket.java deleted file mode 100644 index c40a1b0b7..000000000 --- a/src/main/java/com/hbm/packet/TETurbofanPacket.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.hbm.packet; - -import com.hbm.tileentity.machine.TileEntityMachineTurbofan; - -import cpw.mods.fml.common.network.simpleimpl.IMessage; -import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; -import io.netty.buffer.ByteBuf; -import net.minecraft.client.Minecraft; -import net.minecraft.tileentity.TileEntity; - -public class TETurbofanPacket implements IMessage { - - int x; - int y; - int z; - int spin; - boolean isRunning; - - public TETurbofanPacket() - { - - } - - public TETurbofanPacket(int x, int y, int z, int spin, boolean isRunning) - { - this.x = x; - this.y = y; - this.z = z; - this.spin = spin; - this.isRunning = isRunning; - } - - @Override - public void fromBytes(ByteBuf buf) { - x = buf.readInt(); - y = buf.readInt(); - z = buf.readInt(); - spin = buf.readInt(); - isRunning = buf.readBoolean(); - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeInt(x); - buf.writeInt(y); - buf.writeInt(z); - buf.writeInt(spin); - buf.writeBoolean(isRunning); - } - - public static class Handler implements IMessageHandler { - - @Override - public IMessage onMessage(TETurbofanPacket m, MessageContext ctx) { - TileEntity te = Minecraft.getMinecraft().theWorld.getTileEntity(m.x, m.y, m.z); - - if (te != null && te instanceof TileEntityMachineTurbofan) { - - TileEntityMachineTurbofan gen = (TileEntityMachineTurbofan) te; - gen.spin = m.spin; - gen.wasOn = m.isRunning; - } - return null; - } - } -} diff --git a/src/main/java/com/hbm/render/tileentity/RenderPress.java b/src/main/java/com/hbm/render/tileentity/RenderPress.java index 94358f962..5833f98da 100644 --- a/src/main/java/com/hbm/render/tileentity/RenderPress.java +++ b/src/main/java/com/hbm/render/tileentity/RenderPress.java @@ -10,9 +10,9 @@ import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.entity.item.EntityItem; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MathHelper; public class RenderPress extends TileEntitySpecialRenderer { @@ -34,19 +34,18 @@ public class RenderPress extends TileEntitySpecialRenderer { GL11.glPopMatrix(); - renderTileEntityAt2(tileentity, x, y, z, f); + renderTileEntityAt2(tileentity, x, y, z, f); } - + public void renderTileEntityAt2(TileEntity tileEntity, double x, double y, double z, float f) { GL11.glPushMatrix(); - GL11.glTranslated(x + 0.5D, y + 1 - 0.125D, z + 0.5D); + GL11.glTranslated(x + 0.5D, y, z + 0.5D); GL11.glEnable(GL11.GL_LIGHTING); - GL11.glRotatef(180, 0F, 1F, 0F); - GL11.glScalef(0.95F, 1, 0.95F); + GL11.glScalef(0.99F, 1, 0.99F); TileEntityMachinePress press = (TileEntityMachinePress)tileEntity; - float f1 = press.progress * (1 - 0.125F) / press.maxProgress; - GL11.glTranslated(0, -f1, 0); + double p = (press.lastPress + (press.renderPress - press.lastPress) * f) /(double) press.maxPress; + GL11.glTranslated(0, MathHelper.clamp_double((1D - p), 0D, 1D) * 0.875D, 0); this.bindTexture(ResourceManager.press_head_tex); @@ -54,7 +53,7 @@ public class RenderPress extends TileEntitySpecialRenderer { GL11.glPopMatrix(); - renderTileEntityAt3(tileEntity, x, y, z, f); + renderTileEntityAt3(tileEntity, x, y, z, f); } public void renderTileEntityAt3(TileEntity tileEntity, double x, double y, double z, float f) { @@ -67,16 +66,18 @@ public class RenderPress extends TileEntitySpecialRenderer { GL11.glRotatef(-90, 1F, 0F, 0F); TileEntityMachinePress press = (TileEntityMachinePress)tileEntity; - ItemStack stack = new ItemStack(Item.getItemById(press.item), 1, press.meta); - - EntityItem item = new EntityItem(null, 0.0D, 0.0D, 0.0D, stack); - item.getEntityItem().stackSize = 1; - item.hoverStart = 0.0F; - - RenderItem.renderInFrame = true; - GL11.glTranslatef(0.0F, 1.0F - 0.0625F * 165/100, 0.0F); - this.itemRenderer.doRender(item, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F); - RenderItem.renderInFrame = false; + if(press.syncStack != null) { + ItemStack stack = press.syncStack.copy(); + + EntityItem item = new EntityItem(null, 0.0D, 0.0D, 0.0D, stack); + item.getEntityItem().stackSize = 1; + item.hoverStart = 0.0F; + + RenderItem.renderInFrame = true; + GL11.glTranslatef(0.0F, 1.0F - 0.0625F * 165/100, 0.0F); + this.itemRenderer.doRender(item, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F); + RenderItem.renderInFrame = false; + } GL11.glPopMatrix(); } diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineEPress.java b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineEPress.java index 99879af49..61ea1d563 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineEPress.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineEPress.java @@ -7,7 +7,6 @@ import com.hbm.items.machine.ItemStamp; import com.hbm.lib.Library; import com.hbm.packet.AuxElectricityPacket; import com.hbm.packet.PacketDispatcher; -import com.hbm.packet.TEPressPacket; import com.hbm.tileentity.IGUIProvider; import com.hbm.tileentity.TileEntityLoadedBase; @@ -267,7 +266,6 @@ public class TileEntityMachineEPress extends TileEntityLoadedBase implements ISi } } - PacketDispatcher.wrapper.sendToAllAround(new TEPressPacket(xCoord, yCoord, zCoord, slots[2], progress), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 150)); PacketDispatcher.wrapper.sendToAllAround(new AuxElectricityPacket(xCoord, yCoord, zCoord, power), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50)); } } diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityMachinePress.java b/src/main/java/com/hbm/tileentity/machine/TileEntityMachinePress.java index 43c34db48..354fef320 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityMachinePress.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityMachinePress.java @@ -5,110 +5,183 @@ import com.hbm.inventory.container.ContainerMachinePress; import com.hbm.inventory.gui.GUIMachinePress; import com.hbm.inventory.recipes.PressRecipes; import com.hbm.items.machine.ItemStamp; -import com.hbm.packet.PacketDispatcher; -import com.hbm.packet.TEPressPacket; import com.hbm.tileentity.IGUIProvider; +import com.hbm.tileentity.TileEntityMachineBase; -import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; -import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityFurnace; import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -public class TileEntityMachinePress extends TileEntity implements ISidedInventory, IGUIProvider { +public class TileEntityMachinePress extends TileEntityMachineBase implements IGUIProvider { - private ItemStack slots[]; + public int speed = 0; // speed ticks up once (or four times if preheated) when operating + public static final int maxSpeed = 400; // max speed ticks for acceleration + public static final int progressAtMax = 25; // max progress speed when hot + public int burnTime = 0; // burn ticks of the loaded fuel, 200 ticks equal one operation - public int progress = 0; - public int power = 0; - public int burnTime = 0; - public final static int maxProgress = 200; - public final static int maxPower = 700; - public int maxBurn = 160; - public int item; - public int meta; - boolean isRetracting = false; + public int press; // extension of the press, operation is completed if maxPress is reached + public double renderPress; // client-side version of the press var, a double for smoother rendering + public double lastPress; // for interp + private int syncPress; // for interp + private int turnProgress; // for interp 3: revenge of the sith + public final static int maxPress = 200; // max tick count per operation assuming speed is 1 + boolean isRetracting = false; // direction the press is currently going + private int delay; // delay between direction changes to look a bit more appealing - private String customName; + public ItemStack syncStack; public TileEntityMachinePress() { - slots = new ItemStack[4]; + super(4); } @Override - public int getSizeInventory() { - return slots.length; + public String getName() { + return "container.press"; } - + @Override - public ItemStack getStackInSlot(int i) { - return slots[i]; - } - - @Override - public ItemStack getStackInSlotOnClosing(int i) { - if(slots[i] != null) - { - ItemStack itemStack = slots[i]; - slots[i] = null; - return itemStack; + public void updateEntity() { + + if(!worldObj.isRemote) { + + boolean preheated = false; + + for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { + if(worldObj.getBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ) == ModBlocks.press_preheater) { + preheated = true; + break; + } + } + + boolean canProcess = this.canProcess(); + + if((canProcess || this.isRetracting) && this.burnTime >= 200) { + this.speed += preheated ? 4 : 1; + + if(this.speed > this.maxSpeed) { + this.speed = this.maxSpeed; + } + } else { + this.speed -= 1; + if(this.speed < 0) { + this.speed = 0; + } + } + + if(delay <= 0) { + + int stampSpeed = speed * progressAtMax / maxSpeed; + + if(this.isRetracting) { + this.press -= stampSpeed; + + if(this.press <= 0) { + this.isRetracting = false; + this.delay = 5; + } + } else if(canProcess) { + this.press += stampSpeed; + + if(this.press >= this.maxPress) { + this.worldObj.playSoundEffect(this.xCoord, this.yCoord, this.zCoord, "hbm:block.pressOperate", 1.5F, 1.0F); + ItemStack output = PressRecipes.getOutput(slots[2], slots[1]); + if(slots[3] == null) { + slots[3] = output.copy(); + } else { + slots[3].stackSize += output.stackSize; + } + this.decrStackSize(2, 1); + + if(slots[1].getMaxDamage() != 0) { + slots[1].setItemDamage(slots[1].getItemDamage() + 1); + if(slots[1].getItemDamage() >= slots[1].getMaxDamage()) { + slots[1] = null; + } + } + + this.isRetracting = true; + this.delay = 5; + if(this.burnTime >= 200) { + this.burnTime -= 200; // only subtract fuel if operation was actually successful + } + + this.markDirty(); + } + } else if(this.press > 0){ + this.isRetracting = true; + } + } else { + delay--; + } + + if(slots[0] != null && burnTime < 200 && TileEntityFurnace.getItemBurnTime(slots[0]) > 0) { // less than one operation stored? burn more fuel! + burnTime += TileEntityFurnace.getItemBurnTime(slots[0]); + this.decrStackSize(0, 1); + this.markChanged(); + } + + NBTTagCompound data = new NBTTagCompound(); + data.setInteger("speed", speed); + data.setInteger("burnTime", burnTime); + data.setInteger("press", press); + if(slots[2] != null) { + NBTTagCompound stack = new NBTTagCompound(); + slots[2].writeToNBT(stack); + data.setTag("stack", stack); + } + + this.networkPack(data, 50); + } else { - return null; - } - } - - @Override - public void setInventorySlotContents(int i, ItemStack itemStack) { - slots[i] = itemStack; - if(itemStack != null && itemStack.stackSize > getInventoryStackLimit()) - { - itemStack.stackSize = getInventoryStackLimit(); - } - } - - @Override - public String getInventoryName() { - return this.hasCustomInventoryName() ? this.customName : "container.press"; - } - - @Override - public boolean hasCustomInventoryName() { - return this.customName != null && this.customName.length() > 0; - } - - public void setCustomName(String name) { - this.customName = name; - } - - @Override - public int getInventoryStackLimit() { - return 64; - } - - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - if(worldObj.getTileEntity(xCoord, yCoord, zCoord) != this) - { - return false; - }else{ - return player.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) <=64; + + // approach-based interpolation, GO! + this.lastPress = this.renderPress; + + if(this.turnProgress > 0) { + this.renderPress = this.renderPress + ((this.syncPress - this.renderPress) / (double) this.turnProgress); + --this.turnProgress; + } else { + this.renderPress = this.syncPress; + } } } @Override - public void openInventory() {} - @Override - public void closeInventory() {} + public void networkUnpack(NBTTagCompound nbt) { + this.speed = nbt.getInteger("speed"); + this.burnTime = nbt.getInteger("burnTime"); + this.syncPress = nbt.getInteger("press"); + + if(nbt.hasKey("stack")) { + NBTTagCompound stack = nbt.getCompoundTag("stack"); + this.syncStack = ItemStack.loadItemStackFromNBT(stack); + } else { + this.syncStack = null; + } + + this.turnProgress = 2; + } + + public boolean canProcess() { + if(burnTime < 200) return false; + if(slots[1] == null || slots[2] == null) return false; + + ItemStack output = PressRecipes.getOutput(slots[2], slots[1]); + + if(output == null) return false; + + if(slots[3] == null) return true; + if(slots[3].stackSize + output.stackSize <= slots[3].getMaxStackSize() && slots[3].getItem() == output.getItem() && slots[3].getItemDamage() == output.getItemDamage()) return true; + return false; + } @Override public boolean isItemValidForSlot(int i, ItemStack stack) { @@ -123,80 +196,9 @@ public class TileEntityMachinePress extends TileEntity implements ISidedInventor } @Override - public ItemStack decrStackSize(int i, int j) { - if(slots[i] != null) - { - if(slots[i].stackSize <= j) - { - ItemStack itemStack = slots[i]; - slots[i] = null; - return itemStack; - } - ItemStack itemStack1 = slots[i].splitStack(j); - if (slots[i].stackSize == 0) - { - slots[i] = null; - } - - return itemStack1; - } else { - return null; - } + public int[] getAccessibleSlotsFromSide(int side) { + return side == 0 ? new int[] { 3 } : new int[] { 0, 1, 2 }; } - - @Override - public void readFromNBT(NBTTagCompound nbt) { - super.readFromNBT(nbt); - NBTTagList list = nbt.getTagList("items", 10); - - progress = nbt.getInteger("progress"); - power = nbt.getInteger("power"); - burnTime = nbt.getInteger("burnTime"); - maxBurn = nbt.getInteger("maxBurn"); - isRetracting = nbt.getBoolean("ret"); - - slots = new ItemStack[getSizeInventory()]; - - for(int i = 0; i < list.tagCount(); i++) - { - NBTTagCompound nbt1 = list.getCompoundTagAt(i); - byte b0 = nbt1.getByte("slot"); - if(b0 >= 0 && b0 < slots.length) - { - slots[b0] = ItemStack.loadItemStackFromNBT(nbt1); - } - } - } - - @Override - public void writeToNBT(NBTTagCompound nbt) { - super.writeToNBT(nbt); - NBTTagList list = new NBTTagList(); - - nbt.setInteger("progress", progress); - nbt.setInteger("power", power); - nbt.setInteger("burnTime", burnTime); - nbt.setInteger("maxBurn", maxBurn); - nbt.setBoolean("ret", isRetracting); - - for(int i = 0; i < slots.length; i++) - { - if(slots[i] != null) - { - NBTTagCompound nbt1 = new NBTTagCompound(); - nbt1.setByte("slot", (byte)i); - slots[i].writeToNBT(nbt1); - list.appendTag(nbt1); - } - } - nbt.setTag("items", list); - } - - @Override - public int[] getAccessibleSlotsFromSide(int side) - { - return side == 0 ? new int[] { 3 } : new int[]{ 0, 1, 2 }; - } @Override public boolean canInsertItem(int i, ItemStack itemStack, int j) { @@ -209,128 +211,38 @@ public class TileEntityMachinePress extends TileEntity implements ISidedInventor } @Override - public void updateEntity() { - if(!worldObj.isRemote) { - - boolean preheated = false; - - if(power < maxPower / 3 - 5) { - for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { - if(worldObj.getBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ) == ModBlocks.press_preheater) { - preheated = true; - break; - } - } - } - - if(preheated) - power += 2; - - if(burnTime > 0) { - this.burnTime--; - this.power++; - if(power > maxPower) { - power = maxPower; - } - } else { - if(power > 0) { - power--; - } - } - - if(!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)) { - if(slots[0] != null && this.burnTime == 0 && TileEntityFurnace.getItemBurnTime(slots[0]) > 0) { - this.maxBurn = this.burnTime = TileEntityFurnace.getItemBurnTime(slots[0]) / 8; - slots[0].stackSize--; - if(slots[0].stackSize <= 0) { - - if(slots[0].getItem().getContainerItem() != null) - slots[0] = new ItemStack(slots[0].getItem().getContainerItem()); - else - slots[0] = null; - } - } - - if(power >= maxPower / 3) { - - int speed = power * 25 / maxPower; - - if(slots[1] != null && slots[2] != null) { - ItemStack stack = PressRecipes.getOutput(slots[2], slots[1]); - if(stack != null && - (slots[3] == null || - (slots[3].getItem() == stack.getItem() && - slots[3].stackSize + stack.stackSize <= slots[3].getMaxStackSize()))) { - - if(progress >= maxProgress) { - - isRetracting = true; - - if(slots[3] == null) - slots[3] = stack.copy(); - else - slots[3].stackSize += stack.stackSize; - - slots[2].stackSize--; - if(slots[2].stackSize <= 0) - slots[2] = null; - - if(slots[1].getMaxDamage() != 0) { - slots[1].setItemDamage(slots[1].getItemDamage() + 1); - if(slots[1].getItemDamage() >= slots[1].getMaxDamage()) - slots[1] = null; - } - - this.worldObj.playSoundEffect(this.xCoord, this.yCoord, this.zCoord, "hbm:block.pressOperate", 1.5F, 1.0F); - } - - if(!isRetracting) - progress += speed; - - } else { - isRetracting = true; - } - } else { - isRetracting = true; - } - - if(isRetracting) - progress -= speed; - } else { - isRetracting = true; - } - - if(progress <= 0) { - isRetracting = false; - progress = 0; - } - } - - PacketDispatcher.wrapper.sendToAllAround(new TEPressPacket(xCoord, yCoord, zCoord, slots[2], progress), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 150)); - } + public void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + press = nbt.getInteger("press"); + burnTime = nbt.getInteger("burnTime"); + speed = nbt.getInteger("speed"); + isRetracting = nbt.getBoolean("ret"); } - public int getPowerScaled(int i) { - return (power * i) / maxPower; - } - - public int getProgressScaled(int i) { - return (progress * i) / maxProgress; - } - - public int getBurnScaled(int i) { - return (burnTime * i) / maxBurn; + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + nbt.setInteger("press", press); + nbt.setInteger("burnTime", burnTime); + nbt.setInteger("speed", speed); + nbt.setBoolean("ret", isRetracting); } + AxisAlignedBB aabb; + @Override public AxisAlignedBB getRenderBoundingBox() { - return TileEntity.INFINITE_EXTENT_AABB; + + if(aabb != null) + return aabb; + + aabb = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 3, zCoord + 1); + return aabb; } @Override @SideOnly(Side.CLIENT) - public double getMaxRenderDistanceSquared() - { + public double getMaxRenderDistanceSquared() { return 65536.0D; }