Normalize indentation

This commit is contained in:
Cynthia Foxwell 2024-03-14 19:47:27 -06:00
parent 8712c28b0e
commit b803b794f8
14 changed files with 370 additions and 378 deletions

View file

@ -3,5 +3,5 @@ package pm.c7.scout;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
public class ScoutNetworking { public class ScoutNetworking {
public static final Identifier ENABLE_SLOTS = new Identifier(ScoutUtil.MOD_ID, "enable_slots"); public static final Identifier ENABLE_SLOTS = new Identifier(ScoutUtil.MOD_ID, "enable_slots");
} }

View file

@ -4,7 +4,7 @@ import net.minecraft.util.collection.DefaultedList;
import pm.c7.scout.screen.BagSlot; import pm.c7.scout.screen.BagSlot;
public interface ScoutScreenHandler { public interface ScoutScreenHandler {
DefaultedList<BagSlot> scout$getSatchelSlots(); DefaultedList<BagSlot> scout$getSatchelSlots();
DefaultedList<BagSlot> scout$getLeftPouchSlots(); DefaultedList<BagSlot> scout$getLeftPouchSlots();
DefaultedList<BagSlot> scout$getRightPouchSlots(); DefaultedList<BagSlot> scout$getRightPouchSlots();
} }

View file

