Finish fixing RTP
This commit is contained in:
parent
516f067fb9
commit
a58cc55a5e
10 changed files with 89 additions and 59 deletions
|
@ -7,9 +7,18 @@ import java.nio.file.Path;
|
|||
import java.util.UUID;
|
||||
|
||||
import dev.zontreck.essentials.AriasEssentials;
|
||||
import dev.zontreck.essentials.Messages;
|
||||
import dev.zontreck.essentials.commands.teleport.TeleportActioner;
|
||||
import dev.zontreck.essentials.commands.teleport.TeleportContainer;
|
||||
import dev.zontreck.essentials.commands.teleport.TeleportDestination;
|
||||
import dev.zontreck.essentials.events.RTPNotCancelledEvent;
|
||||
import dev.zontreck.essentials.homes.HomesProvider;
|
||||
import dev.zontreck.libzontreck.chat.ChatColor;
|
||||
import dev.zontreck.libzontreck.events.ProfileLoadedEvent;
|
||||
import dev.zontreck.libzontreck.events.ProfileUnloadedEvent;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import dev.zontreck.libzontreck.vectors.WorldPosition;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
|
@ -34,4 +43,15 @@ public class ForgeEventsHandler {
|
|||
AriasEssentials.player_homes.remove(UUID.fromString(ev.user_id));
|
||||
AriasEssentials.LOGGER.info("Homes unloaded");
|
||||
}
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public void onRTPNotCancelled(final RTPNotCancelledEvent ev)
|
||||
{
|
||||
final TeleportContainer contain = ev.container.container;
|
||||
|
||||
ChatHelpers.broadcastTo(contain.PlayerInst.getUUID(), new TextComponent(Messages.ESSENTIALS_PREFIX + ChatColor.DARK_PURPLE+" A suitable location has been found. Wormhole opening now!"), contain.PlayerInst.server);
|
||||
TeleportActioner.ApplyTeleportEffect(contain.PlayerInst);
|
||||
TeleportActioner.PerformTeleport(contain);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,6 +80,8 @@ public class RTPContainer {
|
|||
public void newPosition() {
|
||||
if(!AriasEssentials.ALIVE)return;
|
||||
containingThread=Thread.currentThread();
|
||||
if(tries>=30)return;
|
||||
AriasEssentials.LOGGER.info("RTPContainer starts looking for new position");
|
||||
Random rng = new Random(Instant.now().getEpochSecond());
|
||||
Vector3 pos = new Vector3(rng.nextDouble(0xFFFF), 0, rng.nextDouble(0xFFFF));
|
||||
BlockPos bpos = pos.asBlockPos();
|
||||
|
@ -107,6 +109,7 @@ public class RTPContainer {
|
|||
}
|
||||
|
||||
tries++;
|
||||
AriasEssentials.LOGGER.info("RTPContainer returns new position");
|
||||
}
|
||||
|
||||
private void spiralPositions(Vector3 position)
|
||||
|
@ -133,8 +136,8 @@ public class RTPContainer {
|
|||
}
|
||||
newPosition();
|
||||
}
|
||||
|
||||
public boolean isSafe(BlockPos blockPos) {
|
||||
private boolean safe(BlockPos blockPos)
|
||||
{
|
||||
containingThread=Thread.currentThread();
|
||||
BlockState b = container.Dimension.getBlockState(blockPos);
|
||||
BlockState b2 = container.Dimension.getBlockState(blockPos.above());
|
||||
|
@ -152,4 +155,13 @@ public class RTPContainer {
|
|||
return false;
|
||||
|
||||
}
|
||||
public boolean isSafe(BlockPos blockPos) {
|
||||
boolean s = safe(blockPos);
|
||||
if(s)
|
||||
{
|
||||
AriasEssentials.LOGGER.info("/!\\ SAFE /!\\");
|
||||
}else AriasEssentials.LOGGER.info("/!\\ NOT SAFE /!\\");
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package dev.zontreck.essentials.util;
|
|||
import dev.zontreck.essentials.AriasEssentials;
|
||||
import dev.zontreck.essentials.Messages;
|
||||
import dev.zontreck.essentials.events.RTPEvent;
|
||||
import dev.zontreck.essentials.events.RTPNotCancelledEvent;
|
||||
import dev.zontreck.libzontreck.chat.ChatColor;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import dev.zontreck.libzontreck.util.DelayedExecutorService;
|
||||
|
@ -43,7 +44,7 @@ public class RandomPositionLocator implements Runnable
|
|||
levl.setChunkForced(cpos.x, cpos.z, true);
|
||||
|
||||
int curChecks=0;
|
||||
while(curChecks<30)
|
||||
while(curChecks<10)
|
||||
{
|
||||
if(contain.isSafe(contain.container.world_pos.Position.asBlockPos()))
|
||||
{
|
||||
|
@ -54,9 +55,13 @@ public class RandomPositionLocator implements Runnable
|
|||
if(MinecraftForge.EVENT_BUS.post(new RTPEvent(contain.container.PlayerInst, contain.container.world_pos)))
|
||||
{
|
||||
contain.complete=false;
|
||||
contain.container.Position = contain.container.world_pos.Position.asMinecraftVector();
|
||||
ChatHelpers.broadcastTo(contain.container.PlayerInst.getUUID(), new TextComponent(Messages.ESSENTIALS_PREFIX + ChatColor.doColors(" !Dark_Red!Last position checked was probably claimed. Another mod has asked us not to send you to that location, continuing the search")), contain.container.PlayerInst.server);
|
||||
|
||||
break;
|
||||
}else {
|
||||
AriasEssentials.LOGGER.info("RTP Not cancelled. Actioning");
|
||||
new RTPNotCancelledEvent(contain).send();
|
||||
}
|
||||
return;
|
||||
}else {
|
||||
|
@ -80,7 +85,8 @@ public class RandomPositionLocator implements Runnable
|
|||
// Schedule the task to execute
|
||||
//run();
|
||||
RandomPositionLocator next = new RandomPositionLocator(contain);
|
||||
DelayedExecutorService.getInstance().schedule(next, 2);
|
||||
DelayedExecutorService.getInstance().schedule(next, 1);
|
||||
AriasEssentials.LOGGER.info("Giving up current RTP search. Scheduling another search in 1 second");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue