Skip to content

Commit

Permalink
added back jei/top/jade integration
Browse files Browse the repository at this point in the history
  • Loading branch information
desht committed Jun 24, 2023
1 parent 7c749f3 commit 2b5133a
Show file tree
Hide file tree
Showing 10 changed files with 343 additions and 235 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
package me.desht.modularrouters.integration.jei;

public class BulkFilterScreenGhost /*implements IGhostIngredientHandler<BulkItemFilterScreen>*/ {
// @Override
// public <I> List<Target<I>> getTargets(BulkItemFilterScreen gui, I ingredient, boolean doStart) {
// List<Target<I>> res = new ArrayList<>();
// for (int i = 0; i < gui.getMenu().slots.size(); i++) {
// Slot s = gui.getMenu().getSlot(i);
// if (s instanceof FilterSlot) {
// res.add(new GhostTarget<>(gui, s));
// }
// }
// return res;
// }
//
// @Override
// public void onComplete() {
// }
import me.desht.modularrouters.client.gui.filter.BulkItemFilterScreen;
import me.desht.modularrouters.container.FilterSlot;
import mezz.jei.api.gui.handlers.IGhostIngredientHandler;
import mezz.jei.api.ingredients.ITypedIngredient;
import net.minecraft.world.inventory.Slot;

import java.util.ArrayList;
import java.util.List;

public class BulkFilterScreenGhost implements IGhostIngredientHandler<BulkItemFilterScreen> {
@Override
public <I> List<Target<I>> getTargetsTyped(BulkItemFilterScreen gui, ITypedIngredient<I> ingredient, boolean doStart) {
List<Target<I>> res = new ArrayList<>();
for (int i = 0; i < gui.getMenu().slots.size(); i++) {
Slot s = gui.getMenu().getSlot(i);
if (s instanceof FilterSlot) {
res.add(new GhostTarget<>(gui, s));
}
}
return res;
}

@Override
public void onComplete() {
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
package me.desht.modularrouters.integration.jei;

import me.desht.modularrouters.network.ModuleFilterMessage;
import me.desht.modularrouters.network.PacketHandler;
import mezz.jei.api.gui.handlers.IGhostIngredientHandler;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.renderer.Rect2i;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil;

record GhostTarget<I>(AbstractContainerScreen<?> gui, Slot slot) /*implements IGhostIngredientHandler.Target<I>*/ {
// @Override
// public Rect2i getArea() {
// return new Rect2i(slot.x + gui.getGuiLeft(), slot.y + gui.getGuiTop(), 16, 16);
// }
//
// @Override
// public void accept(I ingredient) {
// if (ingredient instanceof ItemStack stack) {
// PacketHandler.NETWORK.sendToServer(new ModuleFilterMessage(slot.index, stack));
// } else if (ingredient instanceof FluidStack fluidStack) {
// ItemStack bucket = FluidUtil.getFilledBucket(fluidStack);
// if (!bucket.isEmpty()) {
// PacketHandler.NETWORK.sendToServer(new ModuleFilterMessage(slot.index, bucket));
// }
// }
// }
record GhostTarget<I>(AbstractContainerScreen<?> gui, Slot slot) implements IGhostIngredientHandler.Target<I> {
@Override
public Rect2i getArea() {
return new Rect2i(slot.x + gui.getGuiLeft(), slot.y + gui.getGuiTop(), 16, 16);
}

@Override
public void accept(I ingredient) {
if (ingredient instanceof ItemStack stack) {
PacketHandler.NETWORK.sendToServer(new ModuleFilterMessage(slot.index, stack));
} else if (ingredient instanceof FluidStack fluidStack) {
ItemStack bucket = FluidUtil.getFilledBucket(fluidStack);
if (!bucket.isEmpty()) {
PacketHandler.NETWORK.sendToServer(new ModuleFilterMessage(slot.index, bucket));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
package me.desht.modularrouters.integration.jei;

//@JeiPlugin
public class JEIModularRoutersPlugin /*implements IModPlugin*/ {
// @Override
// public ResourceLocation getPluginUid() {
// return RL("default");
// }
//
// @Override
// public void registerGuiHandlers(IGuiHandlerRegistration registration) {
// registration.addGhostIngredientHandler(AbstractModuleScreen.class, new ModuleScreenGhost());
// registration.addGhostIngredientHandler(BulkItemFilterScreen.class, new BulkFilterScreenGhost());
//
// registration.addGuiContainerHandler(ModularRouterScreen.class, new IGuiContainerHandler<>() {
// @Override
// public List<Rect2i> getGuiExtraAreas(ModularRouterScreen routerScreen) {
// return routerScreen.getExtraArea();
// }
// });
// }
import me.desht.modularrouters.client.gui.ModularRouterScreen;
import me.desht.modularrouters.client.gui.filter.BulkItemFilterScreen;
import me.desht.modularrouters.client.gui.module.AbstractModuleScreen;
import mezz.jei.api.IModPlugin;
import mezz.jei.api.JeiPlugin;
import mezz.jei.api.gui.handlers.IGuiContainerHandler;
import mezz.jei.api.registration.IGuiHandlerRegistration;
import net.minecraft.client.renderer.Rect2i;
import net.minecraft.resources.ResourceLocation;

import java.util.List;

import static me.desht.modularrouters.util.MiscUtil.RL;

@JeiPlugin
public class JEIModularRoutersPlugin implements IModPlugin {
@Override
public ResourceLocation getPluginUid() {
return RL("default");
}

@Override
public void registerGuiHandlers(IGuiHandlerRegistration registration) {
registration.addGhostIngredientHandler(AbstractModuleScreen.class, new ModuleScreenGhost());
registration.addGhostIngredientHandler(BulkItemFilterScreen.class, new BulkFilterScreenGhost());

registration.addGuiContainerHandler(ModularRouterScreen.class, new IGuiContainerHandler<>() {
@Override
public List<Rect2i> getGuiExtraAreas(ModularRouterScreen routerScreen) {
return routerScreen.getExtraArea();
}
});
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
package me.desht.modularrouters.integration.jei;

public class ModuleScreenGhost /*implements IGhostIngredientHandler<AbstractModuleScreen>*/ {
// @Override
// public <I> List<Target<I>> getTargets(AbstractModuleScreen gui, I ingredient, boolean doStart) {
// List<Target<I>> res = new ArrayList<>();
// for (int i = 0; i < gui.getMenu().slots.size(); i++) {
// Slot s = gui.getMenu().getSlot(i);
// if (s instanceof FilterSlot) {
// res.add(new GhostTarget<>(gui, s));
// }
// }
// return res;
// }
//
// @Override
// public void onComplete() {
// }
import me.desht.modularrouters.client.gui.module.AbstractModuleScreen;
import me.desht.modularrouters.container.FilterSlot;
import mezz.jei.api.gui.handlers.IGhostIngredientHandler;
import mezz.jei.api.ingredients.ITypedIngredient;
import net.minecraft.world.inventory.Slot;

import java.util.ArrayList;
import java.util.List;

public class ModuleScreenGhost implements IGhostIngredientHandler<AbstractModuleScreen> {
@Override
public <I> List<Target<I>> getTargetsTyped(AbstractModuleScreen gui, ITypedIngredient<I> ingredient, boolean doStart) {
List<Target<I>> res = new ArrayList<>();
for (int i = 0; i < gui.getMenu().slots.size(); i++) {
Slot s = gui.getMenu().getSlot(i);
if (s instanceof FilterSlot) {
res.add(new GhostTarget<>(gui, s));
}
}
return res;
}

@Override
public void onComplete() {
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package me.desht.modularrouters.integration.top;

import mcjty.theoneprobe.api.IElement;
import mcjty.theoneprobe.api.IElementFactory;
import me.desht.modularrouters.item.module.ModuleItem;
import me.desht.modularrouters.util.ModuleHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import org.apache.commons.lang3.Validate;

public class ElementModule /*implements IElement*/ {
public class ElementModule implements IElement {
private final ItemStack stack;
private final ModuleItem.RelativeDirection dir;

Expand All @@ -21,41 +26,43 @@ public ElementModule(FriendlyByteBuf buf) {
this.dir = buf.readEnum(ModuleItem.RelativeDirection.class);
}

// @Override
// public void render(PoseStack matrixStack, int x, int y) {
@Override
public void render(GuiGraphics graphics, int x, int y) {
graphics.renderItem(stack, x + (getWidth() - 18) / 2, y + (getHeight() - 18) / 2);
graphics.renderItemDecorations(Minecraft.getInstance().font, stack, x + (getWidth() - 18) / 2, y + (getHeight() - 18) / 2, dir.getSymbol());
// GuiUtil.renderItemStack(matrixStack, Minecraft.getInstance(), stack, x + (getWidth() - 18) / 2, y + (getHeight() - 18) / 2, dir.getSymbol());
// }
//
// @Override
// public int getWidth() {
// return 20;
// }
//
// @Override
// public int getHeight() {
// return 20;
// }
//
// @Override
// public void toBytes(FriendlyByteBuf buffer) {
// buffer.writeItem(stack);
// buffer.writeEnum(dir);
// }
//
// @Override
// public ResourceLocation getID() {
// return TOPCompatibility.ELEMENT_MODULE_ITEM;
// }
//
// public static class Factory implements IElementFactory {
// @Override
// public IElement createElement(FriendlyByteBuf buf) {
// return new ElementModule(buf);
// }
//
// @Override
// public ResourceLocation getId() {
// return TOPCompatibility.ELEMENT_MODULE_ITEM;
// }
// }
}

@Override
public int getWidth() {
return 20;
}

@Override
public int getHeight() {
return 20;
}

@Override
public void toBytes(FriendlyByteBuf buffer) {
buffer.writeItem(stack);
buffer.writeEnum(dir);
}

@Override
public ResourceLocation getID() {
return TOPCompatibility.ELEMENT_MODULE_ITEM;
}

public static class Factory implements IElementFactory {
@Override
public IElement createElement(FriendlyByteBuf buf) {
return new ElementModule(buf);
}

@Override
public ResourceLocation getId() {
return TOPCompatibility.ELEMENT_MODULE_ITEM;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
package me.desht.modularrouters.integration.top;

import mcjty.theoneprobe.api.*;
import me.desht.modularrouters.ModularRouters;
import me.desht.modularrouters.block.ModularRouterBlock;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.fml.InterModComms;

import java.util.function.Function;

import static me.desht.modularrouters.util.MiscUtil.RL;

Expand All @@ -13,25 +22,25 @@ public static void register() {
if (registered)
return;
registered = true;
// InterModComms.sendTo("theoneprobe", "getTheOneProbe", () -> (Function<ITheOneProbe, Void>) iTheOneProbe -> {
// ModularRouters.LOGGER.info("Enabled support for The One Probe");
//
// iTheOneProbe.registerElementFactory(new ElementModule.Factory());
//
// iTheOneProbe.registerProvider(new IProbeInfoProvider() {
// @Override
// public ResourceLocation getID() {
// return RL("default");
// }
//
// @Override
// public void addProbeInfo(ProbeMode probeMode, IProbeInfo probeInfo, Player player, Level world, BlockState blockState, IProbeHitData iProbeHitData) {
// if (blockState.getBlock() instanceof ModularRouterBlock) {
// TOPInfoProvider.addProbeInfo(probeMode, probeInfo, player, world, blockState, iProbeHitData);
// }
// }
// });
// return null;
// });
InterModComms.sendTo("theoneprobe", "getTheOneProbe", () -> (Function<ITheOneProbe, Void>) iTheOneProbe -> {
ModularRouters.LOGGER.info("Enabled support for The One Probe");

iTheOneProbe.registerElementFactory(new ElementModule.Factory());

iTheOneProbe.registerProvider(new IProbeInfoProvider() {
@Override
public ResourceLocation getID() {
return RL("default");
}

@Override
public void addProbeInfo(ProbeMode probeMode, IProbeInfo probeInfo, Player player, Level world, BlockState blockState, IProbeHitData iProbeHitData) {
if (blockState.getBlock() instanceof ModularRouterBlock) {
TOPInfoProvider.addProbeInfo(probeMode, probeInfo, player, world, blockState, iProbeHitData);
}
}
});
return null;
});
}
}
Loading

0 comments on commit 2b5133a

Please sign in to comment.