From caeeaf397c2041f88e6e66c3ea96d997896a6e68 Mon Sep 17 00:00:00 2001 From: Henry Mao Date: Sun, 10 Feb 2013 23:00:16 +0800 Subject: [PATCH] Added 3 tiers of crates --- .../client/render/BlockRenderingHandler.java | 2 +- .../client/render/RenderCrate.java | 24 +++ .../assemblyline/common/AssemblyLine.java | 18 +- .../assemblyline/common/block/BlockCrate.java | 48 ++++-- .../common/block/ItemBlockCrate.java | 15 +- .../common/block/TileEntityCrate.java | 37 +++- .../machine/crane/BlockCraneController.java | 5 +- .../common/machine/crane/BlockCraneFrame.java | 162 ++++++++++++++++++ 8 files changed, 277 insertions(+), 34 deletions(-) create mode 100644 src/minecraft/assemblyline/common/machine/crane/BlockCraneFrame.java diff --git a/src/minecraft/assemblyline/client/render/BlockRenderingHandler.java b/src/minecraft/assemblyline/client/render/BlockRenderingHandler.java index f3e7ea5e2..c7479b28e 100644 --- a/src/minecraft/assemblyline/client/render/BlockRenderingHandler.java +++ b/src/minecraft/assemblyline/client/render/BlockRenderingHandler.java @@ -84,7 +84,7 @@ public class BlockRenderingHandler implements ISimpleBlockRenderingHandler RenderCraneController.MODEL.render(0.0625f); GL11.glPopMatrix(); } - else if (block.blockID == AssemblyLine.blockCraneRail.blockID) + else if (block.blockID == AssemblyLine.blockCraneFrame.blockID) { GL11.glBindTexture(GL11.GL_TEXTURE_2D, FMLClientHandler.instance().getClient().renderEngine.getTexture(AssemblyLine.TEXTURE_PATH + RenderCraneRail.TEXTURE)); GL11.glPushMatrix(); diff --git a/src/minecraft/assemblyline/client/render/RenderCrate.java b/src/minecraft/assemblyline/client/render/RenderCrate.java index 52054a54b..dac1a71cc 100644 --- a/src/minecraft/assemblyline/client/render/RenderCrate.java +++ b/src/minecraft/assemblyline/client/render/RenderCrate.java @@ -89,6 +89,29 @@ public class RenderCrate extends TileEntitySpecialRenderer GL11.glPopMatrix(); } + switch (tileEntity.getTier()) + { + default: + { + itemName = "\u00a7a" + itemName; + amount = "\u00a7a" + amount; + break; + } + case 1: + { + itemName = "\u00a74" + itemName; + amount = "\u00a74" + amount; + + break; + } + case 2: + { + itemName = "\u00a79" + itemName; + amount = "\u00a79" + amount; + break; + } + } + this.renderText(itemName, side, 0.02f, x, y - 0.35f, z); if (amount != "") @@ -158,6 +181,7 @@ public class RenderCrate extends TileEntitySpecialRenderer // Find Center GL11.glTranslatef(displayWidth / 2, 1F, displayHeight / 2); GL11.glRotatef(-90, 1, 0, 0); + FontRenderer fontRenderer = this.getFontRenderer(); int requiredWidth = Math.max(fontRenderer.getStringWidth(text), 1); diff --git a/src/minecraft/assemblyline/common/AssemblyLine.java b/src/minecraft/assemblyline/common/AssemblyLine.java index 9c78accdc..81090c9ad 100644 --- a/src/minecraft/assemblyline/common/AssemblyLine.java +++ b/src/minecraft/assemblyline/common/AssemblyLine.java @@ -22,7 +22,7 @@ import assemblyline.common.machine.BlockRejector; import assemblyline.common.machine.armbot.BlockArmbot; import assemblyline.common.machine.belt.BlockConveyorBelt; import assemblyline.common.machine.crane.BlockCraneController; -import assemblyline.common.machine.crane.BlockCraneRail; +import assemblyline.common.machine.crane.BlockCraneFrame; import assemblyline.common.machine.detector.BlockDetector; import assemblyline.common.machine.encoder.BlockEncoder; import assemblyline.common.machine.encoder.ItemDisk; @@ -81,7 +81,7 @@ public class AssemblyLine public static Block blockRejector; public static Block blockArmbot; public static Block blockCraneController; - public static Block blockCraneRail; + public static Block blockCraneFrame; public static Block blockTurntable; public static BlockMulti blockMulti; @@ -110,8 +110,8 @@ public class AssemblyLine blockEncoder = new BlockEncoder(CONFIGURATION.getBlock("Encoder", BLOCK_ID_PREFIX + 7).getInt(), 7); blockArmbot = new BlockArmbot(CONFIGURATION.getBlock("Armbot", BLOCK_ID_PREFIX + 8).getInt()); blockMulti = new BlockMulti(CONFIGURATION.getBlock("Multiblock", BLOCK_ID_PREFIX + 9).getInt()); - blockCraneController = new BlockCraneController(CONFIGURATION.getBlock("CraneController", BLOCK_ID_PREFIX + 10).getInt()); - blockCraneRail = new BlockCraneRail(CONFIGURATION.getBlock("CraneParts", BLOCK_ID_PREFIX + 11).getInt()); + blockCraneController = new BlockCraneController(CONFIGURATION.getBlock("Crane Controller", BLOCK_ID_PREFIX + 10).getInt()); + blockCraneFrame = new BlockCraneFrame(CONFIGURATION.getBlock("Crane Frame", BLOCK_ID_PREFIX + 11).getInt()); blockTurntable = new BlockTurntable(CONFIGURATION.getBlock("Turntable", BLOCK_ID_PREFIX + 12).getInt(), 10); itemImprint = new ItemImprinter(CONFIGURATION.getItem("Imprint", ITEM_ID_PREFIX).getInt()); @@ -129,7 +129,7 @@ public class AssemblyLine GameRegistry.registerBlock(blockArmbot, "Armbot"); GameRegistry.registerBlock(blockTurntable, "Turntable"); GameRegistry.registerBlock(blockCraneController, "Crane Controller"); - GameRegistry.registerBlock(blockCraneRail, "Crane Rail"); + GameRegistry.registerBlock(blockCraneFrame, "Crane Frame"); TabAssemblyLine.itemStack = new ItemStack(AssemblyLine.blockConveyorBelt); UpdateNotifier.INSTANCE.checkUpdate(NAME, VERSION, "http://calclavia.com/downloads/al/recommendedversion.txt"); @@ -157,14 +157,16 @@ public class AssemblyLine // Imprint GameRegistry.addRecipe(new ShapedOreRecipe(itemImprint, new Object[] { "R", "P", "I", 'P', Item.paper, 'R', Item.redstone, 'I', new ItemStack(Item.dyePowder, 1, 0) })); - // Imprinter + // Imprinter (VANILLA) GameRegistry.addRecipe(new ShapedOreRecipe(blockImprinter, new Object[] { "SIS", "SPS", "WCW", 'S', Item.ingotIron, 'C', Block.chest, 'W', Block.workbench, 'P', Block.pistonBase, 'I', new ItemStack(Item.dyePowder, 1, 0) })); // Detector GameRegistry.addRecipe(new ShapedOreRecipe(blockDetector, new Object[] { "SES", "SCS", "SPS", 'S', "ingotSteel", 'C', "basicCircuit", 'E', Item.eyeOfEnder })); - // Crate - GameRegistry.addRecipe(new ShapedOreRecipe(blockCrate, new Object[] { "TST", "S S", "TST", 'S', Item.ingotIron, 'T', Block.wood })); + // Crate (VANILLA) + GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockCrate, 1, 0), new Object[] { "TST", "S S", "TST", 'S', Item.ingotIron, 'T', Block.wood })); + GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockCrate, 1, 1), new Object[] { "TST", "SCS", "TST", 'C', new ItemStack(blockCrate, 1, 0), 'S', Item.ingotIron, 'T', Block.wood })); + GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockCrate, 1, 2), new Object[] { "TST", "SCS", "TST", 'C', new ItemStack(blockCrate, 1, 1), 'S', Item.ingotIron, 'T', Block.wood })); // Conveyor Belt GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockConveyorBelt, 10), new Object[] { "III", "WMW", 'I', "ingotSteel", 'W', Block.wood, 'M', "motor" })); diff --git a/src/minecraft/assemblyline/common/block/BlockCrate.java b/src/minecraft/assemblyline/common/block/BlockCrate.java index 83c1a3c49..16885ac43 100644 --- a/src/minecraft/assemblyline/common/block/BlockCrate.java +++ b/src/minecraft/assemblyline/common/block/BlockCrate.java @@ -1,5 +1,8 @@ package assemblyline.common.block; +import java.util.List; + +import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -51,7 +54,7 @@ public class BlockCrate extends BlockMachine if (allMode) { - this.ejectItems(tileEntity, player, TileEntityCrate.MAX_LIMIT); + this.ejectItems(tileEntity, player, tileEntity.getMaxLimit()); } else { @@ -108,7 +111,7 @@ public class BlockCrate extends BlockMachine { if (allMode) { - this.ejectItems(tileEntity, player, TileEntityCrate.MAX_LIMIT); + this.ejectItems(tileEntity, player, tileEntity.getMaxLimit()); } else { @@ -222,23 +225,27 @@ public class BlockCrate extends BlockMachine { if (containingStack.stackSize > 0) { - int amountToTake = Math.min(containingStack.stackSize, maxStack); - ItemStack dropStack = containingStack.copy(); - dropStack.stackSize = amountToTake; - - if (!world.isRemote) + while (maxStack > 0) { - EntityItem entityItem = new EntityItem(world, player.posX, player.posY, player.posZ, dropStack); + int amountToTake = Math.min(containingStack.stackSize, Math.min(maxStack, 64)); + ItemStack dropStack = containingStack.copy(); + dropStack.stackSize = amountToTake; - float var13 = 0.05F; - entityItem.motionX = ((float) world.rand.nextGaussian() * var13); - entityItem.motionY = ((float) world.rand.nextGaussian() * var13 + 0.2F); - entityItem.motionZ = ((float) world.rand.nextGaussian() * var13); - entityItem.delayBeforeCanPickup = 0; - world.spawnEntityInWorld(entityItem); + if (!world.isRemote) + { + EntityItem entityItem = new EntityItem(world, player.posX, player.posY, player.posZ, dropStack); + + float var13 = 0.05F; + entityItem.motionX = ((float) world.rand.nextGaussian() * var13); + entityItem.motionY = ((float) world.rand.nextGaussian() * var13 + 0.2F); + entityItem.motionZ = ((float) world.rand.nextGaussian() * var13); + entityItem.delayBeforeCanPickup = 0; + world.spawnEntityInWorld(entityItem); + } + + containingStack.stackSize -= amountToTake; + maxStack -= amountToTake; } - - containingStack.stackSize -= amountToTake; } if (containingStack.stackSize <= 0) @@ -335,4 +342,13 @@ public class BlockCrate extends BlockMachine return new TileEntityCrate(); } + @Override + public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List list) + { + for (int i = 0; i < 3; i++) + { + list.add(new ItemStack(this, 1, i)); + } + } + } diff --git a/src/minecraft/assemblyline/common/block/ItemBlockCrate.java b/src/minecraft/assemblyline/common/block/ItemBlockCrate.java index 6b367816c..8a7180ac6 100644 --- a/src/minecraft/assemblyline/common/block/ItemBlockCrate.java +++ b/src/minecraft/assemblyline/common/block/ItemBlockCrate.java @@ -16,10 +16,15 @@ public class ItemBlockCrate extends ItemBlock public ItemBlockCrate(int par1) { super(par1); - this.setMaxDamage(0); this.setMaxStackSize(1); } + @Override + public String getItemNameIS(ItemStack itemStack) + { + return this.getItemName() + "." + itemStack.getItemDamage(); + } + @Override public void addInformation(ItemStack itemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) { @@ -46,7 +51,7 @@ public class ItemBlockCrate extends ItemBlock if (containingStack != null) { - player.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 5, (int) ((float) containingStack.stackSize / (float) TileEntityCrate.MAX_LIMIT) * 5)); + player.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 5, (int) ((float) containingStack.stackSize / (float) TileEntityCrate.getMaxLimit(itemStack.getItemDamage())) * 5)); } } } @@ -93,6 +98,12 @@ public class ItemBlockCrate extends ItemBlock return containingStack; } + @Override + public int getMetadata(int par1) + { + return par1; + } + @Override public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata) { diff --git a/src/minecraft/assemblyline/common/block/TileEntityCrate.java b/src/minecraft/assemblyline/common/block/TileEntityCrate.java index 4d21a3a8e..5f8c1b086 100644 --- a/src/minecraft/assemblyline/common/block/TileEntityCrate.java +++ b/src/minecraft/assemblyline/common/block/TileEntityCrate.java @@ -8,6 +8,7 @@ import net.minecraft.nbt.NBTTagList; import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.Packet250CustomPayload; +import universalelectricity.prefab.implement.ITier; import universalelectricity.prefab.network.IPacketReceiver; import universalelectricity.prefab.network.PacketManager; import universalelectricity.prefab.tile.TileEntityAdvanced; @@ -18,12 +19,30 @@ import com.google.common.io.ByteArrayDataInput; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.Side; -public class TileEntityCrate extends TileEntityAdvanced implements IInventory, IPacketReceiver +public class TileEntityCrate extends TileEntityAdvanced implements ITier, IInventory, IPacketReceiver { - public static final int MAX_LIMIT = 2048; private ItemStack[] containingItems = new ItemStack[1]; public long prevClickTime = -1000; + public int getMaxLimit() + { + return getMaxLimit(this.getTier()); + } + + public static int getMaxLimit(int tier) + { + if (tier >= 2) + { + return 16384; + } + else if (tier >= 1) + { + return 4096; + } + + return 2048; + } + @Override public boolean canUpdate() { @@ -233,7 +252,7 @@ public class TileEntityCrate extends TileEntityAdvanced implements IInventory, I @Override public int getInventoryStackLimit() { - return MAX_LIMIT; + return this.getMaxLimit(); } @Override @@ -247,4 +266,16 @@ public class TileEntityCrate extends TileEntityAdvanced implements IInventory, I { return "Crate"; } + + @Override + public int getTier() + { + return this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord); + } + + @Override + public void setTier(int tier) + { + this.worldObj.setBlockMetadata(this.xCoord, this.yCoord, this.zCoord, tier); + } } diff --git a/src/minecraft/assemblyline/common/machine/crane/BlockCraneController.java b/src/minecraft/assemblyline/common/machine/crane/BlockCraneController.java index e4bc7e3c3..91a7e4b41 100644 --- a/src/minecraft/assemblyline/common/machine/crane/BlockCraneController.java +++ b/src/minecraft/assemblyline/common/machine/crane/BlockCraneController.java @@ -13,12 +13,9 @@ import cpw.mods.fml.relauncher.SideOnly; public class BlockCraneController extends BlockMachine { - public BlockCraneController(int id) { - super("cranecontroller", id, UniversalElectricity.machine); - this.setResistance(5.0f); - this.setHardness(5.0f); + super("craneController", id, UniversalElectricity.machine); this.setCreativeTab(TabAssemblyLine.INSTANCE); } diff --git a/src/minecraft/assemblyline/common/machine/crane/BlockCraneFrame.java b/src/minecraft/assemblyline/common/machine/crane/BlockCraneFrame.java new file mode 100644 index 000000000..3c7bae86b --- /dev/null +++ b/src/minecraft/assemblyline/common/machine/crane/BlockCraneFrame.java @@ -0,0 +1,162 @@ +package assemblyline.common.machine.crane; + +import net.minecraft.block.material.Material; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.ForgeDirection; +import universalelectricity.core.UniversalElectricity; +import universalelectricity.prefab.BlockMachine; +import assemblyline.client.render.BlockRenderingHandler; +import assemblyline.common.TabAssemblyLine; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class BlockCraneFrame extends BlockMachine +{ + public BlockCraneFrame(int id) + { + super("craneFrame", id, UniversalElectricity.machine); + this.setCreativeTab(TabAssemblyLine.INSTANCE); + this.setBlockBounds(0.25f, 0.25f, 0.25f, 0.75f, 0.75f, 0.75f); + } + + @Override + @SideOnly(Side.CLIENT) + public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) + { + return super.getSelectedBoundingBoxFromPool(world, x, y, z); + } + + @Override + public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) + { + TileEntity tE = world.getBlockTileEntity(x, y, z); + if (tE != null && tE instanceof TileEntityCraneRail) + { + AxisAlignedBB middle = AxisAlignedBB.getBoundingBox(0.25f, 0.25f, 0.25f, 0.75f, 0.75f, 0.75f); + AxisAlignedBB up = AxisAlignedBB.getBoundingBox(0.25f, 0.75f, 0.25f, 0.75f, 1.0f, 0.75f); + AxisAlignedBB down = AxisAlignedBB.getBoundingBox(0.25f, 0.0f, 0.25f, 0.75f, 0.25f, 0.75f); + AxisAlignedBB left = AxisAlignedBB.getBoundingBox(0.0f, 0.25f, 0.25f, 0.25f, 0.75f, 0.75f); + AxisAlignedBB right = AxisAlignedBB.getBoundingBox(0.75f, 0.25f, 0.25f, 1.0f, 0.75f, 0.75f); + AxisAlignedBB front = AxisAlignedBB.getBoundingBox(0.25f, 0.25f, 0.0f, 0.75f, 0.75f, 0.25f); + AxisAlignedBB back = AxisAlignedBB.getBoundingBox(0.25f, 0.25f, 0.75f, 0.75f, 0.75f, 1.0f); + boolean connectUp = CraneHelper.canFrameConnectTo(tE, x, y + 1, z, ForgeDirection.DOWN); + boolean connectDown = CraneHelper.canFrameConnectTo(tE, x, y - 1, z, ForgeDirection.UP); + // EAST, X- + boolean connectLeft = CraneHelper.canFrameConnectTo(tE, x - 1, y, z, ForgeDirection.EAST); + // WAST, X+ + boolean connectRight = CraneHelper.canFrameConnectTo(tE, x + 1, y, z, ForgeDirection.WEST); + // SOUTH, Z- + boolean connectFront = CraneHelper.canFrameConnectTo(tE, x, y, z - 1, ForgeDirection.SOUTH); + // NORTH, Z+ + boolean connectBack = CraneHelper.canFrameConnectTo(tE, x, y, z + 1, ForgeDirection.NORTH); + if (connectUp) + { + middle.maxY = up.maxY; + } + if (connectDown) + { + middle.minY = down.minY; + } + if (connectLeft) + { + middle.minX = left.minX; + } + if (connectRight) + { + middle.maxX = right.maxX; + } + if (connectFront) + { + middle.minZ = front.minZ; + } + if (connectBack) + { + middle.maxZ = back.maxZ; + } + setBlockBounds((float) middle.minX, (float) middle.minY, (float) middle.minZ, (float) middle.maxX, (float) middle.maxY, (float) middle.maxZ); + middle.offset(x, y, z); + return middle; + } + return super.getCollisionBoundingBoxFromPool(world, x, y, z); + } + + @Override + public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) + { + TileEntity tE = world.getBlockTileEntity(x, y, z); + if (tE != null && tE instanceof TileEntityCraneRail) + { + AxisAlignedBB middle = AxisAlignedBB.getBoundingBox(0.25f, 0.25f, 0.25f, 0.75f, 0.75f, 0.75f); + AxisAlignedBB up = AxisAlignedBB.getBoundingBox(0.25f, 0.75f, 0.25f, 0.75f, 1.0f, 0.75f); + AxisAlignedBB down = AxisAlignedBB.getBoundingBox(0.25f, 0.0f, 0.25f, 0.75f, 0.25f, 0.75f); + AxisAlignedBB left = AxisAlignedBB.getBoundingBox(0.0f, 0.25f, 0.25f, 0.25f, 0.75f, 0.75f); + AxisAlignedBB right = AxisAlignedBB.getBoundingBox(0.75f, 0.25f, 0.25f, 1.0f, 0.75f, 0.75f); + AxisAlignedBB front = AxisAlignedBB.getBoundingBox(0.25f, 0.25f, 0.0f, 0.75f, 0.75f, 0.25f); + AxisAlignedBB back = AxisAlignedBB.getBoundingBox(0.25f, 0.25f, 0.75f, 0.75f, 0.75f, 1.0f); + boolean connectUp = CraneHelper.canFrameConnectTo(tE, x, y + 1, z, ForgeDirection.DOWN); + boolean connectDown = CraneHelper.canFrameConnectTo(tE, x, y - 1, z, ForgeDirection.UP); + // EAST, X- + boolean connectLeft = CraneHelper.canFrameConnectTo(tE, x - 1, y, z, ForgeDirection.EAST); + // WAST, X+ + boolean connectRight = CraneHelper.canFrameConnectTo(tE, x + 1, y, z, ForgeDirection.WEST); + // SOUTH, Z- + boolean connectFront = CraneHelper.canFrameConnectTo(tE, x, y, z - 1, ForgeDirection.SOUTH); + // NORTH, Z+ + boolean connectBack = CraneHelper.canFrameConnectTo(tE, x, y, z + 1, ForgeDirection.NORTH); + if (connectUp) + { + middle.maxY = up.maxY; + } + if (connectDown) + { + middle.minY = down.minY; + } + if (connectLeft) + { + middle.minX = left.minX; + } + if (connectRight) + { + middle.maxX = right.maxX; + } + if (connectFront) + { + middle.minZ = front.minZ; + } + if (connectBack) + { + middle.maxZ = back.maxZ; + } + setBlockBounds((float) middle.minX, (float) middle.minY, (float) middle.minZ, (float) middle.maxX, (float) middle.maxY, (float) middle.maxZ); + return; + } + setBlockBounds(0.25f, 0.25f, 0.25f, 0.75f, 0.75f, 0.75f); + } + + @Override + public TileEntity createNewTileEntity(World world, int metadata) + { + return new TileEntityCraneRail(); + } + + @Override + public boolean renderAsNormalBlock() + { + return false; + } + + @Override + public boolean isOpaqueCube() + { + return false; + } + + @Override + public int getRenderType() + { + return BlockRenderingHandler.BLOCK_RENDER_ID; + } +}