@ -16,6 +16,7 @@ import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList; import net.minecraft.nbt.NbtList;
import net.minecraft.screen.PlayerScreenHandler; import net.minecraft.screen.PlayerScreenHandler;
import net.minecraft.screen.slot.Slot; import net.minecraft.screen.slot.Slot;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.Pair; import net.minecraft.util.Pair;
import net.minecraft.util.collection.DefaultedList; import net.minecraft.util.collection.DefaultedList;
@ -44,59 +45,59 @@ public class ScoutUtil {
public static final int BAG_SLOTS_END = RIGHT_POUCH_SLOT_START - MAX_POUCH_SLOTS; public static final int BAG_SLOTS_END = RIGHT_POUCH_SLOT_START - MAX_POUCH_SLOTS;
public static ItemStack findBagItem(PlayerEntity player, BaseBagItem.BagType type, boolean right) { public static ItemStack findBagItem(PlayerEntity player, BaseBagItem.BagType type, boolean right) {
ItemStack targetStack = ItemStack.EMPTY; ItemStack targetStack = ItemStack.EMPTY;
boolean hasFirstPouch = false; boolean hasFirstPouch = false;
Optional<TrinketComponent> _component = TrinketsApi.getTrinketComponent(player); Optional<TrinketComponent> _component = TrinketsApi.getTrinketComponent(player);
if (_component.isPresent()) { if (_component.isPresent()) {
TrinketComponent component = _component.get(); TrinketComponent component = _component.get();
for (Pair<SlotReference, ItemStack> pair : component.getAllEquipped()) { for (Pair<SlotReference, ItemStack> pair : component.getAllEquipped()) {
ItemStack slotStack = pair.getRight(); ItemStack slotStack = pair.getRight();
if (slotStack.getItem() instanceof BaseBagItem bagItem) { if (slotStack.getItem() instanceof BaseBagItem bagItem) {
if (bagItem.getType() == type) { if (bagItem.getType() == type) {
if (type == BagType.POUCH) { if (type == BagType.POUCH) {
if (right && !hasFirstPouch) { if (right && !hasFirstPouch) {
hasFirstPouch = true; hasFirstPouch = true;
} else { } else {
targetStack = slotStack; targetStack = slotStack;
break; break;
} }
} else { } else {
targetStack = slotStack; targetStack = slotStack;
break; break;
} }
} }
} }
} }
} }
return targetStack; return targetStack;
} }
public static NbtList inventoryToTag(Inventory inventory) { public static NbtList inventoryToTag(Inventory inventory) {
NbtList tag = new NbtList(); NbtList tag = new NbtList();
for(int i = 0; i < inventory.size(); i++) { for(int i = 0; i < inventory.size(); i++) {
NbtCompound stackTag = new NbtCompound(); NbtCompound stackTag = new NbtCompound();
stackTag.putInt("Slot", i); stackTag.putInt("Slot", i);
stackTag.put("Stack", inventory.getStack(i).writeNbt(new NbtCompound())); stackTag.put("Stack", inventory.getStack(i).writeNbt(new NbtCompound()));
tag.add(stackTag); tag.add(stackTag);
} }
return tag; return tag;
} }
public static void inventoryFromTag(NbtList tag, Inventory inventory) { public static void inventoryFromTag(NbtList tag, Inventory inventory) {
inventory.clear(); inventory.clear();
tag.forEach(element -> { tag.forEach(element -> {
NbtCompound stackTag = (NbtCompound) element; NbtCompound stackTag = (NbtCompound) element;
int slot = stackTag.getInt("Slot"); int slot = stackTag.getInt("Slot");
ItemStack stack = ItemStack.fromNbt(stackTag.getCompound("Stack")); ItemStack stack = ItemStack.fromNbt(stackTag.getCompound("Stack"));
inventory.setStack(slot, stack); inventory.setStack(slot, stack);
}); });
} }
public static boolean isBagSlot(int slot) { public static boolean isBagSlot(int slot) {
return slot <= SATCHEL_SLOT_START && slot > BAG_SLOTS_END; return slot <= SATCHEL_SLOT_START && slot > BAG_SLOTS_END;

View file

@ -27,79 +27,79 @@ import pm.c7.scout.mixin.client.HandledScreenAccessor;
import pm.c7.scout.screen.BagSlot; import pm.c7.scout.screen.BagSlot;
public class ScoutClient implements ClientModInitializer { public class ScoutClient implements ClientModInitializer {
@Override @Override
public void onInitializeClient(ModContainer mod) { public void onInitializeClient(ModContainer mod) {
ClientPlayNetworking.registerGlobalReceiver(ScoutNetworking.ENABLE_SLOTS, (client, handler, packet, sender) -> { ClientPlayNetworking.registerGlobalReceiver(ScoutNetworking.ENABLE_SLOTS, (client, handler, packet, sender) -> {
client.execute(() -> { client.execute(() -> {
assert client.player != null; assert client.player != null;
ScoutScreenHandler screenHandler = (ScoutScreenHandler) client.player.playerScreenHandler; ScoutScreenHandler screenHandler = (ScoutScreenHandler) client.player.playerScreenHandler;
ItemStack satchelStack = ScoutUtil.findBagItem(client.player, BagType.SATCHEL, false); ItemStack satchelStack = ScoutUtil.findBagItem(client.player, BagType.SATCHEL, false);
DefaultedList<BagSlot> satchelSlots = screenHandler.scout$getSatchelSlots(); DefaultedList<BagSlot> satchelSlots = screenHandler.scout$getSatchelSlots();
for (int i = 0; i < ScoutUtil.MAX_SATCHEL_SLOTS; i++) { for (int i = 0; i < ScoutUtil.MAX_SATCHEL_SLOTS; i++) {
BagSlot slot = satchelSlots.get(i); BagSlot slot = satchelSlots.get(i);
slot.setInventory(null); slot.setInventory(null);
slot.setEnabled(false); slot.setEnabled(false);
} }
if (!satchelStack.isEmpty()) { if (!satchelStack.isEmpty()) {
BaseBagItem satchelItem = (BaseBagItem) satchelStack.getItem(); BaseBagItem satchelItem = (BaseBagItem) satchelStack.getItem();
Inventory satchelInv = satchelItem.getInventory(satchelStack); Inventory satchelInv = satchelItem.getInventory(satchelStack);
for (int i = 0; i < satchelItem.getSlotCount(); i++) { for (int i = 0; i < satchelItem.getSlotCount(); i++) {
BagSlot slot = satchelSlots.get(i); BagSlot slot = satchelSlots.get(i);
slot.setInventory(satchelInv); slot.setInventory(satchelInv);
slot.setEnabled(true); slot.setEnabled(true);
} }
} }
ItemStack leftPouchStack = ScoutUtil.findBagItem(client.player, BagType.POUCH, false); ItemStack leftPouchStack = ScoutUtil.findBagItem(client.player, BagType.POUCH, false);
DefaultedList<BagSlot> leftPouchSlots = screenHandler.scout$getLeftPouchSlots(); DefaultedList<BagSlot> leftPouchSlots = screenHandler.scout$getLeftPouchSlots();
for (int i = 0; i < ScoutUtil.MAX_POUCH_SLOTS; i++) { for (int i = 0; i < ScoutUtil.MAX_POUCH_SLOTS; i++) {
BagSlot slot = leftPouchSlots.get(i); BagSlot slot = leftPouchSlots.get(i);
slot.setInventory(null); slot.setInventory(null);
slot.setEnabled(false); slot.setEnabled(false);
} }
if (!leftPouchStack.isEmpty()) { if (!leftPouchStack.isEmpty()) {
BaseBagItem leftPouchItem = (BaseBagItem) leftPouchStack.getItem(); BaseBagItem leftPouchItem = (BaseBagItem) leftPouchStack.getItem();
Inventory leftPouchInv = leftPouchItem.getInventory(leftPouchStack); Inventory leftPouchInv = leftPouchItem.getInventory(leftPouchStack);
for (int i = 0; i < leftPouchItem.getSlotCount(); i++) { for (int i = 0; i < leftPouchItem.getSlotCount(); i++) {
BagSlot slot = leftPouchSlots.get(i); BagSlot slot = leftPouchSlots.get(i);
slot.setInventory(leftPouchInv); slot.setInventory(leftPouchInv);
slot.setEnabled(true); slot.setEnabled(true);
} }
} }
ItemStack rightPouchStack = ScoutUtil.findBagItem(client.player, BagType.POUCH, true); ItemStack rightPouchStack = ScoutUtil.findBagItem(client.player, BagType.POUCH, true);
DefaultedList<BagSlot> rightPouchSlots = screenHandler.scout$getRightPouchSlots(); DefaultedList<BagSlot> rightPouchSlots = screenHandler.scout$getRightPouchSlots();
for (int i = 0; i < ScoutUtil.MAX_POUCH_SLOTS; i++) { for (int i = 0; i < ScoutUtil.MAX_POUCH_SLOTS; i++) {
BagSlot slot = rightPouchSlots.get(i); BagSlot slot = rightPouchSlots.get(i);
slot.setInventory(null); slot.setInventory(null);
slot.setEnabled(false); slot.setEnabled(false);
} }
if (!rightPouchStack.isEmpty()) { if (!rightPouchStack.isEmpty()) {
BaseBagItem rightPouchItem = (BaseBagItem) rightPouchStack.getItem(); BaseBagItem rightPouchItem = (BaseBagItem) rightPouchStack.getItem();
Inventory rightPouchInv = rightPouchItem.getInventory(rightPouchStack); Inventory rightPouchInv = rightPouchItem.getInventory(rightPouchStack);
for (int i = 0; i < rightPouchItem.getSlotCount(); i++) { for (int i = 0; i < rightPouchItem.getSlotCount(); i++) {
BagSlot slot = rightPouchSlots.get(i); BagSlot slot = rightPouchSlots.get(i);
slot.setInventory(rightPouchInv); slot.setInventory(rightPouchInv);
slot.setEnabled(true); slot.setEnabled(true);
} }
} }
}); });
}); });
TooltipComponentCallback.EVENT.register(data -> { TooltipComponentCallback.EVENT.register(data -> {
if (data instanceof BagTooltipData d) { if (data instanceof BagTooltipData d) {
return new BagTooltipComponent(d); return new BagTooltipComponent(d);
} }
return null; return null;
}); });
LivingEntityFeatureRendererRegistrationCallback.EVENT.register((entityType, entityRenderer, registrationHelper, context) -> { LivingEntityFeatureRendererRegistrationCallback.EVENT.register((entityType, entityRenderer, registrationHelper, context) -> {
if (entityType == EntityType.PLAYER) { if (entityType == EntityType.PLAYER) {
@ -200,5 +200,5 @@ public class ScoutClient implements ClientModInitializer {
} }
} }
}); });
} }
} }

View file

@ -12,34 +12,34 @@ import pm.c7.scout.item.BaseBagItem.BagType;
import pm.c7.scout.mixin.client.HandledScreenAccessor; import pm.c7.scout.mixin.client.HandledScreenAccessor;
public class ScoutEmiPlugin implements EmiPlugin { public class ScoutEmiPlugin implements EmiPlugin {
@Override @Override
public void register(EmiRegistry registry) { public void register(EmiRegistry registry) {
registry.addExclusionArea(InventoryScreen.class, (screen, consumer) -> { registry.addExclusionArea(InventoryScreen.class, (screen, consumer) -> {
MinecraftClient client = MinecraftClient.getInstance(); MinecraftClient client = MinecraftClient.getInstance();
ItemStack leftPouchStack = ScoutUtil.findBagItem(client.player, BagType.POUCH, false); ItemStack leftPouchStack = ScoutUtil.findBagItem(client.player, BagType.POUCH, false);
if (!leftPouchStack.isEmpty()) { if (!leftPouchStack.isEmpty()) {
BaseBagItem bagItem = (BaseBagItem) leftPouchStack.getItem(); BaseBagItem bagItem = (BaseBagItem) leftPouchStack.getItem();
int slots = bagItem.getSlotCount(); int slots = bagItem.getSlotCount();
int columns = (int) Math.ceil(slots / 3); int columns = (int) Math.ceil(slots / 3);
int x = ((HandledScreenAccessor) screen).getX() - (columns * 18); int x = ((HandledScreenAccessor) screen).getX() - (columns * 18);
int y = ((HandledScreenAccessor) screen).getY() + 76; int y = ((HandledScreenAccessor) screen).getY() + 76;
consumer.accept(new Bounds(x, y, columns * 18, 68)); consumer.accept(new Bounds(x, y, columns * 18, 68));
} }
ItemStack rightPouchStack = ScoutUtil.findBagItem(client.player, BagType.POUCH, true); ItemStack rightPouchStack = ScoutUtil.findBagItem(client.player, BagType.POUCH, true);
if (!rightPouchStack.isEmpty()) { if (!rightPouchStack.isEmpty()) {
BaseBagItem bagItem = (BaseBagItem) rightPouchStack.getItem(); BaseBagItem bagItem = (BaseBagItem) rightPouchStack.getItem();
int slots = bagItem.getSlotCount(); int slots = bagItem.getSlotCount();
int columns = (int) Math.ceil(slots / 3); int columns = (int) Math.ceil(slots / 3);
int x = ((HandledScreenAccessor) screen).getX() + 176; int x = ((HandledScreenAccessor) screen).getX() + 176;
int y = ((HandledScreenAccessor) screen).getY() + 76; int y = ((HandledScreenAccessor) screen).getY() + 76;
consumer.accept(new Bounds(x, y, columns * 18, 68)); consumer.accept(new Bounds(x, y, columns * 18, 68));
} }
}); });
} }
} }

View file

@ -5,19 +5,19 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.collection.DefaultedList; import net.minecraft.util.collection.DefaultedList;
public class BagTooltipData implements TooltipData { public class BagTooltipData implements TooltipData {
private final DefaultedList<ItemStack> inventory; private final DefaultedList<ItemStack> inventory;
private final int slotCount; private final int slotCount;
public BagTooltipData(DefaultedList<ItemStack> inventory, int slots) { public BagTooltipData(DefaultedList<ItemStack> inventory, int slots) {
this.inventory = inventory; this.inventory = inventory;
this.slotCount = slots; this.slotCount = slots;
} }
public DefaultedList<ItemStack> getInventory() { public DefaultedList<ItemStack> getInventory() {
return this.inventory; return this.inventory;
} }
public int getSlotCount() { public int getSlotCount() {
return this.slotCount; return this.slotCount;
} }
} }

View file

@ -31,85 +31,85 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
public class BaseBagItem extends TrinketItem { public class BaseBagItem extends TrinketItem {
private static final String ITEMS_KEY = "Items"; private static final String ITEMS_KEY = "Items";
private final int slots; private final int slots;
private final BagType type; private final BagType type;
public BaseBagItem(Settings settings, int slots, BagType type) { public BaseBagItem(Settings settings, int slots, BagType type) {
super(settings); super(settings);
if (type == BagType.SATCHEL && slots > ScoutUtil.MAX_SATCHEL_SLOTS) { if (type == BagType.SATCHEL && slots > ScoutUtil.MAX_SATCHEL_SLOTS) {
throw new IllegalArgumentException("Satchel has too many slots."); throw new IllegalArgumentException("Satchel has too many slots.");
} }
if (type == BagType.POUCH && slots > ScoutUtil.MAX_POUCH_SLOTS) { if (type == BagType.POUCH && slots > ScoutUtil.MAX_POUCH_SLOTS) {
throw new IllegalArgumentException("Pouch has too many slots."); throw new IllegalArgumentException("Pouch has too many slots.");
} }
this.slots = slots; this.slots = slots;
this.type = type; this.type = type;
} }
public int getSlotCount() { public int getSlotCount() {
return this.slots; return this.slots;
} }
public BagType getType() { public BagType getType() {
return this.type; return this.type;
} }
@Override @Override
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) { public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) {
super.appendTooltip(stack, world, tooltip, context); super.appendTooltip(stack, world, tooltip, context);
tooltip.add(Text.translatable("tooltip.scout.slots", Text.literal(String.valueOf(this.slots)).formatted(Formatting.BLUE)).formatted(Formatting.GRAY)); tooltip.add(Text.translatable("tooltip.scout.slots", Text.literal(String.valueOf(this.slots)).formatted(Formatting.BLUE)).formatted(Formatting.GRAY));
} }
public Inventory getInventory(ItemStack stack) { public Inventory getInventory(ItemStack stack) {
SimpleInventory inventory = new SimpleInventory(this.slots) { SimpleInventory inventory = new SimpleInventory(this.slots) {
@Override @Override
public void markDirty() { public void markDirty() {
stack.getOrCreateNbt().put(ITEMS_KEY, ScoutUtil.inventoryToTag(this)); stack.getOrCreateNbt().put(ITEMS_KEY, ScoutUtil.inventoryToTag(this));
super.markDirty(); super.markDirty();
} }
}; };
NbtCompound compound = stack.getOrCreateNbt(); NbtCompound compound = stack.getOrCreateNbt();
if (!compound.contains(ITEMS_KEY)) { if (!compound.contains(ITEMS_KEY)) {
compound.put(ITEMS_KEY, new NbtList()); compound.put(ITEMS_KEY, new NbtList());
} }
NbtList items = compound.getList(ITEMS_KEY, 10); NbtList items = compound.getList(ITEMS_KEY, 10);
ScoutUtil.inventoryFromTag(items, inventory); ScoutUtil.inventoryFromTag(items, inventory);
return inventory; return inventory;
} }
@Override @Override
public Optional<TooltipData> getTooltipData(ItemStack stack) { public Optional<TooltipData> getTooltipData(ItemStack stack) {
DefaultedList<ItemStack> stacks = DefaultedList.of(); DefaultedList<ItemStack> stacks = DefaultedList.of();
Inventory inventory = getInventory(stack); Inventory inventory = getInventory(stack);
for (int i = 0; i < slots; i++) { for (int i = 0; i < slots; i++) {
stacks.add(inventory.getStack(i)); stacks.add(inventory.getStack(i));
} }
if (stacks.stream().allMatch(ItemStack::isEmpty)) return Optional.empty(); if (stacks.stream().allMatch(ItemStack::isEmpty)) return Optional.empty();
return Optional.of(new BagTooltipData(stacks, slots)); return Optional.of(new BagTooltipData(stacks, slots));
} }
@Override @Override
public void onEquip(ItemStack stack, SlotReference slotRef, LivingEntity entity) { public void onEquip(ItemStack stack, SlotReference slotRef, LivingEntity entity) {
if (entity instanceof PlayerEntity player)
updateSlots(player);
}
@Override
public void onUnequip(ItemStack stack, SlotReference slotRef, LivingEntity entity) {
if (entity instanceof PlayerEntity player) if (entity instanceof PlayerEntity player)
updateSlots(player); updateSlots(player);
} }
@Override
public void onUnequip(ItemStack stack, SlotReference slotRef, LivingEntity entity) {
if (entity instanceof PlayerEntity player)
updateSlots(player);
}
private void updateSlots(PlayerEntity player) { private void updateSlots(PlayerEntity player) {
ScoutScreenHandler handler = (ScoutScreenHandler) player.playerScreenHandler; ScoutScreenHandler handler = (ScoutScreenHandler) player.playerScreenHandler;
@ -177,37 +177,37 @@ public class BaseBagItem extends TrinketItem {
} }
} }
@Override @Override
public boolean canEquip(ItemStack stack, SlotReference slot, LivingEntity entity) { public boolean canEquip(ItemStack stack, SlotReference slot, LivingEntity entity) {
Item item = stack.getItem(); Item item = stack.getItem();
ItemStack slotStack = slot.inventory().getStack(slot.index()); ItemStack slotStack = slot.inventory().getStack(slot.index());
Item slotItem = slotStack.getItem(); Item slotItem = slotStack.getItem();
if (slotItem instanceof BaseBagItem) { if (slotItem instanceof BaseBagItem) {
if (((BaseBagItem) item).getType() == BagType.SATCHEL) { if (((BaseBagItem) item).getType() == BagType.SATCHEL) {
if (((BaseBagItem) slotItem).getType() == BagType.SATCHEL) { if (((BaseBagItem) slotItem).getType() == BagType.SATCHEL) {
return true; return true;
} else { } else {
return ScoutUtil.findBagItem((PlayerEntity) entity, BagType.SATCHEL, false).isEmpty(); return ScoutUtil.findBagItem((PlayerEntity) entity, BagType.SATCHEL, false).isEmpty();
} }
} else if (((BaseBagItem) item).getType() == BagType.POUCH) { } else if (((BaseBagItem) item).getType() == BagType.POUCH) {
if (((BaseBagItem) slotItem).getType() == BagType.POUCH) { if (((BaseBagItem) slotItem).getType() == BagType.POUCH) {
return true; return true;
} else { } else {
return ScoutUtil.findBagItem((PlayerEntity) entity, BagType.POUCH, true).isEmpty(); return ScoutUtil.findBagItem((PlayerEntity) entity, BagType.POUCH, true).isEmpty();
} }
} }
} else { } else {
if (((BaseBagItem) item).getType() == BagType.SATCHEL) { if (((BaseBagItem) item).getType() == BagType.SATCHEL) {
return ScoutUtil.findBagItem((PlayerEntity) entity, BagType.SATCHEL, false).isEmpty(); return ScoutUtil.findBagItem((PlayerEntity) entity, BagType.SATCHEL, false).isEmpty();
} else if (((BaseBagItem) item).getType() == BagType.POUCH) { } else if (((BaseBagItem) item).getType() == BagType.POUCH) {
return ScoutUtil.findBagItem((PlayerEntity) entity, BagType.POUCH, true).isEmpty(); return ScoutUtil.findBagItem((PlayerEntity) entity, BagType.POUCH, true).isEmpty();
} }
} }
return false; return false;
} }
@Override @Override
public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) { public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
@ -219,8 +219,8 @@ public class BaseBagItem extends TrinketItem {
} }
} }
public enum BagType { public enum BagType {
SATCHEL, SATCHEL,
POUCH POUCH
} }
} }

