Skip to content

Commit 5657f78

Browse files
authored
Merge pull request #53 from FTBTeam/dev
Dev
2 parents 0ddd353 + 831eb09 commit 5657f78

File tree

6 files changed

+75
-61
lines changed

6 files changed

+75
-61
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77

8+
## [2001.2.1]
9+
10+
### Added
11+
* The `/rtp` command now makes better use of block and biome tags to control valid RTP destinations
12+
* `ftbessentials:ignore_rtp` block tag lists blocks which are not valid for the player to land on (leaves and Bedrock by default)
13+
* `ftbessentials:ignore_rtp` biome tag lists biomes which are not valid for the player to land in (`#minecraft:is_ocean` by default)
14+
15+
### Fixed
16+
* Fixed an event handler running on the client side which shouldn't have been
17+
* Led to undesirable effects like players flying when they shouldn't
18+
819
## [2001.2.0]
920

1021
### Added

common/src/main/java/dev/ftb/mods/ftbessentials/FTBEEventHandler.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,21 @@ private static void playerLoggedOut(ServerPlayer serverPlayer) {
122122
}
123123

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

128-
if (data.isGod() && !abilities.invulnerable) {
129-
abilities.invulnerable = true;
130-
player.onUpdateAbilities();
131-
}
129+
if (data.isGod() && !abilities.invulnerable) {
130+
abilities.invulnerable = true;
131+
player.onUpdateAbilities();
132+
}
132133

133-
if (data.canFly() && !abilities.mayfly) {
134-
abilities.mayfly = true;
135-
player.onUpdateAbilities();
136-
}
137-
});
134+
if (data.canFly() && !abilities.mayfly) {
135+
abilities.mayfly = true;
136+
player.onUpdateAbilities();
137+
}
138+
});
139+
}
138140
}
139141

