mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-19 14:59:32 +00:00
Do not throw when bot nbt is illegal (#746)
* fix: do not throw when bot nbt illegal * fix: fix logic and format * refactor: better format * refactor: better format * refactor: better format * refactor: better format * refactor: better format
This commit is contained in:
@@ -133,12 +133,12 @@ public abstract class ServerBotAction<E extends ServerBotAction<E>> {
|
||||
public void load(@NotNull CompoundTag nbt) {
|
||||
this.uuid = nbt.read("actionUUID", UUIDUtil.CODEC).orElse(UUID.randomUUID());
|
||||
|
||||
this.initialTickDelay = nbt.getInt("initialTickDelay").orElse(0);
|
||||
this.initialTickInterval = nbt.getInt("initialTickInterval").orElse(0);
|
||||
this.initialNumber = nbt.getInt("initialNumber").orElse(0);
|
||||
this.initialTickDelay = nbt.getIntOr("initialTickDelay", 0);
|
||||
this.initialTickInterval = nbt.getIntOr("initialTickInterval", 0);
|
||||
this.initialNumber = nbt.getIntOr("initialNumber", 0);
|
||||
|
||||
this.tickToNext = nbt.getInt("tickToNext").orElse(0);
|
||||
this.numberRemaining = nbt.getInt("numberRemaining").orElse(0);
|
||||
this.tickToNext = nbt.getIntOr("tickToNext", 0);
|
||||
this.numberRemaining = nbt.getIntOr("numberRemaining", 0);
|
||||
}
|
||||
|
||||
public void stop(@NotNull ServerBot bot, BotActionStopEvent.Reason reason) {
|
||||
|
||||
@@ -38,8 +38,8 @@ public class ServerFishAction extends ServerTimerBotAction<ServerFishAction> {
|
||||
@Override
|
||||
public void load(@NotNull CompoundTag nbt) {
|
||||
super.load(nbt);
|
||||
this.initialFishInterval = nbt.getInt("initialFishInterval").orElseThrow();
|
||||
this.tickToNextFish = nbt.getInt("tickToNextFish").orElseThrow();
|
||||
this.initialFishInterval = nbt.getIntOr("initialFishInterval", this.initialFishInterval);
|
||||
this.tickToNextFish = nbt.getIntOr("tickToNextFish", this.tickToNextFish);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -105,9 +105,9 @@ public abstract class ServerUseBotAction<T extends ServerUseBotAction<T>> extend
|
||||
@Override
|
||||
public void load(@NotNull CompoundTag nbt) {
|
||||
super.load(nbt);
|
||||
this.useTickTimeout = nbt.getInt("useTick").orElseThrow();
|
||||
this.useTickTimeout = nbt.getIntOr("useTick", this.useTickTimeout);
|
||||
this.alreadyUsedTick = nbt.getInt("alreadyUsedTick").orElseGet(
|
||||
() -> this.useTickTimeout - nbt.getInt("tickToRelease").orElseThrow()
|
||||
() -> nbt.getInt("tickToRelease").map(tickToRelease -> this.useTickTimeout - tickToRelease).orElse(this.alreadyUsedTick)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user