From 4cce5df0f6bb276c8d335c8f176fd8114d45e97d Mon Sep 17 00:00:00 2001 From: Henry Mao Date: Sun, 3 Feb 2013 14:20:53 +0800 Subject: [PATCH] More Armbot + Imprinter Tweaks --- src/minecraft/assemblyline/api/IArmbot.java | 2 + .../machine/armbot/TileEntityArmbot.java | 27 ++++--- .../machine/command/CommandRotateBy.java | 2 +- .../machine/command/CommandRotateTo.java | 2 +- .../imprinter/TileEntityImprinter.java | 74 ++++++++++--------- 5 files changed, 60 insertions(+), 47 deletions(-) diff --git a/src/minecraft/assemblyline/api/IArmbot.java b/src/minecraft/assemblyline/api/IArmbot.java index 72fbaf0ed..bd84dd8e9 100644 --- a/src/minecraft/assemblyline/api/IArmbot.java +++ b/src/minecraft/assemblyline/api/IArmbot.java @@ -17,6 +17,8 @@ public interface IArmbot */ public void grabEntity(Entity entity); + public void grabItem(ItemStack itemStack); + /** * Drops a specific entity from the Armbot's hand. */ diff --git a/src/minecraft/assemblyline/common/machine/armbot/TileEntityArmbot.java b/src/minecraft/assemblyline/common/machine/armbot/TileEntityArmbot.java index d6fc653fd..a3934c0cb 100644 --- a/src/minecraft/assemblyline/common/machine/armbot/TileEntityArmbot.java +++ b/src/minecraft/assemblyline/common/machine/armbot/TileEntityArmbot.java @@ -129,21 +129,22 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult if (block != null) { - if (Block.isNormalCube(block.blockID)) + if (Block.isNormalCube(block.blockID) && block.getBlockHardness(this.worldObj, handPosition.intX(), handPosition.intY(), handPosition.intZ()) != -1) { TileEntity tileEntity = this.getHandPosition().getTileEntity(this.worldObj); + if (tileEntity == null) { - block.dropBlockAsItem(this.worldObj, this.xCoord, this.yCoord, this.zCoord, handPosition.getBlockMetadata(this.worldObj), 0); + if (!this.worldObj.isRemote) + { + block.dropBlockAsItem(this.worldObj, handPosition.intX(), handPosition.intY(), handPosition.intZ(), handPosition.getBlockMetadata(this.worldObj), 0); + } + handPosition.setBlockWithNotify(this.worldObj, 0); } - else + else if (!(tileEntity instanceof IArmbotUseable)) { - if (!(tileEntity instanceof IArmbotUseable)) - { - block.dropBlockAsItem(this.worldObj, this.xCoord, this.yCoord, this.zCoord, handPosition.getBlockMetadata(this.worldObj), 0); - handPosition.setBlockWithNotify(this.worldObj, 0); - } + handPosition.setBlockWithNotify(this.worldObj, 0); } } } @@ -232,7 +233,7 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult if (this.ticks % 5 == 0 && FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) { // sound is 0.25 seconds long (20 ticks/second) - this.worldObj.playSound(this.xCoord, this.yCoord, this.zCoord, "assemblyline.conveyor", 2f, 1.7f, true); + this.worldObj.playSound(this.xCoord, this.yCoord, this.zCoord, "assemblyline.conveyor", 0.8f, 1.7f, true); } if (Math.abs(this.renderYaw - this.rotationYaw) < this.ROTATION_SPEED + 0.1f) @@ -915,7 +916,7 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult { if (entity instanceof EntityItem) { - this.grabbedItems.add(((EntityItem) entity).getEntityItem()); + this.grabItem(((EntityItem) entity).getEntityItem()); entity.setDead(); } else @@ -924,6 +925,12 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult } } + @Override + public void grabItem(ItemStack itemStack) + { + this.grabbedItems.add(itemStack); + } + @Override public void dropEntity(Entity entity) { diff --git a/src/minecraft/assemblyline/common/machine/command/CommandRotateBy.java b/src/minecraft/assemblyline/common/machine/command/CommandRotateBy.java index 3aad1ebc2..128c2f9c9 100644 --- a/src/minecraft/assemblyline/common/machine/command/CommandRotateBy.java +++ b/src/minecraft/assemblyline/common/machine/command/CommandRotateBy.java @@ -73,7 +73,7 @@ public class CommandRotateBy extends Command if (Math.abs(this.tileEntity.rotationPitch - this.targetRotationPitch) > 0.001f) this.tileEntity.rotationPitch = this.targetRotationPitch; - if (this.ticks < this.totalTicks) { return true; } + //if (this.ticks < this.totalTicks) { return true; } if (Math.abs(this.tileEntity.renderPitch - this.tileEntity.rotationPitch) > 0.001f) { return true; } if (Math.abs(this.tileEntity.renderYaw - this.tileEntity.rotationYaw) > 0.001f) { return true; } diff --git a/src/minecraft/assemblyline/common/machine/command/CommandRotateTo.java b/src/minecraft/assemblyline/common/machine/command/CommandRotateTo.java index cdb475cb0..c94207bfc 100644 --- a/src/minecraft/assemblyline/common/machine/command/CommandRotateTo.java +++ b/src/minecraft/assemblyline/common/machine/command/CommandRotateTo.java @@ -72,7 +72,7 @@ public class CommandRotateTo extends Command this.tileEntity.rotationYaw = this.targetRotationYaw; this.tileEntity.rotationPitch = this.targetRotationPitch; - if (this.ticks < this.totalTicks) { return true; } + //if (this.ticks < this.totalTicks) { return true; } if (Math.abs(this.tileEntity.renderPitch - this.tileEntity.rotationPitch) > 0.001f) { return true; } if (Math.abs(this.tileEntity.renderYaw - this.tileEntity.rotationYaw) > 0.001f) { return true; } diff --git a/src/minecraft/assemblyline/common/machine/imprinter/TileEntityImprinter.java b/src/minecraft/assemblyline/common/machine/imprinter/TileEntityImprinter.java index e006c36a5..e4276858c 100644 --- a/src/minecraft/assemblyline/common/machine/imprinter/TileEntityImprinter.java +++ b/src/minecraft/assemblyline/common/machine/imprinter/TileEntityImprinter.java @@ -382,46 +382,54 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv } else { - /** - * Fail to, hence consume from crafting grid. - */ - InventoryCrafting inventoryCrafting = this.getCraftingMatrix(); - GameRegistry.onItemCrafted(entityPlayer, itemStack, inventoryCrafting); - - for (int var3 = 0; var3 < inventoryCrafting.getSizeInventory(); ++var3) + try { - ItemStack var4 = inventoryCrafting.getStackInSlot(var3); + /** + * Fail to, hence consume from crafting grid. + */ + InventoryCrafting inventoryCrafting = this.getCraftingMatrix(); + GameRegistry.onItemCrafted(entityPlayer, itemStack, inventoryCrafting); - if (var4 != null) + for (int var3 = 0; var3 < inventoryCrafting.getSizeInventory(); ++var3) { - inventoryCrafting.decrStackSize(var3, 1); + ItemStack var4 = inventoryCrafting.getStackInSlot(var3); - if (var4.getItem().hasContainerItem()) + if (var4 != null) { - ItemStack var5 = var4.getItem().getContainerItemStack(var4); + inventoryCrafting.decrStackSize(var3, 1); - if (var5.isItemStackDamageable() && var5.getItemDamage() > var5.getMaxDamage()) + if (var4.getItem().hasContainerItem()) { - MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(entityPlayer, var5)); - var5 = null; - } + ItemStack var5 = var4.getItem().getContainerItemStack(var4); - if (var5 != null && (!var4.getItem().doesContainerItemLeaveCraftingGrid(var4) || !entityPlayer.inventory.addItemStackToInventory(var5))) - { - if (inventoryCrafting.getStackInSlot(var3) == null) + if (var5.isItemStackDamageable() && var5.getItemDamage() > var5.getMaxDamage()) { - inventoryCrafting.setInventorySlotContents(var3, var5); + MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(entityPlayer, var5)); + var5 = null; } - else + + if (var5 != null && (!var4.getItem().doesContainerItemLeaveCraftingGrid(var4) || !entityPlayer.inventory.addItemStackToInventory(var5))) { - entityPlayer.dropPlayerItem(var5); + if (inventoryCrafting.getStackInSlot(var3) == null) + { + inventoryCrafting.setInventorySlotContents(var3, var5); + } + else + { + entityPlayer.dropPlayerItem(var5); + } } } } } - } - this.replaceCraftingMatrix(inventoryCrafting); + this.replaceCraftingMatrix(inventoryCrafting); + } + catch (Exception e) + { + System.out.println("Imprinter: Failed to craft"); + e.printStackTrace(); + } } } } @@ -614,26 +622,22 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv } /** - * Armbot - * - * @param tileEntity - * @param heldEntity - * @return + * Tries to let the Armbot craft an item. */ @Override public boolean onUse(IArmbot armbot, String[] args) { this.onInventoryChanged(); - TileEntityArmbot armbotTile = (TileEntityArmbot) armbot; - if (this.imprinterMatrix[3] != null) + if (this.imprinterMatrix[2] != null) { - armbot.grabEntity(new EntityItem(this.worldObj, this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, this.imprinterMatrix[3])); - this.imprinterMatrix[3] = null; + armbot.grabItem(this.imprinterMatrix[2].copy()); + this.onPickUpFromResult(null, this.imprinterMatrix[2]); + this.imprinterMatrix[2] = null; } - /* - * if (armbotTile.getGrabbedEntities().size() > 0) { Entity heldEntity = + /** + * OLD CODE if (armbotTile.getGrabbedEntities().size() > 0) { Entity heldEntity = * armbot.getGrabbedEntities().get(0); * * if (heldEntity != null) { if (heldEntity instanceof EntityItem) { ItemStack stack =