simplify stackableShulkerBoxes rule
This commit is contained in:
1 parent
4e57eecf2d
commit
a0bd6e22ac
6 files changed
+29
-190
No files matched your search
@@ -1,49 +0,0 @@
|
|||||||
package carpet.helpers;
|
|
||||||
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
|
|
||||||
import static net.minecraft.nbt.Tag.TAG_COMPOUND;
|
|
||||||
import static net.minecraft.nbt.Tag.TAG_LIST;
|
|
||||||
|
|
||||||
public class InventoryHelper
|
|
||||||
{
|
|
||||||
public static boolean cleanUpShulkerBoxTag(ItemStack stack)
|
|
||||||
{
|
|
||||||
boolean changed = false;
|
|
||||||
CompoundTag tag = stack.getTag();
|
|
||||||
|
|
||||||
if (tag == null || !tag.contains("BlockEntityTag", TAG_COMPOUND))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
CompoundTag bet = tag.getCompound("BlockEntityTag");
|
|
||||||
if (bet.contains("Items", TAG_LIST) && bet.getList("Items", TAG_COMPOUND).isEmpty())
|
|
||||||
{
|
|
||||||
bet.remove("Items");
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bet.isEmpty() || (bet.size() == 1 && bet.getString("id").equals("minecraft:shulker_box")))
|
|
||||||
{
|
|
||||||
tag.remove("BlockEntityTag");
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
if (tag.isEmpty())
|
|
||||||
{
|
|
||||||
stack.setTag(null);
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
return changed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean shulkerBoxHasItems(ItemStack stack)
|
|
||||||
{
|
|
||||||
CompoundTag tag = stack.getTag();
|
|
||||||
|
|
||||||
if (tag == null || !tag.contains("BlockEntityTag", TAG_COMPOUND))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
CompoundTag bet = tag.getCompound("BlockEntityTag");
|
|
||||||
return bet.contains("Items", TAG_LIST) && !bet.getList("Items", TAG_COMPOUND).isEmpty();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package carpet.mixins;
|
|
||||||
|
|
||||||
import carpet.CarpetSettings;
|
|
||||||
import carpet.helpers.InventoryHelper;
|
|
||||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
|
||||||
import net.minecraft.world.inventory.Slot;
|
|
||||||
import net.minecraft.world.item.BlockItem;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.level.block.ShulkerBoxBlock;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
|
||||||
|
|
||||||
@Mixin(AbstractContainerMenu.class)
|
|
||||||
public class AbstractContainerMenu_stackableSBoxesMixin
|
|
||||||
{
|
|
||||||
@Redirect(method = "doClick", at = @At(
|
|
||||||
value = "INVOKE",
|
|
||||||
target = "Lnet/minecraft/world/inventory/Slot;getMaxStackSize(Lnet/minecraft/world/item/ItemStack;)I"
|
|
||||||
))
|
|
||||||
private int getMaxCountForSboxesInScreenHander(Slot slot, ItemStack stack)
|
|
||||||
{
|
|
||||||
if (CarpetSettings.shulkerBoxStackSize > 1 &&
|
|
||||||
stack.getItem() instanceof BlockItem &&
|
|
||||||
((BlockItem)stack.getItem()).getBlock() instanceof ShulkerBoxBlock &&
|
|
||||||
!InventoryHelper.shulkerBoxHasItems(stack)
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return CarpetSettings.shulkerBoxStackSize;
|
|
||||||
}
|
|
||||||
return slot.getMaxStackSize(stack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +1,15 @@
|
|||||||
package carpet.mixins;
|
package carpet.mixins;
|
||||||
|
|
||||||
import carpet.CarpetSettings;
|
import carpet.CarpetSettings;
|
||||||
import carpet.helpers.InventoryHelper;
|
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.EntityType;
|
import net.minecraft.world.entity.EntityType;
|
||||||
import net.minecraft.world.entity.LightningBolt;
|
import net.minecraft.world.entity.LightningBolt;
|
||||||
import net.minecraft.world.entity.item.ItemEntity;
|
import net.minecraft.world.entity.item.ItemEntity;
|
||||||
import net.minecraft.world.item.BlockItem;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.ShulkerBoxBlock;
|
|
||||||
import carpet.fakes.ItemEntityInterface;
|
import carpet.fakes.ItemEntityInterface;
|
||||||
import java.util.Objects;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
|
|
||||||
@Mixin(ItemEntity.class)
|
@Mixin(ItemEntity.class)
|
||||||
public abstract class ItemEntityMixin extends Entity implements ItemEntityInterface
|
public abstract class ItemEntityMixin extends Entity implements ItemEntityInterface
|
||||||
@@ -45,70 +36,4 @@ public abstract class ItemEntityMixin extends Entity implements ItemEntityInterf
|
|||||||
public int getPickupDelayCM() {
|
public int getPickupDelayCM() {
|
||||||
return this.pickupDelay;
|
return this.pickupDelay;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method="<init>(Lnet/minecraft/world/level/Level;DDDLnet/minecraft/world/item/ItemStack;)V", at = @At("RETURN"))
|
|
||||||
private void removeEmptyShulkerBoxTags(Level worldIn, double x, double y, double z, ItemStack stack, CallbackInfo ci)
|
|
||||||
{
|
|
||||||
if (CarpetSettings.shulkerBoxStackSize > 1
|
|
||||||
&& stack.getItem() instanceof BlockItem bi
|
|
||||||
&& bi.getBlock() instanceof ShulkerBoxBlock)
|
|
||||||
{
|
|
||||||
InventoryHelper.cleanUpShulkerBoxTag(stack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Redirect(
|
|
||||||
method = "isMergable()Z",
|
|
||||||
at = @At(
|
|
||||||
value = "INVOKE",
|
|
||||||
target = "Lnet/minecraft/world/item/ItemStack;getMaxStackSize()I"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
private int getItemStackMaxAmount(ItemStack stack) {
|
|
||||||
if (CarpetSettings.shulkerBoxStackSize > 1 && stack.getItem() instanceof BlockItem && ((BlockItem)stack.getItem()).getBlock() instanceof ShulkerBoxBlock)
|
|
||||||
return CarpetSettings.shulkerBoxStackSize;
|
|
||||||
|
|
||||||
return stack.getMaxStackSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(
|
|
||||||
method = "tryToMerge(Lnet/minecraft/world/entity/item/ItemEntity;)V",
|
|
||||||
at = @At("HEAD"),
|
|
||||||
cancellable = true
|
|
||||||
)
|
|
||||||
private void tryStackShulkerBoxes(ItemEntity other, CallbackInfo ci)
|
|
||||||
{
|
|
||||||
ItemEntity self = (ItemEntity)(Object)this;
|
|
||||||
ItemStack selfStack = self.getItem();
|
|
||||||
if (CarpetSettings.shulkerBoxStackSize == 1 || !(selfStack.getItem() instanceof BlockItem bi) || !(bi.getBlock() instanceof ShulkerBoxBlock)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack otherStack = other.getItem();
|
|
||||||
if (selfStack.getItem() == otherStack.getItem()
|
|
||||||
&& !InventoryHelper.shulkerBoxHasItems(selfStack)
|
|
||||||
&& !InventoryHelper.shulkerBoxHasItems(otherStack)
|
|
||||||
&& Objects.equals(selfStack.getTag(), otherStack.getTag()) // empty block entity tags are cleaned up when spawning
|
|
||||||
&& selfStack.getCount() != CarpetSettings.shulkerBoxStackSize)
|
|
||||||
{
|
|
||||||
int amount = Math.min(otherStack.getCount(), CarpetSettings.shulkerBoxStackSize - selfStack.getCount());
|
|
||||||
|
|
||||||
selfStack.grow(amount);
|
|
||||||
self.setItem(selfStack);
|
|
||||||
|
|
||||||
this.pickupDelay = Math.max(((ItemEntityInterface)other).getPickupDelayCM(), this.pickupDelay);
|
|
||||||
this.age = Math.min(other.getAge(), this.age);
|
|
||||||
|
|
||||||
otherStack.shrink(amount);
|
|
||||||
if (otherStack.isEmpty())
|
|
||||||
{
|
|
||||||
other.discard();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
other.setItem(otherStack);
|
|
||||||
}
|
|
||||||
ci.cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package carpet.mixins;
|
||||||
|
|
||||||
|
import carpet.CarpetSettings;
|
||||||
|
import net.minecraft.core.component.DataComponents;
|
||||||
|
import net.minecraft.world.item.BlockItem;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.component.ItemContainerContents;
|
||||||
|
import net.minecraft.world.level.block.ShulkerBoxBlock;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
@Mixin(ItemStack.class)
|
||||||
|
public class ItemStack_stackableShulkerBoxesMixin
|
||||||
|
{
|
||||||
|
@Inject(method = "getMaxStackSize", at = @At("HEAD"), cancellable = true)
|
||||||
|
private void getCMMAxStackSize(CallbackInfoReturnable<Integer> cir)
|
||||||
|
{
|
||||||
|
if (CarpetSettings.shulkerBoxStackSize > 1
|
||||||
|
&& ((ItemStack)((Object)this)).getItem() instanceof BlockItem blockItem
|
||||||
|
&& blockItem.getBlock() instanceof ShulkerBoxBlock
|
||||||
|
&& ((ItemStack) ((Object) this)).getOrDefault(DataComponents.CONTAINER, ItemContainerContents.EMPTY).stream().findAny().isEmpty()
|
||||||
|
) {
|
||||||
|
cir.setReturnValue(CarpetSettings.shulkerBoxStackSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
package carpet.mixins;
|
|
||||||
|
|
||||||
import carpet.CarpetSettings;
|
|
||||||
import carpet.helpers.InventoryHelper;
|
|
||||||
import net.minecraft.world.inventory.Slot;
|
|
||||||
import net.minecraft.world.item.BlockItem;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.level.block.ShulkerBoxBlock;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
|
||||||
|
|
||||||
@Mixin(Slot.class)
|
|
||||||
public class Slot_stackableSBoxesMixin {
|
|
||||||
@Redirect(method = "safeInsert(Lnet/minecraft/world/item/ItemStack;I)Lnet/minecraft/world/item/ItemStack;", at = @At(
|
|
||||||
value = "INVOKE",
|
|
||||||
target = "Lnet/minecraft/world/inventory/Slot;getMaxStackSize(Lnet/minecraft/world/item/ItemStack;)I"
|
|
||||||
))
|
|
||||||
private int getMaxCountForSboxesInSlot(Slot slot, ItemStack stack)
|
|
||||||
{
|
|
||||||
if (CarpetSettings.shulkerBoxStackSize > 1 &&
|
|
||||||
stack.getItem() instanceof BlockItem &&
|
|
||||||
((BlockItem)stack.getItem()).getBlock() instanceof ShulkerBoxBlock &&
|
|
||||||
!InventoryHelper.shulkerBoxHasItems(stack)
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return CarpetSettings.shulkerBoxStackSize;
|
|
||||||
}
|
|
||||||
return slot.getMaxStackSize(stack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -101,8 +101,7 @@
|
|||||||
"AbstractContainerMenu_ctrlQCraftingMixin",
|
"AbstractContainerMenu_ctrlQCraftingMixin",
|
||||||
"Connection_packetCounterMixin",
|
"Connection_packetCounterMixin",
|
||||||
"AbstractCauldronBlock_stackableSBoxesMixin",
|
"AbstractCauldronBlock_stackableSBoxesMixin",
|
||||||
"Slot_stackableSBoxesMixin",
|
"ItemStack_stackableShulkerBoxesMixin",
|
||||||
"AbstractContainerMenu_stackableSBoxesMixin",
|
|
||||||
"ItemEntityMixin",
|
"ItemEntityMixin",
|
||||||
"TntBlock_noUpdateMixin",
|
"TntBlock_noUpdateMixin",
|
||||||
"Explosion_optimizedTntMixin",
|
"Explosion_optimizedTntMixin",
|
||||||
|
|||||||
Reference in new issue
Block a user