ActionResultType
This commit is contained in:
@@ -65,19 +65,19 @@ public class StorageMonitorNetworkNode extends NetworkNode implements IComparabl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean depositAll(PlayerEntity player) {
|
public ActionResultType depositAll(PlayerEntity player) {
|
||||||
if (network == null) {
|
if (network == null) {
|
||||||
return false;
|
return ActionResultType.FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!network.getSecurityManager().hasPermission(Permission.INSERT, player)) {
|
if (!network.getSecurityManager().hasPermission(Permission.INSERT, player)) {
|
||||||
return false;
|
return ActionResultType.FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pair<ItemStack, Long> deposit = deposits.get(player.getGameProfile().getName());
|
Pair<ItemStack, Long> deposit = deposits.get(player.getGameProfile().getName());
|
||||||
|
|
||||||
if (deposit == null) {
|
if (deposit == null) {
|
||||||
return false;
|
return ActionResultType.FAIL; // TODO correct?
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack inserted = deposit.getKey();
|
ItemStack inserted = deposit.getKey();
|
||||||
@@ -93,7 +93,7 @@ public class StorageMonitorNetworkNode extends NetworkNode implements IComparabl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return ActionResultType.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResultType deposit(PlayerEntity player, ItemStack toInsert) {
|
public ActionResultType deposit(PlayerEntity player, ItemStack toInsert) {
|
||||||
|
@@ -0,0 +1,68 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.integration.jei;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.container.slot.filter.FilterSlot;
|
||||||
|
import com.raoulvdberge.refinedstorage.container.slot.filter.FluidFilterSlot;
|
||||||
|
import com.raoulvdberge.refinedstorage.container.slot.legacy.LegacyFilterSlot;
|
||||||
|
import com.raoulvdberge.refinedstorage.screen.BaseScreen;
|
||||||
|
import mezz.jei.api.gui.handlers.IGhostIngredientHandler;
|
||||||
|
import net.minecraft.client.renderer.Rectangle2d;
|
||||||
|
import net.minecraft.inventory.container.Slot;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GhostIngredientHandler implements IGhostIngredientHandler<BaseScreen> {
|
||||||
|
@Override
|
||||||
|
public <I> List<Target<I>> getTargets(BaseScreen gui, I ingredient, boolean doStart) {
|
||||||
|
List<Target<I>> targets = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Slot slot : gui.getContainer().inventorySlots) {
|
||||||
|
if (!slot.isEnabled()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle2d bounds = new Rectangle2d(gui.getGuiLeft() + slot.xPos, gui.getGuiTop() + slot.yPos, 17, 17);
|
||||||
|
|
||||||
|
if (ingredient instanceof ItemStack) {
|
||||||
|
if (slot instanceof LegacyFilterSlot || slot instanceof FilterSlot) {
|
||||||
|
targets.add(new Target<I>() {
|
||||||
|
@Override
|
||||||
|
public Rectangle2d getArea() {
|
||||||
|
return bounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(I ingredient) {
|
||||||
|
slot.putStack((ItemStack) ingredient);
|
||||||
|
|
||||||
|
// RS.INSTANCE.network.sendToServer(new MessageSlotFilterSet(slot.slotNumber, (ItemStack) ingredient));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if (ingredient instanceof FluidStack) {
|
||||||
|
if (slot instanceof FluidFilterSlot) {
|
||||||
|
targets.add(new Target<I>() {
|
||||||
|
@Override
|
||||||
|
public Rectangle2d getArea() {
|
||||||
|
return bounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(I ingredient) {
|
||||||
|
// RS.INSTANCE.network.sendToServer(new MessageSlotFilterSetFluid(slot.slotNumber, StackUtils.copy((FluidStack) ingredient, Fluid.BUCKET_VOLUME)));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return targets;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onComplete() {
|
||||||
|
// NO OP
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,87 @@
|
|||||||
|
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.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.gui.ingredient.IGuiIngredient;
|
||||||
|
import mezz.jei.api.recipe.category.IRecipeCategory;
|
||||||
|
import mezz.jei.api.recipe.transfer.IRecipeTransferError;
|
||||||
|
import mezz.jei.api.recipe.transfer.IRecipeTransferHandler;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
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 GridRecipeTransferHandler implements IRecipeTransferHandler {
|
||||||
|
public static final long TRANSFER_SCROLLBAR_DELAY_MS = 200;
|
||||||
|
public static long LAST_TRANSFER_TIME;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends Container> getContainerClass() {
|
||||||
|
return GridContainer.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IRecipeTransferError transferRecipe(Container container, IRecipeLayout recipeLayout, PlayerEntity player, boolean maxTransfer, boolean doTransfer) {
|
||||||
|
IGrid grid = ((GridContainer) container).getGrid();
|
||||||
|
|
||||||
|
if (doTransfer) {
|
||||||
|
LAST_TRANSFER_TIME = System.currentTimeMillis();
|
||||||
|
|
||||||
|
if (grid.getGridType() == GridType.PATTERN && !isCraftingRecipe(recipeLayout.getRecipeCategory())) {
|
||||||
|
List<ItemStack> inputs = new LinkedList<>();
|
||||||
|
List<ItemStack> outputs = new LinkedList<>();
|
||||||
|
|
||||||
|
List<FluidStack> fluidInputs = new LinkedList<>();
|
||||||
|
List<FluidStack> fluidOutputs = new LinkedList<>();
|
||||||
|
|
||||||
|
for (IGuiIngredient<ItemStack> guiIngredient : recipeLayout.getItemStacks().getGuiIngredients().values()) {
|
||||||
|
if (guiIngredient != null && guiIngredient.getDisplayedIngredient() != null) {
|
||||||
|
ItemStack ingredient = guiIngredient.getDisplayedIngredient().copy();
|
||||||
|
|
||||||
|
if (guiIngredient.isInput()) {
|
||||||
|
inputs.add(ingredient);
|
||||||
|
} else {
|
||||||
|
outputs.add(ingredient);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (IGuiIngredient<FluidStack> guiIngredient : recipeLayout.getFluidStacks().getGuiIngredients().values()) {
|
||||||
|
if (guiIngredient != null && guiIngredient.getDisplayedIngredient() != null) {
|
||||||
|
FluidStack ingredient = guiIngredient.getDisplayedIngredient().copy();
|
||||||
|
|
||||||
|
if (guiIngredient.isInput()) {
|
||||||
|
fluidInputs.add(ingredient);
|
||||||
|
} else {
|
||||||
|
fluidOutputs.add(ingredient);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RS.NETWORK_HANDLER.sendToServer(new GridProcessingTransferMessage(inputs, outputs, fluidInputs, fluidOutputs));
|
||||||
|
} else {
|
||||||
|
RS.NETWORK_HANDLER.sendToServer(new GridTransferMessage(
|
||||||
|
recipeLayout.getItemStacks().getGuiIngredients(),
|
||||||
|
container.inventorySlots.stream().filter(s -> s.inventory instanceof CraftingInventory).collect(Collectors.toList())
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isCraftingRecipe(IRecipeCategory<?> recipeCategory) {
|
||||||
|
return recipeCategory.getUid().equals(VanillaRecipeCategoryUid.CRAFTING);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,40 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.integration.jei;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.container.BaseContainer;
|
||||||
|
import com.raoulvdberge.refinedstorage.container.slot.filter.FluidFilterSlot;
|
||||||
|
import com.raoulvdberge.refinedstorage.screen.BaseScreen;
|
||||||
|
import com.raoulvdberge.refinedstorage.screen.grid.GridScreen;
|
||||||
|
import com.raoulvdberge.refinedstorage.util.RenderUtils;
|
||||||
|
import mezz.jei.api.gui.handlers.IGuiContainerHandler;
|
||||||
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
public class GuiContainerHandler implements IGuiContainerHandler<BaseScreen> {
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Object getIngredientUnderMouse(BaseScreen screen, double mouseX, double mouseY) {
|
||||||
|
mouseX -= screen.getGuiLeft();
|
||||||
|
mouseY -= screen.getGuiTop();
|
||||||
|
|
||||||
|
if (screen instanceof GridScreen) {
|
||||||
|
GridScreen grid = (GridScreen) screen;
|
||||||
|
|
||||||
|
if (!grid.getSearchField().isFocused() && grid.isOverSlotArea(mouseX, mouseY)) {
|
||||||
|
return grid.getSlotNumber() >= 0 && grid.getSlotNumber() < grid.getView().getStacks().size() ? grid.getView().getStacks().get(grid.getSlotNumber()).getIngredient() : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (screen.getContainer() instanceof BaseContainer) {
|
||||||
|
for (FluidFilterSlot slot : ((BaseContainer) screen.getContainer()).getFluidSlots()) {
|
||||||
|
FluidStack fluidInSlot = slot.getFluidInventory().getFluid(slot.getSlotIndex());
|
||||||
|
|
||||||
|
if (!fluidInSlot.isEmpty() && RenderUtils.inBounds(slot.xPos, slot.yPos, 18, 18, mouseX, mouseY)) {
|
||||||
|
return fluidInSlot;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,40 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.integration.jei;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.RS;
|
||||||
|
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;
|
||||||
|
|
||||||
|
@JeiPlugin
|
||||||
|
public class RSJeiPlugin implements IModPlugin {
|
||||||
|
private static final ResourceLocation ID = new ResourceLocation(RS.ID, "plugin");
|
||||||
|
|
||||||
|
public static IJeiRuntime RUNTIME;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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());
|
||||||
|
|
||||||
|
// TODO: https://github.com/mezz/JustEnoughItems/issues/1307
|
||||||
|
// registration.addGhostIngredientHandler(BaseScreen.class, new GhostIngredientHandler());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRuntimeAvailable(IJeiRuntime runtime) {
|
||||||
|
RUNTIME = runtime;
|
||||||
|
}
|
||||||
|
}
|
@@ -47,7 +47,7 @@ public abstract class NetworkItem extends EnergyItem implements INetworkItemProv
|
|||||||
applyNetwork(world.getServer(), stack, n -> n.getNetworkItemManager().open(player, player.getHeldItem(hand), player.inventory.currentItem), player::sendMessage);
|
applyNetwork(world.getServer(), stack, n -> n.getNetworkItemManager().open(player, player.getHeldItem(hand), player.inventory.currentItem), player::sendMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ActionResult.newResult(ActionResultType.SUCCESS, stack);
|
return ActionResult.func_226248_a_(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void applyNetwork(MinecraftServer server, ItemStack stack, Consumer<INetwork> onNetwork, Consumer<ITextComponent> onError) {
|
public void applyNetwork(MinecraftServer server, ItemStack stack, Consumer<INetwork> onNetwork, Consumer<ITextComponent> onError) {
|
||||||
|
@@ -45,7 +45,7 @@ public class SecurityCardItem extends Item {
|
|||||||
stack.getTag().putString(NBT_OWNER_NAME, player.getGameProfile().getName());
|
stack.getTag().putString(NBT_OWNER_NAME, player.getGameProfile().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return ActionResult.newResult(ActionResultType.SUCCESS, stack);
|
return ActionResult.func_226248_a_(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@@ -54,7 +54,7 @@ public class PortableGridBlockItem extends EnergyBlockItem {
|
|||||||
API.instance().getGridManager().openGrid(PortableGridGridFactory.ID, (ServerPlayerEntity) player, stack, player.inventory.currentItem);
|
API.instance().getGridManager().openGrid(PortableGridGridFactory.ID, (ServerPlayerEntity) player, stack, player.inventory.currentItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ActionResult.newResult(ActionResultType.SUCCESS, stack);
|
return ActionResult.func_226248_a_(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user