2013-07-26 21:18:53 -07:00
|
|
|
package tconstruct.blocks.logic;
|
|
|
|
|
|
|
|
|
|
import tconstruct.inventory.PartCrafterChestContainer;
|
|
|
|
|
import tconstruct.inventory.PartCrafterContainer;
|
2013-12-01 12:19:43 +00:00
|
|
|
import mantle.blocks.abstracts.InventoryLogic;
|
2013-07-26 21:18:53 -07:00
|
|
|
import tconstruct.library.crafting.PatternBuilder;
|
|
|
|
|
import tconstruct.library.util.IPattern;
|
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
|
|
|
import net.minecraft.inventory.Container;
|
|
|
|
|
import net.minecraft.inventory.ISidedInventory;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
2013-08-16 13:51:33 -07:00
|
|
|
public class PartBuilderLogic extends InventoryLogic implements ISidedInventory
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
boolean craftedTop;
|
|
|
|
|
boolean craftedBottom;
|
|
|
|
|
|
2013-08-16 13:51:33 -07:00
|
|
|
public PartBuilderLogic()
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
super(10);
|
|
|
|
|
craftedTop = false;
|
|
|
|
|
craftedBottom = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getDefaultName ()
|
|
|
|
|
{
|
|
|
|
|
return "toolstation.parts";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Container getGuiContainer (InventoryPlayer inventoryplayer, World world, int x, int y, int z)
|
|
|
|
|
{
|
|
|
|
|
for (int xPos = x - 1; xPos <= x + 1; xPos++)
|
|
|
|
|
{
|
|
|
|
|
for (int zPos = z - 1; zPos <= z + 1; zPos++)
|
|
|
|
|
{
|
2014-01-08 23:46:45 -05:00
|
|
|
TileEntity tile = world.func_147438_o(xPos, y, zPos);
|
2013-07-26 21:18:53 -07:00
|
|
|
if (tile != null && tile instanceof PatternChestLogic)
|
|
|
|
|
return new PartCrafterChestContainer(inventoryplayer, this, (PatternChestLogic) tile);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return new PartCrafterContainer(inventoryplayer, this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Called when emptying a slot, not when another item is placed in it
|
|
|
|
|
public ItemStack decrStackSize (int slotID, int quantity)
|
|
|
|
|
{
|
|
|
|
|
ItemStack returnStack = super.decrStackSize(slotID, quantity);
|
|
|
|
|
tryBuildPart(slotID);
|
|
|
|
|
return returnStack;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void tryBuildPart (int slotID)
|
|
|
|
|
{
|
|
|
|
|
if (slotID == 4 || slotID == 5)
|
|
|
|
|
{
|
|
|
|
|
if (!craftedTop && inventory[0] != null)
|
|
|
|
|
{
|
|
|
|
|
int value = PatternBuilder.instance.getPartValue(inventory[2]);
|
|
|
|
|
IPattern item = (IPattern) inventory[0].getItem();
|
|
|
|
|
int cost = item != null ? item.getPatternCost(inventory[0]) : 0;
|
|
|
|
|
if (value > 0 && cost > 0)
|
|
|
|
|
{
|
|
|
|
|
int decrease = cost / value;
|
|
|
|
|
if (cost % value != 0)
|
|
|
|
|
decrease++;
|
|
|
|
|
super.decrStackSize(2, decrease); //Call super to avoid crafting again
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (inventory[4] != null || inventory[5] != null)
|
|
|
|
|
craftedTop = true;
|
|
|
|
|
else
|
|
|
|
|
craftedTop = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!craftedTop)
|
|
|
|
|
buildTopPart();
|
|
|
|
|
|
|
|
|
|
if (slotID == 6 || slotID == 7)
|
|
|
|
|
{
|
|
|
|
|
if (!craftedBottom && inventory[1] != null)
|
|
|
|
|
{
|
|
|
|
|
int value = PatternBuilder.instance.getPartValue(inventory[3]);
|
|
|
|
|
IPattern item = (IPattern) inventory[1].getItem();
|
|
|
|
|
int cost = item != null ? item.getPatternCost(inventory[1]) : 0;
|
|
|
|
|
if (value > 0 && cost > 0)
|
|
|
|
|
{
|
|
|
|
|
int decrease = cost / value;
|
|
|
|
|
if (cost % value != 0)
|
|
|
|
|
decrease++;
|
|
|
|
|
super.decrStackSize(3, decrease); //Call super to avoid crafting again
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (inventory[6] != null || inventory[7] != null)
|
|
|
|
|
craftedBottom = true;
|
|
|
|
|
else
|
|
|
|
|
craftedBottom = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!craftedBottom)
|
|
|
|
|
buildBottomPart();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Called when a slot has something placed into it.
|
|
|
|
|
public void setInventorySlotContents (int slot, ItemStack itemstack)
|
|
|
|
|
{
|
|
|
|
|
super.setInventorySlotContents(slot, itemstack);
|
|
|
|
|
if ((slot == 0 || slot == 2) && !craftedTop)
|
|
|
|
|
buildTopPart();
|
|
|
|
|
if ((slot == 1 || slot == 3) && !craftedBottom)
|
|
|
|
|
buildBottomPart();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void buildTopPart ()
|
|
|
|
|
{
|
|
|
|
|
ItemStack[] parts = PatternBuilder.instance.getToolPart(inventory[2], inventory[0], inventory[1]);
|
|
|
|
|
if (parts != null)
|
|
|
|
|
{
|
|
|
|
|
inventory[4] = parts[0];
|
|
|
|
|
inventory[5] = parts[1];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
inventory[4] = inventory[5] = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void buildBottomPart ()
|
|
|
|
|
{
|
|
|
|
|
ItemStack[] parts = PatternBuilder.instance.getToolPart(inventory[3], inventory[1], inventory[0]);
|
|
|
|
|
if (parts != null)
|
|
|
|
|
{
|
|
|
|
|
inventory[6] = parts[0];
|
|
|
|
|
inventory[7] = parts[1];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
inventory[6] = inventory[7] = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* NBT */
|
2014-01-18 02:52:49 -05:00
|
|
|
public void func_145839_a (NBTTagCompound tags)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-01-18 02:52:49 -05:00
|
|
|
super.func_145839_a(tags);
|
2013-07-26 21:18:53 -07:00
|
|
|
craftedTop = tags.getBoolean("CraftedTop");
|
|
|
|
|
craftedBottom = tags.getBoolean("CraftedBottom");
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-18 02:52:49 -05:00
|
|
|
public void func_145841_b (NBTTagCompound tags)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-01-18 02:52:49 -05:00
|
|
|
super.func_145841_b(tags);
|
2013-07-26 21:18:53 -07:00
|
|
|
tags.setBoolean("CraftedTop", craftedTop);
|
|
|
|
|
tags.setBoolean("CraftedBottom", craftedBottom);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int[] getAccessibleSlotsFromSide (int side)
|
|
|
|
|
{
|
|
|
|
|
return new int[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean canInsertItem (int i, ItemStack itemstack, int j)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean canExtractItem (int i, ItemStack itemstack, int j)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-01-18 02:52:49 -05:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String func_145825_b ()
|
|
|
|
|
{
|
|
|
|
|
return getDefaultName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean func_145818_k_ ()
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|