From 2b5133aab157347913458f0cd43a7e9b2be6f096 Mon Sep 17 00:00:00 2001 From: Des Herriott Date: Sat, 24 Jun 2023 10:20:30 +0100 Subject: [PATCH] added back jei/top/jade integration --- .../jei/BulkFilterScreenGhost.java | 41 +++++---- .../integration/jei/GhostTarget.java | 41 +++++---- .../jei/JEIModularRoutersPlugin.java | 52 +++++++---- .../integration/jei/ModuleScreenGhost.java | 41 +++++---- .../integration/top/ElementModule.java | 81 +++++++++-------- .../integration/top/TOPCompatibility.java | 49 ++++++---- .../integration/top/TOPInfoProvider.java | 72 +++++++++------ .../waila/RouterComponentProvider.java | 91 +++++++++++-------- .../integration/waila/RouterDataProvider.java | 81 ++++++++++------- .../integration/waila/WailaIntegration.java | 29 +++--- 10 files changed, 343 insertions(+), 235 deletions(-) diff --git a/src/main/java/me/desht/modularrouters/integration/jei/BulkFilterScreenGhost.java b/src/main/java/me/desht/modularrouters/integration/jei/BulkFilterScreenGhost.java index a8d91f8e..65b2ab72 100644 --- a/src/main/java/me/desht/modularrouters/integration/jei/BulkFilterScreenGhost.java +++ b/src/main/java/me/desht/modularrouters/integration/jei/BulkFilterScreenGhost.java @@ -1,19 +1,28 @@ package me.desht.modularrouters.integration.jei; -public class BulkFilterScreenGhost /*implements IGhostIngredientHandler*/ { -// @Override -// public List> getTargets(BulkItemFilterScreen gui, I ingredient, boolean doStart) { -// List> 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 { + @Override + public List> getTargetsTyped(BulkItemFilterScreen gui, ITypedIngredient ingredient, boolean doStart) { + List> 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() { + } } diff --git a/src/main/java/me/desht/modularrouters/integration/jei/GhostTarget.java b/src/main/java/me/desht/modularrouters/integration/jei/GhostTarget.java index 0001ad3f..8c411cfe 100644 --- a/src/main/java/me/desht/modularrouters/integration/jei/GhostTarget.java +++ b/src/main/java/me/desht/modularrouters/integration/jei/GhostTarget.java @@ -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(AbstractContainerScreen gui, Slot slot) /*implements IGhostIngredientHandler.Target*/ { -// @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(AbstractContainerScreen gui, Slot slot) implements IGhostIngredientHandler.Target { + @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)); + } + } + } } diff --git a/src/main/java/me/desht/modularrouters/integration/jei/JEIModularRoutersPlugin.java b/src/main/java/me/desht/modularrouters/integration/jei/JEIModularRoutersPlugin.java index 619040c2..08a49614 100644 --- a/src/main/java/me/desht/modularrouters/integration/jei/JEIModularRoutersPlugin.java +++ b/src/main/java/me/desht/modularrouters/integration/jei/JEIModularRoutersPlugin.java @@ -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 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 getGuiExtraAreas(ModularRouterScreen routerScreen) { + return routerScreen.getExtraArea(); + } + }); + } } diff --git a/src/main/java/me/desht/modularrouters/integration/jei/ModuleScreenGhost.java b/src/main/java/me/desht/modularrouters/integration/jei/ModuleScreenGhost.java index 920dc7c6..b35ae6f2 100644 --- a/src/main/java/me/desht/modularrouters/integration/jei/ModuleScreenGhost.java +++ b/src/main/java/me/desht/modularrouters/integration/jei/ModuleScreenGhost.java @@ -1,19 +1,28 @@ package me.desht.modularrouters.integration.jei; -public class ModuleScreenGhost /*implements IGhostIngredientHandler*/ { -// @Override -// public List> getTargets(AbstractModuleScreen gui, I ingredient, boolean doStart) { -// List> 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 { + @Override + public List> getTargetsTyped(AbstractModuleScreen gui, ITypedIngredient ingredient, boolean doStart) { + List> 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() { + } } diff --git a/src/main/java/me/desht/modularrouters/integration/top/ElementModule.java b/src/main/java/me/desht/modularrouters/integration/top/ElementModule.java index f0f52a30..d480bd07 100644 --- a/src/main/java/me/desht/modularrouters/integration/top/ElementModule.java +++ b/src/main/java/me/desht/modularrouters/integration/top/ElementModule.java @@ -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; @@ -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; + } + } } diff --git a/src/main/java/me/desht/modularrouters/integration/top/TOPCompatibility.java b/src/main/java/me/desht/modularrouters/integration/top/TOPCompatibility.java index a4cd2bab..6ad93baa 100644 --- a/src/main/java/me/desht/modularrouters/integration/top/TOPCompatibility.java +++ b/src/main/java/me/desht/modularrouters/integration/top/TOPCompatibility.java @@ -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; @@ -13,25 +22,25 @@ public static void register() { if (registered) return; registered = true; -// InterModComms.sendTo("theoneprobe", "getTheOneProbe", () -> (Function) 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 -> { + 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; + }); } } \ No newline at end of file diff --git a/src/main/java/me/desht/modularrouters/integration/top/TOPInfoProvider.java b/src/main/java/me/desht/modularrouters/integration/top/TOPInfoProvider.java index 105c0efe..01973702 100644 --- a/src/main/java/me/desht/modularrouters/integration/top/TOPInfoProvider.java +++ b/src/main/java/me/desht/modularrouters/integration/top/TOPInfoProvider.java @@ -1,34 +1,46 @@ package me.desht.modularrouters.integration.top; +import mcjty.theoneprobe.api.IProbeHitData; +import mcjty.theoneprobe.api.IProbeInfo; +import mcjty.theoneprobe.api.ProbeMode; +import me.desht.modularrouters.core.ModBlockEntities; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.items.IItemHandler; + class TOPInfoProvider { -// static void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, Player player, Level world, BlockState blockState, IProbeHitData data) { -// world.getBlockEntity(data.getPos(), ModBlockEntities.MODULAR_ROUTER.get()).ifPresent(router -> { -// if (router.isPermitted(player)) { -// IItemHandler modules = router.getModules(); -// IProbeInfo sub = probeInfo.horizontal(); -// for (int i = 0; i < modules.getSlots(); i++) { -// ItemStack stack = modules.getStackInSlot(i); -// if (!stack.isEmpty()) { -// sub.element(new ElementModule(stack)); -// } -// } -// sub = probeInfo.horizontal(); -// IItemHandler upgrades = router.getUpgrades(); -// for (int i = 0; i < upgrades.getSlots(); i++) { -// ItemStack stack = upgrades.getStackInSlot(i); -// if (!stack.isEmpty()) { -// sub.item(stack); -// } -// } -// -// probeInfo.text(Component.literal(ChatFormatting.YELLOW.toString()) -// .append(Component.translatable("modularrouters.guiText.tooltip.redstone.label")) -// .append(ChatFormatting.WHITE + ": ") -// .append(Component.translatable(router.getRedstoneBehaviour().getTranslationKey())) -// ); -// } else { -// probeInfo.text(Component.translatable("modularrouters.chatText.security.accessDenied")); -// } -// }); -// } + static void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, Player player, Level world, BlockState blockState, IProbeHitData data) { + world.getBlockEntity(data.getPos(), ModBlockEntities.MODULAR_ROUTER.get()).ifPresent(router -> { + if (router.isPermitted(player)) { + IItemHandler modules = router.getModules(); + IProbeInfo sub = probeInfo.horizontal(); + for (int i = 0; i < modules.getSlots(); i++) { + ItemStack stack = modules.getStackInSlot(i); + if (!stack.isEmpty()) { + sub.element(new ElementModule(stack)); + } + } + sub = probeInfo.horizontal(); + IItemHandler upgrades = router.getUpgrades(); + for (int i = 0; i < upgrades.getSlots(); i++) { + ItemStack stack = upgrades.getStackInSlot(i); + if (!stack.isEmpty()) { + sub.item(stack); + } + } + + probeInfo.text(Component.literal(ChatFormatting.YELLOW.toString()) + .append(Component.translatable("modularrouters.guiText.tooltip.redstone.label")) + .append(ChatFormatting.WHITE + ": ") + .append(Component.translatable(router.getRedstoneBehaviour().getTranslationKey())) + ); + } else { + probeInfo.text(Component.translatable("modularrouters.chatText.security.accessDenied")); + } + }); + } } diff --git a/src/main/java/me/desht/modularrouters/integration/waila/RouterComponentProvider.java b/src/main/java/me/desht/modularrouters/integration/waila/RouterComponentProvider.java index 8a52ef58..a86003aa 100644 --- a/src/main/java/me/desht/modularrouters/integration/waila/RouterComponentProvider.java +++ b/src/main/java/me/desht/modularrouters/integration/waila/RouterComponentProvider.java @@ -1,40 +1,59 @@ package me.desht.modularrouters.integration.waila; -public class RouterComponentProvider /*implements IBlockComponentProvider*/ { -// @Override -// public void appendTooltip(ITooltip iTooltip, BlockAccessor blockAccessor, IPluginConfig iPluginConfig) { -// CompoundTag data = blockAccessor.getServerData(); -// if (blockAccessor.getBlockEntity() instanceof ModularRouterBlockEntity) { -// if (data.getBoolean("Denied")) { -// iTooltip.add(xlate("modularrouters.chatText.security.accessDenied")); -// } else { -// if (data.getInt("ModuleCount") > 0) { -// List componentList = new ArrayList<>(); -// MiscUtil.appendMultilineText(componentList, ChatFormatting.WHITE, "modularrouters.itemText.misc.moduleCount", data.getInt("ModuleCount")); -// iTooltip.addAll(componentList); -// } -// CompoundTag upgrades = data.getCompound("Upgrades"); -// if (!upgrades.isEmpty()) { -// iTooltip.add(xlate("modularrouters.itemText.misc.upgrades")); -// for (String k : upgrades.getAllKeys()) { -// iTooltip.add(xlate("modularrouters.itemText.misc.upgradeCount", upgrades.getInt(k), I18n.get(k))); -// } -// } -// RouterRedstoneBehaviour rrb = RouterRedstoneBehaviour.values()[data.getInt("RedstoneMode")]; -// iTooltip.add(xlate("modularrouters.guiText.tooltip.redstone.label") -// .append(": " + ChatFormatting.AQUA) -// .append(xlate("modularrouters.guiText.tooltip.redstone." + rrb)) -// ); -// if (data.getBoolean("EcoMode")) { -// iTooltip.add(xlate("modularrouters.itemText.misc.ecoMode")); -// } -// } -// } -// } -// -// @Override -// public ResourceLocation getUid() { -// return RL("router"); -// } +import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; +import me.desht.modularrouters.logic.RouterRedstoneBehaviour; +import me.desht.modularrouters.util.MiscUtil; +import net.minecraft.ChatFormatting; +import net.minecraft.client.resources.language.I18n; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import snownee.jade.api.BlockAccessor; +import snownee.jade.api.IBlockComponentProvider; +import snownee.jade.api.ITooltip; +import snownee.jade.api.config.IPluginConfig; + +import java.util.ArrayList; +import java.util.List; + +import static me.desht.modularrouters.client.util.ClientUtil.xlate; +import static me.desht.modularrouters.util.MiscUtil.RL; + +public class RouterComponentProvider implements IBlockComponentProvider { + @Override + public void appendTooltip(ITooltip iTooltip, BlockAccessor blockAccessor, IPluginConfig iPluginConfig) { + CompoundTag data = blockAccessor.getServerData(); + if (blockAccessor.getBlockEntity() instanceof ModularRouterBlockEntity) { + if (data.getBoolean("Denied")) { + iTooltip.add(xlate("modularrouters.chatText.security.accessDenied")); + } else { + if (data.getInt("ModuleCount") > 0) { + List componentList = new ArrayList<>(); + MiscUtil.appendMultilineText(componentList, ChatFormatting.WHITE, "modularrouters.itemText.misc.moduleCount", data.getInt("ModuleCount")); + iTooltip.addAll(componentList); + } + CompoundTag upgrades = data.getCompound("Upgrades"); + if (!upgrades.isEmpty()) { + iTooltip.add(xlate("modularrouters.itemText.misc.upgrades")); + for (String k : upgrades.getAllKeys()) { + iTooltip.add(xlate("modularrouters.itemText.misc.upgradeCount", upgrades.getInt(k), I18n.get(k))); + } + } + RouterRedstoneBehaviour rrb = RouterRedstoneBehaviour.values()[data.getInt("RedstoneMode")]; + iTooltip.add(xlate("modularrouters.guiText.tooltip.redstone.label") + .append(": " + ChatFormatting.AQUA) + .append(xlate("modularrouters.guiText.tooltip.redstone." + rrb)) + ); + if (data.getBoolean("EcoMode")) { + iTooltip.add(xlate("modularrouters.itemText.misc.ecoMode")); + } + } + } + } + + @Override + public ResourceLocation getUid() { + return RL("router"); + } } diff --git a/src/main/java/me/desht/modularrouters/integration/waila/RouterDataProvider.java b/src/main/java/me/desht/modularrouters/integration/waila/RouterDataProvider.java index 2cbcaa07..31063782 100644 --- a/src/main/java/me/desht/modularrouters/integration/waila/RouterDataProvider.java +++ b/src/main/java/me/desht/modularrouters/integration/waila/RouterDataProvider.java @@ -1,36 +1,51 @@ package me.desht.modularrouters.integration.waila; -public class RouterDataProvider /*implements IServerDataProvider*/ { -// @Override -// public void appendServerData(CompoundTag compoundTag, ServerPlayer serverPlayer, Level level, BlockEntity blockEntity, boolean b) { -// if (blockEntity instanceof ModularRouterBlockEntity router) { -// if (router.isPermitted(serverPlayer)) { -// compoundTag.putInt("ModuleCount", router.getModuleCount()); -// compoundTag.putInt("RedstoneMode", router.getRedstoneBehaviour().ordinal()); -// compoundTag.putBoolean("EcoMode", router.getEcoMode()); -// compoundTag.put("Upgrades", getUpgrades(router)); -// } else { -// compoundTag.putBoolean("Denied", true); -// } -// } -// } -// -// private CompoundTag getUpgrades(ModularRouterBlockEntity router) { -// IItemHandler handler = router.getUpgrades(); -// Map counts = new HashMap<>(); -// for (int i = 0; i < handler.getSlots(); i++) { -// ItemStack stack = handler.getStackInSlot(i); -// if (stack.getItem() instanceof UpgradeItem) { -// counts.put(stack.getItem(), counts.getOrDefault(stack.getItem(), 0) + stack.getCount()); -// } -// } -// CompoundTag upgrades = new CompoundTag(); -// counts.forEach((k, v) -> upgrades.putInt(k.getDescriptionId(), v)); -// return upgrades; -// } -// -// @Override -// public ResourceLocation getUid() { -// return RL("router"); -// } +import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; +import me.desht.modularrouters.item.upgrade.UpgradeItem; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraftforge.items.IItemHandler; +import snownee.jade.api.BlockAccessor; +import snownee.jade.api.IServerDataProvider; + +import java.util.HashMap; +import java.util.Map; + +import static me.desht.modularrouters.util.MiscUtil.RL; + +public class RouterDataProvider implements IServerDataProvider { + @Override + public void appendServerData(CompoundTag compoundTag, BlockAccessor accessor) { + if (accessor.getBlockEntity() instanceof ModularRouterBlockEntity router) { + if (router.isPermitted(accessor.getPlayer())) { + compoundTag.putInt("ModuleCount", router.getModuleCount()); + compoundTag.putInt("RedstoneMode", router.getRedstoneBehaviour().ordinal()); + compoundTag.putBoolean("EcoMode", router.getEcoMode()); + compoundTag.put("Upgrades", getUpgrades(router)); + } else { + compoundTag.putBoolean("Denied", true); + } + } + } + + private CompoundTag getUpgrades(ModularRouterBlockEntity router) { + IItemHandler handler = router.getUpgrades(); + Map counts = new HashMap<>(); + for (int i = 0; i < handler.getSlots(); i++) { + ItemStack stack = handler.getStackInSlot(i); + if (stack.getItem() instanceof UpgradeItem) { + counts.put(stack.getItem(), counts.getOrDefault(stack.getItem(), 0) + stack.getCount()); + } + } + CompoundTag upgrades = new CompoundTag(); + counts.forEach((k, v) -> upgrades.putInt(k.getDescriptionId(), v)); + return upgrades; + } + + @Override + public ResourceLocation getUid() { + return RL("router"); + } } diff --git a/src/main/java/me/desht/modularrouters/integration/waila/WailaIntegration.java b/src/main/java/me/desht/modularrouters/integration/waila/WailaIntegration.java index f2bf2caa..3da8eea0 100644 --- a/src/main/java/me/desht/modularrouters/integration/waila/WailaIntegration.java +++ b/src/main/java/me/desht/modularrouters/integration/waila/WailaIntegration.java @@ -1,14 +1,21 @@ package me.desht.modularrouters.integration.waila; -//@WailaPlugin -public class WailaIntegration /*implements IWailaPlugin*/ { -// @Override -// public void register(IWailaCommonRegistration registration) { -// registration.registerBlockDataProvider(new RouterDataProvider(), ModularRouterBlockEntity.class); -// } -// -// @Override -// public void registerClient(IWailaClientRegistration registration) { -// registration.registerBlockComponent(new RouterComponentProvider(), ModularRouterBlock.class); -// } +import me.desht.modularrouters.block.ModularRouterBlock; +import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; +import snownee.jade.api.IWailaClientRegistration; +import snownee.jade.api.IWailaCommonRegistration; +import snownee.jade.api.IWailaPlugin; +import snownee.jade.api.WailaPlugin; + +@WailaPlugin +public class WailaIntegration implements IWailaPlugin { + @Override + public void register(IWailaCommonRegistration registration) { + registration.registerBlockDataProvider(new RouterDataProvider(), ModularRouterBlockEntity.class); + } + + @Override + public void registerClient(IWailaClientRegistration registration) { + registration.registerBlockComponent(new RouterComponentProvider(), ModularRouterBlock.class); + } }