Start working on recipe transfer handlers in grid..

This commit is contained in:
Raoul Van den Berge
2016-03-29 13:02:22 +02:00
parent df5eb27ee9
commit ccf916d17d
5 changed files with 101 additions and 2 deletions

View File

@@ -0,0 +1,65 @@
package refinedstorage.jei;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.recipe.transfer.IRecipeTransferError;
import mezz.jei.api.recipe.transfer.IRecipeTransferHandler;
import mezz.jei.gui.ingredients.IGuiIngredient;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import refinedstorage.RefinedStorage;
import refinedstorage.container.ContainerGrid;
import refinedstorage.network.MessageGridCraftingTransfer;
import java.util.List;
import java.util.Map;
// Thanks to https://github.com/zerofall/EZStorage/blob/master/src/main/java/com/zerofall/ezstorage/jei/RecipeTransferHandler.java
public class GridRecipeTransferHandler implements IRecipeTransferHandler {
@Override
public Class<? extends Container> getContainerClass() {
return ContainerGrid.class;
}
@Override
public String getRecipeCategoryUid() {
return "minecraft.crafting";
}
@Override
public IRecipeTransferError transferRecipe(Container container, IRecipeLayout recipeLayout, EntityPlayer player, boolean maxTransfer, boolean doTransfer) {
if (doTransfer) {
Map<Integer, ? extends IGuiIngredient<ItemStack>> inputs = recipeLayout.getItemStacks().getGuiIngredients();
NBTTagCompound recipe = new NBTTagCompound();
for (Slot slot : container.inventorySlots) {
if (slot.inventory instanceof InventoryCrafting) {
IGuiIngredient<ItemStack> ingredient = inputs.get(slot.getSlotIndex() + 1);
if (ingredient != null) {
List<ItemStack> possibleItems = ingredient.getAllIngredients();
NBTTagList tags = new NBTTagList();
for (ItemStack stack : possibleItems) {
NBTTagCompound tag = new NBTTagCompound();
stack.writeToNBT(tag);
tags.appendTag(tag);
}
recipe.setTag("#" + slot.getSlotIndex(), tags);
}
}
}
RefinedStorage.NETWORK.sendToServer(new MessageGridCraftingTransfer(recipe));
}
return null;
}
}

View File

@@ -13,7 +13,8 @@ import refinedstorage.tile.TileStorage;
public class PluginRefinedStorage extends BlankModPlugin {
@Override
public void register(IModRegistry registry) {
// @TODO: JEI transfer handler
registry.getRecipeTransferRegistry().addRecipeTransferHandler(new GridRecipeTransferHandler());
registry.addRecipeCategories(new SoldererRecipeCategory(registry.getJeiHelpers().getGuiHelper()));
registry.addRecipeHandlers(new SoldererRecipeHandler());

View File

@@ -0,0 +1,33 @@
package refinedstorage.network;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
public class MessageGridCraftingTransfer extends MessageHandlerPlayerToServer<MessageGridCraftingTransfer> implements IMessage {
private NBTTagCompound recipe;
public MessageGridCraftingTransfer() {
}
public MessageGridCraftingTransfer(NBTTagCompound recipe) {
this.recipe = recipe;
}
@Override
public void fromBytes(ByteBuf buf) {
recipe = ByteBufUtils.readTag(buf);
}
@Override
public void toBytes(ByteBuf buf) {
ByteBufUtils.writeTag(buf, recipe);
}
@Override
public void handle(MessageGridCraftingTransfer message, EntityPlayerMP player) {
// @TODO: Make it do something
}
}

View File

@@ -38,6 +38,7 @@ public class CommonProxy {
RefinedStorage.NETWORK.registerMessage(MessagePriorityUpdate.class, MessagePriorityUpdate.class, 10, Side.SERVER);
RefinedStorage.NETWORK.registerMessage(MessageGridSortingUpdate.class, MessageGridSortingUpdate.class, 11, Side.SERVER);
RefinedStorage.NETWORK.registerMessage(MessageGridCraftingPush.class, MessageGridCraftingPush.class, 12, Side.SERVER);
RefinedStorage.NETWORK.registerMessage(MessageGridCraftingTransfer.class, MessageGridCraftingTransfer.class, 13, Side.SERVER);
NetworkRegistry.INSTANCE.registerGuiHandler(RefinedStorage.INSTANCE, new GuiHandler());

View File

@@ -144,7 +144,6 @@ public class InventoryUtils {
int toGo = stack.stackSize;
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
// @TODO: Test this better
if (!inventory.isItemValidForSlot(i, stack)) {
continue;
}