修复部分情况下物品传输条件的判断问题
This commit is contained in:
parent
24b04c1176
commit
7d3b7e6572
1 changed files with 13 additions and 2 deletions
|
@ -233,8 +233,9 @@ public abstract class VehicleEntity extends Entity implements Container {
|
||||||
if (!this.hasContainer() || slot >= this.getContainerSize() || slot < 0) return;
|
if (!this.hasContainer() || slot >= this.getContainerSize() || slot < 0) return;
|
||||||
|
|
||||||
this.items.set(slot, pStack);
|
this.items.set(slot, pStack);
|
||||||
if (!pStack.isEmpty() && pStack.getCount() > this.getMaxStackSize()) {
|
var limit = Math.min(this.getMaxStackSize(), pStack.getMaxStackSize());
|
||||||
pStack.setCount(this.getMaxStackSize());
|
if (!pStack.isEmpty() && pStack.getCount() > limit) {
|
||||||
|
pStack.setCount(limit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,6 +269,15 @@ public abstract class VehicleEntity extends Entity implements Container {
|
||||||
@Override
|
@Override
|
||||||
public boolean canPlaceItem(int slot, @NotNull ItemStack stack) {
|
public boolean canPlaceItem(int slot, @NotNull ItemStack stack) {
|
||||||
if (!this.hasContainer() || slot >= this.getContainerSize() || slot < 0) return false;
|
if (!this.hasContainer() || slot >= this.getContainerSize() || slot < 0) return false;
|
||||||
|
|
||||||
|
var currentStack = this.items.get(slot);
|
||||||
|
if (!currentStack.isEmpty() && currentStack.getItem() != stack.getItem()) return false;
|
||||||
|
|
||||||
|
var currentCount = currentStack.getCount();
|
||||||
|
var stackCount = stack.getCount();
|
||||||
|
int combinedCount = currentCount + stackCount;
|
||||||
|
if (combinedCount > this.getMaxStackSize() || combinedCount > stack.getMaxStackSize()) return false;
|
||||||
|
|
||||||
return Container.super.canPlaceItem(slot, stack);
|
return Container.super.canPlaceItem(slot, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -492,6 +502,7 @@ public abstract class VehicleEntity extends Entity implements Container {
|
||||||
}
|
}
|
||||||
|
|
||||||
// energy start
|
// energy start
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消耗指定电量
|
* 消耗指定电量
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue