From 455307b193d16934761f55568746b2f25790f007 Mon Sep 17 00:00:00 2001 From: pahimar Date: Tue, 12 Feb 2013 21:47:17 -0500 Subject: [PATCH] Some more work on the calcinator --- .../pahimar/ee3/block/BlockCalcinator.java | 26 ++++++++++++++++++- .../ee3/inventory/ContainerCalcinator.java | 3 +-- .../pahimar/ee3/inventory/SlotCalcinator.java | 18 +++++++++++++ .../ee3/item/crafting/CalcinationManager.java | 12 +++++++++ .../crafting}/TransmutationManager.java | 2 +- 5 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 ee3_common/com/pahimar/ee3/inventory/SlotCalcinator.java create mode 100644 ee3_common/com/pahimar/ee3/item/crafting/CalcinationManager.java rename ee3_common/com/pahimar/ee3/{transmutation => item/crafting}/TransmutationManager.java (94%) diff --git a/ee3_common/com/pahimar/ee3/block/BlockCalcinator.java b/ee3_common/com/pahimar/ee3/block/BlockCalcinator.java index c2a1ea94..92948e40 100644 --- a/ee3_common/com/pahimar/ee3/block/BlockCalcinator.java +++ b/ee3_common/com/pahimar/ee3/block/BlockCalcinator.java @@ -1,10 +1,14 @@ package com.pahimar.ee3.block; +import java.util.Random; + 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.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; @@ -25,6 +29,11 @@ import com.pahimar.ee3.tileentity.TileCalcinator; */ public class BlockCalcinator extends BlockEE { + /** + * Is the random generator used by calcinator to drop the inventory contents in random directions. + */ + private Random rand = new Random(); + public BlockCalcinator(int id) { super(id, Material.rock); @@ -66,6 +75,7 @@ public class BlockCalcinator extends BlockEE { @Override public void breakBlock(World world, int x, int y, int z, int id, int meta) { + dropInventory(world, x, y, z); super.breakBlock(world, x, y, z, id, meta); } @@ -84,7 +94,6 @@ public class BlockCalcinator extends BlockEE { } private void dropInventory(World world, int x, int y, int z) { - TileEntity tileEntity = world.getBlockTileEntity(x, y, z); if (!(tileEntity instanceof IInventory)) { @@ -99,7 +108,22 @@ public class BlockCalcinator extends BlockEE { ItemStack itemStack = inventory.getStackInSlot(i); if ((itemStack != null) && (itemStack.stackSize > 0)) { + float dX = this.rand.nextFloat() * 0.8F + 0.1F; + float dY = this.rand.nextFloat() * 0.8F + 0.1F; + float dZ = this.rand.nextFloat() * 0.8F + 0.1F; + EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(itemStack.itemID, itemStack.stackSize, itemStack.getItemDamage())); + + if (itemStack.hasTagCompound()) { + entityItem.getEntityItem().setTagCompound((NBTTagCompound)itemStack.getTagCompound().copy()); + } + + float factor = 0.05F; + entityItem.motionX = (this.rand.nextGaussian() * factor); + entityItem.motionY = (this.rand.nextGaussian() * factor + 0.2F); + entityItem.motionZ = (this.rand.nextGaussian() * factor); + world.spawnEntityInWorld(entityItem); + itemStack.stackSize = 0; } } } diff --git a/ee3_common/com/pahimar/ee3/inventory/ContainerCalcinator.java b/ee3_common/com/pahimar/ee3/inventory/ContainerCalcinator.java index 1e1f9bae..1b5dd5e2 100644 --- a/ee3_common/com/pahimar/ee3/inventory/ContainerCalcinator.java +++ b/ee3_common/com/pahimar/ee3/inventory/ContainerCalcinator.java @@ -35,7 +35,7 @@ public class ContainerCalcinator extends Container { this.addSlotToContainer(new Slot(calcinator, 1, 56, 62)); // Add the calcined results slot to the container - // TODO Add a slot here + this.addSlotToContainer(new SlotCalcinator(calcinator, 2, 116, 35)); // Add the player's inventory slots to the container for (int inventoryRowIndex = 0; inventoryRowIndex < 3; ++inventoryRowIndex) { @@ -52,7 +52,6 @@ public class ContainerCalcinator extends Container { public boolean canInteractWith(EntityPlayer player) { - //return calcinator.isUseableByPlayer(player); return true; } diff --git a/ee3_common/com/pahimar/ee3/inventory/SlotCalcinator.java b/ee3_common/com/pahimar/ee3/inventory/SlotCalcinator.java new file mode 100644 index 00000000..326a3980 --- /dev/null +++ b/ee3_common/com/pahimar/ee3/inventory/SlotCalcinator.java @@ -0,0 +1,18 @@ +package com.pahimar.ee3.inventory; + +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +public class SlotCalcinator extends Slot { + + public SlotCalcinator(IInventory inventory, int x, int y, int z) { + + super(inventory, x, y, z); + } + + public boolean isItemValid(ItemStack par1ItemStack) { + return false; + } + +} diff --git a/ee3_common/com/pahimar/ee3/item/crafting/CalcinationManager.java b/ee3_common/com/pahimar/ee3/item/crafting/CalcinationManager.java new file mode 100644 index 00000000..b1ddcb35 --- /dev/null +++ b/ee3_common/com/pahimar/ee3/item/crafting/CalcinationManager.java @@ -0,0 +1,12 @@ +package com.pahimar.ee3.item.crafting; + + +public class CalcinationManager { + + private static final CalcinationManager calcinationBase = new CalcinationManager(); + + public static final CalcinationManager calcination() { + + return calcinationBase; + } +} diff --git a/ee3_common/com/pahimar/ee3/transmutation/TransmutationManager.java b/ee3_common/com/pahimar/ee3/item/crafting/TransmutationManager.java similarity index 94% rename from ee3_common/com/pahimar/ee3/transmutation/TransmutationManager.java rename to ee3_common/com/pahimar/ee3/item/crafting/TransmutationManager.java index 944c775c..e0e91ec6 100644 --- a/ee3_common/com/pahimar/ee3/transmutation/TransmutationManager.java +++ b/ee3_common/com/pahimar/ee3/item/crafting/TransmutationManager.java @@ -1,4 +1,4 @@ -package com.pahimar.ee3.transmutation; +package com.pahimar.ee3.item.crafting; import java.util.ArrayList; import java.util.List;