Re-add JEI transfer
This commit is contained in:
@@ -1,21 +1,20 @@
|
||||
package com.raoulvdberge.refinedstorage.integration.jei;
|
||||
/*
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.GridType;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeGrid;
|
||||
import com.raoulvdberge.refinedstorage.container.ContainerGrid;
|
||||
import com.raoulvdberge.refinedstorage.network.MessageGridProcessingTransfer;
|
||||
import com.raoulvdberge.refinedstorage.network.MessageGridTransfer;
|
||||
import mezz.jei.api.gui.IGuiIngredient;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.GridNetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.container.GridContainer;
|
||||
import com.raoulvdberge.refinedstorage.network.grid.GridProcessingTransferMessage;
|
||||
import com.raoulvdberge.refinedstorage.network.grid.GridTransferMessage;
|
||||
import mezz.jei.api.constants.VanillaRecipeCategoryUid;
|
||||
import mezz.jei.api.gui.IRecipeLayout;
|
||||
import mezz.jei.api.recipe.VanillaRecipeCategoryUid;
|
||||
import mezz.jei.api.gui.ingredient.IGuiIngredient;
|
||||
import mezz.jei.api.recipe.transfer.IRecipeTransferError;
|
||||
import mezz.jei.api.recipe.transfer.IRecipeTransferHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.inventory.CraftingInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
@@ -23,9 +22,9 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class RecipeTransferHandlerGrid implements IRecipeTransferHandler {
|
||||
public static final long TRANSFER_SCROLL_DELAY_MS = 200;
|
||||
public static long LAST_TRANSFER;
|
||||
public class GridRecipeTransferHandler implements IRecipeTransferHandler {
|
||||
public static final long TRANSFER_SCROLLBAR_DELAY_MS = 200;
|
||||
public static long LAST_TRANSFER_TIME;
|
||||
|
||||
private static final IRecipeTransferError ERROR_CANNOT_TRANSFER = new IRecipeTransferError() {
|
||||
@Override
|
||||
@@ -34,24 +33,24 @@ public class RecipeTransferHandlerGrid implements IRecipeTransferHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showError(Minecraft minecraft, int mouseX, int mouseY, IRecipeLayout recipeLayout, int recipeX, int recipeY) {
|
||||
// NO OP
|
||||
public void showError(int i, int i1, IRecipeLayout iRecipeLayout, int i2, int i3) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public Class<? extends Container> getContainerClass() {
|
||||
return ContainerGrid.class;
|
||||
return GridContainer.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRecipeTransferError transferRecipe(Container container, IRecipeLayout recipeLayout, PlayerEntity player, boolean maxTransfer, boolean doTransfer) {
|
||||
IGrid grid = ((ContainerGrid) container).getGrid();
|
||||
IGrid grid = ((GridContainer) container).getGrid();
|
||||
|
||||
if (doTransfer) {
|
||||
LAST_TRANSFER = System.currentTimeMillis();
|
||||
LAST_TRANSFER_TIME = System.currentTimeMillis();
|
||||
|
||||
if (grid.getGridType() == GridType.PATTERN && ((NetworkNodeGrid) grid).isProcessingPattern()) {
|
||||
if (grid.getGridType() == GridType.PATTERN && ((GridNetworkNode) grid).isProcessingPattern()) {
|
||||
List<ItemStack> inputs = new LinkedList<>();
|
||||
List<ItemStack> outputs = new LinkedList<>();
|
||||
|
||||
@@ -82,12 +81,15 @@ public class RecipeTransferHandlerGrid implements IRecipeTransferHandler {
|
||||
}
|
||||
}
|
||||
|
||||
RS.INSTANCE.network.sendToServer(new MessageGridProcessingTransfer(inputs, outputs, fluidInputs, fluidOutputs));
|
||||
RS.NETWORK_HANDLER.sendToServer(new GridProcessingTransferMessage(inputs, outputs, fluidInputs, fluidOutputs));
|
||||
} else {
|
||||
RS.INSTANCE.network.sendToServer(new MessageGridTransfer(recipeLayout.getItemStacks().getGuiIngredients(), container.inventorySlots.stream().filter(s -> s.inventory instanceof InventoryCrafting).collect(Collectors.toList())));
|
||||
RS.NETWORK_HANDLER.sendToServer(new GridTransferMessage(
|
||||
recipeLayout.getItemStacks().getGuiIngredients(),
|
||||
container.inventorySlots.stream().filter(s -> s.inventory instanceof CraftingInventory).collect(Collectors.toList())
|
||||
));
|
||||
}
|
||||
} else {
|
||||
if (grid.getGridType() == GridType.PATTERN && ((NetworkNodeGrid) grid).isProcessingPattern()) {
|
||||
if (grid.getGridType() == GridType.PATTERN && ((GridNetworkNode) grid).isProcessingPattern()) {
|
||||
if (recipeLayout.getRecipeCategory().getUid().equals(VanillaRecipeCategoryUid.CRAFTING)) {
|
||||
return ERROR_CANNOT_TRANSFER;
|
||||
}
|
||||
@@ -101,4 +103,3 @@ public class RecipeTransferHandlerGrid implements IRecipeTransferHandler {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
*/
|
@@ -5,6 +5,7 @@ import com.raoulvdberge.refinedstorage.screen.BaseScreen;
|
||||
import mezz.jei.api.IModPlugin;
|
||||
import mezz.jei.api.JeiPlugin;
|
||||
import mezz.jei.api.registration.IGuiHandlerRegistration;
|
||||
import mezz.jei.api.registration.IRecipeTransferRegistration;
|
||||
import mezz.jei.api.runtime.IJeiRuntime;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
@@ -14,8 +15,6 @@ public class RSJeiPlugin implements IModPlugin {
|
||||
|
||||
public static IJeiRuntime RUNTIME;
|
||||
|
||||
// TODO registry.getRecipeTransferRegistry().addUniversalRecipeTransferHandler(new RecipeTransferHandlerGrid());
|
||||
|
||||
// TODO registry.addRecipeRegistryPlugin(new RecipeRegistryPluginCover());
|
||||
// TODO registry.addRecipeRegistryPlugin(new RecipeRegistryPluginHollowCover());
|
||||
|
||||
@@ -27,6 +26,11 @@ public class RSJeiPlugin implements IModPlugin {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerRecipeTransferHandlers(IRecipeTransferRegistration registration) {
|
||||
registration.addUniversalRecipeTransferHandler(new GridRecipeTransferHandler());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerGuiHandlers(IGuiHandlerRegistration registration) {
|
||||
registration.addGuiContainerHandler(BaseScreen.class, new GuiContainerHandler());
|
||||
|
@@ -1,172 +0,0 @@
|
||||
package com.raoulvdberge.refinedstorage.network;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.GridType;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeGrid;
|
||||
import com.raoulvdberge.refinedstorage.container.GridContainer;
|
||||
import com.raoulvdberge.refinedstorage.inventory.fluid.FluidInventory;
|
||||
import com.raoulvdberge.refinedstorage.inventory.item.ItemHandlerBase;
|
||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
public class MessageGridProcessingTransfer extends MessageHandlerPlayerToServer<MessageGridProcessingTransfer> implements IMessage {
|
||||
private Collection<ItemStack> inputs;
|
||||
private Collection<ItemStack> outputs;
|
||||
|
||||
private Collection<FluidStack> fluidInputs;
|
||||
private Collection<FluidStack> fluidOutputs;
|
||||
|
||||
public MessageGridProcessingTransfer() {
|
||||
}
|
||||
|
||||
public MessageGridProcessingTransfer(Collection<ItemStack> inputs, Collection<ItemStack> outputs, Collection<FluidStack> fluidInputs, Collection<FluidStack> fluidOutputs) {
|
||||
this.inputs = inputs;
|
||||
this.outputs = outputs;
|
||||
this.fluidInputs = fluidInputs;
|
||||
this.fluidOutputs = fluidOutputs;
|
||||
}
|
||||
|
||||
@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(StackUtils.readItemStack(buf));
|
||||
}
|
||||
|
||||
size = buf.readInt();
|
||||
|
||||
this.outputs = new ArrayList<>(size);
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
this.outputs.add(StackUtils.readItemStack(buf));
|
||||
}
|
||||
|
||||
size = buf.readInt();
|
||||
|
||||
this.fluidInputs = new ArrayList<>(size);
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
this.fluidInputs.add(StackUtils.readFluidStack(buf));
|
||||
}
|
||||
|
||||
size = buf.readInt();
|
||||
|
||||
this.fluidOutputs = new ArrayList<>(size);
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
this.fluidOutputs.add(StackUtils.readFluidStack(buf));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(inputs.size());
|
||||
|
||||
for (ItemStack stack : inputs) {
|
||||
StackUtils.writeItemStack(buf, stack);
|
||||
}
|
||||
|
||||
buf.writeInt(outputs.size());
|
||||
|
||||
for (ItemStack stack : outputs) {
|
||||
StackUtils.writeItemStack(buf, stack);
|
||||
}
|
||||
|
||||
buf.writeInt(fluidInputs.size());
|
||||
|
||||
for (FluidStack stack : fluidInputs) {
|
||||
StackUtils.writeFluidStack(buf, stack);
|
||||
}
|
||||
|
||||
buf.writeInt(fluidOutputs.size());
|
||||
|
||||
for (FluidStack stack : fluidOutputs) {
|
||||
StackUtils.writeFluidStack(buf, stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(MessageGridProcessingTransfer message, ServerPlayerEntity player) {
|
||||
if (player.openContainer instanceof ContainerGrid) {
|
||||
IGrid grid = ((ContainerGrid) player.openContainer).getGrid();
|
||||
|
||||
if (grid.getGridType() == GridType.PATTERN) {
|
||||
ItemHandlerBase handler = ((NetworkNodeGrid) grid).getProcessingMatrix();
|
||||
FluidInventory handlerFluid = ((NetworkNodeGrid) grid).getProcessingMatrixFluids();
|
||||
|
||||
clearInputsAndOutputs(handler);
|
||||
clearInputsAndOutputs(handlerFluid);
|
||||
|
||||
setInputs(handler, message.inputs);
|
||||
setOutputs(handler, message.outputs);
|
||||
|
||||
setFluidInputs(handlerFluid, message.fluidInputs);
|
||||
setFluidOutputs(handlerFluid, message.fluidOutputs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void clearInputsAndOutputs(ItemHandlerBase handler) {
|
||||
for (int i = 0; i < 9 * 2; ++i) {
|
||||
handler.setStackInSlot(i, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
private void clearInputsAndOutputs(FluidInventory handler) {
|
||||
for (int i = 0; i < 9 * 2; ++i) {
|
||||
handler.setFluid(i, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void setInputs(ItemHandlerBase handler, Collection<ItemStack> stacks) {
|
||||
setSlots(handler, stacks, 0, 9);
|
||||
}
|
||||
|
||||
private void setOutputs(ItemHandlerBase handler, Collection<ItemStack> stacks) {
|
||||
setSlots(handler, stacks, 9, 18);
|
||||
}
|
||||
|
||||
private void setSlots(ItemHandlerBase handler, Collection<ItemStack> stacks, int begin, int end) {
|
||||
for (ItemStack stack : stacks) {
|
||||
handler.setStackInSlot(begin, stack);
|
||||
|
||||
begin++;
|
||||
|
||||
if (begin >= end) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setFluidInputs(FluidInventory inventory, Collection<FluidStack> stacks) {
|
||||
setFluidSlots(inventory, stacks, 0, 9);
|
||||
}
|
||||
|
||||
private void setFluidOutputs(FluidInventory inventory, Collection<FluidStack> stacks) {
|
||||
setFluidSlots(inventory, stacks, 9, 18);
|
||||
}
|
||||
|
||||
private void setFluidSlots(FluidInventory inventory, Collection<FluidStack> stacks, int begin, int end) {
|
||||
for (FluidStack stack : stacks) {
|
||||
|
||||
inventory.setFluid(begin, stack.copy());
|
||||
|
||||
begin++;
|
||||
|
||||
if (begin >= end) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,82 +0,0 @@
|
||||
package com.raoulvdberge.refinedstorage.network;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.GridType;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
||||
import com.raoulvdberge.refinedstorage.container.GridContainer;
|
||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import mezz.jei.api.gui.IGuiIngredient;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MessageGridTransfer extends MessageHandlerPlayerToServer<MessageGridTransfer> implements IMessage {
|
||||
private Map<Integer, ? extends IGuiIngredient<ItemStack>> inputs;
|
||||
private List<Slot> slots;
|
||||
|
||||
private ItemStack[][] recipe = new ItemStack[9][];
|
||||
|
||||
public MessageGridTransfer() {
|
||||
}
|
||||
|
||||
public MessageGridTransfer(Map<Integer, ? extends IGuiIngredient<ItemStack>> inputs, List<Slot> slots) {
|
||||
this.inputs = inputs;
|
||||
this.slots = slots;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
int slots = buf.readInt();
|
||||
|
||||
for (int i = 0; i < slots; ++i) {
|
||||
int ingredients = buf.readInt();
|
||||
|
||||
recipe[i] = new ItemStack[ingredients];
|
||||
|
||||
for (int j = 0; j < ingredients; ++j) {
|
||||
recipe[i][j] = StackUtils.readItemStack(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(slots.size());
|
||||
|
||||
for (Slot slot : slots) {
|
||||
IGuiIngredient<ItemStack> ingredient = inputs.get(slot.getSlotIndex() + 1);
|
||||
|
||||
List<ItemStack> ingredients = new ArrayList<>();
|
||||
|
||||
if (ingredient != null) {
|
||||
for (ItemStack possibleStack : ingredient.getAllIngredients()) {
|
||||
if (possibleStack != null) {
|
||||
ingredients.add(possibleStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buf.writeInt(ingredients.size());
|
||||
|
||||
for (ItemStack possibleStack : ingredients) {
|
||||
StackUtils.writeItemStack(buf, possibleStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(MessageGridTransfer message, ServerPlayerEntity player) {
|
||||
if (player.openContainer instanceof ContainerGrid) {
|
||||
IGrid grid = ((ContainerGrid) player.openContainer).getGrid();
|
||||
|
||||
if (grid.getGridType() == GridType.CRAFTING || grid.getGridType() == GridType.PATTERN) {
|
||||
grid.onRecipeTransfer(player, message.recipe);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -43,6 +43,8 @@ public class NetworkHandler {
|
||||
handler.registerMessage(id++, GridFluidDeltaMessage.class, GridFluidDeltaMessage::encode, GridFluidDeltaMessage::decode, GridFluidDeltaMessage::handle);
|
||||
handler.registerMessage(id++, GridFluidInsertHeldMessage.class, GridFluidInsertHeldMessage::encode, GridFluidInsertHeldMessage::decode, GridFluidInsertHeldMessage::handle);
|
||||
handler.registerMessage(id++, GridFluidPullMessage.class, GridFluidPullMessage::encode, GridFluidPullMessage::decode, GridFluidPullMessage::handle);
|
||||
handler.registerMessage(id++, GridTransferMessage.class, GridTransferMessage::encode, GridTransferMessage::decode, GridTransferMessage::handle);
|
||||
handler.registerMessage(id++, GridProcessingTransferMessage.class, GridProcessingTransferMessage::encode, GridProcessingTransferMessage::decode, GridProcessingTransferMessage::handle);
|
||||
}
|
||||
|
||||
public void sendToServer(Object message) {
|
||||
|
@@ -0,0 +1,176 @@
|
||||
package com.raoulvdberge.refinedstorage.network.grid;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.GridType;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.GridNetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.container.GridContainer;
|
||||
import com.raoulvdberge.refinedstorage.inventory.fluid.FluidInventory;
|
||||
import com.raoulvdberge.refinedstorage.inventory.item.BaseItemHandler;
|
||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class GridProcessingTransferMessage {
|
||||
private Collection<ItemStack> inputs;
|
||||
private Collection<ItemStack> outputs;
|
||||
private Collection<FluidStack> fluidInputs;
|
||||
private Collection<FluidStack> fluidOutputs;
|
||||
|
||||
public GridProcessingTransferMessage(Collection<ItemStack> inputs, Collection<ItemStack> outputs, Collection<FluidStack> fluidInputs, Collection<FluidStack> fluidOutputs) {
|
||||
this.inputs = inputs;
|
||||
this.outputs = outputs;
|
||||
this.fluidInputs = fluidInputs;
|
||||
this.fluidOutputs = fluidOutputs;
|
||||
}
|
||||
|
||||
public static GridProcessingTransferMessage decode(PacketBuffer buf) {
|
||||
int size = buf.readInt();
|
||||
|
||||
List<ItemStack> inputs = new ArrayList<>(size);
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
inputs.add(StackUtils.readItemStack(buf));
|
||||
}
|
||||
|
||||
size = buf.readInt();
|
||||
|
||||
List<ItemStack> outputs = new ArrayList<>(size);
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
outputs.add(StackUtils.readItemStack(buf));
|
||||
}
|
||||
|
||||
size = buf.readInt();
|
||||
|
||||
List<FluidStack> fluidInputs = new ArrayList<>(size);
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
fluidInputs.add(FluidStack.readFromPacket(buf));
|
||||
}
|
||||
|
||||
size = buf.readInt();
|
||||
|
||||
List<FluidStack> fluidOutputs = new ArrayList<>(size);
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
fluidOutputs.add(FluidStack.readFromPacket(buf));
|
||||
}
|
||||
|
||||
return new GridProcessingTransferMessage(inputs, outputs, fluidInputs, fluidOutputs);
|
||||
}
|
||||
|
||||
public static void encode(GridProcessingTransferMessage message, PacketBuffer buf) {
|
||||
buf.writeInt(message.inputs.size());
|
||||
|
||||
for (ItemStack stack : message.inputs) {
|
||||
StackUtils.writeItemStack(buf, stack);
|
||||
}
|
||||
|
||||
buf.writeInt(message.outputs.size());
|
||||
|
||||
for (ItemStack stack : message.outputs) {
|
||||
StackUtils.writeItemStack(buf, stack);
|
||||
}
|
||||
|
||||
buf.writeInt(message.fluidInputs.size());
|
||||
|
||||
for (FluidStack stack : message.fluidInputs) {
|
||||
stack.writeToPacket(buf);
|
||||
}
|
||||
|
||||
buf.writeInt(message.fluidOutputs.size());
|
||||
|
||||
for (FluidStack stack : message.fluidOutputs) {
|
||||
stack.writeToPacket(buf);
|
||||
}
|
||||
}
|
||||
|
||||
public static void handle(GridProcessingTransferMessage message, Supplier<NetworkEvent.Context> ctx) {
|
||||
PlayerEntity player = ctx.get().getSender();
|
||||
|
||||
if (player != null) {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
if (player.openContainer instanceof GridContainer) {
|
||||
IGrid grid = ((GridContainer) player.openContainer).getGrid();
|
||||
|
||||
if (grid.getGridType() == GridType.PATTERN) {
|
||||
BaseItemHandler handler = ((GridNetworkNode) grid).getProcessingMatrix();
|
||||
FluidInventory handlerFluid = ((GridNetworkNode) grid).getProcessingMatrixFluids();
|
||||
|
||||
clearInputsAndOutputs(handler);
|
||||
clearInputsAndOutputs(handlerFluid);
|
||||
|
||||
setInputs(handler, message.inputs);
|
||||
setOutputs(handler, message.outputs);
|
||||
|
||||
setFluidInputs(handlerFluid, message.fluidInputs);
|
||||
setFluidOutputs(handlerFluid, message.fluidOutputs);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
|
||||
private static void clearInputsAndOutputs(BaseItemHandler handler) {
|
||||
for (int i = 0; i < 9 * 2; ++i) {
|
||||
handler.setStackInSlot(i, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
private static void clearInputsAndOutputs(FluidInventory handler) {
|
||||
for (int i = 0; i < 9 * 2; ++i) {
|
||||
handler.setFluid(i, FluidStack.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setInputs(BaseItemHandler handler, Collection<ItemStack> stacks) {
|
||||
setSlots(handler, stacks, 0, 9);
|
||||
}
|
||||
|
||||
private static void setOutputs(BaseItemHandler handler, Collection<ItemStack> stacks) {
|
||||
setSlots(handler, stacks, 9, 18);
|
||||
}
|
||||
|
||||
private static void setSlots(BaseItemHandler handler, Collection<ItemStack> stacks, int begin, int end) {
|
||||
for (ItemStack stack : stacks) {
|
||||
handler.setStackInSlot(begin, stack);
|
||||
|
||||
begin++;
|
||||
|
||||
if (begin >= end) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void setFluidInputs(FluidInventory inventory, Collection<FluidStack> stacks) {
|
||||
setFluidSlots(inventory, stacks, 0, 9);
|
||||
}
|
||||
|
||||
private static void setFluidOutputs(FluidInventory inventory, Collection<FluidStack> stacks) {
|
||||
setFluidSlots(inventory, stacks, 9, 18);
|
||||
}
|
||||
|
||||
private static void setFluidSlots(FluidInventory inventory, Collection<FluidStack> stacks, int begin, int end) {
|
||||
for (FluidStack stack : stacks) {
|
||||
|
||||
inventory.setFluid(begin, stack.copy());
|
||||
|
||||
begin++;
|
||||
|
||||
if (begin >= end) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,92 @@
|
||||
package com.raoulvdberge.refinedstorage.network.grid;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.GridType;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
||||
import com.raoulvdberge.refinedstorage.container.GridContainer;
|
||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
||||
import mezz.jei.api.gui.ingredient.IGuiIngredient;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class GridTransferMessage {
|
||||
private Map<Integer, ? extends IGuiIngredient<ItemStack>> inputs;
|
||||
private List<Slot> slots;
|
||||
|
||||
private ItemStack[][] recipe = new ItemStack[9][];
|
||||
|
||||
public GridTransferMessage() {
|
||||
}
|
||||
|
||||
public GridTransferMessage(Map<Integer, ? extends IGuiIngredient<ItemStack>> inputs, List<Slot> slots) {
|
||||
this.inputs = inputs;
|
||||
this.slots = slots;
|
||||
}
|
||||
|
||||
public static GridTransferMessage decode(PacketBuffer buf) {
|
||||
GridTransferMessage msg = new GridTransferMessage();
|
||||
|
||||
int slots = buf.readInt();
|
||||
|
||||
for (int i = 0; i < slots; ++i) {
|
||||
int ingredients = buf.readInt();
|
||||
|
||||
msg.recipe[i] = new ItemStack[ingredients];
|
||||
|
||||
for (int j = 0; j < ingredients; ++j) {
|
||||
msg.recipe[i][j] = StackUtils.readItemStack(buf);
|
||||
}
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
public static void encode(GridTransferMessage message, PacketBuffer buf) {
|
||||
buf.writeInt(message.slots.size());
|
||||
|
||||
for (Slot slot : message.slots) {
|
||||
IGuiIngredient<ItemStack> ingredient = message.inputs.get(slot.getSlotIndex() + 1);
|
||||
|
||||
List<ItemStack> ingredients = new ArrayList<>();
|
||||
|
||||
if (ingredient != null) {
|
||||
for (ItemStack possibleStack : ingredient.getAllIngredients()) {
|
||||
if (possibleStack != null) {
|
||||
ingredients.add(possibleStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buf.writeInt(ingredients.size());
|
||||
|
||||
for (ItemStack possibleStack : ingredients) {
|
||||
StackUtils.writeItemStack(buf, possibleStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void handle(GridTransferMessage message, Supplier<NetworkEvent.Context> ctx) {
|
||||
PlayerEntity player = ctx.get().getSender();
|
||||
|
||||
if (player != null) {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
if (player.openContainer instanceof GridContainer) {
|
||||
IGrid grid = ((GridContainer) player.openContainer).getGrid();
|
||||
|
||||
if (grid.getGridType() == GridType.CRAFTING || grid.getGridType() == GridType.PATTERN) {
|
||||
grid.onRecipeTransfer(player, message.recipe);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
@@ -1,6 +1,8 @@
|
||||
package com.raoulvdberge.refinedstorage.screen.widget;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.integration.jei.GridRecipeTransferHandler;
|
||||
import com.raoulvdberge.refinedstorage.integration.jei.JeiIntegration;
|
||||
import com.raoulvdberge.refinedstorage.screen.BaseScreen;
|
||||
import com.raoulvdberge.refinedstorage.util.RenderUtils;
|
||||
import net.minecraft.client.gui.IGuiEventListener;
|
||||
@@ -65,6 +67,13 @@ public class ScrollbarWidget implements IGuiEventListener {
|
||||
my -= screen.getGuiTop();
|
||||
|
||||
if (button == 0 && RenderUtils.inBounds(x, y, width, height, mx, my)) {
|
||||
// Prevent accidental scrollbar click after clicking recipe transfer button
|
||||
if (JeiIntegration.isLoaded() && System.currentTimeMillis() - GridRecipeTransferHandler.LAST_TRANSFER_TIME <= GridRecipeTransferHandler.TRANSFER_SCROLLBAR_DELAY_MS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
updateOffset(my);
|
||||
|
||||
clicked = true;
|
||||
|
||||
return true;
|
||||
@@ -79,10 +88,14 @@ public class ScrollbarWidget implements IGuiEventListener {
|
||||
my -= screen.getGuiTop();
|
||||
|
||||
if (clicked && RenderUtils.inBounds(x, y, width, height, mx, my)) {
|
||||
setOffset((int) Math.floor((float) (my - y) / (float) (height - SCROLLER_HEIGHT) * (float) maxOffset));
|
||||
updateOffset(my);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateOffset(double my) {
|
||||
setOffset((int) Math.floor((float) (my - y) / (float) (height - SCROLLER_HEIGHT) * (float) maxOffset));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(double mx, double my, int button) {
|
||||
if (clicked) {
|
||||
|
Reference in New Issue
Block a user