Skip to content

Commit

Permalink
Re-add JEI transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulvdberge committed Oct 15, 2019
1 parent f46ac1e commit caa7392
Show file tree
Hide file tree
Showing 8 changed files with 314 additions and 280 deletions.
47 changes: 24 additions & 23 deletions ...ration/jei/RecipeTransferHandlerGrid.java → ...ration/jei/GridRecipeTransferHandler.java
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
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;

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
Expand All @@ -34,24 +33,24 @@ public Type getType() {
}

@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<>();

Expand Down Expand Up @@ -82,12 +81,15 @@ public IRecipeTransferError transferRecipe(Container container, IRecipeLayout re
}
}

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;
}
Expand All @@ -101,4 +103,3 @@ public IRecipeTransferError transferRecipe(Container container, IRecipeLayout re
return null;
}
}
*/
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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;

Expand All @@ -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());

Expand All @@ -27,6 +26,11 @@ public ResourceLocation getPluginUid() {
return ID;
}

@Override
public void registerRecipeTransferHandlers(IRecipeTransferRegistration registration) {
registration.addUniversalRecipeTransferHandler(new GridRecipeTransferHandler());
}

@Override
public void registerGuiHandlers(IGuiHandlerRegistration registration) {
registration.addGuiContainerHandler(BaseScreen.class, new GuiContainerHandler());
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public void register() {
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) {
Expand Down
Loading

0 comments on commit caa7392

Please sign in to comment.