Recipe transfer
This commit is contained in:
@@ -14,9 +14,13 @@ import java.util.List;
|
|||||||
public class ContainerGrid extends ContainerBase {
|
public class ContainerGrid extends ContainerBase {
|
||||||
private List<Slot> craftingSlots = new ArrayList<Slot>();
|
private List<Slot> craftingSlots = new ArrayList<Slot>();
|
||||||
|
|
||||||
|
private TileGrid grid;
|
||||||
|
|
||||||
public ContainerGrid(EntityPlayer player, TileGrid grid) {
|
public ContainerGrid(EntityPlayer player, TileGrid grid) {
|
||||||
super(player);
|
super(player);
|
||||||
|
|
||||||
|
this.grid = grid;
|
||||||
|
|
||||||
addPlayerInventory(8, grid.getType() == EnumGridType.CRAFTING ? 174 : 126);
|
addPlayerInventory(8, grid.getType() == EnumGridType.CRAFTING ? 174 : 126);
|
||||||
|
|
||||||
if (grid.getType() == EnumGridType.CRAFTING) {
|
if (grid.getType() == EnumGridType.CRAFTING) {
|
||||||
@@ -42,6 +46,10 @@ public class ContainerGrid extends ContainerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TileGrid getGrid() {
|
||||||
|
return grid;
|
||||||
|
}
|
||||||
|
|
||||||
public List<Slot> getCraftingSlots() {
|
public List<Slot> getCraftingSlots() {
|
||||||
return craftingSlots;
|
return craftingSlots;
|
||||||
}
|
}
|
||||||
|
@@ -2,9 +2,15 @@ package refinedstorage.network;
|
|||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraftforge.common.util.Constants;
|
||||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||||
|
import refinedstorage.block.EnumGridType;
|
||||||
|
import refinedstorage.container.ContainerGrid;
|
||||||
|
import refinedstorage.tile.TileGrid;
|
||||||
|
|
||||||
public class MessageGridCraftingTransfer extends MessageHandlerPlayerToServer<MessageGridCraftingTransfer> implements IMessage {
|
public class MessageGridCraftingTransfer extends MessageHandlerPlayerToServer<MessageGridCraftingTransfer> implements IMessage {
|
||||||
private NBTTagCompound recipe;
|
private NBTTagCompound recipe;
|
||||||
@@ -28,6 +34,26 @@ public class MessageGridCraftingTransfer extends MessageHandlerPlayerToServer<Me
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(MessageGridCraftingTransfer message, EntityPlayerMP player) {
|
public void handle(MessageGridCraftingTransfer message, EntityPlayerMP player) {
|
||||||
// @TODO: Make it do something
|
if (player.openContainer instanceof ContainerGrid) {
|
||||||
|
TileGrid grid = ((ContainerGrid) player.openContainer).getGrid();
|
||||||
|
|
||||||
|
if (grid.getType() == EnumGridType.CRAFTING) {
|
||||||
|
ItemStack[][] actualRecipe = new ItemStack[9][];
|
||||||
|
|
||||||
|
for (int x = 0; x < actualRecipe.length; x++) {
|
||||||
|
NBTTagList list = message.recipe.getTagList("#" + x, Constants.NBT.TAG_COMPOUND);
|
||||||
|
|
||||||
|
if (list.tagCount() > 0) {
|
||||||
|
actualRecipe[x] = new ItemStack[list.tagCount()];
|
||||||
|
|
||||||
|
for (int y = 0; y < list.tagCount(); y++) {
|
||||||
|
actualRecipe[x][y] = ItemStack.loadItemStackFromNBT(list.getCompoundTagAt(y));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
grid.onRecipeTransfer(actualRecipe);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -124,6 +124,38 @@ public class TileGrid extends TileMachine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onRecipeTransfer(ItemStack[][] recipe) {
|
||||||
|
if (isConnected()) {
|
||||||
|
for (int i = 0; i < craftingInventory.getSizeInventory(); ++i) {
|
||||||
|
ItemStack slot = craftingInventory.getStackInSlot(i);
|
||||||
|
|
||||||
|
if (slot != null) {
|
||||||
|
if (!getController().push(slot)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
craftingInventory.setInventorySlotContents(i, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < craftingInventory.getSizeInventory(); ++i) {
|
||||||
|
if (recipe[i] != null) {
|
||||||
|
ItemStack[] possibilities = recipe[i];
|
||||||
|
|
||||||
|
for (ItemStack possibility : possibilities) {
|
||||||
|
ItemStack took = getController().take(possibility);
|
||||||
|
|
||||||
|
if (took != null) {
|
||||||
|
craftingInventory.setInventorySlotContents(i, possibility);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int getSortingDirection() {
|
public int getSortingDirection() {
|
||||||
return sortingDirection;
|
return sortingDirection;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user