Scout/src/main/java/pm/c7/scout/client/compat/ScoutEmiPlugin.java

93 lines
2.8 KiB
Java
Raw Normal View History

2024-03-14 05:09:55 +00:00
package pm.c7.scout.client.compat;
import dev.emi.emi.api.EmiPlugin;
import dev.emi.emi.api.EmiRegistry;
import dev.emi.emi.api.widget.Bounds;
import net.minecraft.client.MinecraftClient;
2024-03-18 18:01:19 +00:00
import net.minecraft.client.gui.screen.ingame.GenericContainerScreen;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.screen.ingame.ShulkerBoxScreen;
2024-03-14 05:09:55 +00:00
import net.minecraft.item.ItemStack;
import pm.c7.scout.ScoutUtil;
2024-03-18 18:01:19 +00:00
import pm.c7.scout.client.ScoutUtilClient;
2024-03-14 05:09:55 +00:00
import pm.c7.scout.item.BaseBagItem;
import pm.c7.scout.item.BaseBagItem.BagType;
import pm.c7.scout.mixin.client.HandledScreenAccessor;
public class ScoutEmiPlugin implements EmiPlugin {
2024-03-15 01:47:27 +00:00
@Override
public void register(EmiRegistry registry) {
2024-03-18 18:01:19 +00:00
registry.addGenericExclusionArea((screen, consumer) -> {
if (!(screen instanceof HandledScreen<?> handledScreen)) return;
if (ScoutUtilClient.isScreenBlacklisted(screen)) return;
2024-03-15 01:47:27 +00:00
MinecraftClient client = MinecraftClient.getInstance();
2024-03-18 18:01:19 +00:00
var handledScreenAccessor = (HandledScreenAccessor) handledScreen;
var sx = handledScreenAccessor.getX();
var sy = handledScreenAccessor.getY();
var sw = handledScreenAccessor.getBackgroundWidth();
var sh = handledScreenAccessor.getBackgroundHeight();
ItemStack satchelStack = ScoutUtil.findBagItem(client.player, BagType.SATCHEL, false);
if (!satchelStack.isEmpty()) {
BaseBagItem bagItem = (BaseBagItem) satchelStack.getItem();
int slots = bagItem.getSlotCount();
int rows = (int) Math.ceil(slots / 9);
int x = sx;
int y = sy + sh;
if (screen instanceof GenericContainerScreen || screen instanceof ShulkerBoxScreen) {
y -= 1;
}
int w = sw;
int h = (rows * 18) + 8;
consumer.accept(new Bounds(x, y, w, h));
}
2024-03-15 01:47:27 +00:00
ItemStack leftPouchStack = ScoutUtil.findBagItem(client.player, BagType.POUCH, false);
if (!leftPouchStack.isEmpty()) {
BaseBagItem bagItem = (BaseBagItem) leftPouchStack.getItem();
int slots = bagItem.getSlotCount();
int columns = (int) Math.ceil(slots / 3);
2024-03-18 18:01:19 +00:00
int x = sx - (columns * 18);
int y = (sy + sh) - 100;
if (screen instanceof GenericContainerScreen || screen instanceof ShulkerBoxScreen) {
y -= 1;
}
2024-03-15 01:47:27 +00:00
2024-03-18 18:01:19 +00:00
int w = (columns * 18);
int h = 68;
consumer.accept(new Bounds(x, y, w, h));
2024-03-15 01:47:27 +00:00
}
ItemStack rightPouchStack = ScoutUtil.findBagItem(client.player, BagType.POUCH, true);
if (!rightPouchStack.isEmpty()) {
BaseBagItem bagItem = (BaseBagItem) rightPouchStack.getItem();
int slots = bagItem.getSlotCount();
int columns = (int) Math.ceil(slots / 3);
2024-03-18 18:01:19 +00:00
int x = sx + sw;
int y = (sy + sh) - 100;
if (screen instanceof GenericContainerScreen || screen instanceof ShulkerBoxScreen) {
y -= 1;
}
int w = (columns * 18);
int h = 68;
2024-03-15 01:47:27 +00:00
2024-03-18 18:01:19 +00:00
consumer.accept(new Bounds(x, y, w, h));
2024-03-15 01:47:27 +00:00
}
});
}
2024-03-14 05:09:55 +00:00
}