Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix nether portals spawning when teleporting to other dims #8

Merged
merged 1 commit into from
Nov 10, 2023
Merged
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
23 changes: 16 additions & 7 deletions src/main/java/serverutils/lib/math/TeleporterDimPos.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;

import serverutils.ServerUtilities;
import serverutils.ServerUtilitiesConfig;
import serverutils.lib.util.ITeleporter;
import serverutils.lib.util.ServerUtils;
import serverutils.lib.util.misc.EmptyTeleporter;

public class TeleporterDimPos implements ITeleporter {
public class TeleporterDimPos {

public final double posX, posY, posZ;
public final int dim;
Expand Down Expand Up @@ -39,14 +41,12 @@ public BlockDimPos block() {
return new BlockDimPos(posX, posY, posZ, dim);
}

@Override
public void placeEntity(World world, Entity entity, float yaw) {
entity.motionX = entity.motionY = entity.motionZ = 0D;
entity.fallDistance = 0F;

if (entity instanceof EntityPlayerMP && ((EntityPlayerMP) entity).playerNetServerHandler != null) {
((EntityPlayerMP) entity).playerNetServerHandler
.setPlayerLocation(posX, posY, posZ, yaw, entity.rotationPitch);
if (entity instanceof EntityPlayerMP playerMP && playerMP.playerNetServerHandler != null) {
playerMP.playerNetServerHandler.setPlayerLocation(posX, posY, posZ, yaw, entity.rotationPitch);
} else {
entity.setLocationAndAngles(posX, posY, posZ, yaw, entity.rotationPitch);
}
Expand All @@ -72,7 +72,16 @@ public Entity teleport(@Nullable Entity entity) {
}

if (dim != entity.dimension) {
entity.travelToDimension(dim);
MinecraftServer server = ServerUtils.getServer();
WorldServer currentDim = server.worldServerForDimension(entity.dimension);
WorldServer newDim = server.worldServerForDimension(dim);
if (entity instanceof EntityPlayerMP playerMP) {
server.getConfigurationManager()
.transferPlayerToDimension(playerMP, dim, new EmptyTeleporter(newDim, this));
} else {
server.getConfigurationManager()
.transferEntityToWorld(entity, dim, currentDim, newDim, new EmptyTeleporter(newDim, this));
}
return entity;
}

Expand Down
27 changes: 0 additions & 27 deletions src/main/java/serverutils/lib/util/ITeleporter.java

This file was deleted.

44 changes: 44 additions & 0 deletions src/main/java/serverutils/lib/util/misc/EmptyTeleporter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package serverutils.lib.util.misc;

import net.minecraft.entity.Entity;
import net.minecraft.world.Teleporter;
import net.minecraft.world.WorldServer;

import serverutils.lib.math.TeleporterDimPos;

public class EmptyTeleporter extends Teleporter {

private final TeleporterDimPos destination;

public EmptyTeleporter(WorldServer worldIn, TeleporterDimPos dest) {
super(worldIn);
this.destination = dest;
}

@Override
public void removeStalePortalLocations(long p_85189_1_) {}

@Override
public void placeInPortal(Entity p_77185_1_, double p_77185_2_, double p_77185_4_, double p_77185_6_,
float p_77185_8_) {
p_77185_1_.motionX = p_77185_1_.motionY = p_77185_1_.motionZ = 0.0D;
p_77185_1_.fallDistance = 0F;
p_77185_1_.setLocationAndAngles(
destination.posX,
destination.posY,
destination.posZ,
p_77185_1_.rotationYaw,
0.0F);
}

@Override
public boolean placeInExistingPortal(Entity p_77184_1_, double p_77184_2_, double p_77184_4_, double p_77184_6_,
float p_77184_8_) {
return false;
}

@Override
public boolean makePortal(Entity entity) {
return false;
}
}