View file

@ -9,14 +9,13 @@ import pm.c7.scout.item.BaseBagItem;
@Mixin(ItemStack.class) @Mixin(ItemStack.class)
public class ItemStackMixin { public class ItemStackMixin {
// Trinkets calls areEqual to check whether it should unequip old and equip new (https://github.com/emilyploszaj/trinkets/blob/7cb63ce0/src/main/java/dev/emi/trinkets/mixin/LivingEntityMixin.java#L155-L158)
// Trinkets calls areEqual to check whether it should unequip old and equip new (https://github.com/emilyploszaj/trinkets/blob/7cb63ce0/src/main/java/dev/emi/trinkets/mixin/LivingEntityMixin.java#L155-L158) // Excluding ourselves from this check to force unequip/equip when switching bag items fixes a duplication bug
// Excluding ourselves from this check to force unequip/equip when switching bag items fixes a duplication bug // Gross and hacky but oh well, can't mixin mixins.
// Gross and hacky but oh well, can't mixin mixins. @Inject(method = "areEqual", at = @At("HEAD"), cancellable = true)
@Inject(method = "areEqual", at = @At("HEAD"), cancellable = true) private static void scout$grossTrinketsEquipFix(ItemStack stack, ItemStack otherStack, CallbackInfoReturnable<Boolean> callbackInfo) {
private static void scout$grossTrinketsEquipFix(ItemStack stack, ItemStack otherStack, CallbackInfoReturnable<Boolean> callbackInfo) { if (stack.getItem() instanceof BaseBagItem && otherStack.getItem() instanceof BaseBagItem) {
if (stack.getItem() instanceof BaseBagItem && otherStack.getItem() instanceof BaseBagItem) { callbackInfo.setReturnValue(false);
callbackInfo.setReturnValue(false); }
} }
}
} }

View file

@ -18,84 +18,84 @@ import pm.c7.scout.screen.BagSlot;
@Mixin(value = PlayerScreenHandler.class, priority = 950) @Mixin(value = PlayerScreenHandler.class, priority = 950)
@Transformer(PlayerScreenHandlerTransformer.class) @Transformer(PlayerScreenHandlerTransformer.class)
public abstract class PlayerScreenHandlerMixin extends ScreenHandler implements ScoutScreenHandler { public abstract class PlayerScreenHandlerMixin extends ScreenHandler implements ScoutScreenHandler {
protected PlayerScreenHandlerMixin() { protected PlayerScreenHandlerMixin() {
super(null, 0); super(null, 0);
} }
@Unique @Unique
public final DefaultedList<BagSlot> scout$satchelSlots = DefaultedList.ofSize(ScoutUtil.MAX_SATCHEL_SLOTS); public final DefaultedList<BagSlot> scout$satchelSlots = DefaultedList.ofSize(ScoutUtil.MAX_SATCHEL_SLOTS);
@Unique @Unique
public final DefaultedList<BagSlot> scout$leftPouchSlots = DefaultedList.ofSize(ScoutUtil.MAX_POUCH_SLOTS); public final DefaultedList<BagSlot> scout$leftPouchSlots = DefaultedList.ofSize(ScoutUtil.MAX_POUCH_SLOTS);
@Unique @Unique
public final DefaultedList<BagSlot> scout$rightPouchSlots = DefaultedList.ofSize(ScoutUtil.MAX_POUCH_SLOTS); public final DefaultedList<BagSlot> scout$rightPouchSlots = DefaultedList.ofSize(ScoutUtil.MAX_POUCH_SLOTS);
@Inject(method = "<init>", at = @At("RETURN")) @Inject(method = "<init>", at = @At("RETURN"))
private void scout$addSlots(PlayerInventory inventory, boolean onServer, PlayerEntity owner, CallbackInfo callbackInfo) { private void scout$addSlots(PlayerInventory inventory, boolean onServer, PlayerEntity owner, CallbackInfo callbackInfo) {
// satchel // satchel
int x = 8; int x = 8;
int y = 168; int y = 168;
for (int i = 0; i < ScoutUtil.MAX_SATCHEL_SLOTS; i++) { for (int i = 0; i < ScoutUtil.MAX_SATCHEL_SLOTS; i++) {
if (i % 9 == 0) { if (i % 9 == 0) {
x = 8; x = 8;
} }
BagSlot slot = new BagSlot(i, x, y); BagSlot slot = new BagSlot(i, x, y);
slot.id = ScoutUtil.SATCHEL_SLOT_START - i; slot.id = ScoutUtil.SATCHEL_SLOT_START - i;
scout$satchelSlots.add(slot); scout$satchelSlots.add(slot);
x += 18; x += 18;
if ((i + 1) % 9 == 0) { if ((i + 1) % 9 == 0) {
y += 18; y += 18;
} }
} }
// left pouch // left pouch
x = 8; x = 8;
y = 66; y = 66;
for (int i = 0; i < ScoutUtil.MAX_POUCH_SLOTS; i++) { for (int i = 0; i < ScoutUtil.MAX_POUCH_SLOTS; i++) {
if (i % 3 == 0) { if (i % 3 == 0) {
x -= 18; x -= 18;
y += 54; y += 54;
} }
BagSlot slot = new BagSlot(i, x, y); BagSlot slot = new BagSlot(i, x, y);
slot.id = ScoutUtil.LEFT_POUCH_SLOT_START - i; slot.id = ScoutUtil.LEFT_POUCH_SLOT_START - i;
scout$leftPouchSlots.add(slot); scout$leftPouchSlots.add(slot);
y -= 18; y -= 18;
} }
// right pouch // right pouch
x = 152; x = 152;
y = 66; y = 66;
for (int i = 0; i < ScoutUtil.MAX_POUCH_SLOTS; i++) { for (int i = 0; i < ScoutUtil.MAX_POUCH_SLOTS; i++) {
if (i % 3 == 0) { if (i % 3 == 0) {
x += 18; x += 18;
y += 54; y += 54;
} }
BagSlot slot = new BagSlot(i, x, y); BagSlot slot = new BagSlot(i, x, y);
slot.id = ScoutUtil.RIGHT_POUCH_SLOT_START - i; slot.id = ScoutUtil.RIGHT_POUCH_SLOT_START - i;
scout$rightPouchSlots.add(slot); scout$rightPouchSlots.add(slot);
y -= 18; y -= 18;
} }
} }
@Override @Override
public final DefaultedList<BagSlot> scout$getSatchelSlots() { public final DefaultedList<BagSlot> scout$getSatchelSlots() {
return scout$satchelSlots; return scout$satchelSlots;
} }
@Override @Override
public final DefaultedList<BagSlot> scout$getLeftPouchSlots() { public final DefaultedList<BagSlot> scout$getLeftPouchSlots() {
return scout$leftPouchSlots; return scout$leftPouchSlots;
} }
@Override @Override
public final DefaultedList<BagSlot> scout$getRightPouchSlots() { public final DefaultedList<BagSlot> scout$getRightPouchSlots() {
return scout$rightPouchSlots; return scout$rightPouchSlots;
} }
} }

