generated from AriasCreations/vsmodtemplate
Change method of finding a safe position
This commit is contained in:
parent
74d85c57e1
commit
6598eb44da
3 changed files with 15 additions and 49 deletions
|
@ -49,53 +49,18 @@ public class RTPFactory
|
||||||
/// <returns>A safe position if able to be found</returns>
|
/// <returns>A safe position if able to be found</returns>
|
||||||
public static PlayerPosition GetSafePosition(RTPData data, RTPPosition position)
|
public static PlayerPosition GetSafePosition(RTPData data, RTPPosition position)
|
||||||
{
|
{
|
||||||
Random rng = ServerUtilities.rng;
|
PlayerPosition PPos = PlayerPosition.from(data.player.Entity);
|
||||||
IServerPlayer isp = data.player;
|
BlockPos check = new(
|
||||||
EntityPos vPos = isp.Entity.Pos;
|
x: position.x,
|
||||||
BlockPos bPos = new BlockPos(isp.Entity.Pos.Dimension);
|
y: 1,
|
||||||
IServerWorldAccessor iswa = isp.Entity.World as IServerWorldAccessor;
|
z: position.z,
|
||||||
|
dim: position.dimension
|
||||||
|
);
|
||||||
|
|
||||||
int tries = 10000;
|
int height = ServerUtilities.API.World.BlockAccessor.GetTerrainMapheightAt(check);
|
||||||
PlayerPosition PPos = PlayerPosition.from(isp.Entity);
|
|
||||||
//PlayerPosition original = PlayerPosition.from(isp.Entity);
|
|
||||||
|
|
||||||
|
PPos.Y = height + 1;
|
||||||
// Generate random X and Z within max RTP distance
|
return PPos;
|
||||||
bPos.X = position.x;
|
|
||||||
bPos.Z = position.z;
|
|
||||||
bPos.Y = 255;
|
|
||||||
|
|
||||||
Block lastAboveLast = null;
|
|
||||||
Block lastBlock = null;
|
|
||||||
Block curBlock;
|
|
||||||
|
|
||||||
// Scan downwards to find a valid landing spot
|
|
||||||
for (int i = 255; i > 0; i--)
|
|
||||||
{
|
|
||||||
bPos.Y = i;
|
|
||||||
curBlock = iswa.BlockAccessor.GetBlock(bPos);
|
|
||||||
|
|
||||||
if (curBlock.MatterState == EnumMatterState.Solid)
|
|
||||||
{
|
|
||||||
if (lastBlock != null && lastBlock.BlockMaterial == EnumBlockMaterial.Air &&
|
|
||||||
lastAboveLast != null && lastAboveLast.BlockMaterial == EnumBlockMaterial.Air)
|
|
||||||
{
|
|
||||||
// Found a valid spot: curBlock is solid, lastBlock & lastAboveLast are gas (air)
|
|
||||||
PPos.X = bPos.X;
|
|
||||||
PPos.Y = bPos.Y + 1;
|
|
||||||
PPos.Z = bPos.Z;
|
|
||||||
|
|
||||||
ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-found", tries));
|
|
||||||
|
|
||||||
return PPos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lastAboveLast = lastBlock;
|
|
||||||
lastBlock = curBlock;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null; // Return null if no valid position is found after retries
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -179,13 +144,14 @@ public class RTPFactory
|
||||||
if (pos == null)
|
if (pos == null)
|
||||||
{
|
{
|
||||||
// Let this get checked again
|
// Let this get checked again
|
||||||
RTPCache.Remove(data);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Found! Perform teleport and remove the RTP Check
|
// Found! Perform teleport and remove the RTP Check
|
||||||
RTPCache.Remove(data);
|
RTPCache.Remove(data);
|
||||||
pos.Merge(data.player.Entity);
|
pos.Merge(data.player.Entity);
|
||||||
|
|
||||||
|
ServerUtilities.SendMessageTo(data.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp", GetDistance(new Vec2i(data.StartPosition.X, data.StartPosition.Z), new Vec2i(pos.X, pos.Z))));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove this check
|
// Remove this check
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
"back": "You've been taken back to your last position",
|
"back": "You've been taken back to your last position",
|
||||||
|
|
||||||
"rtp-search": "Searching for a random position...",
|
"rtp-search": "Searching for a random position...",
|
||||||
"rtp-progress": "Still searchinf for a random position...",
|
"rtp-progress": "Still searching for a random position...",
|
||||||
"rtp": "You have been teleported [{0}] blocks away!",
|
"rtp": "You have been teleported [{0}] blocks away!",
|
||||||
"rtp-found": "Found a valid landing position after {0} tries.",
|
"rtp-found": "Found a valid landing position after {0} tries.",
|
||||||
"rtp-fail": "Giving up on RTP search. No valid position could be found. Try again later",
|
"rtp-fail": "Giving up on RTP search. No valid position could be found. Try again later",
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
"modid": "ariasserverutils",
|
"modid": "ariasserverutils",
|
||||||
"name": "Aria's Server Utilities",
|
"name": "Aria's Server Utilities",
|
||||||
"authors": ["zontreck"],
|
"authors": ["zontreck"],
|
||||||
"description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 10:22 AM MST",
|
"description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 10:36 AM MST",
|
||||||
"version": "1.0.6-dev.12",
|
"version": "1.0.6-dev.13",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"game": ""
|
"game": ""
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue