fix: 载具堆叠改为Slot层,仅玩家背包可叠
删除全局ItemInstanceMixin(会让所有容器都叠)。新增SlotMixin:仅当container是玩家Inventory且物品是矿车/船时返回64。
This commit is contained in:
1 parent
c647189f77
commit
9e03c076ae
3 files changed
+46
-41
No files matched your search
@@ -1,40 +0,0 @@
|
||||
package com.github.zly2006.carpetslsaddition.mixin.item;
|
||||
|
||||
import com.github.zly2006.carpetslsaddition.SLSCarpetSettings;
|
||||
import net.minecraft.world.item.BoatItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemInstance;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.MinecartItem;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 载具堆叠:让矿车/船的物品可以堆叠到 64。
|
||||
*
|
||||
* <p>26.1.2 的堆叠上限来自 {@code ItemInstance.getMaxStackSize()} 的 default 实现:
|
||||
* 读取 {@code DataComponents.MAX_STACK_SIZE} 组件,默认 1(故矿车/船默认不堆叠)。
|
||||
*
|
||||
* <p>本 mixin 注入该 default 方法:规则 {@code stackableVehicles} 开启时,
|
||||
* 若物品是矿车({@link MinecartItem})或船({@link BoatItem}),返回 64。
|
||||
* 由于堆叠上限变大,同类载具在拾取/整理时会自动合并,实现"自动堆叠"。
|
||||
*/
|
||||
@Mixin(ItemInstance.class)
|
||||
public interface ItemInstanceMixin {
|
||||
|
||||
@Inject(method = "getMaxStackSize", at = @At("HEAD"), cancellable = true)
|
||||
private void stackableVehicles(CallbackInfoReturnable<Integer> cir) {
|
||||
if (!SLSCarpetSettings.stackableVehicles) {
|
||||
return;
|
||||
}
|
||||
if (!((Object) this instanceof ItemStack stack)) {
|
||||
return;
|
||||
}
|
||||
Item item = stack.getItem();
|
||||
if (item instanceof MinecartItem || item instanceof BoatItem) {
|
||||
cir.setReturnValue(64);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.github.zly2006.carpetslsaddition.mixin.item;
|
||||
|
||||
import com.github.zly2006.carpetslsaddition.SLSCarpetSettings;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.BoatItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.MinecartItem;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 载具堆叠(仅玩家背包):矿车/船在【玩家背包】内可堆叠到 64,其他容器不堆叠。
|
||||
*
|
||||
* <p>原理:{@code Slot.getMaxStackSize(ItemStack)} = min(容器上限, 物品上限)。
|
||||
* 载具的物品上限全局为 1(默认不叠)。本 mixin 在【容器是玩家背包 Inventory】且物品是载具时,
|
||||
* 直接返回 64,绕过 min 限制。
|
||||
*
|
||||
* <p>这样只有玩家背包(物品栏 36 格)内能叠,箱子/漏斗/潜影盒等其他容器不受影响。
|
||||
*/
|
||||
@Mixin(Slot.class)
|
||||
public abstract class SlotMixin {
|
||||
|
||||
@Inject(method = "getMaxStackSize(Lnet/minecraft/world/item/ItemStack;)I", at = @At("HEAD"), cancellable = true)
|
||||
private void stackableVehiclesInPlayerInventory(ItemStack stack, CallbackInfoReturnable<Integer> cir) {
|
||||
if (!SLSCarpetSettings.stackableVehicles) {
|
||||
return;
|
||||
}
|
||||
if (stack == null || stack.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Slot self = (Slot) (Object) this;
|
||||
// 仅玩家背包
|
||||
if (!(self.container instanceof Inventory)) {
|
||||
return;
|
||||
}
|
||||
Item item = stack.getItem();
|
||||
if (item instanceof MinecartItem || item instanceof BoatItem) {
|
||||
cir.setReturnValue(64);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
"block.MixinDecoratedPotBlock",
|
||||
"block.MixinTrialSpawnerData",
|
||||
"block.MixinTrialSpawnerState",
|
||||
"item.ItemInstanceMixin",
|
||||
"item.SlotMixin",
|
||||
"carpet.MixinEntityPlayerMPFake",
|
||||
"carpet.MixinPlayerCommand",
|
||||
"elytra.ItemAccessor",
|
||||
|
||||
Reference in new issue
Block a user