package com.hypixel.hytale.component.system; import com.hypixel.hytale.component.Resource; import com.hypixel.hytale.component.ResourceType; import com.hypixel.hytale.component.Store; import com.hypixel.hytale.component.system.tick.TickingSystem; import javax.annotation.Nonnull; public abstract class DelayedSystem extends TickingSystem { @Nonnull private final ResourceType> resourceType = this.registerResource(DelayedSystem.Data.class, DelayedSystem.Data::new); private final float intervalSec; public DelayedSystem(float intervalSec) { this.intervalSec = intervalSec; } @Nonnull public ResourceType> getResourceType() { return this.resourceType; } public float getIntervalSec() { return this.intervalSec; } @Override public void tick(float dt, int systemIndex, @Nonnull Store store) { DelayedSystem.Data data = store.getResource(this.resourceType); data.dt += dt; if (data.dt >= this.intervalSec) { float fullDeltaTime = data.dt; data.dt = 0.0F; this.delayedTick(fullDeltaTime, systemIndex, store); } } public abstract void delayedTick(float var1, int var2, @Nonnull Store var3); private static class Data implements Resource { private float dt; @Nonnull @Override public Resource clone() { DelayedSystem.Data data = new DelayedSystem.Data<>(); data.dt = this.dt; return data; } } }