Skip to content

Commit

Permalink
Merge pull request #53 from FTBTeam/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
desht authored Oct 10, 2023
2 parents 0ddd353 + 831eb09 commit 5657f78
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 61 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [2001.2.1]

### Added
* The `/rtp` command now makes better use of block and biome tags to control valid RTP destinations
* `ftbessentials:ignore_rtp` block tag lists blocks which are not valid for the player to land on (leaves and Bedrock by default)
* `ftbessentials:ignore_rtp` biome tag lists biomes which are not valid for the player to land in (`#minecraft:is_ocean` by default)

### Fixed
* Fixed an event handler running on the client side which shouldn't have been
* Led to undesirable effects like players flying when they shouldn't

## [2001.2.0]

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,21 @@ private static void playerLoggedOut(ServerPlayer serverPlayer) {
}

private static void playerTickPost(Player player) {
FTBEPlayerData.getOrCreate(player).ifPresent(data -> {
var abilities = player.getAbilities();
if (!player.level().isClientSide) {
FTBEPlayerData.getOrCreate(player).ifPresent(data -> {
var abilities = player.getAbilities();

if (data.isGod() && !abilities.invulnerable) {
abilities.invulnerable = true;
player.onUpdateAbilities();
}
if (data.isGod() && !abilities.invulnerable) {
abilities.invulnerable = true;
player.onUpdateAbilities();
}

if (data.canFly() && !abilities.mayfly) {
abilities.mayfly = true;
player.onUpdateAbilities();
}
});
if (data.canFly() && !abilities.mayfly) {
abilities.mayfly = true;
player.onUpdateAbilities();
}
});
}
}

