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