From 1a7e4632fa1cf1ed767118e628559c6a270eb08a Mon Sep 17 00:00:00 2001 From: Robotia Date: Thu, 3 Mar 2016 19:23:08 -0500 Subject: [PATCH] Pass environment to transferrer and register with client --- .../craftbukkit/entity/CraftPlayer.java | 3 +-- .../ThermiteTeleportationHandler.java | 26 ++++++++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 4dd0c8df..297781a9 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -494,7 +494,6 @@ public boolean teleport(Location location, PlayerTeleportEvent.TeleportCause cau // Grab the To and From World Handles. net.minecraft.world.WorldServer fromWorld = ((CraftWorld) from.getWorld()).getHandle(); net.minecraft.world.WorldServer toWorld = ((CraftWorld) to.getWorld()).getHandle(); - // Close any foreign inventory if (getHandle().openContainer != getHandle().inventoryContainer) { getHandle().closeScreen(); @@ -506,7 +505,7 @@ public boolean teleport(Location location, PlayerTeleportEvent.TeleportCause cau } else { //Thermos....transfer them correctly?! this.getHandle().mountEntity(null); - thermos.thermite.ThermiteTeleportationHandler.transferPlayerToDimension(this.getHandle(), toWorld.dimension, this.getHandle().mcServer.getConfigurationManager()); + thermos.thermite.ThermiteTeleportationHandler.transferPlayerToDimension(this.getHandle(), toWorld.dimension, this.getHandle().mcServer.getConfigurationManager(), to.getWorld().getEnvironment()); //this.getHandle().playerNetServerHandler.teleport(to); this.getHandle().playerNetServerHandler.teleport(to); //this.getHandle().playerNetServerHandler.setPlayerLocation(to.getX(), to.getY(), to.getZ(), this.getHandle().rotationYaw, this.getHandle().rotationPitch); diff --git a/src/main/java/thermos/thermite/ThermiteTeleportationHandler.java b/src/main/java/thermos/thermite/ThermiteTeleportationHandler.java index fd77bcd3..09916c36 100644 --- a/src/main/java/thermos/thermite/ThermiteTeleportationHandler.java +++ b/src/main/java/thermos/thermite/ThermiteTeleportationHandler.java @@ -2,7 +2,11 @@ import java.util.Iterator; +import org.bukkit.World.Environment; + import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.network.FMLEmbeddedChannel; +import cpw.mods.fml.common.network.FMLOutboundHandler; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.network.play.server.S07PacketRespawn; @@ -12,12 +16,15 @@ import net.minecraft.util.MathHelper; import net.minecraft.world.WorldProvider; import net.minecraft.world.WorldServer; +import net.minecraftforge.common.DimensionManager; +import net.minecraftforge.common.network.ForgeMessage; +import net.minecraftforge.common.network.ForgeNetworkHandler; public class ThermiteTeleportationHandler { - public static void transferEntityToDimension(Entity ent, int dim, ServerConfigurationManager manager) { + public static void transferEntityToDimension(Entity ent, int dim, ServerConfigurationManager manager, Environment environ) { if (ent instanceof EntityPlayerMP) { - transferPlayerToDimension((EntityPlayerMP) ent, dim, manager); + transferPlayerToDimension((EntityPlayerMP) ent, dim, manager, environ); return; } WorldServer worldserver = manager.getServerInstance().worldServerForDimension(ent.dimension); @@ -53,15 +60,22 @@ public static void transferEntityToWorld(Entity ent, WorldServer oldWorld, World ent.setWorld(newWorld); } - public static void transferPlayerToDimension(EntityPlayerMP player, int dim, ServerConfigurationManager manager) { + public static void transferPlayerToDimension(EntityPlayerMP player, int dim, ServerConfigurationManager manager, Environment environ) { int oldDim = player.dimension; WorldServer worldserver = manager.getServerInstance().worldServerForDimension(player.dimension); player.dimension = dim; WorldServer worldserver1 = manager.getServerInstance().worldServerForDimension(player.dimension); - int fakeDim = dim; - if(!net.minecraftforge.common.DimensionManager.isDimensionRegistered(dim))fakeDim = 0; - player.playerNetServerHandler.sendPacket(new S07PacketRespawn(fakeDim, player.worldObj.difficultySetting, player.worldObj.getWorldInfo() + // Cauldron dont crash the client, let 'em know there's a new dimension in town + if (DimensionManager.isBukkitDimension(dim)) + { + FMLEmbeddedChannel serverChannel = ForgeNetworkHandler.getServerChannel(); + serverChannel.attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER); + serverChannel.attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player); + serverChannel.writeOutbound(new ForgeMessage.DimensionRegisterMessage(dim, environ.getId())); + } + // Cauldron end + player.playerNetServerHandler.sendPacket(new S07PacketRespawn(dim, worldserver1.difficultySetting, worldserver1.getWorldInfo() .getTerrainType(), player.theItemInWorldManager.getGameType())); worldserver.removePlayerEntityDangerously(player); if (player.riddenByEntity != null) {