fix: emptyShulkerBoxStack
This commit is contained in:
6 files changed
+93
-24
No files matched your search
+6
-6
@@ -1,23 +1,23 @@
|
|||||||
package com.github.zly2006.carpetslsaddition.mixin.shulker;
|
package com.github.zly2006.carpetslsaddition.mixin.shulker;
|
||||||
|
|
||||||
import com.github.zly2006.carpetslsaddition.SLSCarpetSettings;
|
|
||||||
import com.github.zly2006.carpetslsaddition.util.ShulkerBoxItemUtil;
|
import com.github.zly2006.carpetslsaddition.util.ShulkerBoxItemUtil;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
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.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
@Mixin(ItemStack.class)
|
@Mixin(ItemStack.class)
|
||||||
public class MixinItemStack {
|
public class MixinItemStack {
|
||||||
@Inject(
|
@Inject(
|
||||||
method = "getMaxCount",
|
method = "capCount",
|
||||||
at = @At("HEAD"),
|
at = @At("HEAD"),
|
||||||
cancellable = true
|
cancellable = true
|
||||||
)
|
)
|
||||||
private void getMaxCount(CallbackInfoReturnable<Integer> cir) {
|
private void capCount(int maxCount, CallbackInfo ci) {
|
||||||
if (SLSCarpetSettings.emptyShulkerBoxStack && ShulkerBoxItemUtil.isEmptyShulkerBoxItem((ItemStack) (Object) this)) {
|
if (ShulkerBoxItemUtil.isEmptyShulkerBoxItem((ItemStack) (Object) this)) {
|
||||||
cir.setReturnValue(ShulkerBoxItemUtil.SHULKERBOX_MAX_STACK_AMOUNT);
|
ci.cancel();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
package com.github.zly2006.carpetslsaddition.mixin.shulker;
|
||||||
|
|
||||||
|
import com.github.zly2006.carpetslsaddition.SLSCarpetSettings;
|
||||||
|
import com.github.zly2006.carpetslsaddition.util.ShulkerBoxItemUtil;
|
||||||
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
|
import net.minecraft.inventory.Inventory;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
|
||||||
|
@Mixin(PlayerInventory.class)
|
||||||
|
public abstract class MixinPlayerInventory implements Inventory {
|
||||||
|
@Redirect(
|
||||||
|
method = "canStackAddMore",
|
||||||
|
at = @At(
|
||||||
|
value = "INVOKE",
|
||||||
|
target = "Lnet/minecraft/item/ItemStack;isStackable()Z"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
private boolean isStackable(ItemStack instance) {
|
||||||
|
if (SLSCarpetSettings.emptyShulkerBoxStack && ShulkerBoxItemUtil.isEmptyShulkerBoxItem(instance)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return instance.isStackable();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxCount(ItemStack stack) {
|
||||||
|
if (SLSCarpetSettings.emptyShulkerBoxStack && ShulkerBoxItemUtil.isEmptyShulkerBoxItem(stack)) {
|
||||||
|
return ShulkerBoxItemUtil.SHULKERBOX_MAX_STACK_AMOUNT;
|
||||||
|
}
|
||||||
|
return Inventory.super.getMaxCount(stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
+18
-9
@@ -1,26 +1,35 @@
|
|||||||
package com.github.zly2006.carpetslsaddition.mixin.shulker;
|
package com.github.zly2006.carpetslsaddition.mixin.shulker;
|
||||||
|
|
||||||
import com.github.zly2006.carpetslsaddition.util.ShulkerBoxItemUtil;
|
import com.github.zly2006.carpetslsaddition.util.ShulkerBoxItemUtil;
|
||||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
|
||||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.screen.ScreenHandler;
|
import net.minecraft.screen.ScreenHandler;
|
||||||
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.Redirect;
|
||||||
|
|
||||||
@Mixin(ScreenHandler.class)
|
@Mixin(ScreenHandler.class)
|
||||||
public abstract class MixinScreenHandler {
|
public abstract class MixinScreenHandler {
|
||||||
@WrapOperation(
|
@Redirect(
|
||||||
method = "internalOnSlotClick",
|
method = "*",
|
||||||
at = @At(
|
at = @At(
|
||||||
value = "INVOKE",
|
value = "INVOKE",
|
||||||
target = "Lnet/minecraft/item/ItemStack;areItemsAndComponentsEqual(Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ItemStack;)Z"
|
target = "Lnet/minecraft/item/ItemStack;areItemsAndComponentsEqual(Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ItemStack;)Z"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
private boolean checkEqual(ItemStack stack, ItemStack otherStack, Operation<Boolean> original) {
|
private boolean checkEqual(ItemStack stack, ItemStack otherStack) {
|
||||||
if (ShulkerBoxItemUtil.shulkerBoxEqual(stack, otherStack)) {
|
if (ShulkerBoxItemUtil.shulkerBoxEqual(stack, otherStack)) return true;
|
||||||
return true;
|
return ItemStack.areItemsAndComponentsEqual(stack, otherStack);
|
||||||
}
|
}
|
||||||
return original.call(stack, otherStack);
|
|
||||||
|
@Redirect(
|
||||||
|
method = "*",
|
||||||
|
at = @At(
|
||||||
|
value = "INVOKE",
|
||||||
|
target = "Lnet/minecraft/item/ItemStack;isStackable()Z"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
private boolean isStackable(ItemStack stack) {
|
||||||
|
if (ShulkerBoxItemUtil.isEmptyShulkerBoxItem(stack)) return true;
|
||||||
|
return stack.isStackable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
package com.github.zly2006.carpetslsaddition.mixin.shulker;
|
||||||
|
|
||||||
|
import com.github.zly2006.carpetslsaddition.SLSCarpetSettings;
|
||||||
|
import com.github.zly2006.carpetslsaddition.util.ShulkerBoxItemUtil;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
|
||||||
|
@Mixin(ServerPlayNetworkHandler.class)
|
||||||
|
public class MixinServerPlayNetworkHandler {
|
||||||
|
@Redirect(
|
||||||
|
method = "onCreativeInventoryAction",
|
||||||
|
at = @At(
|
||||||
|
value = "INVOKE",
|
||||||
|
target = "Lnet/minecraft/item/ItemStack;getMaxCount()I"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
private int getMaxCount(ItemStack instance) {
|
||||||
|
if (SLSCarpetSettings.emptyShulkerBoxStack && ShulkerBoxItemUtil.isEmptyShulkerBoxItem(instance)) {
|
||||||
|
return ShulkerBoxItemUtil.SHULKERBOX_MAX_STACK_AMOUNT;
|
||||||
|
}
|
||||||
|
return instance.getMaxCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,11 +2,8 @@ package com.github.zly2006.carpetslsaddition.util;
|
|||||||
|
|
||||||
import net.minecraft.block.ShulkerBoxBlock;
|
import net.minecraft.block.ShulkerBoxBlock;
|
||||||
import net.minecraft.component.DataComponentTypes;
|
import net.minecraft.component.DataComponentTypes;
|
||||||
import net.minecraft.component.type.NbtComponent;
|
|
||||||
import net.minecraft.item.BlockItem;
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NbtList;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@@ -19,8 +16,8 @@ public class ShulkerBoxItemUtil {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return Objects.equals(
|
return Objects.equals(
|
||||||
stack.getComponents().filtered(s -> s != DataComponentTypes.BLOCK_ENTITY_DATA),
|
stack.getComponents().filtered(s -> s != DataComponentTypes.CONTAINER),
|
||||||
stack.getComponents().filtered(s -> s != DataComponentTypes.BLOCK_ENTITY_DATA)
|
stack.getComponents().filtered(s -> s != DataComponentTypes.CONTAINER)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return ItemStack.areItemsAndComponentsEqual(stack, otherStack);
|
return ItemStack.areItemsAndComponentsEqual(stack, otherStack);
|
||||||
@@ -29,11 +26,11 @@ public class ShulkerBoxItemUtil {
|
|||||||
public static boolean isEmptyShulkerBoxItem(ItemStack itemStack) {
|
public static boolean isEmptyShulkerBoxItem(ItemStack itemStack) {
|
||||||
if (itemStack.getItem() instanceof BlockItem &&
|
if (itemStack.getItem() instanceof BlockItem &&
|
||||||
((BlockItem) itemStack.getItem()).getBlock() instanceof ShulkerBoxBlock) {
|
((BlockItem) itemStack.getItem()).getBlock() instanceof ShulkerBoxBlock) {
|
||||||
NbtComponent tag = itemStack.getComponents().get(DataComponentTypes.BLOCK_ENTITY_DATA);
|
if (itemStack.getComponents().contains(DataComponentTypes.CONTAINER)) {
|
||||||
if (tag != null && tag.contains("Items")) {
|
return !itemStack.getComponents().get(DataComponentTypes.CONTAINER).iterateNonEmpty().iterator().hasNext();
|
||||||
return tag.getNbt().getList("Items", 10).isEmpty();
|
} else {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,9 @@
|
|||||||
"screen.MixinAnvilScreenHandler",
|
"screen.MixinAnvilScreenHandler",
|
||||||
"server.MixinMinecraftServer",
|
"server.MixinMinecraftServer",
|
||||||
"shulker.MixinItemStack",
|
"shulker.MixinItemStack",
|
||||||
|
"shulker.MixinPlayerInventory",
|
||||||
"shulker.MixinScreenHandler",
|
"shulker.MixinScreenHandler",
|
||||||
|
"shulker.MixinServerPlayNetworkHandler",
|
||||||
"shulker.MixinSlot",
|
"shulker.MixinSlot",
|
||||||
"world.MixinSleepManager",
|
"world.MixinSleepManager",
|
||||||
"world.MixinSpawnHelper",
|
"world.MixinSpawnHelper",
|
||||||
|
|||||||
Reference in new issue
Block a user