Nuanxia0v0
如何在1.18版本的等价交换中做得
1.只能买不能卖
2.卖获得emc会减少

krewella
  1. package moze_intel.projecte.gameObjs.container.inventory;

  2.         /**
  3.          * @apiNote Call on server only
  4.          */
  5.         public void addEmc(BigInteger value) {
  6.                 int compareToZero = value.compareTo(BigInteger.ZERO);
  7.                 if (compareToZero == 0) {
  8.                         //Optimization to not look at the items if nothing will happen anyways
  9.                         return;
  10.                 } else if (compareToZero < 0) {
  11.                         //Make sure it is using the correct method so that it handles the klein stars properly
  12.                         removeEmc(value.negate());
  13.                         return;
  14.                 }
  15.                 List<Integer> inputLocksChanged = new ArrayList<>();
  16.                 //Start by trying to add it to the EMC items on the left
  17.                 for (int slotIndex = 0; slotIndex < inputLocks.getSlots(); slotIndex++) {
  18.                         if (slotIndex == LOCK_INDEX) {
  19.                                 continue;
  20.                         }
  21.                         ItemStack stack = inputLocks.getStackInSlot(slotIndex);
  22.                         if (!stack.isEmpty()) {
  23.                                 Optional<IItemEmcHolder> holderCapability = stack.getCapability(PECapabilities.EMC_HOLDER_ITEM_CAPABILITY).resolve();
  24.                                 if (holderCapability.isPresent()) {
  25.                                         IItemEmcHolder emcHolder = holderCapability.get();
  26.                                         long shrunkenValue = MathUtils.clampToLong(value);
  27.                                         long actualInserted = emcHolder.insertEmc(stack, shrunkenValue, EmcAction.EXECUTE);
  28.                                         if (actualInserted > 0) {
  29.                                                 inputLocksChanged.add(slotIndex);
  30.                                                 value = value.subtract(BigInteger.valueOf(actualInserted));
  31.                                                 if (value.compareTo(BigInteger.ZERO) == 0) {
  32.                                                         //If we fit it all then sync the changes to the client and exit
  33.                                                         syncChangedSlots(inputLocksChanged, TargetUpdateType.ALL);
  34.                                                         return;
  35.                                                 }
  36.                                         }
  37.                                 }
  38.                         }
  39.                 }
  40.                 syncChangedSlots(inputLocksChanged, TargetUpdateType.NONE);
  41.                 //Note: We act as if there is no "max" EMC for the player given we use a BigInteger
  42.                 // This means we don't have to try to put the overflow into the lock slot if there is an EMC storage item there
  43.                 updateEmcAndSync(provider.getEmc().add(value));
  44.         }
复制代码

应该是这个方法控制增加emc,修改下试试吧

Nuanxia0v0
krewella 发表于 2023-3-13 06:55
应该是这个方法控制增加emc,修改下试试吧

是放在哪里呢,稍微解释一下这个 谢谢`

krewella
Nuanxia0v0 发表于 2023-3-13 07:56
是放在哪里呢,稍微解释一下这个 谢谢`

不一定是对的,可以尝试下,具体的做法是把源代码下载下来,修改源代码后编译

第一页 上一页 下一页 最后一页