From 16f3832d1693f3ca829575e0914d15a38e02b788 Mon Sep 17 00:00:00 2001 From: gnembon Date: Sun, 8 Aug 2021 23:07:38 -0300 Subject: [PATCH 1/2] Fixes inventory behaviour with stackable empty shulker boxes. fixes #1048 --- .../ScreenHandler_stackableSBoxesMixin.java | 33 +++++++++++++++++++ .../mixins/Slot_stackableSBoxesMixin.java | 2 +- src/main/resources/carpet.mixins.json | 1 + 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/main/java/carpet/mixins/ScreenHandler_stackableSBoxesMixin.java diff --git a/src/main/java/carpet/mixins/ScreenHandler_stackableSBoxesMixin.java b/src/main/java/carpet/mixins/ScreenHandler_stackableSBoxesMixin.java new file mode 100644 index 00000000..6c8ff20e --- /dev/null +++ b/src/main/java/carpet/mixins/ScreenHandler_stackableSBoxesMixin.java @@ -0,0 +1,33 @@ +package carpet.mixins; + +import carpet.CarpetSettings; +import carpet.helpers.InventoryHelper; +import net.minecraft.block.ShulkerBoxBlock; +import net.minecraft.item.BlockItem; +import net.minecraft.item.ItemStack; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.screen.slot.Slot; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(ScreenHandler.class) +public class ScreenHandler_stackableSBoxesMixin +{ + @Redirect(method = "internalOnSlotClick", at = @At( + value = "INVOKE", + target = "Lnet/minecraft/screen/slot/Slot;getMaxItemCount(Lnet/minecraft/item/ItemStack;)I" + )) + private int getMaxCountForSboxesInScreenHander(Slot slot, ItemStack stack) + { + if (CarpetSettings.stackableShulkerBoxes && + stack.getItem() instanceof BlockItem && + ((BlockItem)stack.getItem()).getBlock() instanceof ShulkerBoxBlock && + !InventoryHelper.shulkerBoxHasItems(stack) + ) + { + return CarpetSettings.SHULKER_STACK_SIZE; + } + return slot.getMaxItemCount(stack); + } +} diff --git a/src/main/java/carpet/mixins/Slot_stackableSBoxesMixin.java b/src/main/java/carpet/mixins/Slot_stackableSBoxesMixin.java index 557ea506..317ca1b6 100644 --- a/src/main/java/carpet/mixins/Slot_stackableSBoxesMixin.java +++ b/src/main/java/carpet/mixins/Slot_stackableSBoxesMixin.java @@ -16,7 +16,7 @@ public class Slot_stackableSBoxesMixin { value = "INVOKE", target = "Lnet/minecraft/screen/slot/Slot;getMaxItemCount(Lnet/minecraft/item/ItemStack;)I" )) - private int getMaxCountForSboxes(Slot slot, ItemStack stack) + private int getMaxCountForSboxesInSlot(Slot slot, ItemStack stack) { if (CarpetSettings.stackableShulkerBoxes && stack.getItem() instanceof BlockItem && diff --git a/src/main/resources/carpet.mixins.json b/src/main/resources/carpet.mixins.json index 24f70d9b..40d083d7 100644 --- a/src/main/resources/carpet.mixins.json +++ b/src/main/resources/carpet.mixins.json @@ -136,6 +136,7 @@ "CauldronBlock_stackableSBoxesMixin", "AbstractCauldronBlock_stackableSBoxesMixin", "Slot_stackableSBoxesMixin", + "ScreenHandler_stackableSBoxesMixin", "ItemEntityMixin", "TntBlockMixin", "ExplosionMixin", From 92063fa8917d4591234efe73bb9201942f814f11 Mon Sep 17 00:00:00 2001 From: gnembon Date: Mon, 9 Aug 2021 00:36:09 -0300 Subject: [PATCH 2/2] Handles rogue spawn reports with an error message. Fixes #1052 --- src/main/java/carpet/utils/SpawnReporter.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/carpet/utils/SpawnReporter.java b/src/main/java/carpet/utils/SpawnReporter.java index 3acf936a..87d2cfcd 100644 --- a/src/main/java/carpet/utils/SpawnReporter.java +++ b/src/main/java/carpet/utils/SpawnReporter.java @@ -1,5 +1,6 @@ package carpet.utils; +import carpet.CarpetSettings; import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2LongMap; import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap; @@ -85,6 +86,11 @@ public class SpawnReporter long count = spawn_stats.get(key).getOrDefault(mob.getType(), 0L); spawn_stats.get(key).put(mob.getType(), count + 1); spawned_mobs.get(key).put(Pair.of(mob.getType(), pos)); + if (!local_spawns.containsKey(cat)) + { + CarpetSettings.LOG.error("Rogue spawn detected for category "+cat.getName()+" for mob "+mob.getType().getName().getString()+". If you see this message let carpet peeps know about it on github issues."); + local_spawns.put(cat, 0L); + } local_spawns.put(cat, local_spawns.get(cat)+1); }