make crafting grid work

This commit is contained in:
Raoul Van den Berge
2015-12-22 16:01:52 +01:00
parent f502595758
commit 1dfe250ddc
9 changed files with 170 additions and 20 deletions

View File

@@ -1,5 +1,7 @@
package storagecraft.container;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
@@ -10,6 +12,8 @@ public abstract class ContainerBase extends Container
{
private EntityPlayer player;
private List<Slot> playerInventorySlots = new ArrayList<Slot>();
public ContainerBase(EntityPlayer player)
{
this.player = player;
@@ -26,7 +30,11 @@ public abstract class ContainerBase extends Container
for (int i = 0; i < 9; i++)
{
addSlotToContainer(new Slot(player.inventory, id, xInventory + i * 18, yInventory + 4 + (3 * 18)));
Slot slot = new Slot(player.inventory, id, xInventory + i * 18, yInventory + 4 + (3 * 18));
playerInventorySlots.add(slot);
addSlotToContainer(slot);
id++;
}
@@ -35,7 +43,11 @@ public abstract class ContainerBase extends Container
{
for (int x = 0; x < 9; x++)
{
addSlotToContainer(new Slot(player.inventory, id, xInventory + x * 18, yInventory + y * 18));
Slot slot = new Slot(player.inventory, id, xInventory + x * 18, yInventory + y * 18);
playerInventorySlots.add(slot);
addSlotToContainer(slot);
id++;
}
@@ -75,4 +87,9 @@ public abstract class ContainerBase extends Container
{
return true;
}
public List<Slot> getPlayerInventorySlots()
{
return playerInventorySlots;
}
}

View File

@@ -11,6 +11,8 @@ public class ContainerGrid extends ContainerBase
{
super(player);
addPlayerInventory(8, grid.isCrafting() ? 174 : 108);
if (grid.isCrafting())
{
int x = 44;
@@ -29,9 +31,7 @@ public class ContainerGrid extends ContainerBase
}
}
addSlotToContainer(new SlotGridCraftingResult(player, grid.getCraftingMatrix(), grid.getCraftingResult(), 0, 125, 124));
addSlotToContainer(new SlotGridCraftingResult(player, grid.getCraftingMatrix(), grid.getCraftingResult(), grid, 0, 125, 124));
}
addPlayerInventory(8, grid.isCrafting() ? 174 : 108);
}
}

View File

@@ -3,11 +3,37 @@ package storagecraft.container.slot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.SlotCrafting;
import net.minecraft.item.ItemStack;
import storagecraft.tile.TileGrid;
public class SlotGridCraftingResult extends SlotCrafting
{
public SlotGridCraftingResult(EntityPlayer player, IInventory craftingMatrix, IInventory craftingResult, int id, int x, int y)
private IInventory craftingMatrix;
private TileGrid grid;
public SlotGridCraftingResult(EntityPlayer player, IInventory craftingMatrix, IInventory craftingResult, TileGrid grid, int id, int x, int y)
{
super(player, craftingMatrix, craftingResult, id, x, y);
this.craftingMatrix = craftingMatrix;
this.grid = grid;
}
@Override
public void onPickupFromSlot(EntityPlayer player, ItemStack stack)
{
ItemStack[] matrixSlots = new ItemStack[craftingMatrix.getSizeInventory()];
for (int i = 0; i < craftingMatrix.getSizeInventory(); ++i)
{
if (craftingMatrix.getStackInSlot(i) != null)
{
matrixSlots[i] = craftingMatrix.getStackInSlot(i).copy();
}
}
super.onPickupFromSlot(player, stack);
grid.onCrafted(matrixSlots);
}
}