View file

@ -5,10 +5,8 @@ import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screen.ingame.AbstractFurnaceScreen; import net.minecraft.client.gui.screen.ingame.AbstractFurnaceScreen;
import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.screen.recipe.book.RecipeBookProvider; import net.minecraft.client.gui.screen.recipe.book.RecipeBookProvider;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.screen.AbstractFurnaceScreenHandler; import net.minecraft.screen.AbstractFurnaceScreenHandler;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;

View file

@ -9,10 +9,10 @@ import org.spongepowered.asm.mixin.gen.Accessor;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
@Mixin(HandledScreen.class) @Mixin(HandledScreen.class)
public interface HandledScreenAccessor { public interface HandledScreenAccessor {
@Accessor("x") @Accessor("x")
int getX(); int getX();
@Accessor("y") @Accessor("y")
int getY(); int getY();
@Accessor("backgroundWidth") @Accessor("backgroundWidth")
int getBackgroundWidth(); int getBackgroundWidth();
@Accessor("backgroundHeight") @Accessor("backgroundHeight")

View file

@ -9,7 +9,6 @@ import net.minecraft.client.gui.screen.ingame.GenericContainerScreen;
import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider; import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider;
import net.minecraft.client.gui.screen.ingame.ShulkerBoxScreen; import net.minecraft.client.gui.screen.ingame.ShulkerBoxScreen;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.slot.Slot; import net.minecraft.screen.slot.Slot;
@ -277,7 +276,6 @@ public abstract class HandledScreenMixin<T extends ScreenHandler> extends Screen
for (int i = ScoutUtil.SATCHEL_SLOT_START; i > ScoutUtil.BAG_SLOTS_END; i--) { for (int i = ScoutUtil.SATCHEL_SLOT_START; i > ScoutUtil.BAG_SLOTS_END; i--) {
BagSlot slot = (BagSlot) ScoutUtil.getBagSlot(i, this.client.player.playerScreenHandler); BagSlot slot = (BagSlot) ScoutUtil.getBagSlot(i, this.client.player.playerScreenHandler);
if (slot != null && slot.isEnabled()) { if (slot != null && slot.isEnabled()) {
RenderSystem.setShader(GameRenderer::getPositionTexShader);
this.drawSlot(graphics, slot); this.drawSlot(graphics, slot);
} }

View file

@ -1,19 +1,15 @@
package pm.c7.scout.mixin.client; package pm.c7.scout.mixin.client;
import com.mojang.blaze3d.systems.RenderSystem;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screen.ingame.AbstractInventoryScreen; import net.minecraft.client.gui.screen.ingame.AbstractInventoryScreen;
import net.minecraft.client.gui.screen.ingame.InventoryScreen; import net.minecraft.client.gui.screen.ingame.InventoryScreen;
import net.minecraft.client.gui.screen.recipe.book.RecipeBookProvider; import net.minecraft.client.gui.screen.recipe.book.RecipeBookProvider;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.screen.PlayerScreenHandler; import net.minecraft.screen.PlayerScreenHandler;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import pm.c7.scout.ScoutUtil; import pm.c7.scout.ScoutUtil;
import pm.c7.scout.item.BaseBagItem; import pm.c7.scout.item.BaseBagItem;
@ -22,45 +18,45 @@ import pm.c7.scout.item.BaseBagItem.BagType;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
@Mixin(InventoryScreen.class) @Mixin(InventoryScreen.class)
public abstract class InventoryScreenMixin extends AbstractInventoryScreen<PlayerScreenHandler> implements RecipeBookProvider { public abstract class InventoryScreenMixin extends AbstractInventoryScreen<PlayerScreenHandler> implements RecipeBookProvider {
private InventoryScreenMixin() { private InventoryScreenMixin() {
super(null, null, null); super(null, null, null);
} }
@Inject(method = "isClickOutsideBounds", at = @At("TAIL"), cancellable = true) @Inject(method = "isClickOutsideBounds", at = @At("TAIL"), cancellable = true)
private void scout$adjustOutsideBounds(double mouseX, double mouseY, int left, int top, int button, CallbackInfoReturnable<Boolean> callbackInfo) { private void scout$adjustOutsideBounds(double mouseX, double mouseY, int left, int top, int button, CallbackInfoReturnable<Boolean> callbackInfo) {
if (this.client != null && this.client.player != null) { if (this.client != null && this.client.player != null) {
ItemStack backStack = ScoutUtil.findBagItem(this.client.player, BagType.SATCHEL, false); ItemStack backStack = ScoutUtil.findBagItem(this.client.player, BagType.SATCHEL, false);
if (!backStack.isEmpty()) { if (!backStack.isEmpty()) {
BaseBagItem bagItem = (BaseBagItem) backStack.getItem(); BaseBagItem bagItem = (BaseBagItem) backStack.getItem();
int slots = bagItem.getSlotCount(); int slots = bagItem.getSlotCount();
int rows = (int) Math.ceil(slots / 9); int rows = (int) Math.ceil(slots / 9);
if (mouseY < (top + this.backgroundHeight) + 8 + (18 * rows) && mouseY >= (top + this.backgroundHeight) && mouseX >= left && mouseY < (left + this.backgroundWidth)) { if (mouseY < (top + this.backgroundHeight) + 8 + (18 * rows) && mouseY >= (top + this.backgroundHeight) && mouseX >= left && mouseY < (left + this.backgroundWidth)) {
callbackInfo.setReturnValue(false); callbackInfo.setReturnValue(false);
} }
} }
ItemStack leftPouchStack = ScoutUtil.findBagItem(this.client.player, BagType.POUCH, false); ItemStack leftPouchStack = ScoutUtil.findBagItem(this.client.player, BagType.POUCH, false);
if (!leftPouchStack.isEmpty()) { if (!leftPouchStack.isEmpty()) {
BaseBagItem bagItem = (BaseBagItem) leftPouchStack.getItem(); BaseBagItem bagItem = (BaseBagItem) leftPouchStack.getItem();
int slots = bagItem.getSlotCount(); int slots = bagItem.getSlotCount();
int columns = (int) Math.ceil(slots / 3); int columns = (int) Math.ceil(slots / 3);
if (mouseX >= left - (columns * 18) && mouseX < left && mouseY >= (top + this.backgroundHeight) - 90 && mouseY < (top + this.backgroundHeight) - 22) { if (mouseX >= left - (columns * 18) && mouseX < left && mouseY >= (top + this.backgroundHeight) - 90 && mouseY < (top + this.backgroundHeight) - 22) {
callbackInfo.setReturnValue(false); callbackInfo.setReturnValue(false);
} }
} }
ItemStack rightPouchStack = ScoutUtil.findBagItem(this.client.player, BagType.POUCH, true); ItemStack rightPouchStack = ScoutUtil.findBagItem(this.client.player, BagType.POUCH, true);
if (!rightPouchStack.isEmpty()) { if (!rightPouchStack.isEmpty()) {
BaseBagItem bagItem = (BaseBagItem) rightPouchStack.getItem(); BaseBagItem bagItem = (BaseBagItem) rightPouchStack.getItem();
int slots = bagItem.getSlotCount(); int slots = bagItem.getSlotCount();
int columns = (int) Math.ceil(slots / 3); int columns = (int) Math.ceil(slots / 3);
if (mouseX >= (left + this.backgroundWidth) && mouseX < (left + this.backgroundWidth) + (columns * 18) && mouseY >= (top + this.backgroundHeight) - 90 && mouseY < (top + this.backgroundHeight) - 22) { if (mouseX >= (left + this.backgroundWidth) && mouseX < (left + this.backgroundWidth) + (columns * 18) && mouseY >= (top + this.backgroundHeight) - 90 && mouseY < (top + this.backgroundHeight) - 22) {
callbackInfo.setReturnValue(false); callbackInfo.setReturnValue(false);
} }
} }
} }
} }
} }

View file

@ -19,36 +19,36 @@ import pm.c7.scout.item.BaseBagItem.BagType;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
@Mixin(value = RecipeBookWidget.class, priority = 950) @Mixin(value = RecipeBookWidget.class, priority = 950)
public class RecipeBookWidgetMixin { public class RecipeBookWidgetMixin {
@Shadow @Shadow
protected MinecraftClient client; protected MinecraftClient client;
@Shadow @Shadow
private int leftOffset; private int leftOffset;
@Inject(method = "findLeftEdge", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true) @Inject(method = "findLeftEdge", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
private void scout$modifyRecipeBookPosition(int width, int backgroundWidth, CallbackInfoReturnable<Integer> callbackInfo, int x) { private void scout$modifyRecipeBookPosition(int width, int backgroundWidth, CallbackInfoReturnable<Integer> callbackInfo, int x) {
if (this.client != null && this.client.player != null && this.isOpen()) { if (this.client != null && this.client.player != null && this.isOpen()) {
ItemStack leftPouchStack = ScoutUtil.findBagItem(this.client.player, BagType.POUCH, false); ItemStack leftPouchStack = ScoutUtil.findBagItem(this.client.player, BagType.POUCH, false);
if (!leftPouchStack.isEmpty()) { if (!leftPouchStack.isEmpty()) {
BaseBagItem bagItem = (BaseBagItem) leftPouchStack.getItem(); BaseBagItem bagItem = (BaseBagItem) leftPouchStack.getItem();
int slots = bagItem.getSlotCount(); int slots = bagItem.getSlotCount();
int columns = (int) Math.ceil(slots / 3); int columns = (int) Math.ceil(slots / 3);
// Realign as best we can when "Keep crafting screens centered" is enabled in Better Recipe Book // Realign as best we can when "Keep crafting screens centered" is enabled in Better Recipe Book
if (this.leftOffset != 86) { if (this.leftOffset != 86) {
int diff = this.leftOffset - 86; int diff = this.leftOffset - 86;
x -= diff; x -= diff;
} }
x += 18 * columns; x += 18 * columns;
callbackInfo.setReturnValue(x); callbackInfo.setReturnValue(x);
} }
} }
} }
@Shadow @Shadow
public boolean isOpen() { public boolean isOpen() {
return false; return false;
} }
} }