crafting works, still have to make it so it gets from the network
This commit is contained in:
@@ -2,6 +2,7 @@ package storagecraft.container;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import storagecraft.container.slot.SlotGridCraftingResult;
|
||||
import storagecraft.tile.TileGrid;
|
||||
|
||||
public class ContainerGrid extends ContainerBase
|
||||
@@ -17,7 +18,7 @@ public class ContainerGrid extends ContainerBase
|
||||
|
||||
for (int i = 0; i < 9; ++i)
|
||||
{
|
||||
addSlotToContainer(new Slot(grid.getCraftingInventory(), i, x, y));
|
||||
addSlotToContainer(new Slot(grid.getCraftingMatrix(), i, x, y));
|
||||
|
||||
x += 18;
|
||||
|
||||
@@ -28,7 +29,7 @@ public class ContainerGrid extends ContainerBase
|
||||
}
|
||||
}
|
||||
|
||||
addSlotToContainer(new Slot(grid.getCraftingInventory(), 9, 125, 124));
|
||||
addSlotToContainer(new SlotGridCraftingResult(player, grid.getCraftingMatrix(), grid.getCraftingResult(), 0, 125, 124));
|
||||
}
|
||||
|
||||
addPlayerInventory(8, grid.isCrafting() ? 174 : 108);
|
||||
|
@@ -0,0 +1,28 @@
|
||||
package storagecraft.container;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import storagecraft.tile.TileGrid;
|
||||
|
||||
public class ContainerGridCrafting extends Container
|
||||
{
|
||||
private TileGrid grid;
|
||||
|
||||
public ContainerGridCrafting(TileGrid grid)
|
||||
{
|
||||
this.grid = grid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCraftMatrixChanged(IInventory inventory)
|
||||
{
|
||||
grid.onCraftingMatrixChanged();
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
package storagecraft.container.slot;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.SlotCrafting;
|
||||
|
||||
public class SlotGridCraftingResult extends SlotCrafting
|
||||
{
|
||||
public SlotGridCraftingResult(EntityPlayer player, IInventory craftingMatrix, IInventory craftingResult, int id, int x, int y)
|
||||
{
|
||||
super(player, craftingMatrix, craftingResult, id, x, y);
|
||||
}
|
||||
}
|
@@ -74,6 +74,7 @@ public class MessageStoragePush implements IMessage, IMessageHandler<MessageStor
|
||||
}
|
||||
else
|
||||
{
|
||||
// @TODO: This crashes sometimes on shift??
|
||||
stack = player.inventory.getStackInSlot(message.slot);
|
||||
}
|
||||
|
||||
|
@@ -1,12 +1,16 @@
|
||||
package storagecraft.tile;
|
||||
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import storagecraft.container.ContainerGridCrafting;
|
||||
import storagecraft.inventory.InventorySimple;
|
||||
import storagecraft.util.InventoryUtils;
|
||||
|
||||
public class TileGrid extends TileMachine
|
||||
{
|
||||
private InventorySimple craftingInventory = new InventorySimple("crafting", 10);
|
||||
private InventoryCrafting craftingMatrix = new InventoryCrafting(new ContainerGridCrafting(this), 3, 3);
|
||||
private InventorySimple craftingResult = new InventorySimple("craftingResult", 1);
|
||||
|
||||
@Override
|
||||
public int getEnergyUsage()
|
||||
@@ -29,9 +33,19 @@ public class TileGrid extends TileMachine
|
||||
return getType() == 1;
|
||||
}
|
||||
|
||||
public InventorySimple getCraftingInventory()
|
||||
public InventoryCrafting getCraftingMatrix()
|
||||
{
|
||||
return craftingInventory;
|
||||
return craftingMatrix;
|
||||
}
|
||||
|
||||
public void onCraftingMatrixChanged()
|
||||
{
|
||||
craftingResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(craftingMatrix, worldObj));
|
||||
}
|
||||
|
||||
public InventorySimple getCraftingResult()
|
||||
{
|
||||
return craftingResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -39,7 +53,7 @@ public class TileGrid extends TileMachine
|
||||
{
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
InventoryUtils.restoreInventory(craftingInventory, nbt);
|
||||
InventoryUtils.restoreInventory(craftingMatrix, nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,6 +61,6 @@ public class TileGrid extends TileMachine
|
||||
{
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
InventoryUtils.saveInventory(craftingInventory, nbt);
|
||||
InventoryUtils.saveInventory(craftingMatrix, nbt);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user