Provide access to the haveTime supplier in WorldTickEvent and ServerTickEvent (#8470)

This commit is contained in:
Joseph Tarbit authored and GitHub committed 2022-03-06 14:42:58 +00:00
1 parent cdd91968b4
commit 41c88f6e52
3 files changed
+107 -8

No files matched your search

@@ -6,6 +6,9 @@
package net.minecraftforge.event;
import net.minecraft.world.entity.player.Player;
import java.util.function.BooleanSupplier;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.Level;
import net.minecraftforge.eventbus.api.Event;
@@ -31,9 +34,34 @@ public class TickEvent extends Event
}
public static class ServerTickEvent extends TickEvent {
private final BooleanSupplier haveTime;
/**
* TODO: Remove in 1.19
*
* @deprecated Use {@link ServerTickEvent#ServerTickEvent(Phase, BooleanSupplier)}
*/
@Deprecated(forRemoval = true, since = "1.18.1")
public ServerTickEvent(Phase phase)
{
this(phase, () -> false);
}
public ServerTickEvent(Phase phase, BooleanSupplier haveTime)
{
super(Type.SERVER, LogicalSide.SERVER, phase);
this.haveTime = haveTime;
}
/**
* @return {@code true} whether the server has enough time to perform any
* additional tasks (usually IO related) during the current tick,
* otherwise {@code false}
*/
public boolean haveTime()
{
return this.haveTime.getAsBoolean();
}
}
@@ -46,10 +74,36 @@ public class TickEvent extends Event
public static class WorldTickEvent extends TickEvent {
public final Level world;
private final BooleanSupplier haveTime;
/**
* TODO: Remove in 1.19
*
* @deprecated Use {@link WorldTickEvent#WorldTickEvent(LogicalSide, Phase, Level, BooleanSupplier)}
*/
@Deprecated(forRemoval = true, since = "1.18.1")
public WorldTickEvent(LogicalSide side, Phase phase, Level world)
{
this(side, phase, world, () -> false);
}
public WorldTickEvent(LogicalSide side, Phase phase, Level world, BooleanSupplier haveTime)
{
super(Type.WORLD, side, phase);
this.world = world;
this.haveTime = haveTime;
}
/**
* @return {@code true} whether the server has enough time to perform any
* additional tasks (usually IO related) during the current tick,
* otherwise {@code false}
*
* @see ServerTickEvent#haveTime()
*/
public boolean haveTime()
{
return this.haveTime.getAsBoolean();
}
}
public static class PlayerTickEvent extends TickEvent {