Resolved #235 - Engineering table now drops with NBT

This commit is contained in:
Calclavia 2014-02-27 15:56:39 +08:00
parent fd9a87bf9b
commit 7720a9a753
5 changed files with 41 additions and 17 deletions

View file

@ -33,6 +33,7 @@ import calclavia.lib.content.ContentRegistry;
import calclavia.lib.network.PacketAnnotation; import calclavia.lib.network.PacketAnnotation;
import calclavia.lib.network.PacketHandler; import calclavia.lib.network.PacketHandler;
import calclavia.lib.prefab.item.ItemBlockMetadata; import calclavia.lib.prefab.item.ItemBlockMetadata;
import calclavia.lib.prefab.item.ItemBlockSaved;
import calclavia.lib.recipe.UniversalRecipe; import calclavia.lib.recipe.UniversalRecipe;
import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.EventHandler;
@ -90,7 +91,7 @@ public class Archaic
{ {
Settings.load(); Settings.load();
NetworkRegistry.instance().registerGuiHandler(this, proxy); NetworkRegistry.instance().registerGuiHandler(this, proxy);
blockEngineeringTable = contentRegistry.createTile(BlockEngineeringTable.class, TileEngineeringTable.class); blockEngineeringTable = contentRegistry.createBlock(BlockEngineeringTable.class, ItemBlockSaved.class, TileEngineeringTable.class);
blockCrate = contentRegistry.createBlock(BlockCrate.class, ItemBlockCrate.class, TileCrate.class); blockCrate = contentRegistry.createBlock(BlockCrate.class, ItemBlockCrate.class, TileCrate.class);
blockImprinter = contentRegistry.createTile(BlockImprinter.class, TileImprinter.class); blockImprinter = contentRegistry.createTile(BlockImprinter.class, TileImprinter.class);
blockTurntable = contentRegistry.createBlock(BlockTurntable.class); blockTurntable = contentRegistry.createBlock(BlockTurntable.class);

View file

@ -15,6 +15,7 @@ import net.minecraft.world.World;
import universalelectricity.api.vector.Vector2; import universalelectricity.api.vector.Vector2;
import universalelectricity.api.vector.Vector3; import universalelectricity.api.vector.Vector3;
import calclavia.lib.prefab.block.BlockRotatable; import calclavia.lib.prefab.block.BlockRotatable;
import calclavia.lib.prefab.item.ItemBlockSaved;
import calclavia.lib.utility.WorldUtility; import calclavia.lib.utility.WorldUtility;
import calclavia.lib.utility.inventory.InventoryUtility; import calclavia.lib.utility.inventory.InventoryUtility;
import codechicken.multipart.ControlKeyModifer; import codechicken.multipart.ControlKeyModifer;
@ -44,14 +45,19 @@ public class BlockEngineeringTable extends BlockRotatable
@Override @Override
public void onBlockClicked(World world, int x, int y, int z, EntityPlayer player) public void onBlockClicked(World world, int x, int y, int z, EntityPlayer player)
{ {
if (!world.isRemote) if (!world.isRemote && isControlDown(player))
{ {
dropEntireInventory(world, x, y, z, 0, 0); dropInventory(world, x, y, z, 0, 0);
} }
} }
@Override @Override
public void dropEntireInventory(World world, int x, int y, int z, int par5, int par6) public void dropEntireInventory(World world, int x, int y, int z, int par5, int par6)
{
}
public void dropInventory(World world, int x, int y, int z, int par5, int par6)
{ {
TileEntity tileEntity = world.getBlockTileEntity(x, y, z); TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
@ -102,6 +108,8 @@ public class BlockEngineeringTable extends BlockRotatable
} }
} }
} }
inventory.setInventorySlotContents(i, null);
} }
inventory.onInventoryChanged(); inventory.onInventoryChanged();
@ -257,4 +265,17 @@ public class BlockEngineeringTable extends BlockRotatable
return false; return false;
} }
@Override
public void breakBlock(World world, int x, int y, int z, int par5, int par6)
{
ItemBlockSaved.dropBlockWithNBT(this, world, x, y, z);
super.breakBlock(world, x, y, z, par5, par6);
}
/** To cancel the vanilla method of dropping the itemEntity */
@Override
protected void dropBlockAsItem_do(World world, int x, int y, int z, ItemStack stack)
{
}
} }

View file

@ -51,12 +51,14 @@ public class TileEngineeringTable extends TileAdvanced implements IPacketReceive
public static final int[] craftingSlots = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; public static final int[] craftingSlots = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
/** The output inventory containing slots. */ /** The output inventory containing slots. */
public ItemStack[] inventory = new ItemStack[1]; public ItemStack[] outputInventory = new ItemStack[1];
public static int[] inventorySlots;
/** The ability for the engineering table to serach nearby inventories. */ /** The ability for the engineering table to search nearby inventories. */
public boolean searchInventories = true; public boolean searchInventories = true;
/**
* Temporary player inventory stored to draw the player's items.
*/
private InventoryPlayer invPlayer = null; private InventoryPlayer invPlayer = null;
private int[] playerSlots; private int[] playerSlots;
@ -168,7 +170,7 @@ public class TileEngineeringTable extends TileAdvanced implements IPacketReceive
} }
else if (slot < CRAFTING_OUTPUT_END) else if (slot < CRAFTING_OUTPUT_END)
{ {
return inventory[slot - CRAFTING_MATRIX_END]; return outputInventory[slot - CRAFTING_MATRIX_END];
} }
else if (slot < PLAYER_OUTPUT_END && invPlayer != null) else if (slot < PLAYER_OUTPUT_END && invPlayer != null)
{ {
@ -211,9 +213,9 @@ public class TileEngineeringTable extends TileAdvanced implements IPacketReceive
* An external inventory is attempting to craft the item from the engineering table. * An external inventory is attempting to craft the item from the engineering table.
*/ */
if (itemStack == null) if (itemStack == null)
onPickUpFromSlot(null, slot, this.inventory[slot - CRAFTING_MATRIX_END]); onPickUpFromSlot(null, slot, this.outputInventory[slot - CRAFTING_MATRIX_END]);
this.inventory[slot - CRAFTING_MATRIX_END] = itemStack; this.outputInventory[slot - CRAFTING_MATRIX_END] = itemStack;
} }
else if (slot < PLAYER_OUTPUT_END && this.invPlayer != null) else if (slot < PLAYER_OUTPUT_END && this.invPlayer != null)
{ {
@ -311,7 +313,7 @@ public class TileEngineeringTable extends TileAdvanced implements IPacketReceive
{ {
if (!worldObj.isRemote) if (!worldObj.isRemote)
{ {
this.inventory[CRAFTING_OUTPUT_SLOT] = null; this.outputInventory[CRAFTING_OUTPUT_SLOT] = null;
/** Try to craft from crafting grid. If not possible, then craft from imprint. */ /** Try to craft from crafting grid. If not possible, then craft from imprint. */
boolean didCraft = false; boolean didCraft = false;
@ -323,7 +325,7 @@ public class TileEngineeringTable extends TileAdvanced implements IPacketReceive
if (matrixOutput != null && this.getCraftingManager().getIdealRecipe(matrixOutput) != null) if (matrixOutput != null && this.getCraftingManager().getIdealRecipe(matrixOutput) != null)
{ {
this.inventory[CRAFTING_OUTPUT_SLOT] = matrixOutput; this.outputInventory[CRAFTING_OUTPUT_SLOT] = matrixOutput;
didCraft = true; didCraft = true;
} }
@ -349,7 +351,7 @@ public class TileEngineeringTable extends TileAdvanced implements IPacketReceive
ItemStack recipeOutput = idealRecipe.left(); ItemStack recipeOutput = idealRecipe.left();
if (recipeOutput != null & recipeOutput.stackSize > 0) if (recipeOutput != null & recipeOutput.stackSize > 0)
{ {
this.inventory[CRAFTING_OUTPUT_SLOT] = recipeOutput; this.outputInventory[CRAFTING_OUTPUT_SLOT] = recipeOutput;
didCraft = true; didCraft = true;
break; break;
} }
@ -396,7 +398,7 @@ public class TileEngineeringTable extends TileAdvanced implements IPacketReceive
NBTTagList nbtList = nbt.getTagList("Items"); NBTTagList nbtList = nbt.getTagList("Items");
this.craftingMatrix = new ItemStack[9]; this.craftingMatrix = new ItemStack[9];
this.inventory = new ItemStack[1]; this.outputInventory = new ItemStack[1];
for (int i = 0; i < nbtList.tagCount(); ++i) for (int i = 0; i < nbtList.tagCount(); ++i)
{ {

View file

@ -18,7 +18,7 @@ public class RenderHotPlate extends RenderItemOverlayTile
if (tileEntity instanceof TileHotPlate) if (tileEntity instanceof TileHotPlate)
{ {
TileHotPlate tile = (TileHotPlate) tileEntity; TileHotPlate tile = (TileHotPlate) tileEntity;
renderTopOverlay(tileEntity, tile.getInventory().getContainedItems(), ForgeDirection.EAST, 2, 2, x, y - 0.8, z); renderTopOverlay(tileEntity, tile.getInventory().getContainedItems(), ForgeDirection.EAST, 2, 2, x, y - 0.8, z, 0.8f);
} }
} }
} }

View file

@ -41,10 +41,10 @@ public abstract class RenderItemOverlayTile extends TileEntitySpecialRenderer
public void renderTopOverlay(TileEntity tileEntity, ItemStack[] inventory, ForgeDirection dir, double x, double y, double z) public void renderTopOverlay(TileEntity tileEntity, ItemStack[] inventory, ForgeDirection dir, double x, double y, double z)
{ {
renderTopOverlay(tileEntity, inventory, dir, 3, 3, x, y, z); renderTopOverlay(tileEntity, inventory, dir, 3, 3, x, y, z, 0.7f);
} }
public static void renderTopOverlay(TileEntity tileEntity, ItemStack[] inventory, ForgeDirection dir, int matrixX, int matrixZ, double x, double y, double z) public static void renderTopOverlay(TileEntity tileEntity, ItemStack[] inventory, ForgeDirection dir, int matrixX, int matrixZ, double x, double y, double z, float scale)
{ {
GL11.glPushMatrix(); GL11.glPushMatrix();
@ -69,7 +69,7 @@ public abstract class RenderItemOverlayTile extends TileEntitySpecialRenderer
GL11.glTranslated(x + 0.5f, y + 0.5f, z + 0.5f); GL11.glTranslated(x + 0.5f, y + 0.5f, z + 0.5f);
RenderUtility.rotateBlockBasedOnDirection(dir); RenderUtility.rotateBlockBasedOnDirection(dir);
GL11.glTranslated(translation.x, translation.y, translation.z); GL11.glTranslated(translation.x, translation.y, translation.z);
GL11.glScalef(0.7f, 0.7f, 0.7f); GL11.glScalef(scale,scale,scale);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240); OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240);
renderItem(tileEntity.worldObj, ForgeDirection.UP, inventory[i], new Vector3(0, 0, 0), 0, 4); renderItem(tileEntity.worldObj, ForgeDirection.UP, inventory[i], new Vector3(0, 0, 0), 0, 4);
GL11.glPopMatrix(); GL11.glPopMatrix();