add universal RecipeTransferHandler for the ProcessingPatternEncoder
This commit is contained in:
@@ -51,8 +51,8 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
deobfCompile "mezz.jei:jei_1.10.2:3.11.+:api"
|
||||
runtime "mezz.jei:jei_1.10.2:3.11.+"
|
||||
deobfCompile "mezz.jei:jei_1.10.2:3.12.+:api"
|
||||
runtime "mezz.jei:jei_1.10.2:3.12.+"
|
||||
compile "net.darkhax.tesla:Tesla:1.10-1.2.+"
|
||||
compile "net.industrial-craft:industrialcraft-2:2.6.67-ex110:api"
|
||||
deobfCompile "MCMultiPart:MCMultiPart:1.2.1+:universal"
|
||||
|
||||
@@ -19,7 +19,7 @@ import refinedstorage.proxy.CommonProxy;
|
||||
public final class RefinedStorage {
|
||||
public static final String ID = "refinedstorage";
|
||||
public static final String VERSION = "1.2";
|
||||
public static final String DEPENDENCIES = "required-after:Forge@[12.18.1.2088,);required-after:mcmultipart@[1.2.1,);after:JEI@[3.11.0,);";
|
||||
public static final String DEPENDENCIES = "required-after:Forge@[12.18.1.2088,);required-after:mcmultipart@[1.2.1,);after:JEI@[3.12.0,);";
|
||||
public static final String GUI_FACTORY = "refinedstorage.gui.config.ModGuiFactory";
|
||||
|
||||
@SidedProxy(clientSide = "refinedstorage.proxy.ClientProxy", serverSide = "refinedstorage.proxy.ServerProxy")
|
||||
|
||||
@@ -8,6 +8,8 @@ import refinedstorage.container.slot.SlotOutput;
|
||||
import refinedstorage.container.slot.SlotSpecimen;
|
||||
import refinedstorage.tile.TileProcessingPatternEncoder;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class ContainerProcessingPatternEncoder extends ContainerBase {
|
||||
public ContainerProcessingPatternEncoder(TileProcessingPatternEncoder processingPatternEncoder, EntityPlayer player) {
|
||||
super(processingPatternEncoder, player);
|
||||
@@ -65,4 +67,26 @@ public class ContainerProcessingPatternEncoder extends ContainerBase {
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
public void setInputs(Collection<ItemStack> stacks) {
|
||||
setSlots(stacks, 2 , 2 + 9);
|
||||
}
|
||||
|
||||
public void setOutputs(Collection<ItemStack> stacks) {
|
||||
setSlots(stacks, 2 + 9, 2 + 9 * 2);
|
||||
}
|
||||
|
||||
private void setSlots(Collection<ItemStack> stacks, int begin, int end) {
|
||||
for (ItemStack stack : stacks) {
|
||||
for (int i = begin; i < end; ++i) {
|
||||
Slot slot = getSlot(i);
|
||||
|
||||
if (!slot.getHasStack() && slot.isItemValid(stack)) {
|
||||
slot.putStack(stack);
|
||||
slot.onSlotChanged();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package refinedstorage.integration.jei;
|
||||
|
||||
import mezz.jei.api.gui.IGuiIngredient;
|
||||
import mezz.jei.api.gui.IRecipeLayout;
|
||||
import mezz.jei.api.recipe.transfer.IRecipeTransferError;
|
||||
import mezz.jei.api.recipe.transfer.IRecipeTransferHandler;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.api.network.NetworkUtils;
|
||||
import refinedstorage.container.ContainerProcessingPatternEncoder;
|
||||
import refinedstorage.network.MessageProcessingPatternEncoderTransfer;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class RecipeTransferHandlerPattern implements IRecipeTransferHandler<ContainerProcessingPatternEncoder> {
|
||||
@Override
|
||||
public Class<ContainerProcessingPatternEncoder> getContainerClass() {
|
||||
return ContainerProcessingPatternEncoder.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeCategoryUid() {
|
||||
return "patternEncoding";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IRecipeTransferError transferRecipe(ContainerProcessingPatternEncoder container, IRecipeLayout recipeLayout, EntityPlayer player, boolean maxTransfer, boolean doTransfer) {
|
||||
if (doTransfer) {
|
||||
Map<Integer, ItemStack> inputs = new HashMap<>();
|
||||
Map<Integer, ItemStack> outputs = new HashMap<>();
|
||||
for (IGuiIngredient<ItemStack> guiIngredient : recipeLayout.getItemStacks().getGuiIngredients().values()) {
|
||||
if (guiIngredient != null && guiIngredient.getDisplayedIngredient() != null) {
|
||||
ItemStack ingredient = guiIngredient.getDisplayedIngredient();
|
||||
int hashCode = NetworkUtils.getItemStackHashCode(ingredient);
|
||||
if (guiIngredient.isInput()) {
|
||||
if (inputs.containsKey(hashCode)) {
|
||||
inputs.get(hashCode).stackSize++;
|
||||
} else {
|
||||
inputs.put(hashCode, ingredient);
|
||||
}
|
||||
} else {
|
||||
if (outputs.containsKey(hashCode)) {
|
||||
outputs.get(hashCode).stackSize++;
|
||||
} else {
|
||||
outputs.put(hashCode, ingredient);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RefinedStorage.INSTANCE.network.sendToServer(new MessageProcessingPatternEncoderTransfer(inputs.values(), outputs.values()));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,8 @@ public class RefinedStorageJEIPlugin extends BlankModPlugin {
|
||||
public void register(IModRegistry registry) {
|
||||
INSTANCE = this;
|
||||
|
||||
registry.getRecipeTransferRegistry().addRecipeTransferHandler(new RecipeTransferHandlerGrid());
|
||||
registry.getRecipeTransferRegistry().addUniversalRecipeTransferHandler(new RecipeTransferHandlerPattern());
|
||||
registry.getRecipeTransferRegistry().addRecipeTransferHandler(new RecipeTransferHandlerGrid(), "minecraft.crafting");
|
||||
registry.getRecipeTransferRegistry().addRecipeTransferHandler(ContainerSolderer.class, RecipeCategorySolderer.ID, 0, 3, 8, 36);
|
||||
|
||||
registry.addRecipeCategories(new RecipeCategorySolderer(registry.getJeiHelpers().getGuiHelper()));
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package refinedstorage.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import refinedstorage.container.ContainerProcessingPatternEncoder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
public class MessageProcessingPatternEncoderTransfer extends MessageHandlerPlayerToServer<MessageProcessingPatternEncoderTransfer> implements IMessage {
|
||||
|
||||
private Collection<ItemStack> inputs, outputs;
|
||||
|
||||
public MessageProcessingPatternEncoderTransfer() {
|
||||
|
||||
}
|
||||
|
||||
public MessageProcessingPatternEncoderTransfer(Collection<ItemStack> inputs, Collection<ItemStack> outputs) {
|
||||
this.inputs = inputs;
|
||||
this.outputs = outputs;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
int size = buf.readInt();
|
||||
this.inputs = new ArrayList<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
this.inputs.add(ByteBufUtils.readItemStack(buf));
|
||||
}
|
||||
size = buf.readInt();
|
||||
this.outputs = new ArrayList<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
this.outputs.add(ByteBufUtils.readItemStack(buf));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(inputs.size());
|
||||
for (ItemStack stack : inputs) {
|
||||
ByteBufUtils.writeItemStack(buf, stack);
|
||||
}
|
||||
buf.writeInt(outputs.size());
|
||||
for (ItemStack stack : outputs) {
|
||||
ByteBufUtils.writeItemStack(buf, stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(MessageProcessingPatternEncoderTransfer message, EntityPlayerMP player) {
|
||||
if (player.openContainer instanceof ContainerProcessingPatternEncoder) {
|
||||
ContainerProcessingPatternEncoder encoder = (ContainerProcessingPatternEncoder) player.openContainer;
|
||||
|
||||
encoder.setInputs(message.inputs);
|
||||
encoder.setOutputs(message.outputs);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,6 +71,7 @@ public class CommonProxy {
|
||||
RefinedStorage.INSTANCE.network.registerMessage(MessageGridFilterUpdate.class, MessageGridFilterUpdate.class, id++, Side.SERVER);
|
||||
RefinedStorage.INSTANCE.network.registerMessage(MessageGridCraftingPreview.class, MessageGridCraftingPreview.class, id++, Side.SERVER);
|
||||
RefinedStorage.INSTANCE.network.registerMessage(MessageGridCraftingPreviewResponse.class, MessageGridCraftingPreviewResponse.class, id++, Side.CLIENT);
|
||||
RefinedStorage.INSTANCE.network.registerMessage(MessageProcessingPatternEncoderTransfer.class, MessageProcessingPatternEncoderTransfer.class, id++, Side.SERVER);
|
||||
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler(RefinedStorage.INSTANCE, new GuiHandler());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user