Skip to content

Commit

Permalink
Merge pull request #230 from FishyFinn/dev
Browse files Browse the repository at this point in the history
Fixed issue #228 Relative teleports not working with teleport_warmup
  • Loading branch information
sakurawald authored Jan 3, 2025
2 parents 0303973 + addf787 commit 4780e3e
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
import net.minecraft.world.chunk.Chunk;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Iterator;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.Optional;
import java.util.OptionalInt;

@Cite("https://github.com/John-Paul-R/Essential-Commands")
@UtilityClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import net.minecraft.util.Identifier;
import net.minecraft.world.World;
import org.jetbrains.annotations.NotNull;

import java.util.Set;
import java.util.EnumSet;

@Data
Expand Down Expand Up @@ -55,7 +55,7 @@ public double distanceToSqr(@NotNull SpatialPose spatialPose) {
return x * x + y * y + z * z;
}

public void teleport(@NotNull ServerPlayerEntity player) {
public void teleport(@NotNull ServerPlayerEntity player, Set<PositionFlag> flags) {
RegistryKey<World> worldKey = RegistryKey.of(RegistryKeys.WORLD, Identifier.of(this.level));
ServerWorld serverLevel = ServerHelper.getServer().getWorld(worldKey);
if (serverLevel == null) {
Expand All @@ -64,7 +64,10 @@ public void teleport(@NotNull ServerPlayerEntity player) {
}

/* make position flags */
EnumSet<PositionFlag> flags = EnumSet.noneOf(PositionFlag.class);
player.teleport(serverLevel, this.x, this.y, this.z, flags, this.yaw, this.pitch, true);
}

public void teleport(@NotNull ServerPlayerEntity player) {
teleport(player, EnumSet.noneOf(PositionFlag.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,26 @@
import lombok.Getter;
import net.minecraft.entity.boss.BossBar;
import net.minecraft.entity.boss.ServerBossBar;
import net.minecraft.network.packet.s2c.play.PositionFlag;
import net.minecraft.server.network.ServerPlayerEntity;
import org.jetbrains.annotations.NotNull;

import java.util.EnumSet;
import java.util.Set;

@Getter
public class TeleportTicket extends InterruptibleTicket {

private final SpatialPose destination;
private final Set<PositionFlag> flags;

private TeleportTicket(@NotNull ServerPlayerEntity player
, SpatialPose source
, SpatialPose destination
, float progress
, int totalMs
, Interruptible interruptible
, Set<PositionFlag> flags
) {
super(
new ServerBossBar(TextHelper.getTextByKey(player, "teleport_warmup.bossbar.name"), BossBar.Color.BLUE, net.minecraft.entity.boss.BossBar.Style.PROGRESS)
Expand All @@ -29,22 +35,22 @@ private TeleportTicket(@NotNull ServerPlayerEntity player
, interruptible);

this.destination = destination;

this.flags = flags;
// set progress
this.getBossBar().setPercent(progress);
}

public static @NotNull TeleportTicket make(@NotNull ServerPlayerEntity player, SpatialPose source, SpatialPose destination, int totalMs, Interruptible interruptible) {
return new TeleportTicket(player, source, destination, 0f, totalMs, interruptible);
public static @NotNull TeleportTicket make(@NotNull ServerPlayerEntity player, SpatialPose source, SpatialPose destination, int totalMs, Interruptible interruptible, Set<PositionFlag> flags) {
return new TeleportTicket(player, source, destination, 0f, totalMs, interruptible, flags);
}

public static @NotNull TeleportTicket makeVipTicket(@NotNull ServerPlayerEntity player, SpatialPose source, SpatialPose destination) {
return new TeleportTicket(player, source, destination, 1f, 2048, Interruptible.makeUninterruptible());
return new TeleportTicket(player, source, destination, 1f, 2048, Interruptible.makeUninterruptible(), EnumSet.noneOf(PositionFlag.class));
}

@Override
protected void onComplete() {
destination.teleport(player);
destination.teleport(player, flags);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
import io.github.sakurawald.module.initializer.ModuleInitializer;
import io.github.sakurawald.module.initializer.back.config.model.BackConfigModel;
import lombok.Getter;
import net.minecraft.network.packet.s2c.play.PositionFlag;
import net.minecraft.server.network.ServerPlayerEntity;
import org.jetbrains.annotations.NotNull;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Set;

public class BackInitializer extends ModuleInitializer {

Expand All @@ -32,8 +35,8 @@ public class BackInitializer extends ModuleInitializer {
TextHelper.sendActionBarByKey(player, "back.no_previous_position");
return CommandHelper.Return.FAIL;
}

lastPos.teleport(player);
Set<PositionFlag> flags = EnumSet.noneOf(PositionFlag.class);
lastPos.teleport(player,flags);
return CommandHelper.Return.SUCCESS;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.world.World;



public class BedInitializer extends ModuleInitializer {

@CommandNode("bed")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.Vec3d;

import java.util.Optional;


public class JumpInitializer extends ModuleInitializer {

@CommandNode("jump")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.world.Heightmap;
import net.minecraft.world.World;


public class TopInitializer extends ModuleInitializer {

@CommandNode("top")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import io.github.sakurawald.module.initializer.ModuleInitializer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;

import java.util.Optional;


public class TpposInitializer extends ModuleInitializer {

@CommandNode("tppos")
Expand Down Expand Up @@ -50,6 +50,8 @@ private static int tppos(@CommandSource @CommandTarget ServerPlayerEntity player
double $z = z.orElse(player.getZ());
float $yaw = yaw.orElse(player.getYaw());
float $pitch = pitch.orElse(player.getPitch());


SpatialPose spatialPose = new SpatialPose(world, $x, $y, $z, $yaw, $pitch);
spatialPose.teleport(player);
return CommandHelper.Return.SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
import lombok.Getter;
import net.minecraft.server.network.ServerPlayerEntity;
import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.Map;
import java.util.HashMap;
import java.util.Optional;

public class HomeInitializer extends ModuleInitializer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public int compareTo(@NotNull ChunkScore that) {
y = 128;
}


new SpatialPose(dimension, blockPos.getX(), y, blockPos.getZ(), player.getYaw(), player.getPitch())
.teleport(player);
}, 5, TimeUnit.MINUTES))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
import io.github.sakurawald.module.initializer.tpa.structure.TpaRequest;
import lombok.Getter;
import net.minecraft.server.network.ServerPlayerEntity;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;


public class TpaInitializer extends ModuleInitializer {

public static final BaseConfigurationHandler<TpaConfigModel> config = new ObjectConfigurationHandler<>(BaseConfigurationHandler.CONFIG_JSON, TpaConfigModel.class);
Expand Down Expand Up @@ -70,6 +70,7 @@ private static int doResponse(ServerPlayerEntity player, ServerPlayerEntity targ
ServerPlayerEntity who = request.getTeleportWho();
ServerPlayerEntity to = request.getTeleportTo();
MentionPlayersJob.requestJob(config.model().mention_player, request.isTpahere() ? to : who);

new SpatialPose(to.getWorld(), to.getX(), to.getY(), to.getZ(), to.getYaw(), to.getPitch())
.teleport(who);
} else if (status == ResponseStatus.DENY) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import net.minecraft.world.World;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;


public class WorksGui extends PagedGui<Work> {

public WorksGui(ServerPlayerEntity player, @NotNull List<Work> entities, int pageIndex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.github.sakurawald.module.initializer.world.config.model.WorldDataModel;
import io.github.sakurawald.module.initializer.world.gui.WorldGui;
import io.github.sakurawald.module.initializer.world.structure.DimensionNode;

import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
Expand All @@ -31,7 +32,6 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.random.RandomSeed;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -67,6 +67,7 @@ private static void checkBlacklist(CommandContext<ServerCommandSource> ctx, Stri
private static int $tp(@CommandSource ServerPlayerEntity player, Dimension dimension) {
ServerWorld world = dimension.getValue();
BlockPos spawnPos = world.getSpawnPos();

new SpatialPose(world, spawnPos.getX(), spawnPos.getY(), spawnPos.getZ(), player.getYaw(), player.getPitch())
.teleport(player);
return CommandHelper.Return.SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public void interceptTeleportAndAddTicket(ServerWorld serverWorld, double x, dou
, new SpatialPose(serverWorld, x, y, z, yaw, pitch)
, warmup_seconds * 1000
, TeleportWarmupInitializer.config.model().interruptible
, set
);
Managers.getBossBarManager().addTicket(ticket);
cir.cancel();
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@
"role": "zh_TW translator",
"homepage": "https://github.com/notlin4"
}
},
{
"name": "FishyFinn360",
"contact": {
"role": "contributor",
"homepage": "https://github.com/FishyFinn"
}
}
],
"environment": "*",
Expand Down

0 comments on commit 4780e3e

Please sign in to comment.