如何在1.18版本的等价交换中做得
1.只能买不能卖
2.卖获得emc会减少
1.只能买不能卖
2.卖获得emc会减少
- package moze_intel.projecte.gameObjs.container.inventory;
- /**
- * @apiNote Call on server only
- */
- public void addEmc(BigInteger value) {
- int compareToZero = value.compareTo(BigInteger.ZERO);
- if (compareToZero == 0) {
- //Optimization to not look at the items if nothing will happen anyways
- return;
- } else if (compareToZero < 0) {
- //Make sure it is using the correct method so that it handles the klein stars properly
- removeEmc(value.negate());
- return;
- }
- List<Integer> inputLocksChanged = new ArrayList<>();
- //Start by trying to add it to the EMC items on the left
- for (int slotIndex = 0; slotIndex < inputLocks.getSlots(); slotIndex++) {
- if (slotIndex == LOCK_INDEX) {
- continue;
- }
- ItemStack stack = inputLocks.getStackInSlot(slotIndex);
- if (!stack.isEmpty()) {
- Optional<IItemEmcHolder> holderCapability = stack.getCapability(PECapabilities.EMC_HOLDER_ITEM_CAPABILITY).resolve();
- if (holderCapability.isPresent()) {
- IItemEmcHolder emcHolder = holderCapability.get();
- long shrunkenValue = MathUtils.clampToLong(value);
- long actualInserted = emcHolder.insertEmc(stack, shrunkenValue, EmcAction.EXECUTE);
- if (actualInserted > 0) {
- inputLocksChanged.add(slotIndex);
- value = value.subtract(BigInteger.valueOf(actualInserted));
- if (value.compareTo(BigInteger.ZERO) == 0) {
- //If we fit it all then sync the changes to the client and exit
- syncChangedSlots(inputLocksChanged, TargetUpdateType.ALL);
- return;
- }
- }
- }
- }
- }
- syncChangedSlots(inputLocksChanged, TargetUpdateType.NONE);
- //Note: We act as if there is no "max" EMC for the player given we use a BigInteger
- // This means we don't have to try to put the overflow into the lock slot if there is an EMC storage item there
- updateEmcAndSync(provider.getEmc().add(value));
- }
应该是这个方法控制增加emc,修改下试试吧
Nuanxia0v0 发表于 2023-3-13 07:56
是放在哪里呢,稍微解释一下这个 谢谢`
不一定是对的,可以尝试下,具体的做法是把源代码下载下来,修改源代码后编译