Finish fixing RTP
This commit is contained in:
parent
516f067fb9
commit
a58cc55a5e
10 changed files with 89 additions and 59 deletions
|
@ -12,4 +12,4 @@ my_modid="ariasessentials"
|
||||||
mc_version=1.18.2
|
mc_version=1.18.2
|
||||||
forge_version=40.2.1
|
forge_version=40.2.1
|
||||||
parchment_version=2022.11.06
|
parchment_version=2022.11.06
|
||||||
libz_version=1.0.5.0227232305
|
libz_version=1.0.5.0228230829
|
||||||
|
|
|
@ -15,6 +15,7 @@ import dev.zontreck.essentials.commands.CommandRegister;
|
||||||
import dev.zontreck.essentials.homes.Homes;
|
import dev.zontreck.essentials.homes.Homes;
|
||||||
import dev.zontreck.essentials.homes.HomesProvider;
|
import dev.zontreck.essentials.homes.HomesProvider;
|
||||||
import dev.zontreck.essentials.util.EssentialsDatastore;
|
import dev.zontreck.essentials.util.EssentialsDatastore;
|
||||||
|
import dev.zontreck.essentials.util.ForgeEventsHandler;
|
||||||
import dev.zontreck.libzontreck.events.ProfileLoadedEvent;
|
import dev.zontreck.libzontreck.events.ProfileLoadedEvent;
|
||||||
import dev.zontreck.libzontreck.events.ProfileUnloadedEvent;
|
import dev.zontreck.libzontreck.events.ProfileUnloadedEvent;
|
||||||
import dev.zontreck.libzontreck.profiles.Profile;
|
import dev.zontreck.libzontreck.profiles.Profile;
|
||||||
|
@ -24,6 +25,7 @@ import net.minecraftforge.event.server.ServerStoppingEvent;
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||||
|
|
||||||
@Mod(AriasEssentials.MODID)
|
@Mod(AriasEssentials.MODID)
|
||||||
|
@ -36,10 +38,17 @@ public class AriasEssentials {
|
||||||
public AriasEssentials()
|
public AriasEssentials()
|
||||||
{
|
{
|
||||||
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
|
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||||
|
bus.addListener(this::setup);
|
||||||
|
|
||||||
EssentialsDatastore.initialize();
|
EssentialsDatastore.initialize();
|
||||||
MinecraftForge.EVENT_BUS.register(this);
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
MinecraftForge.EVENT_BUS.register(new CommandRegister());
|
MinecraftForge.EVENT_BUS.register(new CommandRegister());
|
||||||
|
MinecraftForge.EVENT_BUS.register(new ForgeEventsHandler());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setup(FMLCommonSetupEvent ev)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class HomesCommand {
|
||||||
for (Home string : homes.getList()) {
|
for (Home string : homes.getList()) {
|
||||||
Style st = Style.EMPTY.withFont(Style.DEFAULT_FONT).withHoverEvent(HoverTip.get(ChatColor.BOLD+ChatColor.DARK_GREEN+"Click here to go to this home")).withClickEvent(Clickable.command("/home "+string.homeName));
|
Style st = Style.EMPTY.withFont(Style.DEFAULT_FONT).withHoverEvent(HoverTip.get(ChatColor.BOLD+ChatColor.DARK_GREEN+"Click here to go to this home")).withClickEvent(Clickable.command("/home "+string.homeName));
|
||||||
|
|
||||||
ChatHelpers.broadcastTo(player.getUUID(), new TextComponent(ChatColor.BOLD + ChatColor.MINECOIN_GOLD+"["+ChatColor.resetChat()+ChatColor.UNDERLINE+ChatColor.BOLD+ChatColor.DARK_GREEN+"HOME"+ChatColor.resetChat()+ChatColor.BOLD+ChatColor.MINECOIN_GOLD+"] "+ChatColor.resetChat()+ChatColor.YELLOW+string).setStyle(st), ctx.getSource().getServer());
|
ChatHelpers.broadcastTo(player.getUUID(), new TextComponent(ChatColor.BOLD + ChatColor.MINECOIN_GOLD+"["+ChatColor.resetChat()+ChatColor.UNDERLINE+ChatColor.BOLD+ChatColor.DARK_GREEN+"HOME"+ChatColor.resetChat()+ChatColor.BOLD+ChatColor.MINECOIN_GOLD+"] "+ChatColor.resetChat()+ChatColor.YELLOW+string.homeName).setStyle(st), ctx.getSource().getServer());
|
||||||
|
|
||||||
}
|
}
|
||||||
}catch(CommandSyntaxException ex)
|
}catch(CommandSyntaxException ex)
|
||||||
|
|
|
@ -2,16 +2,9 @@ package dev.zontreck.essentials.commands.teleport;
|
||||||
|
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
|
|
||||||
import dev.zontreck.essentials.AriasEssentials;
|
|
||||||
import dev.zontreck.essentials.Messages;
|
|
||||||
import dev.zontreck.essentials.util.RTPContainer;
|
|
||||||
import dev.zontreck.essentials.util.RandomPositionFactory;
|
import dev.zontreck.essentials.util.RandomPositionFactory;
|
||||||
import dev.zontreck.libzontreck.chat.ChatColor;
|
|
||||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
|
||||||
import dev.zontreck.libzontreck.vectors.Vector3;
|
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.Commands;
|
import net.minecraft.commands.Commands;
|
||||||
import net.minecraft.network.chat.TextComponent;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
@ -44,7 +37,7 @@ public class RTPCommand {
|
||||||
}
|
}
|
||||||
final ServerPlayer pla = (ServerPlayer)source.getEntity();
|
final ServerPlayer pla = (ServerPlayer)source.getEntity();
|
||||||
|
|
||||||
final TeleportContainer cont = new TeleportContainer(pla, Vec3.ZERO, pla.getRotationVector(), source.getLevel());
|
//final TeleportContainer cont = new TeleportContainer(pla, Vec3.ZERO, pla.getRotationVector(), source.getLevel());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,37 +45,15 @@ public class RTPCommand {
|
||||||
@Override
|
@Override
|
||||||
public void run(){
|
public void run(){
|
||||||
// We can now execute the loop to search for a safe spot!
|
// We can now execute the loop to search for a safe spot!
|
||||||
Vector3 v = new Vector3();
|
//Vector3 v = new Vector3();
|
||||||
// RTP is not designed to be safe really, but we at least want to check if where we are putting the player is air
|
// RTP is not designed to be safe really, but we at least want to check if where we are putting the player is air
|
||||||
|
|
||||||
Vec3 pos = pla.position();
|
Vec3 pos = pla.position();
|
||||||
|
|
||||||
boolean found_place= false;
|
//boolean found_place= false;
|
||||||
RTPContainer container = RandomPositionFactory.beginRTPSearch(pla, pos, pla.getRotationVector(), pla.getLevel());
|
RandomPositionFactory.beginRTPSearch(pla, pos, pla.getRotationVector(), pla.getLevel());
|
||||||
while(!container.complete)
|
return;
|
||||||
{
|
|
||||||
if(!AriasEssentials.ALIVE)
|
|
||||||
{
|
|
||||||
container.aborted=true;
|
|
||||||
container.containingThread.interrupt();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(container.tries>30)
|
|
||||||
{
|
|
||||||
// abort!
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
v = container.container.world_pos.Position;
|
|
||||||
|
|
||||||
ChatHelpers.broadcastTo(pla.getUUID(), new TextComponent(Messages.ESSENTIALS_PREFIX + ChatColor.DARK_PURPLE+" A suitable location has been found. Wormhole opening now!"), pla.server);
|
|
||||||
|
|
||||||
// Apply the effect
|
|
||||||
TeleportActioner.ApplyTeleportEffect(pla);
|
|
||||||
cont.Position=v.asMinecraftVector();
|
|
||||||
|
|
||||||
TeleportActioner.PerformTeleport(cont);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -76,24 +76,8 @@ public class WarpCommand {
|
||||||
if(type==1){
|
if(type==1){
|
||||||
try {
|
try {
|
||||||
dest.Position = Vector3.ZERO;
|
dest.Position = Vector3.ZERO;
|
||||||
RTPContainer cont = RandomPositionFactory.beginRTPSearch(p, Vec3.ZERO, Vec2.ZERO, f_dim);
|
RandomPositionFactory.beginRTPSearch(p, Vec3.ZERO, Vec2.ZERO, f_dim);
|
||||||
while(!cont.complete)
|
return;
|
||||||
{
|
|
||||||
if(!AriasEssentials.ALIVE)
|
|
||||||
{
|
|
||||||
cont.aborted=true;
|
|
||||||
cont.containingThread.interrupt();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(cont.tries>30)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dest.Position = cont.container.world_pos.Position;
|
|
||||||
|
|
||||||
//RTPCommand.findPosition(source.getLevel(), false, p.getUUID());
|
|
||||||
ChatHelpers.broadcastTo(p.getUUID(), new TextComponent(Messages.ESSENTIALS_PREFIX+ChatColor.doColors(" !Dark_Green!Location found, warping!")), p.server);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package dev.zontreck.essentials.configs;
|
||||||
|
|
||||||
|
public class EssentialsConfig {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package dev.zontreck.essentials.events;
|
||||||
|
|
||||||
|
import dev.zontreck.essentials.util.RTPContainer;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
import net.minecraftforge.eventbus.api.Event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired if the RTP Was not cancelled to signal that a warp should occur now!
|
||||||
|
*/
|
||||||
|
public class RTPNotCancelledEvent extends Event
|
||||||
|
{
|
||||||
|
public final RTPContainer container;
|
||||||
|
public RTPNotCancelledEvent(RTPContainer container)
|
||||||
|
{
|
||||||
|
this.container=container;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send()
|
||||||
|
{
|
||||||
|
MinecraftForge.EVENT_BUS.post(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -7,9 +7,18 @@ import java.nio.file.Path;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import dev.zontreck.essentials.AriasEssentials;
|
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.essentials.homes.HomesProvider;
|
||||||
|
import dev.zontreck.libzontreck.chat.ChatColor;
|
||||||
import dev.zontreck.libzontreck.events.ProfileLoadedEvent;
|
import dev.zontreck.libzontreck.events.ProfileLoadedEvent;
|
||||||
import dev.zontreck.libzontreck.events.ProfileUnloadedEvent;
|
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.eventbus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
|
||||||
|
@ -34,4 +43,15 @@ public class ForgeEventsHandler {
|
||||||
AriasEssentials.player_homes.remove(UUID.fromString(ev.user_id));
|
AriasEssentials.player_homes.remove(UUID.fromString(ev.user_id));
|
||||||
AriasEssentials.LOGGER.info("Homes unloaded");
|
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() {
|
public void newPosition() {
|
||||||
if(!AriasEssentials.ALIVE)return;
|
if(!AriasEssentials.ALIVE)return;
|
||||||
containingThread=Thread.currentThread();
|
containingThread=Thread.currentThread();
|
||||||
|
if(tries>=30)return;
|
||||||
|
AriasEssentials.LOGGER.info("RTPContainer starts looking for new position");
|
||||||
Random rng = new Random(Instant.now().getEpochSecond());
|
Random rng = new Random(Instant.now().getEpochSecond());
|
||||||
Vector3 pos = new Vector3(rng.nextDouble(0xFFFF), 0, rng.nextDouble(0xFFFF));
|
Vector3 pos = new Vector3(rng.nextDouble(0xFFFF), 0, rng.nextDouble(0xFFFF));
|
||||||
BlockPos bpos = pos.asBlockPos();
|
BlockPos bpos = pos.asBlockPos();
|
||||||
|
@ -107,6 +109,7 @@ public class RTPContainer {
|
||||||
}
|
}
|
||||||
|
|
||||||
tries++;
|
tries++;
|
||||||
|
AriasEssentials.LOGGER.info("RTPContainer returns new position");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void spiralPositions(Vector3 position)
|
private void spiralPositions(Vector3 position)
|
||||||
|
@ -133,8 +136,8 @@ public class RTPContainer {
|
||||||
}
|
}
|
||||||
newPosition();
|
newPosition();
|
||||||
}
|
}
|
||||||
|
private boolean safe(BlockPos blockPos)
|
||||||
public boolean isSafe(BlockPos blockPos) {
|
{
|
||||||
containingThread=Thread.currentThread();
|
containingThread=Thread.currentThread();
|
||||||
BlockState b = container.Dimension.getBlockState(blockPos);
|
BlockState b = container.Dimension.getBlockState(blockPos);
|
||||||
BlockState b2 = container.Dimension.getBlockState(blockPos.above());
|
BlockState b2 = container.Dimension.getBlockState(blockPos.above());
|
||||||
|
@ -152,4 +155,13 @@ public class RTPContainer {
|
||||||
return false;
|
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.AriasEssentials;
|
||||||
import dev.zontreck.essentials.Messages;
|
import dev.zontreck.essentials.Messages;
|
||||||
import dev.zontreck.essentials.events.RTPEvent;
|
import dev.zontreck.essentials.events.RTPEvent;
|
||||||
|
import dev.zontreck.essentials.events.RTPNotCancelledEvent;
|
||||||
import dev.zontreck.libzontreck.chat.ChatColor;
|
import dev.zontreck.libzontreck.chat.ChatColor;
|
||||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||||
import dev.zontreck.libzontreck.util.DelayedExecutorService;
|
import dev.zontreck.libzontreck.util.DelayedExecutorService;
|
||||||
|
@ -43,7 +44,7 @@ public class RandomPositionLocator implements Runnable
|
||||||
levl.setChunkForced(cpos.x, cpos.z, true);
|
levl.setChunkForced(cpos.x, cpos.z, true);
|
||||||
|
|
||||||
int curChecks=0;
|
int curChecks=0;
|
||||||
while(curChecks<30)
|
while(curChecks<10)
|
||||||
{
|
{
|
||||||
if(contain.isSafe(contain.container.world_pos.Position.asBlockPos()))
|
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)))
|
if(MinecraftForge.EVENT_BUS.post(new RTPEvent(contain.container.PlayerInst, contain.container.world_pos)))
|
||||||
{
|
{
|
||||||
contain.complete=false;
|
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);
|
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;
|
break;
|
||||||
|
}else {
|
||||||
|
AriasEssentials.LOGGER.info("RTP Not cancelled. Actioning");
|
||||||
|
new RTPNotCancelledEvent(contain).send();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}else {
|
}else {
|
||||||
|
@ -80,7 +85,8 @@ public class RandomPositionLocator implements Runnable
|
||||||
// Schedule the task to execute
|
// Schedule the task to execute
|
||||||
//run();
|
//run();
|
||||||
RandomPositionLocator next = new RandomPositionLocator(contain);
|
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