Fix RTP, update libzontreck

This commit is contained in:
zontreck 2024-01-11 00:34:15 -07:00
parent deda27d0fb
commit 21c349ef3c
22 changed files with 192 additions and 149 deletions

View file

@ -89,7 +89,7 @@ minecraft {
server {
property 'forge.enabledGameTestNamespaces', mod_id
args '--nogui'
//args '--nogui'
}
// This run config launches GameTestServer and runs all registered gametests, then exits.

View file

@ -3,7 +3,7 @@
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
libzontreck=1.10.010224.1940
libzontreck=1.10.011024.0312
## Environment Properties
@ -49,7 +49,7 @@ mod_name=Aria's Essentials
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=GPLv3
# The mod version. See https://semver.org/
mod_version=1.2.010224.2002
mod_version=1.2.011124.0032
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html

View file

@ -5,6 +5,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.Executor;
import dev.zontreck.ariaslib.util.DelayedExecutorService;
import dev.zontreck.essentials.client.Keybindings;
@ -14,6 +15,7 @@ import dev.zontreck.essentials.configs.AEServerConfig;
import dev.zontreck.essentials.events.TeleportEvent;
import dev.zontreck.essentials.gui.HeartsRenderer;
import dev.zontreck.essentials.networking.ModMessages;
import dev.zontreck.essentials.rtp.RTPCaches;
import dev.zontreck.essentials.rtp.RTPCachesEventHandlers;
import dev.zontreck.essentials.util.BackPositionCaches;
import dev.zontreck.libzontreck.vectors.WorldPosition;
@ -50,6 +52,9 @@ public class AriasEssentials {
public static final Logger LOGGER = LogUtils.getLogger();
public static boolean ALIVE;
public static Map<UUID, Homes> player_homes = new HashMap<>();
public static boolean DEBUG = true;
public AriasEssentials()
{
@ -71,6 +76,7 @@ public class AriasEssentials {
MinecraftForge.EVENT_BUS.register(new CommandRegister());
MinecraftForge.EVENT_BUS.register(new ForgeEventsHandler());
MinecraftForge.EVENT_BUS.register(new RTPCachesEventHandlers());
MinecraftForge.EVENT_BUS.register(RTPCachesEventHandlers.class);
}
@SubscribeEvent
@ -104,6 +110,11 @@ public class AriasEssentials {
public void onServerStop(final ServerStoppingEvent ev)
{
ALIVE=false;
LOGGER.info("Tearing down Aria's Essentials functions and tasks");
DelayedExecutorService.stop();
DelayedExecutorService.getInstance().EXECUTORS.clear();
RTPCaches.Locations.clear();
}
@SubscribeEvent (priority = EventPriority.HIGHEST)

View file

@ -4,7 +4,7 @@ import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.BoolArgumentType;
import dev.zontreck.essentials.Messages;
import dev.zontreck.essentials.networking.ModMessages;
import dev.zontreck.essentials.networking.S2CUpdateHearts;
import dev.zontreck.essentials.networking.packets.s2c.S2CUpdateHearts;
import dev.zontreck.libzontreck.util.ChatHelpers;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;

View file

@ -9,19 +9,13 @@ 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.configs.AEServerConfig;
import dev.zontreck.essentials.homes.Home;
import dev.zontreck.essentials.homes.NoSuchHomeException;
import dev.zontreck.libzontreck.currency.Bank;
import dev.zontreck.libzontreck.currency.Transaction;
import dev.zontreck.libzontreck.exceptions.InvalidSideException;
import dev.zontreck.essentials.exceptions.NoSuchHomeException;
import dev.zontreck.libzontreck.util.ChatHelpers;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.server.level.ServerPlayer;
import java.time.Instant;
public class HomeCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{

View file

@ -16,6 +16,7 @@ import dev.zontreck.libzontreck.chat.Clickable;
import dev.zontreck.libzontreck.chat.HoverTip;
import dev.zontreck.libzontreck.chestgui.ChestGUI;
import dev.zontreck.libzontreck.chestgui.ChestGUIButton;
import dev.zontreck.libzontreck.chestgui.ChestGUIIdentifier;
import dev.zontreck.libzontreck.lore.LoreEntry;
import dev.zontreck.libzontreck.util.ChatHelpers;
import dev.zontreck.libzontreck.vectors.Vector2i;
@ -29,7 +30,7 @@ import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
public class HomesCommand {
private static final ResourceLocation HOMES_GUI_ID = new ResourceLocation("ariasmods", "homes-gui");
private static final ChestGUIIdentifier HOMES_GUI_ID = new ChestGUIIdentifier("homes-gui");
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
@ -54,7 +55,11 @@ public class HomesCommand {
for (Home string : homes.getList()) {
Style st = Style.EMPTY.withFont(Style.DEFAULT_FONT).withHoverEvent(HoverTip.get(ChatHelpers.macroize(Messages.HOME_HOVER_TEXT))).withClickEvent(Clickable.command("/home "+string.homeName));
ItemStack stack = new ItemStack(Items.BLUE_BED);
ItemStack stack = string.homeIcon.copy();
if(stack.is(Items.AIR))
{
stack = new ItemStack(Items.GRASS_BLOCK, 1);
}
stack.setHoverName(Component.literal(string.homeName));
ChestGUIButton button = new ChestGUIButton(stack, ()-> {
@ -69,15 +74,19 @@ public class HomesCommand {
.withInfo(new LoreEntry.Builder().text(ChatHelpers.macro("!Dark_Purple!This home is in the dimension [0]", string.destination.Dimension).getString()).bold(true).build());
iconY++;
gui.withButton(button);
if(iconY>=9)
{
iconY=0;
iconX++;
}
//ChatHelpers.broadcastTo(player.getUUID(), ChatHelpers.macro(Messages.HOME_FORMAT, string.homeName).setStyle(st), ctx.getSource().getServer());
if(homes.count() > 27)
ChatHelpers.broadcastTo(player.getUUID(), ChatHelpers.macro(Messages.HOME_FORMAT, string.homeName).setStyle(st), ctx.getSource().getServer());
else
gui.withButton(button); // Put this in the else case, to prevent a error when exceeding inventory slots
}
if(homes.count()<=27)
gui.open();
}catch(CommandSyntaxException ex)
{

View file

@ -22,6 +22,7 @@ import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
@ -61,7 +62,7 @@ public class SetHomeCommand {
TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.serverLevel());
Home newhome = new Home(p, homeName, dest);
Home newhome = new Home(p, homeName, dest, new ItemStack(p.getBlockStateOn().getBlock().asItem()));
AriasEssentials.player_homes.get(p.getUUID()).add(newhome);

View file

@ -27,6 +27,8 @@ public class TeleportRunnable extends Task
Action.PlayerInst.teleportTo(Action.Dimension, Action.Position.x, Action.Position.y, Action.Position.z, Action.Rotation.y, Action.Rotation.x);
Action.PlayerInst.onUpdateAbilities();
DelayedExecutorService.getInstance().schedule(new Task("tp_action",true){
public TeleportContainer container=Action;
@Override

View file

@ -20,6 +20,7 @@ import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.MinecraftForge;
@ -44,7 +45,7 @@ public class RTPWarpCommand {
Vec2 rot = p.getRotationVector();
TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.serverLevel());
Warp warp = new Warp(p.getUUID(), string, true, true, dest);
Warp warp = new Warp(p.getUUID(), string, true, true, dest, new ItemStack(p.getBlockStateOn().getBlock().asItem()));
WarpCreatedEvent event = new WarpCreatedEvent(warp);
if(MinecraftForge.EVENT_BUS.post(event))
{

View file

@ -20,6 +20,7 @@ import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.MinecraftForge;
@ -45,7 +46,7 @@ public class SetWarpCommand {
Vec2 rot = p.getRotationVector();
TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.serverLevel());
Warp w = new Warp(p.getUUID(), string, false, true, dest);
Warp w = new Warp(p.getUUID(), string, false, true, dest, new ItemStack(p.getBlockStateOn().getBlock().asItem()));
WarpCreatedEvent event = new WarpCreatedEvent(w);
if(MinecraftForge.EVENT_BUS.post(event)){
ChatHelpers.broadcastTo(p.getUUID(), ChatHelpers.macro(Messages.WARP_CREATE_ERROR, event.denyReason), p.server);

View file

@ -22,6 +22,7 @@ import dev.zontreck.libzontreck.chat.Clickable;
import dev.zontreck.libzontreck.chat.HoverTip;
import dev.zontreck.libzontreck.chestgui.ChestGUI;
import dev.zontreck.libzontreck.chestgui.ChestGUIButton;
import dev.zontreck.libzontreck.chestgui.ChestGUIIdentifier;
import dev.zontreck.libzontreck.lore.LoreEntry;
import dev.zontreck.libzontreck.profiles.Profile;
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
@ -39,7 +40,7 @@ import net.minecraft.server.level.ServerPlayer;
import org.spongepowered.asm.mixin.Mutable;
public class WarpsCommand {
private static final ResourceLocation WARPS_GUI_ID = new ResourceLocation("ariasmods", "ess_warps");
private static final ChestGUIIdentifier WARPS_GUI_ID = new ChestGUIIdentifier("ess_warps");
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(Commands.literal("warps").executes(c-> warps(c.getSource())));
@ -89,6 +90,30 @@ public class WarpsCommand {
String appendType = (warpType == 0) ? Messages.WARP_STANDARD : Messages.WARP_RTP;
HoverEvent hover = HoverTip.get(ChatHelpers.macroize(appendType, warp.destination.Dimension));
ClickEvent click = Clickable.command("/warp "+warpName);
MutableComponent warpMsg = ChatHelpers.macro(ChatColor.GREEN + warpName + ChatColor.resetChat());
warpMsg = ChatHelpers.applyHoverEvent(warpMsg, hover);
// Now, display the warp name, along with the warp's owner information
HoverEvent h2 = HoverTip.get(
ChatHelpers.macroize(Messages.WARP_HOVER_FORMAT,
ChatHelpers.macroize(Messages.WARP_OWNER, prof.name_color, prof.nickname),
ChatHelpers.macroize(Messages.WARP_ACCESS_FORMAT,
(warp.isPublic ? ChatHelpers.macroize(Messages.PUBLIC) : ChatHelpers.macroize(Messages.PRIVATE))
)
)
);
Component ownerInfo = ChatHelpers.applyHoverEvent(ChatHelpers.macro(Messages.HOVER_WARP_INFO), h2);
// Combine the two
warpMsg = warpMsg.copy().append(ownerInfo);
warpMsg = ChatHelpers.applyClickEvent(warpMsg, click);
ChestGUIButton button = new ChestGUIButton(HeadUtilities.get(prof.username, warpName), ()->{
TeleportDestination dest = warp.destination;
if(warpType == 1)
@ -114,6 +139,12 @@ public class WarpsCommand {
.build()
)
.withInfo(new LoreEntry.Builder().text(ChatHelpers.macro(appendType, warp.destination.Dimension).getString()).build());
if(warps.size() > 27)
{
// Say to person
ChatHelpers.broadcastTo(p, warpMsg, p.server);
}else
chestGui.withButton(button);
iconY++;
@ -124,6 +155,7 @@ public class WarpsCommand {
}
if(warps.size() < 27)
chestGui.open();
return 0;

View file

@ -25,6 +25,8 @@ public class AEServerConfig {
public static final ForgeConfigSpec.ConfigValue<Integer> COST_TO_MAKE_WARP;
public static final ForgeConfigSpec.ConfigValue<Integer> MAX_HOMES;
public static final ForgeConfigSpec.ConfigValue<Integer> MAX_WARPS;
public static final ForgeConfigSpec.ConfigValue<List<String>> DIMENSION_BLACKLIST;
public static final ForgeConfigSpec.ConfigValue<String> BLACKLISTED_DIMENSION_ERROR;
@ -44,7 +46,8 @@ public class AEServerConfig {
BUILDER.pop();
BUILDER.push("permissions").comment("This section defines permissions, such as total number of homes, and who can make warps");
MAX_HOMES = BUILDER.comment("Maximum number of homes that are allowed per player (-1 disables the limit entirely)").define("max_homes", -1);
MAX_HOMES = BUILDER.comment("Maximum number of homes that are allowed per player (-1 disables the limit entirely). 27 is the current default as that is the max that can fit in the current /homes gui").define("max_homes", 27);
MAX_WARPS = BUILDER.comment("Maximum number of warps that are allowed to exist. Default is 27, the max number that can fit in the /warps gui").define("max_warps", 27);
BUILDER.pop();
BUILDER.push("teleport");

View file

@ -1,4 +1,4 @@
package dev.zontreck.essentials.homes;
package dev.zontreck.essentials.exceptions;
public class NoSuchHomeException extends Exception{

View file

@ -6,18 +6,23 @@ import dev.zontreck.essentials.commands.teleport.TeleportDestination;
import dev.zontreck.libzontreck.exceptions.InvalidDeserialization;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
public class Home {
public UUID owner;
public String homeName;
public TeleportDestination destination;
public ItemStack homeIcon;
public Home(ServerPlayer player, String name, TeleportDestination dest)
public Home(ServerPlayer player, String name, TeleportDestination dest, ItemStack homeIcon)
{
owner=player.getUUID();
homeName=name;
destination=dest;
this.homeIcon = homeIcon;
}
public Home(CompoundTag tag)
@ -29,6 +34,10 @@ public class Home {
} catch (InvalidDeserialization e) {
e.printStackTrace();
}
if(tag.contains("icon"))
{
homeIcon = ItemStack.of(tag.getCompound("icon"));
} else homeIcon = new ItemStack(Items.BLUE_BED);
}
public CompoundTag serialize()
@ -37,6 +46,7 @@ public class Home {
tag.putUUID("owner", owner);
tag.putString("name", homeName);
tag.put("dest", destination.serialize());
tag.put("icon", homeIcon.serializeNBT());
return tag;
}

View file

@ -7,6 +7,7 @@ import java.util.Map;
import dev.zontreck.essentials.events.HomeCreatedEvent;
import dev.zontreck.essentials.events.HomeDeletedEvent;
import dev.zontreck.essentials.exceptions.NoSuchHomeException;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;

View file

@ -1,6 +1,7 @@
package dev.zontreck.essentials.networking;
import dev.zontreck.essentials.AriasEssentials;
import dev.zontreck.essentials.networking.packets.s2c.S2CUpdateHearts;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.network.NetworkDirection;

View file

@ -1,4 +1,4 @@
package dev.zontreck.essentials.networking;
package dev.zontreck.essentials.networking.packets.s2c;
import dev.zontreck.essentials.configs.AEClientConfig;
import dev.zontreck.libzontreck.networking.packets.IPacket;
@ -36,6 +36,7 @@ public class S2CUpdateHearts
ctx.enqueueWork(()->{
AEClientConfig.ENABLE_HEARTS_RENDER.set(current);
AEClientConfig.ENABLE_HEARTS_RENDER.save();
});
return true;

View file

@ -52,7 +52,7 @@ public class RTP
public WorldPosition position;
private List<Block> BLACKLIST = Lists.of(Blocks.LAVA, Blocks.WATER, Blocks.BEDROCK);
protected int tries;
protected int lastThreadDelay = 1;
protected int lastThreadDelay = 15;
protected RTP withThreadDelay(int delay)
{
@ -136,53 +136,62 @@ public class RTP
moveUp();
}
}
public void newPosition() {
if(!AriasEssentials.ALIVE)return;
containingThread=Thread.currentThread();
if(tries>=30)return;
if (!AriasEssentials.ALIVE || tries >= 25) return;
containingThread = Thread.currentThread();
AriasEssentials.LOGGER.info("RTP 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();
position.getActualDimension().getChunk(bpos.getX() >> 4, bpos.getZ() >> 4, ChunkStatus.SPAWN);
pos = new Vector3(
position.getActualDimension().getHeightmapPos(heightMapType, pos.asBlockPos()));
while (!position.getActualDimension().getWorldBorder().isWithinBounds(pos.asBlockPos())) {
pos = new Vector3(rng.nextDouble(0xffff), 0, rng.nextDouble(0xffff));
bpos = pos.asBlockPos();
position.getActualDimension().getChunk(bpos.getX() >> 4, bpos.getZ() >> 4, ChunkStatus.SPAWN);
pos = new Vector3(
position.getActualDimension().getHeightmapPos(heightMapType, pos.asBlockPos()));
}
Vector3 pos;
BlockPos bpos;
do {
pos = new Vector3(rng.nextDouble(0xFFFF), 150, rng.nextDouble(0xFFFF));
pos = spiralPositions(pos);
position.Position = pos;
bpos = pos.asBlockPos();
} while (!isValidPosition(bpos));
if (pos.y < -60) {
if (pos.y < -30 || pos.y >= position.getActualDimension().getLogicalHeight()) {
newPosition();
return;
}
if (pos.y >= position.getActualDimension().getLogicalHeight()) {
spiralPositions(pos);
}
tries++;
AriasEssentials.LOGGER.info("RTP returns new position");
}
private void spiralPositions(Vector3 position)
{
private boolean isValidPosition(BlockPos bpos) {
ServerLevel dimension = position.getActualDimension();
ChunkStatus status = ChunkStatus.SPAWN;
dimension.getChunk(bpos.getX() >> 4, bpos.getZ() >> 4, status);
Vector3 pos = new Vector3(dimension.getHeightmapPos(heightMapType, bpos));
return dimension.getWorldBorder().isWithinBounds(pos.asBlockPos());
}
private Vector3 spiralPositions(Vector3 position) {
Vec3i posi = position.asMinecraftVec3i();
for(BlockPos pos : BlockPos.spiralAround(new BlockPos(posi.getX(), this.position.getActualDimension().getSeaLevel(), posi.getZ()), 16, Direction.WEST, Direction.NORTH)){
if(isSafe(pos)){
ServerLevel dimension = this.position.getActualDimension();
BlockPos startBlockPos = new BlockPos(posi.getX(), dimension.getSeaLevel(), posi.getZ());
for (BlockPos pos : BlockPos.spiralAround(startBlockPos, 16, Direction.WEST, Direction.NORTH)) {
if (isSafe(pos)) {
// Set the new position
this.position.Position = new Vector3(pos);
return;
return new Vector3(pos);
}
}
return position;
}
private boolean safe(BlockPos blockPos)
{
containingThread=Thread.currentThread();

View file

@ -1,10 +1,12 @@
package dev.zontreck.essentials.rtp;
import dev.zontreck.essentials.AriasEssentials;
import dev.zontreck.essentials.Messages;
import dev.zontreck.essentials.commands.teleport.TeleportActioner;
import dev.zontreck.essentials.events.RTPFoundEvent;
import dev.zontreck.libzontreck.util.ChatHelpers;
import net.minecraft.server.level.ServerLevel;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -15,8 +17,9 @@ public class RTPCachesEventHandlers
@SubscribeEvent
public void onTick(TickEvent.ServerTickEvent event)
{
if(!AriasEssentials.ALIVE) return;
lastTick++;
if(lastTick>=40)
if(lastTick>=400)
{
lastTick=0;
@ -24,16 +27,25 @@ public class RTPCachesEventHandlers
{
try {
MinecraftForge.EVENT_BUS.unregister(this);
firstRun=false;
AriasEssentials.LOGGER.info("Aria's Essentials startup is running. Scanning for initial RTP locations");
for(ServerLevel level : event.getServer().getAllLevels())
{
if(AriasEssentials.DEBUG)
{
AriasEssentials.LOGGER.info("Scanning a level");
}
if(TeleportActioner.isBlacklistedDimension(level))
{
continue;
}
RandomPositionFactory.beginRTPSearch(level); // Populate 10 RTP points
RandomPositionFactory.beginRTPSearch(level);
}
AriasEssentials.LOGGER.info("Startup done. RTP searching will continue in a separate thread");
}catch (Exception e)
{
e.printStackTrace();
@ -43,7 +55,7 @@ public class RTPCachesEventHandlers
}
@SubscribeEvent
public void onRTPFound(RTPFoundEvent event)
public static void onRTPFound(final RTPFoundEvent event)
{
RTPCaches.Locations.add(event.rtp);
ChatHelpers.broadcast(ChatHelpers.macro(Messages.RTP_CACHED, event.rtp.position.Dimension), event.rtp.position.getActualDimension().getServer());

View file

@ -1,37 +0,0 @@
package dev.zontreck.essentials.rtp;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.stream.Stream;
import dev.zontreck.essentials.AriasEssentials;
import dev.zontreck.essentials.commands.teleport.TeleportContainer;
import dev.zontreck.libzontreck.vectors.Vector3;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Vec3i;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkStatus;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.Heightmap.Types;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
@Deprecated
/**
* @see RTP instead
*/
public class RTPContainer {
}

View file

@ -8,73 +8,44 @@ import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraftforge.common.MinecraftForge;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
* This class aims to serve as the Random Position Locate system
* It aims to be as non-thread blocking as possible to avoid server lag
*
* To utilize, initialize a RTPContainer from the RandomPositionFactory and execute from there.
* This class serves as the Random Position Locate system, aiming to be non-thread blocking for improved server performance.
* To utilize, initialize an RTP from the RandomPositionFactory and execute from there.
*/
public class RandomPositionLocator extends Task
{
public class RandomPositionLocator extends Task {
private static final Logger log = LogManager.getLogger("RPL-"+Thread.currentThread().getName());
private final RTP contain;
public RandomPositionLocator(RTP rtp)
{
super("RPL",true);
contain=rtp;
/**
* Constructs a RandomPositionLocator with the specified RTP instance.
*
* @param rtp The RTP instance to use.
*/
public RandomPositionLocator(RTP rtp) {
super("RPL", true);
contain = rtp;
}
@Override
public void run() {
if(!AriasEssentials.ALIVE)return;
if (!AriasEssentials.ALIVE) return;
//ChatHelpers.broadcastTo(contain.container.PlayerInst.getUUID(), ChatHelpers.macro(Messages.RTP_SEARCHING, String.valueOf(contain.tries), "30"), contain.container.PlayerInst.server);
ServerLevel levl = contain.position.getActualDimension();
ChunkAccess chunk = levl.getChunk(contain.position.Position.asBlockPos());
ChunkPos cpos = chunk.getPos();
boolean needsLoading = false;
needsLoading = !(levl.getForcedChunks().contains(cpos.toLong()));
if(needsLoading)
levl.setChunkForced(cpos.x, cpos.z, true);
int curChecks=0;
while(curChecks<3)
{
if(contain.isSafe(contain.position.Position.asBlockPos()))
{
if(needsLoading)
levl.setChunkForced(cpos.x, cpos.z, false);
MinecraftForge.EVENT_BUS.post(new RTPFoundEvent(contain));
return;
} else {
curChecks++;
contain.move();
//AriasEssentials.LOGGER.info("[DEBUG] "+ChatColor.doColors("!Dark_Red!Checking position: "+contain.container.world_pos.Position.toString()+"; "+contain.container.Dimension.getBlockState(contain.container.world_pos.Position.asBlockPos()).getBlock().toString()+"; "+contain.container.Dimension.getBlockState(contain.container.world_pos.Position.asBlockPos().below()).getBlock().toString()));
if (AriasEssentials.DEBUG) {
log.debug("RTP Search thread");
}
}
if(needsLoading)
levl.setChunkForced(cpos.x, cpos.z, false);
contain.newPosition();
if(contain.tries > 30)
if(AriasEssentials.DEBUG)
{
// Abort
return;
}else {
// Schedule the task to execute
//run();
RandomPositionLocator next = new RandomPositionLocator(contain.withThreadDelay(contain.lastThreadDelay+1));
DelayedExecutorService.getInstance().schedule(next, contain.lastThreadDelay+1);
AriasEssentials.LOGGER.info("Giving up current RTP search. Scheduling another search in 1 second");
}
log.debug("Dispatching RTPFoundEvent - " + contain.position.Dimension);
}
contain.position.getActualDimension().getServer().execute(()->{
MinecraftForge.EVENT_BUS.post(new RTPFoundEvent(contain));
});
}
}

View file

@ -8,12 +8,18 @@ import dev.zontreck.essentials.commands.teleport.TeleportDestination;
import dev.zontreck.essentials.events.WarpAccessControlListUpdatedEvent;
import dev.zontreck.essentials.warps.AccessControlList.ACLEntry;
import dev.zontreck.libzontreck.exceptions.InvalidDeserialization;
import dev.zontreck.libzontreck.profiles.Profile;
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
import dev.zontreck.libzontreck.util.ServerUtilities;
import dev.zontreck.libzontreck.util.heads.HeadUtilities;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.IntArrayTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.nbt.Tag;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
public class Warp {
@ -24,7 +30,9 @@ public class Warp {
public TeleportDestination destination;
private AccessControlList ACL;
public Warp(UUID owner, String name, boolean rtp, boolean publicWarp, TeleportDestination destination)
public ItemStack warpIcon;
public Warp(UUID owner, String name, boolean rtp, boolean publicWarp, TeleportDestination destination, ItemStack warpIcon)
{
this.owner=owner;
WarpName=name;
@ -32,11 +40,23 @@ public class Warp {
isPublic=publicWarp;
this.destination=destination;
this.ACL = new AccessControlList();
if(warpIcon==null)
{
try {
Profile prof = Profile.get_profile_of(owner.toString());
this.warpIcon = HeadUtilities.get(prof.username, name);
} catch (UserProfileNotYetExistsException e) {
throw new RuntimeException(e);
}
}else this.warpIcon=warpIcon;
}
public static Warp deserialize(CompoundTag tag) throws InvalidDeserialization
{
Warp warp = new Warp(tag.getUUID("owner"), tag.getString("name"), tag.getBoolean("rtp"), tag.getBoolean("public"), new TeleportDestination(tag.getCompound("destination")));
Warp warp = new Warp(tag.getUUID("owner"), tag.getString("name"), tag.getBoolean("rtp"), tag.getBoolean("public"), new TeleportDestination(tag.getCompound("destination")), ItemStack.of(tag.getCompound("icon")));
if(!warp.isPublic)
{
@ -54,6 +74,7 @@ public class Warp {
tag.putBoolean("rtp", RTP);
tag.putBoolean("public", isPublic);
tag.put("destination", destination.serialize());
tag.put("icon", warpIcon.serializeNBT());
if(!isPublic)
{
tag.put("acl", ACL.serialize());