private static void serverTickPost(MinecraftServer server) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,18 @@
import net.minecraft.commands.arguments.GameProfileArgument;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.tags.BiomeTags;
import net.minecraft.tags.TagKey;
import net.minecraft.util.Mth;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.border.WorldBorder;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
Expand All @@ -38,7 +37,8 @@
* @author LatvianModder
*/
public class TeleportCommands {
public static final TagKey<Block> IGNORE_RTP = TagKey.create(Registries.BLOCK, new ResourceLocation(FTBEssentials.MOD_ID, "ignore_rtp"));
public static final TagKey<Block> IGNORE_RTP_BLOCKS = TagKey.create(Registries.BLOCK, new ResourceLocation(FTBEssentials.MOD_ID, "ignore_rtp"));
public static final TagKey<Biome> IGNORE_RTP_BIOMES = TagKey.create(Registries.BIOME, new ResourceLocation(FTBEssentials.MOD_ID, "ignore_rtp"));

public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
if (FTBEConfig.BACK.isEnabled()) {
Expand Down Expand Up @@ -144,63 +144,58 @@ public static int rtp(ServerPlayer player) {
}
return FTBEPlayerData.getOrCreate(player).map(data -> data.rtpTeleporter.teleport(player, p -> {
p.displayClientMessage(Component.literal("Looking for random location..."), false);
return findBlockPos((ServerLevel) player.level(), p, 1);
return findBlockPos((ServerLevel) player.level(), p);
}).runCommand(player))
.orElse(0);
}

private static TeleportPos findBlockPos(ServerLevel world, ServerPlayer player, int attempt) {
if (attempt > FTBEConfig.RTP_MAX_TRIES.get()) {
player.displayClientMessage(Component.literal("Could not find a valid location to teleport to!").withStyle(ChatFormatting.RED), false);
return new TeleportPos(player);
}

double dist = FTBEConfig.RTP_MIN_DISTANCE.get() + world.random.nextDouble() * (FTBEConfig.RTP_MAX_DISTANCE.get() - FTBEConfig.RTP_MIN_DISTANCE.get());
double angle = world.random.nextDouble() * Math.PI * 2D;

int x = Mth.floor(Math.cos(angle) * dist);
int y = 256;
int z = Mth.floor(Math.sin(angle) * dist);
BlockPos currentPos = new BlockPos(x, y, z);

WorldBorder border = world.getWorldBorder();

if (!border.isWithinBounds(currentPos)) {
return findBlockPos(world, player, attempt + 1);
}

Holder<Biome> biomeKey = world.getBiome(currentPos);
private static TeleportPos findBlockPos(ServerLevel world, ServerPlayer player) {
for (int attempt = 0; attempt < FTBEConfig.RTP_MAX_TRIES.get(); attempt++) {
double dist = FTBEConfig.RTP_MIN_DISTANCE.get() + world.random.nextDouble() * (FTBEConfig.RTP_MAX_DISTANCE.get() - FTBEConfig.RTP_MIN_DISTANCE.get());
double angle = world.random.nextDouble() * Math.PI * 2D;

if (biomeKey.unwrapKey().isPresent() && biomeKey.unwrapKey().get().location().getPath().contains("ocean")) {
return findBlockPos(world, player, attempt + 1);
}
int x = Mth.floor(Math.cos(angle) * dist);
int y = 256;
int z = Mth.floor(Math.sin(angle) * dist);
BlockPos currentPos = new BlockPos(x, y, z);

// TODO: FTB Chunks will listen to RTPEvent and cancel it if position is inside a claimed chunk
EventResult res = FTBEssentialsEvents.RTP_EVENT.invoker().teleport(world, player, currentPos, attempt);
if (res.isFalse()) {
return findBlockPos(world, player, attempt + 1);
}
if (!world.getWorldBorder().isWithinBounds(currentPos)) {
continue;
}
if (world.getBiome(currentPos).is(IGNORE_RTP_BIOMES)) {
continue;
}
// TODO: FTB Chunks will listen to RTPEvent and cancel it if position is inside a claimed chunk
EventResult res = FTBEssentialsEvents.RTP_EVENT.invoker().teleport(world, player, currentPos, attempt);
if (res.isFalse()) {
continue;
}

// TODO: is there an equivalent to HEIGHTMAPS on 1.20?
world.getChunk(currentPos.getX() >> 4, currentPos.getZ() >> 4/*, ChunkStatus.HEIGHTMAPS*/);
BlockPos hmPos = world.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, currentPos);

if (hmPos.getY() > 0) {
if (hmPos.getY() >= world.getLogicalHeight()) { // broken heightmap (nether, other mod dimensions)
for (BlockPos newPos : BlockPos.spiralAround(new BlockPos(hmPos.getX(), world.getSeaLevel(), hmPos.getY()), 16, Direction.EAST, Direction.SOUTH)) {
BlockState bs = world.getBlockState(newPos);
if (bs.blocksMotion() && !bs.is(IGNORE_RTP) && world.isEmptyBlock(newPos.above(1)) && world.isEmptyBlock(newPos.above(2)) && world.isEmptyBlock(newPos.above(3))) {
player.displayClientMessage(Component.literal(String.format("Found good location after %d " + (attempt == 1 ? "attempt" : "attempts") + " @ [x %d, z %d]", attempt, newPos.getX(), newPos.getZ())), false);
return new TeleportPos(world.dimension(), newPos.above());
world.getChunkAt(currentPos);
BlockPos hmPos = world.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, currentPos);

if (hmPos.getY() > 0) {
BlockPos goodPos = null;
if (hmPos.getY() < world.getLogicalHeight()) {
goodPos = hmPos;
} else {
// broken heightmap (nether, other mod dimensions)
for (BlockPos newPos : BlockPos.spiralAround(new BlockPos(hmPos.getX(), world.getSeaLevel(), hmPos.getY()), 16, Direction.EAST, Direction.SOUTH)) {
BlockState bs = world.getBlockState(newPos);
if (bs.blocksMotion() && !bs.is(IGNORE_RTP_BLOCKS) && world.isEmptyBlock(newPos.above(1))
&& world.isEmptyBlock(newPos.above(2)) && world.isEmptyBlock(newPos.above(3))) {
goodPos = newPos;
}
}
}
} else {
player.displayClientMessage(Component.literal(String.format("Found good location after %d " + (attempt == 1 ? "attempt" : "attempts") + " @ [x %d, z %d]", attempt, hmPos.getX(), hmPos.getZ())), false);
return new TeleportPos(world.dimension(), hmPos.above());
if (goodPos != null) {
player.displayClientMessage(Component.literal(String.format("Found good location after %d " + (attempt == 1 ? "attempt" : "attempts") + " @ [x %d, z %d]", attempt, goodPos.getX(), goodPos.getZ())), false);
return new TeleportPos(world.dimension(), goodPos.above());
}
}
}

return findBlockPos(world, player, attempt + 1);
player.displayClientMessage(Component.literal("Could not find a valid location to teleport to!").withStyle(ChatFormatting.RED), false);
return new TeleportPos(player);
}

public static int tpLast(ServerPlayer player, GameProfile to) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"#minecraft:is_ocean"
]
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod_id=ftbessentials
archives_base_name=ftb-essentials
maven_group=dev.ftb.mods
minecraft_version=1.20.1
mod_version=2001.2.0
mod_version=2001.2.1
mod_author=FTB Team

architectury_version=9.0.8
Expand Down

0 comments on commit 5657f78

Please sign in to comment.