Skip to content

Commit

Permalink
调整电网 tick 逻辑,避免重复执行 update
Browse files Browse the repository at this point in the history
  • Loading branch information
Gu-ZT committed Dec 20, 2024
1 parent 570ae28 commit c39c83b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
11 changes: 6 additions & 5 deletions src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,12 @@ protected void tick() {
for (IPowerStorage storage : this.storages) {
need -= storage.getOutputPower();
storages.add(storage);
if (need <= 0) break;
}
if (need > 0) this.update(false);
else for (IPowerStorage storage : storages) {
this.generate += storage.extract(this.consume - this.generate);
if (need <= 0) {
for (IPowerStorage selectStorage : storages) {
this.generate += selectStorage.extract(this.consume - this.generate);
}
break;
}
}
}
this.gridTick();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,12 @@ public void saveAdditional(@NotNull CompoundTag tag, HolderLookup.@NotNull Provi

@Override
public void gridTick() {
if (this.cooldownCount > 1) {
this.cooldownCount -= 1;
return;
}
if (level == null || level.isClientSide()) return;
if (this.cooldownCount-- > 1) return;
this.cooldownCount = COOLDOWN;
int oldPower = this.power;
this.power = (int) Math.floor(this.chargeCount);
if (power != oldPower && grid != null) {
grid.markChanged();
}
if (power != oldPower && grid != null) grid.markChanged();
this.chargeCount = 0;
time++;
}
Expand Down

0 comments on commit c39c83b

Please sign in to comment.