mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-27 11:38:03 +01:00
Fix first tick call
This commit is contained in:
parent
6cc8946963
commit
e8e30b1328
@ -5,25 +5,38 @@ import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import net.minestom.server.event.Event;
|
||||
import net.minestom.server.instance.InstanceContainer;
|
||||
|
||||
/**
|
||||
* Called when an instance processes a tick
|
||||
*/
|
||||
public class InstanceTickEvent extends Event {
|
||||
|
||||
private final int duration;
|
||||
private final int duration;
|
||||
private final InstanceContainer instance;
|
||||
|
||||
public InstanceTickEvent(@NotNull long time, @Nullable long lastTickAge) {
|
||||
public InstanceTickEvent(@NotNull long time, @Nullable long lastTickAge, InstanceContainer someInstance) {
|
||||
this.duration = (int) (time - lastTickAge);
|
||||
this.instance = someInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the duration of the tick in ms
|
||||
*
|
||||
* @return the instance
|
||||
* @return the duration
|
||||
*/
|
||||
@NotNull
|
||||
public int getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the instance of the event
|
||||
*
|
||||
* @return the instance
|
||||
*/
|
||||
@NotNull
|
||||
public InstanceContainer getInstance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
@ -65,6 +65,9 @@ public class InstanceContainer extends Instance {
|
||||
|
||||
private final ReadWriteLock changingBlockLock = new ReentrantReadWriteLock();
|
||||
private final Map<BlockPosition, Block> currentlyChangingBlocks = new HashMap<>();
|
||||
|
||||
// Fields for tick events
|
||||
private long lastTickAge = System.currentTimeMillis();
|
||||
|
||||
// the chunk loader, used when trying to load/save a chunk from another source
|
||||
private IChunkLoader chunkLoader;
|
||||
@ -78,9 +81,6 @@ public class InstanceContainer extends Instance {
|
||||
// Fields for instance copy
|
||||
protected InstanceContainer srcInstance; // only present if this instance has been created using a copy
|
||||
private long lastBlockChangeTime; // Time at which the last block change happened (#setBlock)
|
||||
|
||||
// Fields for tick events
|
||||
private long lastTickAge;
|
||||
|
||||
/**
|
||||
* Creates an {@link InstanceContainer}.
|
||||
@ -794,7 +794,7 @@ public class InstanceContainer extends Instance {
|
||||
super.tick(time);
|
||||
|
||||
// Process tick events
|
||||
InstanceTickEvent chunkTickEvent = new InstanceTickEvent(time, lastTickAge);
|
||||
InstanceTickEvent chunkTickEvent = new InstanceTickEvent(time, lastTickAge, this);
|
||||
callEvent(InstanceTickEvent.class, chunkTickEvent);
|
||||
|
||||
Lock wrlock = changingBlockLock.writeLock();
|
||||
|
Loading…
Reference in New Issue
Block a user