Attempt to fix rtp
This commit is contained in:
parent
8eb93ff176
commit
11864385e4
9 changed files with 93 additions and 184 deletions
|
@ -3,7 +3,7 @@
|
|||
org.gradle.jvmargs=-Xmx3G
|
||||
org.gradle.daemon=false
|
||||
|
||||
libzontreck=1.10.011624.1712
|
||||
libzontreck=1.10.012124.1709
|
||||
|
||||
## 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.011624.1834
|
||||
mod_version=1.2.012124.2356
|
||||
# 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
|
||||
|
|
|
@ -24,6 +24,7 @@ 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.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.Vec2;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
@ -75,7 +76,9 @@ public class SetHomeCommand {
|
|||
|
||||
TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.getLevel());
|
||||
|
||||
Home newhome = new Home(p, homeName, dest, new ItemStack(p.getFeetBlockState().getBlock().asItem()));
|
||||
BlockState bs = p.getLevel().getBlockState(dest.Position.moveDown().asBlockPos());
|
||||
|
||||
Home newhome = new Home(p, homeName, dest, new ItemStack(bs.getBlock().asItem()));
|
||||
AriasEssentials.player_homes.get(p.getUUID()).add(newhome);
|
||||
|
||||
|
||||
|
|
|
@ -3,11 +3,13 @@ package dev.zontreck.essentials.commands.teleport;
|
|||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.BoolArgumentType;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import dev.zontreck.essentials.Messages;
|
||||
import dev.zontreck.libzontreck.chestgui.ChestGUI;
|
||||
import dev.zontreck.libzontreck.chestgui.ChestGUIButton;
|
||||
import dev.zontreck.libzontreck.chestgui.ChestGUIIdentifier;
|
||||
import dev.zontreck.libzontreck.profiles.Profile;
|
||||
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import dev.zontreck.libzontreck.util.ServerUtilities;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
|
@ -21,10 +23,10 @@ public class TPEffectsCommand
|
|||
{
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("tpeffects").then(Commands.argument("enable", BoolArgumentType.bool()).executes(x->tpeffects(x.getSource(), BoolArgumentType.getBool(x, "enable")))));
|
||||
dispatcher.register(Commands.literal("tpeffects_disable").then(Commands.argument("disabled", BoolArgumentType.bool()).executes(x->tpeffects(x.getSource(), BoolArgumentType.getBool(x, "disabled")))));
|
||||
}
|
||||
|
||||
public static int tpeffects(CommandSourceStack source, boolean enabled)
|
||||
public static int tpeffects(CommandSourceStack source, boolean disabled)
|
||||
{
|
||||
ServerPlayer player = null;
|
||||
try {
|
||||
|
@ -35,7 +37,9 @@ public class TPEffectsCommand
|
|||
|
||||
try {
|
||||
Profile prof = Profile.get_profile_of(player.getStringUUID());
|
||||
prof.NBT.putBoolean("tpeffects", enabled);
|
||||
prof.NBT.putBoolean("tpeffects", disabled);
|
||||
|
||||
ChatHelpers.broadcastTo(player.getUUID(), ChatHelpers.macro(Messages.TP_EFFECTS_TOGGLED, disabled ? "disabled" : "enabled"), player.server);
|
||||
|
||||
return 0;
|
||||
} catch (UserProfileNotYetExistsException e) {
|
||||
|
|
|
@ -33,7 +33,7 @@ public class TeleportActioner
|
|||
public static void ApplyTeleportEffect(ServerPlayer player){
|
||||
try {
|
||||
Profile prof = Profile.get_profile_of(player.getStringUUID());
|
||||
if(!prof.NBT.getBoolean("tpeffects"))
|
||||
if(prof.NBT.getBoolean("tpeffects"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ 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.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.Vec2;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
@ -58,7 +59,10 @@ public class SetWarpCommand {
|
|||
Vec2 rot = p.getRotationVector();
|
||||
|
||||
TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.getLevel());
|
||||
Warp w = new Warp(p.getUUID(), string, false, true, dest, new ItemStack(p.getFeetBlockState().getBlock().asItem()));
|
||||
|
||||
BlockState bs = p.getLevel().getBlockState(dest.Position.moveDown().asBlockPos());
|
||||
|
||||
Warp w = new Warp(p.getUUID(), string, false, true, dest, new ItemStack(bs.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);
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package dev.zontreck.essentials.configs.client;
|
||||
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import dev.zontreck.ariaslib.util.FileIO;
|
||||
import dev.zontreck.essentials.util.EssentialsDatastore;
|
||||
import dev.zontreck.essentials.util.FileHandler;
|
||||
import dev.zontreck.libzontreck.util.SNbtIo;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
|
||||
|
@ -30,16 +31,7 @@ public class AEClientConfig
|
|||
Path serverConfig = EssentialsDatastore.of("client.snbt");
|
||||
if(serverConfig.toFile().exists())
|
||||
{
|
||||
|
||||
try {
|
||||
String snbt = FileHandler.readFile(serverConfig.toFile().getAbsolutePath());
|
||||
|
||||
inst = deserialize(NbtUtils.snbtToStructure(snbt));
|
||||
|
||||
|
||||
} catch (CommandSyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
inst = deserialize(SNbtIo.loadSnbt(serverConfig));
|
||||
}else {
|
||||
initNewConfig();
|
||||
}
|
||||
|
@ -68,9 +60,8 @@ public class AEClientConfig
|
|||
|
||||
CompoundTag tag = inst.serialize();
|
||||
|
||||
var snbt = NbtUtils.structureToSnbt(tag);
|
||||
|
||||
FileHandler.writeFile(serverConfig.toFile().getAbsolutePath(), snbt);
|
||||
SNbtIo.writeSnbt(serverConfig, tag);
|
||||
}
|
||||
|
||||
public CompoundTag serialize()
|
||||
|
|
|
@ -1,17 +1,14 @@
|
|||
package dev.zontreck.essentials.configs.server;
|
||||
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import dev.zontreck.ariaslib.util.Lists;
|
||||
import dev.zontreck.essentials.configs.server.sections.*;
|
||||
import dev.zontreck.essentials.util.EssentialsDatastore;
|
||||
import dev.zontreck.essentials.util.FileHandler;
|
||||
import dev.zontreck.essentials.util.Maps;
|
||||
import dev.zontreck.libzontreck.util.SNbtIo;
|
||||
import net.minecraft.nbt.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class AEServerConfig
|
||||
|
@ -52,15 +49,7 @@ public class AEServerConfig
|
|||
if(serverConfig.toFile().exists())
|
||||
{
|
||||
|
||||
try {
|
||||
String snbt = FileHandler.readFile(serverConfig.toFile().getAbsolutePath());
|
||||
|
||||
inst = deserialize(NbtUtils.snbtToStructure(snbt));
|
||||
|
||||
|
||||
} catch (CommandSyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
inst = deserialize(SNbtIo.loadSnbt(serverConfig));
|
||||
}else {
|
||||
initNewConfig();
|
||||
}
|
||||
|
@ -112,9 +101,7 @@ public class AEServerConfig
|
|||
|
||||
CompoundTag tag = inst.serialize();
|
||||
|
||||
var snbt = NbtUtils.structureToSnbt(tag);
|
||||
|
||||
FileHandler.writeFile(serverConfig.toFile().getAbsolutePath(), snbt);
|
||||
SNbtIo.writeSnbt(serverConfig, tag);
|
||||
}
|
||||
|
||||
public CompoundTag serialize()
|
||||
|
|
|
@ -8,6 +8,7 @@ import net.minecraft.core.BlockPos;
|
|||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
@ -20,124 +21,87 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* As of v1.1.121823.x, this is now used for RTP
|
||||
* <p>
|
||||
* This ensures that RTP is only scanned once every so often. This is because RTP lags the server when it is having to check block positions.
|
||||
* <p>
|
||||
* If the RTP system scans each dimension (Not blacklisted), then it can build a list of safe locations that will be rotated out every 2 hours.
|
||||
* <p>
|
||||
* Every 10 minutes, a new RTP location is scanned. This ensures sufficiently semi-random locations. Eventually old locations will be removed from the list.
|
||||
* <p>
|
||||
* At server start, it will scan 10 RTP locations per dimension while there are no players.
|
||||
*/
|
||||
public class RTP
|
||||
{
|
||||
public RTP(ServerLevel level)
|
||||
{
|
||||
position = new WorldPosition(new Vector3(0,500,0), WorldPosition.getDim(level));
|
||||
public class RTP {
|
||||
private static final List<Block> BLACKLIST = Lists.of(Blocks.LAVA, Blocks.WATER, Blocks.BEDROCK);
|
||||
private final int SEARCH_DIRECTION;
|
||||
private final Heightmap.Types heightMapType;
|
||||
private final WorldPosition position;
|
||||
private final ServerLevel dimension;
|
||||
private int tries;
|
||||
|
||||
if(position.getActualDimension().dimensionType().hasCeiling())
|
||||
{
|
||||
public RTP(ServerLevel level) {
|
||||
position = new WorldPosition(new Vector3(0, -60, 0), WorldPosition.getDim(level));
|
||||
dimension = position.getActualDimension();
|
||||
|
||||
if (position.getActualDimension().dimensionType().hasCeiling()) {
|
||||
heightMapType = Heightmap.Types.MOTION_BLOCKING_NO_LEAVES;
|
||||
SearchDirection=-1;
|
||||
SEARCH_DIRECTION = -1;
|
||||
} else {
|
||||
heightMapType = Heightmap.Types.MOTION_BLOCKING_NO_LEAVES;
|
||||
SearchDirection=1;
|
||||
SEARCH_DIRECTION = 1;
|
||||
}
|
||||
}
|
||||
private final int SearchDirection;
|
||||
private Thread containingThread;
|
||||
private final Heightmap.Types heightMapType;
|
||||
public WorldPosition position;
|
||||
private final List<Block> BLACKLIST = Lists.of(Blocks.LAVA, Blocks.WATER, Blocks.BEDROCK);
|
||||
protected int tries;
|
||||
protected int lastThreadDelay = 15;
|
||||
|
||||
protected RTP withThreadDelay(int delay)
|
||||
{
|
||||
lastThreadDelay=delay;
|
||||
if(lastThreadDelay >= 60) lastThreadDelay = 60;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isDimension(ServerLevel level)
|
||||
{
|
||||
public boolean isDimension(ServerLevel level) {
|
||||
String dim = WorldPosition.getDim(level);
|
||||
return dim.equals(position.Dimension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for, and finds, a valid RTP location
|
||||
* @param level The level to scan
|
||||
* @return RTP data
|
||||
*/
|
||||
public static void find(ServerLevel level)
|
||||
{
|
||||
RandomPositionFactory.beginRTPSearch(level);
|
||||
public BlockPos findSafeLandingLocation() {
|
||||
BlockPos targetPos = position.Position.asBlockPos();
|
||||
|
||||
// Search upward for a safe landing location
|
||||
while (!isSafe(targetPos) || !isSafe(targetPos.above())) {
|
||||
targetPos = targetPos.above();
|
||||
}
|
||||
|
||||
public static List<RTP> slicedByDimension(ServerLevel lvl)
|
||||
{
|
||||
List<RTP> slice = new ArrayList<>();
|
||||
return targetPos;
|
||||
}
|
||||
|
||||
Iterator<RTP> it = RTPCaches.Locations.iterator();
|
||||
while(it.hasNext())
|
||||
{
|
||||
RTP nxt = it.next();
|
||||
if(nxt.isDimension(lvl))
|
||||
{
|
||||
slice.add(nxt);
|
||||
private boolean isSafe(BlockPos blockPos) {
|
||||
BlockState blockState = dimension.getBlockState(blockPos);
|
||||
BlockState blockStateAbove = dimension.getBlockState(blockPos.above());
|
||||
BlockState blockStateBelow = dimension.getBlockState(blockPos.below());
|
||||
|
||||
if (blockState.isAir() && blockStateAbove.isAir()) {
|
||||
if (!blockStateBelow.isAir()) {
|
||||
return !BLACKLIST.contains(blockStateBelow.getBlock());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return slice;
|
||||
}
|
||||
|
||||
public static RTP getRTP(ServerLevel level)
|
||||
{
|
||||
public static RTP getRTP(ServerLevel level) {
|
||||
List<RTP> slice = slicedByDimension(level);
|
||||
if(slice.size()>0)
|
||||
{
|
||||
RTP ret = slice.get(AriasEssentials.random.nextInt(0, slice.size()));
|
||||
if (!slice.isEmpty()) {
|
||||
RTP ret = slice.get(AriasEssentials.random.nextInt(slice.size()));
|
||||
RTPCaches.Locations.remove(ret);
|
||||
RandomPositionFactory.beginRTPSearch(ret.position.getActualDimension());
|
||||
return ret;
|
||||
} else return null;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void moveDown() {
|
||||
public void move() {
|
||||
if (SEARCH_DIRECTION == 1) {
|
||||
position.Position = position.Position.moveUp();
|
||||
} else if (SEARCH_DIRECTION == -1) {
|
||||
position.Position = position.Position.moveDown();
|
||||
}
|
||||
|
||||
public void moveUp() {
|
||||
position.Position = position.Position.moveUp();
|
||||
}
|
||||
|
||||
public void move()
|
||||
{
|
||||
if(SearchDirection==1){
|
||||
moveUp();
|
||||
}else if(SearchDirection==0)
|
||||
{
|
||||
moveDown();
|
||||
}
|
||||
}
|
||||
public void moveOpposite()
|
||||
{
|
||||
if(SearchDirection==1){
|
||||
moveDown();
|
||||
}else if(SearchDirection==0)
|
||||
{
|
||||
moveUp();
|
||||
}
|
||||
public void moveOpposite() {
|
||||
move();
|
||||
}
|
||||
|
||||
public void newPosition() {
|
||||
if (!AriasEssentials.ALIVE || tries >= 25) return;
|
||||
|
||||
containingThread = Thread.currentThread();
|
||||
AriasEssentials.LOGGER.info("RTP starts looking for new position");
|
||||
AriasEssentials.LOGGER.info("RTP starts looking for a new position");
|
||||
|
||||
Random rng = new Random(Instant.now().getEpochSecond());
|
||||
|
||||
|
@ -152,30 +116,25 @@ public class RTP
|
|||
bpos = pos.asBlockPos();
|
||||
} while (!isValidPosition(bpos));
|
||||
|
||||
|
||||
if (pos.y < -30 || pos.y >= position.getActualDimension().getLogicalHeight()) {
|
||||
newPosition();
|
||||
return;
|
||||
}
|
||||
|
||||
tries++;
|
||||
AriasEssentials.LOGGER.info("RTP returns new position");
|
||||
AriasEssentials.LOGGER.info("RTP returns a new 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();
|
||||
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)) {
|
||||
|
@ -188,32 +147,17 @@ public class RTP
|
|||
return position;
|
||||
}
|
||||
|
||||
public static List<RTP> slicedByDimension(ServerLevel lvl) {
|
||||
List<RTP> slice = new ArrayList<>();
|
||||
|
||||
private boolean safe(BlockPos blockPos)
|
||||
{
|
||||
containingThread=Thread.currentThread();
|
||||
BlockState b = position.getActualDimension().getBlockState(blockPos);
|
||||
BlockState b2 = position.getActualDimension().getBlockState(blockPos.above());
|
||||
BlockState b3 = position.getActualDimension().getBlockState(blockPos.below());
|
||||
|
||||
if (b.isAir() && b2.isAir()) {
|
||||
if (!b3.isAir()) {
|
||||
return !BLACKLIST.contains(b3.getBlock());
|
||||
} else
|
||||
return false;
|
||||
} else
|
||||
return false;
|
||||
|
||||
}
|
||||
public boolean isSafe(BlockPos blockPos) {
|
||||
return safe(blockPos);
|
||||
/*
|
||||
boolean s = safe(blockPos);
|
||||
if(s)
|
||||
{
|
||||
AriasEssentials.LOGGER.info("/!\\ SAFE /!\\");
|
||||
}else AriasEssentials.LOGGER.info("/!\\ NOT SAFE /!\\");
|
||||
|
||||
return s;*/
|
||||
Iterator<RTP> it = RTPCaches.Locations.iterator();
|
||||
while (it.hasNext()) {
|
||||
RTP nxt = it.next();
|
||||
if (nxt.isDimension(lvl)) {
|
||||
slice.add(nxt);
|
||||
}
|
||||
}
|
||||
|
||||
return slice;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
package dev.zontreck.essentials.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class FileHandler
|
||||
{
|
||||
|
||||
public static String readFile(String filePath) {
|
||||
try {
|
||||
byte[] fileBytes = Files.readAllBytes(Paths.get(filePath));
|
||||
return new String(fileBytes);
|
||||
} catch (IOException e) {
|
||||
return "An error occurred: " + e.getMessage();
|
||||
}
|
||||
}
|
||||
public static void writeFile(String filePath, String newContent) {
|
||||
try {
|
||||
Files.write(Paths.get(filePath), newContent.getBytes());
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue