From d3ebaac06d18472fc69713f0db0b15f62525e46a Mon Sep 17 00:00:00 2001 From: Calclavia Date: Tue, 13 Jan 2015 12:27:14 +0800 Subject: [PATCH] More fixes on block drops --- .../engineering/TileEngineeringTable.scala | 241 +++++++++--------- .../archaic/process/mixing/TileGlassJar.scala | 40 ++- 2 files changed, 145 insertions(+), 136 deletions(-) diff --git a/src/main/scala/resonantinduction/archaic/engineering/TileEngineeringTable.scala b/src/main/scala/resonantinduction/archaic/engineering/TileEngineeringTable.scala index f2ad2ae4b..accdd4291 100644 --- a/src/main/scala/resonantinduction/archaic/engineering/TileEngineeringTable.scala +++ b/src/main/scala/resonantinduction/archaic/engineering/TileEngineeringTable.scala @@ -128,6 +128,124 @@ class TileEngineeringTable extends TileInventory(Material.wood) with IPacketRece } } + override def setInventorySlotContents(slot: Int, itemStack: ItemStack) + { + if (slot < TileEngineeringTable.CRAFTING_MATRIX_END) + { + craftingMatrix(slot) = itemStack + } + else if (slot < TileEngineeringTable.CRAFTING_OUTPUT_END) + { + outputInventory(slot - TileEngineeringTable.CRAFTING_MATRIX_END) = itemStack + } + else if (slot < TileEngineeringTable.PLAYER_OUTPUT_END && this.invPlayer != null) + { + this.invPlayer.setInventorySlotContents(slot - TileEngineeringTable.CRAFTING_OUTPUT_END, itemStack) + val player: EntityPlayer = this.invPlayer.player + if (player.isInstanceOf[EntityPlayerMP]) + { + (player.asInstanceOf[EntityPlayerMP]).sendContainerToPlayer(player.inventoryContainer) + } + } + else if (searchInventories) + { + var idDisplacement: Int = TileEngineeringTable.PLAYER_OUTPUT_END + for (dir <- ForgeDirection.VALID_DIRECTIONS) + { + val tile: TileEntity = toVectorWorld.add(dir).getTileEntity + if (tile.isInstanceOf[IInventory]) + { + val inventory: IInventory = tile.asInstanceOf[IInventory] + val slotID: Int = slot - idDisplacement + if (slotID >= 0 && slotID < inventory.getSizeInventory) + { + inventory.setInventorySlotContents(slotID, itemStack) + } + idDisplacement += inventory.getSizeInventory + } + } + } + onInventoryChanged + } + + /** + * Updates all the output slots. Call this to update the Engineering Table. + */ + override def onInventoryChanged + { + if (worldObj != null) + { + if (!worldObj.isRemote) + { + this.outputInventory(TileEngineeringTable.CRAFTING_OUTPUT_SLOT) = null + var didCraft: Boolean = false + val inventoryCrafting: InventoryCrafting = this.getCraftingMatrix + val matrixOutput: ItemStack = CraftingManager.getInstance.findMatchingRecipe(inventoryCrafting, this.worldObj) + if (matrixOutput != null && this.getCraftingManager.getIdealRecipe(matrixOutput) != null) + { + this.outputInventory(TileEngineeringTable.CRAFTING_OUTPUT_SLOT) = matrixOutput + didCraft = true + } + if (!didCraft) + { + val filterStack: ItemStack = craftingMatrix(TileEngineeringTable.CENTER_SLOT) + if (filterStack != null && filterStack.getItem.isInstanceOf[ItemImprint]) + { + val filters: java.util.List[ItemStack] = ItemImprint.getFilters(filterStack) + for (o <- filters) + { + val outputStack: ItemStack = o + if (outputStack != null) + { + val idealRecipe: Pair[ItemStack, Array[ItemStack]] = this.getCraftingManager.getIdealRecipe(outputStack) + if (idealRecipe != null) + { + val recipeOutput: ItemStack = idealRecipe.left + if (recipeOutput != null & recipeOutput.stackSize > 0) + { + this.outputInventory(TileEngineeringTable.CRAFTING_OUTPUT_SLOT) = recipeOutput + didCraft = true + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord) + return + } + } + } + } + } + } + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord) + } + } + } + + /** + * Gets the AutoCraftingManager that does all the crafting results + */ + def getCraftingManager: AutoCraftingManager = + { + if (craftManager == null) + { + craftManager = new AutoCraftingManager(this) + } + return craftManager + } + + /** + * Construct an InventoryCrafting Matrix on the fly. + * + * @return + */ + def getCraftingMatrix: InventoryCrafting = + { + val inventoryCrafting: InventoryCrafting = new InventoryCrafting(new ContainerDummy(this), 3, 3) + + for (i <- 0 until this.craftingMatrix.length) + { + inventoryCrafting.setInventorySlotContents(i, this.craftingMatrix(i)) + } + return inventoryCrafting + } + override def use(player: EntityPlayer, hitSide: Int, hit: Vector3): Boolean = { if (player.getCurrentEquippedItem != null && player.getCurrentEquippedItem.getItem.isInstanceOf[ItemHammer]) @@ -287,10 +405,7 @@ class TileEngineeringTable extends TileInventory(Material.wood) with IPacketRece return super.configure(player, side, hit) } - override def getDrops(metadata: Int, fortune: Int): ArrayList[ItemStack] = - { - return new ArrayList[ItemStack] - } + override def getDrops(metadata: Int, fortune: Int): ArrayList[ItemStack] = new ArrayList[ItemStack] override def onRemove(block: Block, par6: Int) { @@ -440,124 +555,6 @@ class TileEngineeringTable extends TileInventory(Material.wood) with IPacketRece } } - override def setInventorySlotContents(slot: Int, itemStack: ItemStack) - { - if (slot < TileEngineeringTable.CRAFTING_MATRIX_END) - { - craftingMatrix(slot) = itemStack - } - else if (slot < TileEngineeringTable.CRAFTING_OUTPUT_END) - { - outputInventory(slot - TileEngineeringTable.CRAFTING_MATRIX_END) = itemStack - } - else if (slot < TileEngineeringTable.PLAYER_OUTPUT_END && this.invPlayer != null) - { - this.invPlayer.setInventorySlotContents(slot - TileEngineeringTable.CRAFTING_OUTPUT_END, itemStack) - val player: EntityPlayer = this.invPlayer.player - if (player.isInstanceOf[EntityPlayerMP]) - { - (player.asInstanceOf[EntityPlayerMP]).sendContainerToPlayer(player.inventoryContainer) - } - } - else if (searchInventories) - { - var idDisplacement: Int = TileEngineeringTable.PLAYER_OUTPUT_END - for (dir <- ForgeDirection.VALID_DIRECTIONS) - { - val tile: TileEntity = toVectorWorld.add(dir).getTileEntity - if (tile.isInstanceOf[IInventory]) - { - val inventory: IInventory = tile.asInstanceOf[IInventory] - val slotID: Int = slot - idDisplacement - if (slotID >= 0 && slotID < inventory.getSizeInventory) - { - inventory.setInventorySlotContents(slotID, itemStack) - } - idDisplacement += inventory.getSizeInventory - } - } - } - onInventoryChanged - } - - /** - * Updates all the output slots. Call this to update the Engineering Table. - */ - override def onInventoryChanged - { - if (worldObj != null) - { - if (!worldObj.isRemote) - { - this.outputInventory(TileEngineeringTable.CRAFTING_OUTPUT_SLOT) = null - var didCraft: Boolean = false - val inventoryCrafting: InventoryCrafting = this.getCraftingMatrix - val matrixOutput: ItemStack = CraftingManager.getInstance.findMatchingRecipe(inventoryCrafting, this.worldObj) - if (matrixOutput != null && this.getCraftingManager.getIdealRecipe(matrixOutput) != null) - { - this.outputInventory(TileEngineeringTable.CRAFTING_OUTPUT_SLOT) = matrixOutput - didCraft = true - } - if (!didCraft) - { - val filterStack: ItemStack = craftingMatrix(TileEngineeringTable.CENTER_SLOT) - if (filterStack != null && filterStack.getItem.isInstanceOf[ItemImprint]) - { - val filters: java.util.List[ItemStack] = ItemImprint.getFilters(filterStack) - for (o <- filters) - { - val outputStack: ItemStack = o - if (outputStack != null) - { - val idealRecipe: Pair[ItemStack, Array[ItemStack]] = this.getCraftingManager.getIdealRecipe(outputStack) - if (idealRecipe != null) - { - val recipeOutput: ItemStack = idealRecipe.left - if (recipeOutput != null & recipeOutput.stackSize > 0) - { - this.outputInventory(TileEngineeringTable.CRAFTING_OUTPUT_SLOT) = recipeOutput - didCraft = true - worldObj.markBlockForUpdate(xCoord, yCoord, zCoord) - return - } - } - } - } - } - } - worldObj.markBlockForUpdate(xCoord, yCoord, zCoord) - } - } - } - - /** - * Gets the AutoCraftingManager that does all the crafting results - */ - def getCraftingManager: AutoCraftingManager = - { - if (craftManager == null) - { - craftManager = new AutoCraftingManager(this) - } - return craftManager - } - - /** - * Construct an InventoryCrafting Matrix on the fly. - * - * @return - */ - def getCraftingMatrix: InventoryCrafting = - { - val inventoryCrafting: InventoryCrafting = new InventoryCrafting(new ContainerDummy(this), 3, 3) - - for (i <- 0 until this.craftingMatrix.length) - { - inventoryCrafting.setInventorySlotContents(i, this.craftingMatrix(i)) - } - return inventoryCrafting - } - /** * When some containers are closed they call this on each slot, then drop whatever it returns as * an EntityItem - like when you close a workbench GUI. diff --git a/src/main/scala/resonantinduction/archaic/process/mixing/TileGlassJar.scala b/src/main/scala/resonantinduction/archaic/process/mixing/TileGlassJar.scala index 20f9260ae..4b584c465 100644 --- a/src/main/scala/resonantinduction/archaic/process/mixing/TileGlassJar.scala +++ b/src/main/scala/resonantinduction/archaic/process/mixing/TileGlassJar.scala @@ -1,9 +1,11 @@ package resonantinduction.archaic.process.mixing import java.awt.Color +import java.util.ArrayList import cpw.mods.fml.relauncher.{Side, SideOnly} import io.netty.buffer.ByteBuf +import net.minecraft.block.Block import net.minecraft.block.material.Material import net.minecraft.entity.player.EntityPlayer import net.minecraft.item.ItemStack @@ -14,11 +16,13 @@ import org.lwjgl.opengl.GL11 import resonant.lib.factory.resources.item.TItemResource import resonant.lib.network.discriminator.PacketType import resonant.lib.network.handle.{TPacketReceiver, TPacketSender} +import resonant.lib.prefab.tile.item.ItemBlockSaved import resonant.lib.prefab.tile.spatial.SpatialTile import resonant.lib.render.RenderUtility import resonant.lib.render.model.ModelCube import resonant.lib.transform.region.Cuboid import resonant.lib.transform.vector.Vector3 +import resonant.lib.utility.inventory.InventoryUtility import resonant.lib.wrapper.ByteBufWrapper._ import resonantinduction.core.Reference import resonantinduction.core.resource.Alloy @@ -75,6 +79,14 @@ class TileGlassJar extends SpatialTile(Material.wood) with TPacketReceiver with alloy.load(nbt) } + override def getDrops(metadata: Int, fortune: Int): ArrayList[ItemStack] = new ArrayList[ItemStack] + + override def onRemove(block: Block, par6: Int) + { + val stack: ItemStack = ItemBlockSaved.getItemStackWithNBT(block, world, xi, yi, zi) + InventoryUtility.dropItemStack(world, center, stack) + } + @SideOnly(Side.CLIENT) override def renderInventory(itemStack: ItemStack): Unit = { @@ -88,6 +100,20 @@ class TileGlassJar extends SpatialTile(Material.wood) with TPacketReceiver with GL11.glPopMatrix() } + @SideOnly(Side.CLIENT) + override def renderDynamic(pos: Vector3, frame: Float, pass: Int) + { + GL11.glPushMatrix() + GL11.glTranslated(pos.x + 0.5, pos.y + 0.5, pos.z + 0.5) + renderMixture() + GL11.glPopMatrix() + + GL11.glPushMatrix() + GL11.glTranslated(pos.x + 0.5, pos.y + 0.8, pos.z + 0.5) + renderJar() + GL11.glPopMatrix() + } + def renderMixture(itemStack: ItemStack = null) { val alloy: Alloy = @@ -122,20 +148,6 @@ class TileGlassJar extends SpatialTile(Material.wood) with TPacketReceiver with RenderUtility.disableBlending() } - @SideOnly(Side.CLIENT) - override def renderDynamic(pos: Vector3, frame: Float, pass: Int) - { - GL11.glPushMatrix() - GL11.glTranslated(pos.x + 0.5, pos.y + 0.5, pos.z + 0.5) - renderMixture() - GL11.glPopMatrix() - - GL11.glPushMatrix() - GL11.glTranslated(pos.x + 0.5, pos.y + 0.8, pos.z + 0.5) - renderJar() - GL11.glPopMatrix() - } - override protected def use(player: EntityPlayer, side: Int, hit: Vector3): Boolean = { if (player.getCurrentEquippedItem != null)