Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix /back bug #14

Open
wants to merge 1 commit into
base: MC-1.15.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@
import net.minecraft.world.server.ServerWorld;
import net.minecraft.world.server.TicketType;
import org.jetbrains.annotations.NotNull;
import net.minecraftforge.common.util.ITeleporter;
import net.minecraft.world.dimension.DimensionType;

import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
import java.util.function.Function;

public class TeleportCommand extends VanillaCommandBase {
public TeleportCommand() {
Expand Down Expand Up @@ -116,6 +119,18 @@ private static int teleportToPos(CommandSource source, Collection<? extends Enti
return targets.size();
}

public static void changeDimension(Entity entityIn, ServerWorld worldIn) {
((ServerPlayerEntity) entityIn).changeDimension(worldIn.getDimension().getType() , new ITeleporter()
{
@Override
public Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destWorld, float yaw, Function<Boolean, Entity> repositionEntity)
{
Entity repositionedEntity = repositionEntity.apply(false);
return repositionedEntity;
}
});
}

public static void teleport(CommandSource source, Entity entityIn, ServerWorld worldIn, double x, double y, double z, Set<SPlayerPositionLookPacket.Flags> relativeList, float yaw, float pitch, @Nullable Facing facing) {
if (entityIn instanceof ServerPlayerEntity) {
ChunkPos chunkpos = new ChunkPos(new BlockPos(x, y, z));
Expand All @@ -125,12 +140,10 @@ public static void teleport(CommandSource source, Entity entityIn, ServerWorld w
((ServerPlayerEntity) entityIn).stopSleepInBed(true, true);
}

if (worldIn == entityIn.world) {
((ServerPlayerEntity) entityIn).connection.setPlayerLocation(x, y, z, yaw, pitch, relativeList);
} else {
((ServerPlayerEntity) entityIn).teleport(worldIn, x, y, z, yaw, pitch);
if (worldIn != entityIn.world) {
changeDimension(entityIn, worldIn);
}

((ServerPlayerEntity) entityIn).connection.setPlayerLocation(x, y, z, yaw, pitch, relativeList);
entityIn.setRotationYawHead(yaw);
} else {
float f1 = MathHelper.wrapDegrees(yaw);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.mairwunnx.projectessentials.core.impl.commands

import com.mairwunnx.projectessentials.core.api.v1.MESSAGE_CORE_PREFIX
import com.mairwunnx.projectessentials.core.api.v1.commands.CommandBase
import com.mairwunnx.projectessentials.core.impl.vanilla.commands.TeleportCommand
import com.mairwunnx.projectessentials.core.api.v1.commands.back.BackLocationAPI
import com.mairwunnx.projectessentials.core.api.v1.extensions.getPlayer
import com.mairwunnx.projectessentials.core.api.v1.extensions.isPlayerSender
Expand All @@ -10,7 +11,11 @@ import com.mairwunnx.projectessentials.core.api.v1.messaging.ServerMessagingAPI
import com.mairwunnx.projectessentials.core.api.v1.permissions.hasPermission
import com.mojang.brigadier.builder.LiteralArgumentBuilder.literal
import com.mojang.brigadier.context.CommandContext
import net.minecraft.world.server.TicketType
import net.minecraft.entity.player.ServerPlayerEntity
import net.minecraft.command.CommandSource
import net.minecraft.util.math.ChunkPos
import net.minecraft.util.math.BlockPos

internal object BackLocationCommand : CommandBase(literal("back")) {
override val name = "back"
Expand All @@ -28,11 +33,16 @@ internal object BackLocationCommand : CommandBase(literal("back")) {
if (data != null) {
val pos = data.position
val rot = data.rotation

player.teleport(
data.world, pos.xPos, pos.yPos, pos.zPos, rot.yaw, rot.pitch
)

val chunkpos = ChunkPos(BlockPos(pos.xPos, pos.yPos, pos.zPos))
data.world.getChunkProvider().registerTicket(TicketType.POST_TELEPORT, chunkpos, 1, player.getEntityId())
player.stopRiding()
if (player.isSleeping()) {
player.stopSleepInBed(true, true)
}
if (data.world != player.serverWorld) {
TeleportCommand.changeDimension(player, data.world)
}
player.connection.setPlayerLocation(pos.xPos, pos.yPos, pos.zPos, rot.yaw, rot.pitch)
BackLocationAPI.revoke(player)
MessagingAPI.sendMessage(player, "$MESSAGE_CORE_PREFIX.back.success")
} else {
Expand Down