---- Minecraft Crash Report ----
// You're mean.
Time: 2024-05-22 21:32:05
Description: Exception in server tick loop
java.lang.NoClassDefFoundError: dev/onyxstudios/cca/api/v3/entity/EntityComponentInitializer
at committee.nova.mods.lighteco.api.FabricEco.getBalance(FabricEco.java:70)
at committee.nova.mods.lighteco.api.FabricEco.getBalance(FabricEco.java:33)
at link.botwmcs.ecohelper.util.ApiHandler.getBalance(ApiHandler.java:12)
at link.botwmcs.ecohelper.command.EcoCommand.lambda$register$0(EcoCommand.java:21)
at com.mojang.brigadier.CommandDispatcher.execute(CommandDispatcher.java:264)
at net.minecraft.commands.Commands.performCommand(Commands.java:287)
at net.minecraft.commands.Commands.performPrefixedCommand(Commands.java:280)
at net.minecraft.server.dedicated.DedicatedServer.handleConsoleInputs(DedicatedServer.java:299)
at net.minecraft.server.dedicated.DedicatedServer.tickChildren(DedicatedServer.java:284)
at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:824)
at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:671)
at net.minecraft.server.MinecraftServer.method_29739(MinecraftServer.java:265)
at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: java.lang.ClassNotFoundException: dev.onyxstudios.cca.api.v3.entity.EntityComponentInitializer
... 13 more
以下是代码实现:
public class ApiHandler {
public static double getBalance(Player player) {
Optional<BigDecimal> balance = FabricEco.INSTANCE.getBalance(player);
double checkBalance = balance.map(BigDecimal::doubleValue).orElse(0.0);
return Security.safetyCheck(checkBalance);
}
public static EcoUtils.EcoActionResult addBalance(Player player, double value) {
// First round the value to 2 decimal places
BigDecimal afterValue = MathHelper.roundDouble(value);
// Get the current balance
double currentBalance = getBalance(player);
// Add the value to the current balance
double newBalance = Security.safetyCheck(currentBalance + afterValue.doubleValue());
// Calculate the final value
BigDecimal finalValue = BigDecimal.valueOf(newBalance - currentBalance);
return FabricEco.INSTANCE.debt(player, finalValue);
}
public static EcoUtils.EcoActionResult removeBalance(Player player, double value) {
BigDecimal afterValue = MathHelper.roundDouble(value);
double currentBalance = getBalance(player);
double newBalance = Security.safetyCheck(currentBalance - afterValue.doubleValue());
BigDecimal finalValue = BigDecimal.valueOf(currentBalance - newBalance);
return FabricEco.INSTANCE.credit(player, finalValue);
}
public static EcoUtils.EcoActionResult setBalance(Player player, double value) {
BigDecimal afterValue = MathHelper.roundDouble(value);
double currentBalance = getBalance(player);
double newBalance = Security.safetyCheck(afterValue.doubleValue());
BigDecimal finalValue = BigDecimal.valueOf(newBalance - currentBalance);
return FabricEco.INSTANCE.debt(player, finalValue);
}
}
我在调用lighteco的API的时候,返回给我EVENT_CANCELED
目前不太确定是我的代码问题还是lighteco的问题,不过有意思的是lighteco以modImplementation模式作为依赖之后不会加载lighteco的CCA依赖,会报缺类的报错。我需要在ecohelper侧添加CCA作为额外的API支持。
以下是代码实现:
检查结果是否合法的小方法:
我翻阅lighteco的代码,发现EVENT_CANCELED只有在vary方法中发现
BiPredicate<Player, BigDecimal> argChecker, BiFunction<Player, BigDecimal, BigDecimal> processor, BiPredicate<Player, BigDecimal> resultChecker
这三者任意为false,则会取消事件。 另外,在玩家加入游戏之后,读取playerData中的内容,会发现这里都是空的:所以不太确定是否是LightEco在1.20.1fabric下的playerData注册有问题还是EcoHelper的代码出错,目前暂未想出办法来解决......还请NovaCommittee的大佬们出谋划策