Move RTP functionality into its own thing to reduce overall lag when using RTP
This commit is contained in:
parent
eb1189e67f
commit
408e5d91d6
14 changed files with 422 additions and 264 deletions
|
@ -0,0 +1,44 @@
|
|||
package dev.zontreck.essentials.rtp;
|
||||
|
||||
import dev.zontreck.ariaslib.util.DelayedExecutorService;
|
||||
import dev.zontreck.essentials.commands.teleport.TeleportActioner;
|
||||
import dev.zontreck.essentials.commands.teleport.TeleportContainer;
|
||||
import dev.zontreck.libzontreck.vectors.Vector3;
|
||||
import dev.zontreck.libzontreck.vectors.WorldPosition;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.phys.Vec2;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
/**
|
||||
* The factory system used to start searching for a random teleport position
|
||||
*/
|
||||
public class RandomPositionFactory {
|
||||
|
||||
public static RTP beginRTPSearch(ServerLevel level)
|
||||
{
|
||||
RTP tmp = new RTP(level);
|
||||
tmp.position = new WorldPosition(new Vector3(0,0,0), WorldPosition.getDim(level));
|
||||
Thread tx = new Thread(new RandomPositionLocator(tmp));
|
||||
tx.setName("RTPTask-"+String.valueOf(DelayedExecutorService.getNext()));
|
||||
tx.start();
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
public static void beginRTP(ServerPlayer player, ServerLevel level)
|
||||
{
|
||||
RTP tmp = RTP.getRTP(level);
|
||||
if(tmp == null)
|
||||
{
|
||||
throw new RuntimeException("No valid destinations were found");
|
||||
}
|
||||
|
||||
TeleportActioner.ApplyTeleportEffect(player);
|
||||
TeleportContainer cont = new TeleportContainer(player, tmp.position.Position.asMinecraftVector(), player.getRotationVector(), level);
|
||||
|
||||
TeleportActioner.PerformTeleport(cont);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue