Skip to content

Commit

Permalink
Crafting Station can modify tools if near a Tool Station
Browse files Browse the repository at this point in the history
  • Loading branch information
mDiyo committed Dec 12, 2013
1 parent faedd83 commit 977287e
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 30 deletions.
18 changes: 6 additions & 12 deletions src/main/java/tconstruct/blocks/logic/CraftingStationLogic.java
Expand Up @@ -3,25 +3,23 @@
import java.lang.ref.WeakReference;

import mantle.blocks.abstracts.InventoryLogic;
import mantle.world.CoordTuple;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.world.World;
import tconstruct.inventory.CraftingStationContainer;
import tconstruct.library.crafting.ToolBuilder;
import tconstruct.library.tools.ToolCore;

public class CraftingStationLogic extends InventoryLogic implements ISidedInventory
{
/*public boolean chest;
public boolean doubleChest;
public boolean patternChest;
public boolean nearbyFurnace;*/


public WeakReference<IInventory> chest;
public WeakReference<IInventory> doubleChest;
public WeakReference<IInventory> patternChest;
Expand All @@ -37,7 +35,6 @@ public CraftingStationLogic()
@Override
public Container getGuiContainer (InventoryPlayer inventoryplayer, World world, int x, int y, int z)
{
//System.out.println("Getting container on side: "+FMLCommonHandler.instance().getEffectiveSide());
chest = null;
doubleChest = null;
patternChest = null;
Expand All @@ -47,7 +44,7 @@ public Container getGuiContainer (InventoryPlayer inventoryplayer, World world,
{
for (int xPos = x - 1; xPos <= x + 1; xPos++)
{
for (int zPos = z - 1; zPos <= x + 1; zPos++)
for (int zPos = z - 1; zPos <= z + 1; zPos++)
{
TileEntity tile = world.getBlockTileEntity(xPos, yPos, zPos);
if (chest == null && tile instanceof TileEntityChest)
Expand All @@ -72,9 +69,6 @@ else if (tinkerTable == false && tile instanceof ToolStationLogic)

void checkForChest (World world, int x, int y, int z)
{
if (doubleChest != null)
return;

TileEntity tile = world.getBlockTileEntity(x, y, z);
if (tile instanceof TileEntityChest)
doubleChest = new WeakReference(tile);
Expand All @@ -96,7 +90,7 @@ public boolean canDropInventorySlot (int slot)
@Override
public int[] getAccessibleSlotsFromSide (int var1)
{
return new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
return new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
}

@Override
Expand Down
Expand Up @@ -57,6 +57,7 @@ public Container getGuiContainer (InventoryPlayer inventoryplayer, World world,

public void onInventoryChanged ()
{
System.out.println("Changed");
buildTool(toolName);
if (this.worldObj != null)
{
Expand Down
Expand Up @@ -312,6 +312,7 @@ void drawToolInformation ()
private static final ResourceLocation icons = new ResourceLocation("tinker", "textures/gui/icons.png");
private static final ResourceLocation chest = new ResourceLocation("tinker", "textures/gui/chestside.png");

@Override
protected void drawGuiContainerBackgroundLayer (float par1, int par2, int par3)
{
// Draw the background
Expand Down
33 changes: 32 additions & 1 deletion src/main/java/tconstruct/inventory/CraftingStationContainer.java
Expand Up @@ -11,12 +11,15 @@
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.world.World;
import tconstruct.blocks.logic.CraftingStationLogic;
import tconstruct.library.crafting.ToolBuilder;
import tconstruct.library.tools.ToolCore;

public class CraftingStationContainer extends Container
{
/** The crafting matrix inventory (3x3). */
public InventoryCrafting craftMatrix;// = new InventoryCrafting(this, 3, 3);
public IInventory craftResult;// = new InventoryCraftResult();
private CraftingStationLogic logic;
private World worldObj;
private int posX;
private int posY;
Expand All @@ -28,6 +31,7 @@ public CraftingStationContainer(InventoryPlayer inventorplayer, CraftingStationL
this.posX = x;
this.posY = y;
this.posZ = z;
this.logic = logic;
craftMatrix = new InventoryCraftingStation(this, 3, 3, logic);
craftResult = new InventoryCraftingStationResult(logic);

Expand Down Expand Up @@ -84,7 +88,34 @@ public CraftingStationContainer(InventoryPlayer inventorplayer, CraftingStationL

public void onCraftMatrixChanged (IInventory par1IInventory)
{
this.craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj));
ItemStack tool = modifyTool();
if (tool != null)
this.craftResult.setInventorySlotContents(0, tool);
else
this.craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj));
}



public ItemStack modifyTool ()
{
ItemStack input = craftResult.getStackInSlot(5);
if (input != null)
{
if (input.getItem() instanceof ToolCore)
{
ItemStack[] slots = new ItemStack[8];
for (int i = 0; i < 0; i++)
{
slots[i] = craftResult.getStackInSlot(i + 1);
slots[i + 4] = craftResult.getStackInSlot(i + 6);
}
ItemStack output = ToolBuilder.instance.modifyTool(input, slots, "");
if (output != null)
return output;
}
}
return null;
}

public void onContainerClosed (EntityPlayer par1EntityPlayer)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/tconstruct/items/SpecialFood.java
Expand Up @@ -44,7 +44,7 @@ public ItemStack onEaten (ItemStack stack, World world, EntityPlayer player)
@SideOnly(Side.CLIENT)
public Icon getIconFromDamage (int meta)
{
return icons[meta];
return icons[0];
}

@SideOnly(Side.CLIENT)
Expand Down
43 changes: 27 additions & 16 deletions src/main/java/tconstruct/library/crafting/ToolBuilder.java
Expand Up @@ -144,27 +144,13 @@ else if (headStack.getItem() instanceof ArmorCore)
ToolCore item;
boolean validMaterials = true;
int head = -1, handle = -1, accessory = -1, extra = -1;
/*if (headStack.getItem() instanceof IToolPart)
{
head = ((IToolPart) headStack.getItem()).getMaterialID(headStack);
}
else
validMaterials = false;*/
head = getMaterialID(headStack);
if (head == -1)
validMaterials = false;

handle = getMaterialID(handleStack);
if (handle == -1)
validMaterials = false;
/*if (handleItem == Item.stick)
handle = 0;
else if (handleItem == Item.bone)
handle = 5;
else if (handleItem instanceof IToolPart)
handle = ((IToolPart) handleItem).getMaterialID(handleStack);
else
validMaterials = false;*/

if (!validMaterials)
return null;
Expand Down Expand Up @@ -363,9 +349,34 @@ else if (event.getResult() == Result.ALLOW)
return tool;
}

public ItemStack modifyTool (ItemStack input, ItemStack[] modifiers, String name)
public ItemStack modifyTool (ItemStack input, ItemStack[] slots, String name)
{
return null;
ItemStack tool = input.copy();
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
tags.removeTag("Built");

boolean built = false;
for (ToolMod mod : toolMods)
{
if (mod.matches(slots, tool))
{
built = true;
mod.addMatchingEffect(tool);
mod.modify(slots, tool);
}
}

tags = tool.getTagCompound();
if (name != null && !name.equals("") && !tags.hasKey("display"))
{
tags.setCompoundTag("display", new NBTTagCompound());
tags.getCompoundTag("display").setString("Name", "\u00A7f" + name);
}

if (built)
return tool;
else
return null;
}

public ItemStack modifyArmor (ItemStack input, ItemStack[] slots, String name)
Expand Down

0 comments on commit 977287e

Please sign in to comment.