package org.chrisoft.trashyaddon.modules; import meteordevelopment.meteorclient.events.packets.InventoryEvent; import meteordevelopment.meteorclient.events.packets.PacketEvent; import meteordevelopment.meteorclient.systems.modules.Module; import meteordevelopment.meteorclient.systems.modules.Categories; import meteordevelopment.meteorclient.utils.render.color.Color; import meteordevelopment.orbit.EventHandler; import net.minecraft.item.ItemStack; import net.minecraft.network.packet.c2s.play.CloseHandledScreenC2SPacket; import net.minecraft.network.packet.s2c.play.CloseScreenS2CPacket; import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket; import net.minecraft.screen.PlayerScreenHandler; import net.minecraft.screen.ScreenHandler; import java.util.ArrayList; public class MatchedItemHighlight extends Module { private ScreenHandler screenHandler; private final ArrayList slotColors; private static final Color transparent = new Color(0, 0, 0, 0); public MatchedItemHighlight() { super(Categories.Render, "Combinable Slots", "Highlight items that can be combined in your inventory and a container."); slotColors = new ArrayList<>(); } public void onActivate() { screenHandler = null; } public Color getSlotColor(int index) { if (!this.isActive() || index >= slotColors.size()) return transparent; return slotColors.get(index); } private void updateColors() { if (screenHandler == null) return; slotColors.clear(); for (int i = 0 ; i < screenHandler.slots.size(); ++i) slotColors.add(new Color(transparent)); int firstInventorySlot = screenHandler.slots.size() - 36; if (firstInventorySlot <= 0) return; int colorIndex = 0; for (int i = 0; i < firstInventorySlot; ++ i) { if (screenHandler.getSlot(i).getStack().isEmpty()) continue; for (int j = firstInventorySlot; j < screenHandler.slots.size(); ++ j) { if (screenHandler.getSlot(j).getStack().isEmpty()) continue; if (ItemStack.areItemsAndComponentsEqual(screenHandler.getSlot(i).getStack(), screenHandler.getSlot(j).getStack()) || ItemStack.areItemsAndComponentsEqual(screenHandler.getSlot(j).getStack(), screenHandler.getSlot(i).getStack())) { Color c; if (!slotColors.get(i).equals(transparent)) c = new Color(slotColors.get(i)); else if (!slotColors.get(j).equals(transparent)) c = new Color(slotColors.get(j)); else { c = Color.fromHsv(colorIndex * 45, 0.6, 1.).a(160); ++ colorIndex; if (colorIndex > 7) colorIndex = 0; } slotColors.set(i, new Color(c)); slotColors.set(j, new Color(c)); } } } } @EventHandler private void onInventory(InventoryEvent event) { if (mc.player.currentScreenHandler instanceof PlayerScreenHandler) return; screenHandler = mc.player.currentScreenHandler; if (screenHandler != null && event.packet.getSyncId() == screenHandler.syncId) updateColors(); } @EventHandler private void onReceivePacket(PacketEvent.Receive e) { if (e.packet instanceof ScreenHandlerSlotUpdateS2CPacket p) { if (screenHandler != null && p.getSyncId() == screenHandler.syncId) updateColors(); } else if (e.packet instanceof CloseScreenS2CPacket) { screenHandler = null; slotColors.clear(); } } @EventHandler private void onSendPacket(PacketEvent.Send e) { if (e.packet instanceof CloseHandledScreenC2SPacket p) { screenHandler = null; slotColors.clear(); } } }