140142
private static void serverTickPost(MinecraftServer server) {

common/src/main/java/dev/ftb/mods/ftbessentials/command/TeleportCommands.java

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,18 @@
1717
import net.minecraft.commands.arguments.GameProfileArgument;
1818
import net.minecraft.core.BlockPos;
1919
import net.minecraft.core.Direction;
20-
import net.minecraft.core.Holder;
2120
import net.minecraft.core.registries.Registries;
2221
import net.minecraft.network.chat.Component;
2322
import net.minecraft.resources.ResourceLocation;
2423
import net.minecraft.server.level.ServerLevel;
2524
import net.minecraft.server.level.ServerPlayer;
25+
import net.minecraft.tags.BiomeTags;
2626
import net.minecraft.tags.TagKey;
2727
import net.minecraft.util.Mth;
2828
import net.minecraft.world.level.Level;
2929
import net.minecraft.world.level.biome.Biome;
3030
import net.minecraft.world.level.block.Block;
3131
import net.minecraft.world.level.block.state.BlockState;
32-
import net.minecraft.world.level.border.WorldBorder;
3332
import net.minecraft.world.level.levelgen.Heightmap;
3433
import net.minecraft.world.phys.BlockHitResult;
3534
import net.minecraft.world.phys.Vec3;
@@ -38,7 +37,8 @@
3837
* @author LatvianModder
3938
*/
4039
public class TeleportCommands {
41-
public static final TagKey<Block> IGNORE_RTP = TagKey.create(Registries.BLOCK, new ResourceLocation(FTBEssentials.MOD_ID, "ignore_rtp"));
40+
public static final TagKey<Block> IGNORE_RTP_BLOCKS = TagKey.create(Registries.BLOCK, new ResourceLocation(FTBEssentials.MOD_ID, "ignore_rtp"));
41+
public static final TagKey<Biome> IGNORE_RTP_BIOMES = TagKey.create(Registries.BIOME, new ResourceLocation(FTBEssentials.MOD_ID, "ignore_rtp"));
4242

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

152-
private static TeleportPos findBlockPos(ServerLevel world, ServerPlayer player, int attempt) {
153-
if (attempt > FTBEConfig.RTP_MAX_TRIES.get()) {
154-
player.displayClientMessage(Component.literal("Could not find a valid location to teleport to!").withStyle(ChatFormatting.RED), false);
155-
return new TeleportPos(player);
156-
}
157-
158-
double dist = FTBEConfig.RTP_MIN_DISTANCE.get() + world.random.nextDouble() * (FTBEConfig.RTP_MAX_DISTANCE.get() - FTBEConfig.RTP_MIN_DISTANCE.get());
159-
double angle = world.random.nextDouble() * Math.PI * 2D;
160-
161-
int x = Mth.floor(Math.cos(angle) * dist);
162-
int y = 256;
163-
int z = Mth.floor(Math.sin(angle) * dist);
164-
BlockPos currentPos = new BlockPos(x, y, z);
165-
166-
WorldBorder border = world.getWorldBorder();
167-
168-
if (!border.isWithinBounds(currentPos)) {
169-
return findBlockPos(world, player, attempt + 1);
170-
}
171-
172-
Holder<Biome> biomeKey = world.getBiome(currentPos);
152+
private static TeleportPos findBlockPos(ServerLevel world, ServerPlayer player) {
153+
for (int attempt = 0; attempt < FTBEConfig.RTP_MAX_TRIES.get(); attempt++) {
154+
double dist = FTBEConfig.RTP_MIN_DISTANCE.get() + world.random.nextDouble() * (FTBEConfig.RTP_MAX_DISTANCE.get() - FTBEConfig.RTP_MIN_DISTANCE.get());
155+
double angle = world.random.nextDouble() * Math.PI * 2D;
173156

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

178-
// TODO: FTB Chunks will listen to RTPEvent and cancel it if position is inside a claimed chunk
179-
EventResult res = FTBEssentialsEvents.RTP_EVENT.invoker().teleport(world, player, currentPos, attempt);
180-
if (res.isFalse()) {
181-
return findBlockPos(world, player, attempt + 1);
182-
}
162+
if (!world.getWorldBorder().isWithinBounds(currentPos)) {
163+
continue;
164+
}
165+
if (world.getBiome(currentPos).is(IGNORE_RTP_BIOMES)) {
166+
continue;
167+
}
168+
// TODO: FTB Chunks will listen to RTPEvent and cancel it if position is inside a claimed chunk
169+
EventResult res = FTBEssentialsEvents.RTP_EVENT.invoker().teleport(world, player, currentPos, attempt);
170+
if (res.isFalse()) {
171+
continue;
172+
}
183173

184-
// TODO: is there an equivalent to HEIGHTMAPS on 1.20?
185-
world.getChunk(currentPos.getX() >> 4, currentPos.getZ() >> 4/*, ChunkStatus.HEIGHTMAPS*/);
186-
BlockPos hmPos = world.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, currentPos);
187-
188-
if (hmPos.getY() > 0) {
189-
if (hmPos.getY() >= world.getLogicalHeight()) { // broken heightmap (nether, other mod dimensions)
190-
for (BlockPos newPos : BlockPos.spiralAround(new BlockPos(hmPos.getX(), world.getSeaLevel(), hmPos.getY()), 16, Direction.EAST, Direction.SOUTH)) {
191-
BlockState bs = world.getBlockState(newPos);
192-
if (bs.blocksMotion() && !bs.is(IGNORE_RTP) && world.isEmptyBlock(newPos.above(1)) && world.isEmptyBlock(newPos.above(2)) && world.isEmptyBlock(newPos.above(3))) {
193-
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);
194-
return new TeleportPos(world.dimension(), newPos.above());
174+
world.getChunkAt(currentPos);
175+
BlockPos hmPos = world.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, currentPos);
176+
177+
if (hmPos.getY() > 0) {
178+
BlockPos goodPos = null;
179+
if (hmPos.getY() < world.getLogicalHeight()) {
180+
goodPos = hmPos;
181+
} else {
182+
// broken heightmap (nether, other mod dimensions)
183+
for (BlockPos newPos : BlockPos.spiralAround(new BlockPos(hmPos.getX(), world.getSeaLevel(), hmPos.getY()), 16, Direction.EAST, Direction.SOUTH)) {
184+
BlockState bs = world.getBlockState(newPos);
185+
if (bs.blocksMotion() && !bs.is(IGNORE_RTP_BLOCKS) && world.isEmptyBlock(newPos.above(1))
186+
&& world.isEmptyBlock(newPos.above(2)) && world.isEmptyBlock(newPos.above(3))) {
187+
goodPos = newPos;
188+
}
195189
}
196190
}
197-
} else {
198-
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);
199-
return new TeleportPos(world.dimension(), hmPos.above());
191+
if (goodPos != null) {
192+
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);
193+
return new TeleportPos(world.dimension(), goodPos.above());
194+
}
200195
}
201196
}
202-
203-
return findBlockPos(world, player, attempt + 1);
197+
player.displayClientMessage(Component.literal("Could not find a valid location to teleport to!").withStyle(ChatFormatting.RED), false);
198+
return new TeleportPos(player);
204199
}
205200

206201
public static int tpLast(ServerPlayer player, GameProfile to) {

common/src/main/resources/data/ftbessentials/ignore_rtp.json renamed to common/src/main/resources/data/ftbessentials/tags/blocks/ignore_rtp.json

File renamed without changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"replace": false,
3+
"values": [
4+
"#minecraft:is_ocean"
5+
]
6+
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod_id=ftbessentials
55
archives_base_name=ftb-essentials
66
maven_group=dev.ftb.mods
77
minecraft_version=1.20.1
8-
mod_version=2001.2.0
8+
mod_version=2001.2.1
99
mod_author=FTB Team
1010

1111
architectury_version=9.0.8

0 commit comments

Comments
 (0)