This commit is contained in:
parent
cc4795c9d3
commit
49d58af604
@ -26,19 +26,34 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class EnergyProviderBlockEntity extends BlockEntity implements EnergyProvider, BlockEntityClientSerializable, Tickable {
|
||||
private static volatile boolean isTicking = false;
|
||||
|
||||
private static final List<EnergyProviderBlockEntity> scheduledTicks = new ArrayList<>();
|
||||
private static final List<EnergyProviderBlockEntity> scheduledTicksNext = new ArrayList<>();
|
||||
|
||||
public static void tickScheduled() {
|
||||
isTicking = true;
|
||||
Collections.shuffle(scheduledTicks);
|
||||
for (EnergyProviderBlockEntity provider : scheduledTicks) {
|
||||
provider.serverTick();
|
||||
}
|
||||
scheduledTicks.clear();
|
||||
isTicking = false;
|
||||
for (EnergyProviderBlockEntity entity : scheduledTicksNext) {
|
||||
entity.schedule();
|
||||
}
|
||||
scheduledTicksNext.clear();
|
||||
}
|
||||
|
||||
private void schedule() {
|
||||
if (!scheduledTicks.contains(this)) {
|
||||
scheduledTicks.add(this);
|
||||
List<EnergyProviderBlockEntity> list;
|
||||
if (isTicking) {
|
||||
list = scheduledTicksNext;
|
||||
} else {
|
||||
list = scheduledTicks;
|
||||
}
|
||||
if (!list.contains(this)) {
|
||||
list.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user