fix: emptyShulkerBoxStack
This commit is contained in:
9 files changed
+132
-94
No files matched your search
@@ -7,9 +7,7 @@ import net.minecraft.block.RedstoneBlock;
|
|||||||
import static com.github.zly2006.carpetslsaddition.ServerMain.CARPET_ID;
|
import static com.github.zly2006.carpetslsaddition.ServerMain.CARPET_ID;
|
||||||
|
|
||||||
public class SLSCarpetSettings {
|
public class SLSCarpetSettings {
|
||||||
public static final String PCA = "pca"; // 用于描述兼容PCA的规则
|
|
||||||
public static final String NEED_CLIENT = "needClient"; // 需要客户端安装SLS-Addition或实现相关支持
|
public static final String NEED_CLIENT = "needClient"; // 需要客户端安装SLS-Addition或实现相关支持
|
||||||
public static final String PROTOCOL = "protocol";
|
|
||||||
|
|
||||||
@Rule(categories = {CARPET_ID, RuleCategory.SURVIVAL})
|
@Rule(categories = {CARPET_ID, RuleCategory.SURVIVAL})
|
||||||
public static boolean obtainableReinforcedDeepSlate = false;
|
public static boolean obtainableReinforcedDeepSlate = false;
|
||||||
@@ -35,19 +33,10 @@ public class SLSCarpetSettings {
|
|||||||
@Rule(categories = {CARPET_ID, RuleCategory.CREATIVE})
|
@Rule(categories = {CARPET_ID, RuleCategory.CREATIVE})
|
||||||
public static int maxUpdateQueueSize = -1;
|
public static int maxUpdateQueueSize = -1;
|
||||||
|
|
||||||
@Rule(categories = {CARPET_ID, PCA, PROTOCOL})
|
@Rule(categories = {CARPET_ID, RuleCategory.FEATURE, NEED_CLIENT})
|
||||||
public static boolean pcaSyncProtocol = false;
|
|
||||||
|
|
||||||
@Rule(categories = {CARPET_ID, PCA, PROTOCOL})
|
|
||||||
public static PCA_SYNC_PLAYER_ENTITY_OPTIONS pcaSyncPlayerEntity = PCA_SYNC_PLAYER_ENTITY_OPTIONS.OPS;
|
|
||||||
|
|
||||||
@Rule(categories = {CARPET_ID, PCA, RuleCategory.FEATURE, NEED_CLIENT})
|
|
||||||
public static boolean emptyShulkerBoxStack = false;
|
public static boolean emptyShulkerBoxStack = false;
|
||||||
|
|
||||||
@Rule(categories = {CARPET_ID, PCA, PROTOCOL}, strict = false, options = {"#none"})
|
@Rule(categories = {CARPET_ID, RuleCategory.FEATURE})
|
||||||
public static String xaeroWorldName = "#none";
|
|
||||||
|
|
||||||
@Rule(categories = {CARPET_ID, PCA, RuleCategory.FEATURE})
|
|
||||||
public static boolean playerSit = false;
|
public static boolean playerSit = false;
|
||||||
|
|
||||||
@Rule(categories = {CARPET_ID, RuleCategory.FEATURE})
|
@Rule(categories = {CARPET_ID, RuleCategory.FEATURE})
|
||||||
@@ -58,10 +47,4 @@ public class SLSCarpetSettings {
|
|||||||
|
|
||||||
@Rule(categories = {CARPET_ID, RuleCategory.OPTIMIZATION})
|
@Rule(categories = {CARPET_ID, RuleCategory.OPTIMIZATION})
|
||||||
public static boolean optimizedOnDragonRespawn = false;
|
public static boolean optimizedOnDragonRespawn = false;
|
||||||
|
|
||||||
|
|
||||||
public enum PCA_SYNC_PLAYER_ENTITY_OPTIONS {
|
|
||||||
NOBODY, BOT, OPS, OPS_AND_SELF, EVERYONE
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
-38
@@ -1,38 +0,0 @@
|
|||||||
package com.github.zly2006.carpetslsaddition.mixin.player;
|
|
||||||
|
|
||||||
import net.minecraft.entity.player.PlayerAbilities;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
|
||||||
|
|
||||||
@Mixin(PlayerAbilities.class)
|
|
||||||
public interface AccessorPlayerAbilities {
|
|
||||||
@Accessor("flySpeed")
|
|
||||||
void setFlyingSpeed(float speed);
|
|
||||||
@Accessor("walkSpeed")
|
|
||||||
void setWalkingSpeed(float speed);
|
|
||||||
@Accessor("flying")
|
|
||||||
void setFlying(boolean flying);
|
|
||||||
@Accessor("invulnerable")
|
|
||||||
void setInvulnerable(boolean invulnerable);
|
|
||||||
@Accessor("allowFlying")
|
|
||||||
void setAllowFlying(boolean allowFlying);
|
|
||||||
@Accessor("creativeMode")
|
|
||||||
void setCreativeMode(boolean creativeMode);
|
|
||||||
@Accessor("allowModifyWorld")
|
|
||||||
void setAllowModifyWorld(boolean allowModifyWorld);
|
|
||||||
|
|
||||||
@Accessor("flySpeed")
|
|
||||||
float getFlyingSpeed();
|
|
||||||
@Accessor("walkSpeed")
|
|
||||||
float getWalkingSpeed();
|
|
||||||
@Accessor("flying")
|
|
||||||
boolean isFlying();
|
|
||||||
@Accessor("invulnerable")
|
|
||||||
boolean isInvulnerable();
|
|
||||||
@Accessor("allowFlying")
|
|
||||||
boolean isAllowFlying();
|
|
||||||
@Accessor("creativeMode")
|
|
||||||
boolean isCreativeMode();
|
|
||||||
@Accessor("allowModifyWorld")
|
|
||||||
boolean isAllowModifyWorld();
|
|
||||||
}
|
|
||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
package com.github.zly2006.carpetslsaddition.mixin.player;
|
||||||
|
|
||||||
|
import com.github.zly2006.carpetslsaddition.SLSCarpetSettings;
|
||||||
|
import net.minecraft.entity.player.PlayerAbilities;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
|
import net.minecraft.inventory.Inventory;
|
||||||
|
import net.minecraft.util.Nameable;
|
||||||
|
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, Nameable {
|
||||||
|
@Redirect(
|
||||||
|
method = "insertStack(ILnet/minecraft/item/ItemStack;)Z",
|
||||||
|
at = @At(
|
||||||
|
value = "INVOKE",
|
||||||
|
target = "Lnet/minecraft/entity/player/PlayerEntity;isInCreativeMode()Z"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
private boolean insertStack(PlayerEntity instance) {
|
||||||
|
if (SLSCarpetSettings.creativeNoInfinitePickup) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return instance.isInCreativeMode();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package com.github.zly2006.carpetslsaddition.mixin.screen;
|
|
||||||
|
|
||||||
import com.github.zly2006.carpetslsaddition.util.ShulkerBoxItemUtil;
|
|
||||||
import me.fallenbreath.conditionalmixin.api.annotation.Condition;
|
|
||||||
import me.fallenbreath.conditionalmixin.api.annotation.Restriction;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
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;
|
|
||||||
|
|
||||||
@Restriction(
|
|
||||||
conflict = @Condition("pca")
|
|
||||||
)
|
|
||||||
@Mixin(Slot.class)
|
|
||||||
public class MixinSlot {
|
|
||||||
@Redirect(method = "getMaxItemCount(Lnet/minecraft/item/ItemStack;)I", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;getMaxCount()I", ordinal = 0))
|
|
||||||
private int getMaxItemCount(ItemStack itemStack) {
|
|
||||||
return ShulkerBoxItemUtil.getMaxCount(itemStack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
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 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 MixinItemStack {
|
||||||
|
@Inject(
|
||||||
|
method = "getMaxCount",
|
||||||
|
at = @At("HEAD"),
|
||||||
|
cancellable = true
|
||||||
|
)
|
||||||
|
private void getMaxCount(CallbackInfoReturnable<Integer> cir) {
|
||||||
|
if (SLSCarpetSettings.emptyShulkerBoxStack && ShulkerBoxItemUtil.isEmptyShulkerBoxItem((ItemStack) (Object) this)) {
|
||||||
|
cir.setReturnValue(ShulkerBoxItemUtil.SHULKERBOX_MAX_STACK_AMOUNT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
package com.github.zly2006.carpetslsaddition.mixin.shulker;
|
||||||
|
|
||||||
|
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.screen.ScreenHandler;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
|
||||||
|
@Mixin(ScreenHandler.class)
|
||||||
|
public abstract class MixinScreenHandler {
|
||||||
|
@WrapOperation(
|
||||||
|
method = "internalOnSlotClick",
|
||||||
|
at = @At(
|
||||||
|
value = "INVOKE",
|
||||||
|
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) {
|
||||||
|
if (ShulkerBoxItemUtil.shulkerBoxEqual(stack, otherStack)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return original.call(stack, otherStack);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.github.zly2006.carpetslsaddition.mixin.shulker;
|
||||||
|
|
||||||
|
import com.github.zly2006.carpetslsaddition.SLSCarpetSettings;
|
||||||
|
import com.github.zly2006.carpetslsaddition.util.ShulkerBoxItemUtil;
|
||||||
|
import me.fallenbreath.conditionalmixin.api.annotation.Condition;
|
||||||
|
import me.fallenbreath.conditionalmixin.api.annotation.Restriction;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
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;
|
||||||
|
|
||||||
|
@Restriction(
|
||||||
|
conflict = @Condition("pca")
|
||||||
|
)
|
||||||
|
@Mixin(Slot.class)
|
||||||
|
public class MixinSlot {
|
||||||
|
@Redirect(
|
||||||
|
method = "getMaxItemCount(Lnet/minecraft/item/ItemStack;)I",
|
||||||
|
at = @At(
|
||||||
|
value = "INVOKE",
|
||||||
|
target = "Lnet/minecraft/item/ItemStack;getMaxCount()I",
|
||||||
|
ordinal = 0
|
||||||
|
)
|
||||||
|
)
|
||||||
|
private int getMaxItemCount(ItemStack itemStack) {
|
||||||
|
if (SLSCarpetSettings.emptyShulkerBoxStack && ShulkerBoxItemUtil.isEmptyShulkerBoxItem(itemStack)) {
|
||||||
|
return ShulkerBoxItemUtil.SHULKERBOX_MAX_STACK_AMOUNT;
|
||||||
|
} else {
|
||||||
|
return itemStack.getMaxCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,18 +1,31 @@
|
|||||||
package com.github.zly2006.carpetslsaddition.util;
|
package com.github.zly2006.carpetslsaddition.util;
|
||||||
|
|
||||||
import com.github.zly2006.carpetslsaddition.SLSCarpetSettings;
|
|
||||||
import net.minecraft.block.ShulkerBoxBlock;
|
import net.minecraft.block.ShulkerBoxBlock;
|
||||||
import net.minecraft.component.ComponentType;
|
|
||||||
import net.minecraft.component.DataComponentTypes;
|
import net.minecraft.component.DataComponentTypes;
|
||||||
import net.minecraft.component.type.NbtComponent;
|
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.NbtCompound;
|
|
||||||
import net.minecraft.nbt.NbtList;
|
import net.minecraft.nbt.NbtList;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class ShulkerBoxItemUtil {
|
public class ShulkerBoxItemUtil {
|
||||||
public static final int SHULKERBOX_MAX_STACK_AMOUNT = 64;
|
public static final int SHULKERBOX_MAX_STACK_AMOUNT = 64;
|
||||||
|
|
||||||
|
public static boolean shulkerBoxEqual(ItemStack stack, ItemStack otherStack) {
|
||||||
|
if (ShulkerBoxItemUtil.isEmptyShulkerBoxItem(stack) && ShulkerBoxItemUtil.isEmptyShulkerBoxItem(otherStack)) {
|
||||||
|
if (stack.isEmpty() && otherStack.isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return Objects.equals(
|
||||||
|
stack.getComponents().filtered(s -> s != DataComponentTypes.BLOCK_ENTITY_DATA),
|
||||||
|
stack.getComponents().filtered(s -> s != DataComponentTypes.BLOCK_ENTITY_DATA)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return ItemStack.areItemsAndComponentsEqual(stack, otherStack);
|
||||||
|
}
|
||||||
|
|
||||||
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) {
|
||||||
@@ -29,15 +42,4 @@ public class ShulkerBoxItemUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getMaxCount(ItemStack itemStack) {
|
|
||||||
if (SLSCarpetSettings.emptyShulkerBoxStack && ShulkerBoxItemUtil.isEmptyShulkerBoxItem(itemStack)) {
|
|
||||||
return ShulkerBoxItemUtil.SHULKERBOX_MAX_STACK_AMOUNT;
|
|
||||||
} else {
|
|
||||||
return itemStack.getMaxCount();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isStackable(ItemStack itemStack) {
|
|
||||||
return getMaxCount(itemStack) > 1 && (!itemStack.isDamageable() || !itemStack.isDamaged());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -21,9 +21,11 @@
|
|||||||
"entity.MixinPlayerEntity",
|
"entity.MixinPlayerEntity",
|
||||||
"entity.MixinServerPlayerEntity",
|
"entity.MixinServerPlayerEntity",
|
||||||
"entity.MixinVillagerEntity",
|
"entity.MixinVillagerEntity",
|
||||||
"player.AccessorPlayerAbilities",
|
"player.MixinPlayerInventory",
|
||||||
"screen.MixinSlot",
|
|
||||||
"server.MixinMinecraftServer",
|
"server.MixinMinecraftServer",
|
||||||
|
"shulker.MixinItemStack",
|
||||||
|
"shulker.MixinScreenHandler",
|
||||||
|
"shulker.MixinSlot",
|
||||||
"world.MixinSleepManager",
|
"world.MixinSleepManager",
|
||||||
"world.MixinSpawnHelper",
|
"world.MixinSpawnHelper",
|
||||||
"world.MixinWorld"
|
"world.MixinWorld"
|
||||||
|
|||||||
Reference in new issue
Block a user