make crafting grid work
This commit is contained in:
@@ -1,15 +1,20 @@
|
||||
package storagecraft.tile;
|
||||
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import storagecraft.StorageCraft;
|
||||
import storagecraft.container.ContainerGridCrafting;
|
||||
import storagecraft.inventory.InventorySimple;
|
||||
import storagecraft.network.MessageGridCraftingUpdate;
|
||||
import storagecraft.storage.StorageItem;
|
||||
import storagecraft.util.InventoryUtils;
|
||||
|
||||
public class TileGrid extends TileMachine
|
||||
{
|
||||
private InventoryCrafting craftingMatrix = new InventoryCrafting(new ContainerGridCrafting(this), 3, 3);
|
||||
private ContainerGridCrafting craftingMatrixContainer = new ContainerGridCrafting(this);
|
||||
private InventoryCrafting craftingMatrix = new InventoryCrafting(craftingMatrixContainer, 3, 3);
|
||||
private InventorySimple craftingResult = new InventorySimple("craftingResult", 1);
|
||||
|
||||
@Override
|
||||
@@ -43,6 +48,35 @@ public class TileGrid extends TileMachine
|
||||
craftingResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(craftingMatrix, worldObj));
|
||||
}
|
||||
|
||||
public void onCrafted(ItemStack[] matrixSlots)
|
||||
{
|
||||
if (isConnected() && !worldObj.isRemote)
|
||||
{
|
||||
for (int i = 0; i < craftingMatrix.getSizeInventory(); ++i)
|
||||
{
|
||||
ItemStack slot = craftingMatrix.getStackInSlot(i);
|
||||
|
||||
if (slot == null && matrixSlots[i] != null)
|
||||
{
|
||||
for (StorageItem item : getController().getItems())
|
||||
{
|
||||
if (item.compareNoQuantity(matrixSlots[i].copy()))
|
||||
{
|
||||
craftingMatrix.setInventorySlotContents(i, getController().take(matrixSlots[i].copy()));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onCraftingMatrixChanged();
|
||||
|
||||
// @TODO: HACK!
|
||||
StorageCraft.NETWORK.sendToAll(new MessageGridCraftingUpdate(this));
|
||||
}
|
||||
}
|
||||
|
||||
public InventorySimple getCraftingResult()
|
||||
{
|
||||
return craftingResult;
|
||||
|
Reference in New Issue
Block a user