diff options
Diffstat (limited to 'src/main/java/net/minecraft/server')
9 files changed, 348 insertions, 131 deletions
diff --git a/src/main/java/net/minecraft/server/BlockEnderPortal.java b/src/main/java/net/minecraft/server/BlockEnderPortal.java index d55e41d0..6a5b2748 100644 --- a/src/main/java/net/minecraft/server/BlockEnderPortal.java +++ b/src/main/java/net/minecraft/server/BlockEnderPortal.java @@ -3,6 +3,8 @@ package net.minecraft.server; import java.util.List; import java.util.Random; +import org.bukkit.event.entity.EntityPortalEnterEvent; // CraftBukkit + public class BlockEnderPortal extends BlockContainer { public static boolean a = false; @@ -38,6 +40,10 @@ public class BlockEnderPortal extends BlockContainer { public void a(World world, int i, int j, int k, Entity entity) { if (entity.vehicle == null && entity.passenger == null && !world.isStatic) { + // CraftBukkit start - Entity in portal + EntityPortalEnterEvent event = new EntityPortalEnterEvent(entity.getBukkitEntity(), new org.bukkit.Location(world.getWorld(), i, j, k)); + world.getServer().getPluginManager().callEvent(event); + // CraftBukkit end entity.b(1); } } diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java index ebe0ed06..e1d611ed 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -8,7 +8,9 @@ import java.util.concurrent.Callable; import java.util.UUID; import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.Server; +import org.bukkit.TravelAgent; import org.bukkit.block.BlockFace; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Painting; @@ -19,11 +21,13 @@ import org.bukkit.event.vehicle.VehicleBlockCollisionEvent; import org.bukkit.event.vehicle.VehicleEnterEvent; import org.bukkit.event.vehicle.VehicleExitEvent; import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.event.entity.EntityCombustEvent; import org.bukkit.event.entity.EntityDamageByBlockEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityPortalEvent; import org.bukkit.plugin.PluginManager; // CraftBukkit end @@ -1378,9 +1382,9 @@ public abstract class Entity { this.setPassengerOf(entity); } - protected org.bukkit.entity.Entity bukkitEntity; + protected CraftEntity bukkitEntity; - public org.bukkit.entity.Entity getBukkitEntity() { + public CraftEntity getBukkitEntity() { if (this.bukkitEntity == null) { this.bukkitEntity = org.bukkit.craftbukkit.entity.CraftEntity.getEntity(this.world.getServer(), this); } @@ -1741,24 +1745,53 @@ public abstract class Entity { } public void b(int i) { - if (false && !this.world.isStatic && !this.dead) { // CraftBukkit - disable entity portal support for now. + if (!this.world.isStatic && !this.dead) { this.world.methodProfiler.a("changeDimension"); MinecraftServer minecraftserver = MinecraftServer.getServer(); - int j = this.dimension; - WorldServer worldserver = minecraftserver.getWorldServer(j); - WorldServer worldserver1 = minecraftserver.getWorldServer(i); + // CraftBukkit start - move logic into new function "teleportToLocation" + // int j = this.dimension; + Location enter = this.getBukkitEntity().getLocation(); + Location exit = minecraftserver.getPlayerList().calculateTarget(enter, minecraftserver.getWorldServer(i)); + + TravelAgent agent = (TravelAgent) ((CraftWorld) exit.getWorld()).getHandle().s(); + EntityPortalEvent event = new EntityPortalEvent(this.getBukkitEntity(), enter, exit, agent); + event.getEntity().getServer().getPluginManager().callEvent(event); + if (event.isCancelled() || event.getTo() == null || !this.isAlive()) { + return; + } + exit = event.useTravelAgent() ? event.getPortalTravelAgent().findOrCreate(exit) : event.getTo(); + this.teleportTo(exit, true); + } + } + + public void teleportTo(Location exit, boolean portal) { + if (true) { + WorldServer worldserver = ((CraftWorld) this.getBukkitEntity().getLocation().getWorld()).getHandle(); + WorldServer worldserver1 = ((CraftWorld) exit.getWorld()).getHandle(); + int i = worldserver1.dimension; + // CraftBukkit end this.dimension = i; this.world.kill(this); this.dead = false; this.world.methodProfiler.a("reposition"); - minecraftserver.getPlayerList().a(this, j, worldserver, worldserver1); + // CraftBukkit start - ensure chunks are loaded in case TravelAgent is not used which would initially cause chunks to load during find/create + // minecraftserver.getPlayerList().a(this, j, worldserver, worldserver1); + boolean before = worldserver1.chunkProviderServer.forceChunkLoad; + worldserver1.chunkProviderServer.forceChunkLoad = true; + worldserver1.getMinecraftServer().getPlayerList().repositionEntity(this, exit, portal); + worldserver1.chunkProviderServer.forceChunkLoad = before; + // CraftBukkit end this.world.methodProfiler.c("reloading"); Entity entity = EntityTypes.createEntityByName(EntityTypes.b(this), worldserver1); if (entity != null) { entity.a(this, true); worldserver1.addEntity(entity); + // CraftBukkit start - forward the CraftEntity to the new entity + this.getBukkitEntity().setHandle(entity); + entity.bukkitEntity = this.getBukkitEntity(); + // CraftBukkit end } this.dead = true; diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java index 85663915..7afa68ef 100644 --- a/src/main/java/net/minecraft/server/EntityHuman.java +++ b/src/main/java/net/minecraft/server/EntityHuman.java @@ -4,8 +4,8 @@ import java.util.Iterator; import java.util.List; // CraftBukkit start +import org.bukkit.craftbukkit.entity.CraftHumanEntity; import org.bukkit.craftbukkit.entity.CraftItem; -import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityCombustByEntityEvent; import org.bukkit.event.player.PlayerBedEnterEvent; @@ -37,8 +37,9 @@ public abstract class EntityHuman extends EntityLiving implements ICommandListen public boolean fauxSleeping; public String spawnWorld = ""; - public HumanEntity getBukkitEntity() { - return (HumanEntity) super.getBukkitEntity(); + @Override + public CraftHumanEntity getBukkitEntity() { + return (CraftHumanEntity) super.getBukkitEntity(); } // CraftBukkit end diff --git a/src/main/java/net/minecraft/server/EntityMinecart.java b/src/main/java/net/minecraft/server/EntityMinecart.java index 712853d1..cabc3ce6 100644 --- a/src/main/java/net/minecraft/server/EntityMinecart.java +++ b/src/main/java/net/minecraft/server/EntityMinecart.java @@ -299,7 +299,7 @@ public class EntityMinecart extends Entity implements IInventory { i = this.z(); if (this.ao) { - if (minecraftserver.getAllowNether()) { + if (true || minecraftserver.getAllowNether()) { // CraftBukkit - multi-world should still allow teleport even if default vanilla nether disabled if (this.vehicle == null && this.ap++ >= i) { this.ap = i; this.portalCooldown = this.ab(); diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java index 99f12181..8d61ca63 100644 --- a/src/main/java/net/minecraft/server/EntityPlayer.java +++ b/src/main/java/net/minecraft/server/EntityPlayer.java @@ -15,6 +15,7 @@ import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.event.inventory.InventoryType; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; // CraftBukkit end public class EntityPlayer extends EntityHuman implements ICrafting { @@ -321,21 +322,27 @@ public class EntityPlayer extends EntityHuman implements ICrafting { this.viewingCredits = true; this.playerConnection.sendPacket(new Packet70Bed(4, 0)); } else { - this.a((Statistic) AchievementList.B); - /* CraftBukkit start - removed to fix our handling of The End portals - ChunkCoordinates chunkcoordinates = this.server.getWorldServer(i).getDimensionSpawn(); + if (this.dimension == 1 && i == 0) { + this.a((Statistic) AchievementList.B); + // CraftBukkit start - rely on custom portal management + /* + ChunkCoordinates chunkcoordinates = this.server.getWorldServer(i).getDimensionSpawn(); if (chunkcoordinates != null) { this.netServerHandler.a((double) chunkcoordinates.x, (double) chunkcoordinates.y, (double) chunkcoordinates.z, 0.0F, 0.0F); } i = 1; + */ + // CraftBukkit end } else { this.a((Statistic) AchievementList.x); } - // CraftBukkit end */ - this.server.getPlayerList().changeDimension(this, i); + // CraftBukkit start + TeleportCause cause = (this.dimension == 1 || i == 1) ? TeleportCause.END_PORTAL : TeleportCause.NETHER_PORTAL; + this.server.getPlayerList().changeDimension(this, i, cause); + // CraftBukkit end this.lastSentExp = -1; this.cl = -1; this.cm = -1; diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java index 94b62ac9..fac9ea5e 100644 --- a/src/main/java/net/minecraft/server/PlayerConnection.java +++ b/src/main/java/net/minecraft/server/PlayerConnection.java @@ -37,6 +37,7 @@ import org.bukkit.event.player.PlayerItemHeldEvent; import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.event.player.PlayerToggleSneakEvent; import org.bukkit.event.player.PlayerToggleSprintEvent; import org.bukkit.event.inventory.*; @@ -1126,26 +1127,7 @@ public class PlayerConnection extends Connection { public void a(Packet205ClientCommand packet205clientcommand) { if (packet205clientcommand.a == 1) { if (this.player.viewingCredits) { - // CraftBukkit start - org.bukkit.craftbukkit.PortalTravelAgent pta = new org.bukkit.craftbukkit.PortalTravelAgent(); - Location toLocation; - - if (this.player.getBukkitEntity().getBedSpawnLocation() == null) { - CraftWorld cworld = (CraftWorld) this.server.getWorlds().get(0); - ChunkCoordinates chunkcoordinates = cworld.getHandle().getSpawn(); - toLocation = new Location(cworld, chunkcoordinates.x + 0.5, chunkcoordinates.y, chunkcoordinates.z + 0.5); - this.player.playerConnection.sendPacket(new Packet70Bed(0, 0)); - } else { - toLocation = this.player.getBukkitEntity().getBedSpawnLocation(); - toLocation = new Location(toLocation.getWorld(), toLocation.getX() + 0.5, toLocation.getY(), toLocation.getZ() + 0.5); - } - - PlayerPortalEvent event = new PlayerPortalEvent(this.player.getBukkitEntity(), this.player.getBukkitEntity().getLocation(), toLocation, pta, PlayerPortalEvent.TeleportCause.END_PORTAL); - event.useTravelAgent(false); - - Bukkit.getServer().getPluginManager().callEvent(event); - this.player = this.minecraftServer.getPlayerList().moveToWorld(this.player, 0, true, event.getTo()); - // CraftBukkit end + this.minecraftServer.getPlayerList().changeDimension(this.player, 0, TeleportCause.END_PORTAL); // CraftBukkit - reroute logic through custom portal management } else if (this.player.p().getWorldData().isHardcore()) { if (this.minecraftServer.I() && this.player.name.equals(this.minecraftServer.H())) { this.player.playerConnection.disconnect("You have died. Game over, man, it\'s game over!"); diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java index 04ee0de4..2fb83cf6 100644 --- a/src/main/java/net/minecraft/server/PlayerList.java +++ b/src/main/java/net/minecraft/server/PlayerList.java @@ -13,9 +13,11 @@ import java.util.logging.Logger; // CraftBukkit start import org.bukkit.Location; +import org.bukkit.TravelAgent; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.chunkio.ChunkIOExecutor; +import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerPortalEvent; @@ -24,6 +26,7 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; +import org.bukkit.util.Vector; import org.bukkit.Bukkit; // CraftBukkit end @@ -419,76 +422,134 @@ public abstract class PlayerList { return entityplayer1; } - public void changeDimension(EntityPlayer entityplayer, int i) { - // CraftBukkit start -- Replaced the standard handling of portals with a more customised method. - int dimension = i; - WorldServer fromWorld = this.server.getWorldServer(entityplayer.dimension); - WorldServer toWorld = null; - if (entityplayer.dimension < 10) { - for (WorldServer world : this.server.worlds) { - if (world.dimension == dimension) { - toWorld = world; - } - } + // CraftBukkit start - Replaced the standard handling of portals with a more customised method. + public void changeDimension(EntityPlayer entityplayer, int i, TeleportCause cause) { + WorldServer exitWorld = this.server.getWorldServer(i); + Location enter = entityplayer.getBukkitEntity().getLocation(); + Location exit = null; + if ((cause == TeleportCause.END_PORTAL) && (i == 0)) { + // THE_END -> NORMAL; use bed if available + exit = ((CraftPlayer) entityplayer.getBukkitEntity()).getBedSpawnLocation(); + } + if (exit == null) { + exit = this.calculateTarget(enter, exitWorld); } - Location fromLocation = new Location(fromWorld.getWorld(), entityplayer.locX, entityplayer.locY, entityplayer.locZ, entityplayer.yaw, entityplayer.pitch); - Location toLocation = null; + TravelAgent agent = (TravelAgent) ((CraftWorld) exit.getWorld()).getHandle().s(); + PlayerPortalEvent event = new PlayerPortalEvent(entityplayer.getBukkitEntity(), enter, exit, agent, cause); + Bukkit.getServer().getPluginManager().callEvent(event); + if (event.isCancelled() || event.getTo() == null) { + return; + } + exit = event.useTravelAgent() ? event.getPortalTravelAgent().findOrCreate(exit) : event.getTo(); + exitWorld = ((CraftWorld) exit.getWorld()).getHandle(); - if (toWorld != null) { - if (((dimension == -1) || (dimension == 0)) && ((entityplayer.dimension == -1) || (entityplayer.dimension == 0))) { - double blockRatio = dimension == 0 ? 8 : 0.125; + Vector velocity = entityplayer.getBukkitEntity().getVelocity(); + boolean before = exitWorld.chunkProviderServer.forceChunkLoad; + exitWorld.chunkProviderServer.forceChunkLoad = true; + exitWorld.s().adjustExit(entityplayer, exit, velocity); + exitWorld.chunkProviderServer.forceChunkLoad = before; - toLocation = toWorld == null ? null : new Location(toWorld.getWorld(), (entityplayer.locX * blockRatio), entityplayer.locY, (entityplayer.locZ * blockRatio), entityplayer.yaw, entityplayer.pitch); - } else { - ChunkCoordinates coords = toWorld.getDimensionSpawn(); - if (coords != null) { - toLocation = new Location(toWorld.getWorld(), coords.x, coords.y, coords.z, 90, 0); - } - } + this.moveToWorld(entityplayer, exitWorld.dimension, true, exit); + if (entityplayer.motX != velocity.getX() || entityplayer.motY != velocity.getY() || entityplayer.motZ != velocity.getZ()) { + entityplayer.getBukkitEntity().setVelocity(velocity); } + // CraftBukkit end + } - TeleportCause cause = TeleportCause.UNKNOWN; - int playerEnvironmentId = entityplayer.getBukkitEntity().getWorld().getEnvironment().getId(); - switch (dimension) { - case -1: - cause = TeleportCause.NETHER_PORTAL; - break; - case 0: - if (playerEnvironmentId == -1) { - cause = TeleportCause.NETHER_PORTAL; - } else if (playerEnvironmentId == 1) { - cause = TeleportCause.END_PORTAL; - } + public void a(Entity entity, int i, WorldServer worldserver, WorldServer worldserver1) { + // CraftBukkit start - split into modular functions + Location exit = this.calculateTarget(entity.getBukkitEntity().getLocation(), worldserver1); + this.repositionEntity(entity, exit, true); + } + + // copy of original a(Entity, int, WorldServer, WorldServer) method with only location calculation logic + public Location calculateTarget(Location enter, World target) { + WorldServer worldserver = ((CraftWorld) enter.getWorld()).getHandle(); + WorldServer worldserver1 = ((CraftWorld) target.getWorld()).getHandle(); + int i = worldserver.dimension; + + double y = enter.getY(); + float yaw = enter.getYaw(); + float pitch = enter.getPitch(); + double d0 = enter.getX(); + double d1 = enter.getZ(); + double d2 = 8.0D; + /* + double d3 = entity.locX; + double d4 = entity.locY; + double d5 = entity.locZ; + float f = entity.yaw; - break; - case 1: - cause = TeleportCause.END_PORTAL; - break; - } + worldserver.methodProfiler.a("moving"); + */ + if (worldserver1.dimension == -1) { + d0 /= d2; + d1 /= d2; + /* + entity.setPositionRotation(d0, entity.locY, d1, entity.yaw, entity.pitch); + if (entity.isAlive()) { + worldserver.entityJoinedWorld(entity, false); + } + */ + } else if (worldserver1.dimension == 0) { + d0 *= d2; + d1 *= d2; + /* + entity.setPositionRotation(d0, entity.locY, d1, entity.yaw, entity.pitch); + if (entity.isAlive()) { + worldserver.entityJoinedWorld(entity, false); + } + */ + } else { + ChunkCoordinates chunkcoordinates; - org.bukkit.craftbukkit.PortalTravelAgent pta = new org.bukkit.craftbukkit.PortalTravelAgent(); - PlayerPortalEvent event = new PlayerPortalEvent((Player) entityplayer.getBukkitEntity(), fromLocation, toLocation, pta, cause); + if (i == 1) { + chunkcoordinates = worldserver1.getSpawn(); + } else { + chunkcoordinates = worldserver1.getDimensionSpawn(); + } - if (entityplayer.dimension == 1) { - event.useTravelAgent(false); + d0 = (double) chunkcoordinates.x; + y = (double) chunkcoordinates.y; + d1 = (double) chunkcoordinates.z; + yaw = 90.0F; + pitch = 0.0F; + /* + entity.setPositionRotation(d0, entity.locY, d1, 90.0F, 0.0F); + if (entity.isAlive()) { + worldserver.entityJoinedWorld(entity, false); + } + */ } - Bukkit.getServer().getPluginManager().callEvent(event); - if (event.isCancelled() || event.getTo() == null) { - return; - } + // worldserver.methodProfiler.b(); + if (i != 1) { + // worldserver.methodProfiler.a("placing"); + d0 = (double) MathHelper.a((int) d0, -29999872, 29999872); + d1 = (double) MathHelper.a((int) d1, -29999872, 29999872); + /* + if (entity.isAlive()) { + worldserver1.addEntity(entity); + entity.setPositionRotation(d0, entity.locY, d1, entity.yaw, entity.pitch); + worldserver1.entityJoinedWorld(entity, false); + worldserver1.s().a(entity, d3, d4, d5, f); + } - Location finalLocation = event.getTo(); - if (event.useTravelAgent()) { - finalLocation = event.getPortalTravelAgent().findOrCreate(finalLocation); + worldserver.methodProfiler.b(); + */ } - toWorld = ((CraftWorld) finalLocation.getWorld()).getHandle(); - this.moveToWorld(entityplayer, toWorld.dimension, true, finalLocation); - // CraftBukkit end + + // entity.spawnIn(worldserver1); + return new Location(target.getWorld(), d0, y, d1, yaw, pitch); } - public void a(Entity entity, int i, WorldServer worldserver, WorldServer worldserver1) { + // copy of original a(Entity, int, WorldServer, WorldServer) method with only entity repositioning logic + public void repositionEntity(Entity entity, Location exit, boolean portal) { + int i = entity.dimension; + WorldServer worldserver = (WorldServer) entity.world; + WorldServer worldserver1 = ((CraftWorld) exit.getWorld()).getHandle(); + /* double d0 = entity.locX; double d1 = entity.locZ; double d2 = 8.0D; @@ -496,8 +557,14 @@ public abstract class PlayerList { double d4 = entity.locY; double d5 = entity.locZ; float f = entity.yaw; + */ worldserver.methodProfiler.a("moving"); + entity.setPositionRotation(exit.getX(), exit.getY(), exit.getZ(), exit.getYaw(), exit.getPitch()); + if (entity.isAlive()) { + worldserver.entityJoinedWorld(entity, false); + } + /* if (entity.dimension == -1) { d0 /= d2; d1 /= d2; @@ -529,23 +596,35 @@ public abstract class PlayerList { worldserver.entityJoinedWorld(entity, false); } } + */ worldserver.methodProfiler.b(); if (i != 1) { worldserver.methodProfiler.a("placing"); + /* d0 = (double) MathHelper.a((int) d0, -29999872, 29999872); d1 = (double) MathHelper.a((int) d1, -29999872, 29999872); + */ if (entity.isAlive()) { worldserver1.addEntity(entity); - entity.setPositionRotation(d0, entity.locY, d1, entity.yaw, entity.pitch); + // entity.setPositionRotation(d0, entity.locY, d1, entity.yaw, entity.pitch) worldserver1.entityJoinedWorld(entity, false); - worldserver1.s().a(entity, d3, d4, d5, f); + // worldserver1.s().a(entity, d3, d4, d5, f); + if (portal) { + Vector velocity = entity.getBukkitEntity().getVelocity(); + worldserver1.s().adjustExit(entity, exit, velocity); + entity.setPositionRotation(exit.getX(), exit.getY(), exit.getZ(), exit.getYaw(), exit.getPitch()); + if (entity.motX != velocity.getX() || entity.motY != velocity.getY() || entity.motZ != velocity.getZ()) { + entity.getBukkitEntity().setVelocity(velocity); + } + } } worldserver.methodProfiler.b(); } entity.spawnIn(worldserver1); + // CraftBukkit end } public void tick() { diff --git a/src/main/java/net/minecraft/server/PortalTravelAgent.java b/src/main/java/net/minecraft/server/PortalTravelAgent.java index e7df5c20..7733e806 100644 --- a/src/main/java/net/minecraft/server/PortalTravelAgent.java +++ b/src/main/java/net/minecraft/server/PortalTravelAgent.java @@ -6,13 +6,9 @@ import java.util.List; import java.util.Random; // CraftBukkit start -/* - * HEAR ME, HE WHOM WISHES TO COMMAND THE UPDATERING - * - * FOR SOME REASON WE HAVE OUR OWN PORTAL TRAVEL AGENT IN OBC, WE NEED TO UPDATE - * THAT WITH ANY NEW UPDATES TO THIS FILE. THIS FILE LEFT HERE AS A REMINDER. - * - */ +import org.bukkit.Location; +import org.bukkit.event.entity.EntityPortalExitEvent; +import org.bukkit.util.Vector; // CraftBukkit end public class PortalTravelAgent { @@ -34,9 +30,19 @@ public class PortalTravelAgent { this.b(entity, d0, d1, d2, f); } } else { - int i = MathHelper.floor(entity.locX); - int j = MathHelper.floor(entity.locY) - 1; - int k = MathHelper.floor(entity.locZ); + // CraftBukkit start - modularize end portal creation + ChunkCoordinates created = this.createEndPortal(d0, d1, d2); + entity.setPositionRotation((double) created.x, (double) created.y, (double) created.z, entity.yaw, 0.0F); + entity.motX = entity.motY = entity.motZ = 0.0D; + } + } + + // split out from original a(Entity, double, double, double, float) method in order to enable being called from createPortal + private ChunkCoordinates createEndPortal(double x, double y, double z) { + int i = MathHelper.floor(x); + int j = MathHelper.floor(y) - 1; + int k = MathHelper.floor(z); + // CraftBukkit end byte b0 = 1; byte b1 = 0; @@ -53,19 +59,66 @@ public class PortalTravelAgent { } } - entity.setPositionRotation((double) i, (double) j, (double) k, entity.yaw, 0.0F); - entity.motX = entity.motY = entity.motZ = 0.0D; + // CraftBukkit start + return new ChunkCoordinates(i, j, k); + } + + // use logic based on creation to verify end portal + private ChunkCoordinates findEndPortal(ChunkCoordinates portal) { + int i = portal.x; + int j = portal.y - 1; + int k = portal.z; + byte b0 = 1; + byte b1 = 0; + + for (int l = -2; l <= 2; ++l) { + for (int i1 = -2; i1 <= 2; ++i1) { + for (int j1 = -1; j1 < 3; ++j1) { + int k1 = i + i1 * b0 + l * b1; + int l1 = j + j1; + int i2 = k + i1 * b1 - l * b0; + boolean flag = j1 < 0; + + if (this.a.getTypeId(k1, l1, i2) != (flag ? Block.OBSIDIAN.id : 0)) { + return null; + } + } + } } + return new ChunkCoordinates(i, j, k); } + // CraftBukkit end public boolean b(Entity entity, double d0, double d1, double d2, float f) { - short short1 = 128; + // CraftBukkit start - modularize portal search process and entity teleportation + ChunkCoordinates found = this.findPortal(entity.locX, entity.locY, entity.locZ, 128); + if (found == null) { + return false; + } + + Location exit = new Location(this.a.getWorld(), found.x, found.y, found.z, f, entity.pitch); + Vector velocity = entity.getBukkitEntity().getVelocity(); + this.adjustExit(entity, exit, velocity); + entity.setPositionRotation(exit.getX(), exit.getY(), exit.getZ(), exit.getYaw(), exit.getPitch()); + if (entity.motX != velocity.getX() || entity.motY != velocity.getY() || entity.motZ != velocity.getZ()) { + entity.getBukkitEntity().setVelocity(velocity); + } + return true; + } + + public ChunkCoordinates findPortal(double x, double y, double z, int short1) { + if (this.a.getWorld().getEnvironment() == org.bukkit.World.Environment.THE_END) { + return this.findEndPortal(this.a.worldProvider.h()); + } + // CraftBukkit end double d3 = -1.0D; int i = 0; int j = 0; int k = 0; - int l = MathHelper.floor(entity.locX); - int i1 = MathHelper.floor(entity.locZ); + // CraftBukkit start + int l = MathHelper.floor(x); + int i1 = MathHelper.floor(z); + // CraftBukkit end long j1 = ChunkCoordIntPair.a(l, i1); boolean flag = true; double d4; @@ -82,10 +135,10 @@ public class PortalTravelAgent { flag = false; } else { for (k1 = l - short1; k1 <= l + short1; ++k1) { - double d5 = (double) k1 + 0.5D - entity.locX; + double d5 = (double) k1 + 0.5D - x; // CraftBukkit for (int l1 = i1 - short1; l1 <= i1 + short1; ++l1) { - double d6 = (double) l1 + 0.5D - entity.locZ; + double d6 = (double) l1 + 0.5D - z; // CraftBukkit for (int i2 = this.a.P() - 1; i2 >= 0; --i2) { if (this.a.getTypeId(k1, i2, l1) == Block.PORTAL.id) { @@ -93,7 +146,7 @@ public class PortalTravelAgent { --i2; } - d4 = (double) i2 + 0.5D - entity.locY; + d4 = (double) i2 + 0.5D - y; // CraftBukkit double d7 = d5 * d5 + d4 * d4 + d6 * d6; if (d3 < 0.0D || d7 < d3) { @@ -113,6 +166,32 @@ public class PortalTravelAgent { this.c.put(j1, new ChunkCoordinatesPortal(this, i, j, k, this.a.getTime())); this.d.add(Long.valueOf(j1)); } + // CraftBukkit start - moved entity teleportation logic into exit + return new ChunkCoordinates(i, j, k); + } else { + return null; + } + } + // entity repositioning logic split out from original b method and combined with repositioning logic for The End from original a method + public void adjustExit(Entity entity, Location position, Vector velocity) { + Location from = position.clone(); + Vector before = velocity.clone(); + int i = position.getBlockX(); + int j = position.getBlockY(); + int k = position.getBlockZ(); + float f = position.getYaw(); + + if (this.a.getWorld().getEnvironment() == org.bukkit.World.Environment.THE_END) { + // entity.setPositionRotation((double) i, (double) j, (double) k, entity.yaw, 0.0F); + // entity.motX = entity.motY = entity.motZ = 0.0D; + position.setPitch(0.0F); + position.setX(0); + position.setY(0); + position.setZ(0); + } else { + double d4; + int k1; + // CraftBukkit end double d8 = (double) i + 0.5D; double d9 = (double) j + 0.5D; @@ -195,29 +274,59 @@ public class PortalTravelAgent { f6 = 1.0F; } - double d10 = entity.motX; - double d11 = entity.motZ; + // CraftBukkit start + double d10 = velocity.getX(); + double d11 = velocity.getZ(); + // CraftBukkit end - entity.motX = d10 * (double) f3 + d11 * (double) f6; - entity.motZ = d10 * (double) f5 + d11 * (double) f4; - entity.yaw = f - (float) (k2 * 90) + (float) (j2 * 90); + // CraftBukkit start - adjust position and velocity instances instead of entity + velocity.setX(d10 * (double) f3 + d11 * (double) f6); + velocity.setZ(d10 * (double) f5 + d11 * (double) f4); + f = f - (float) (k2 * 90) + (float) (j2 * 90); } else { - entity.motX = entity.motY = entity.motZ = 0.0D; + // entity.motX = entity.motY = entity.motZ = 0.0D; + velocity.setX(0); + velocity.setY(0); + velocity.setZ(0); } - entity.setPositionRotation(d8, d9, d4, entity.yaw, entity.pitch); - return true; + // entity.setPositionRotation(d8, d9, d4, entity.yaw, entity.pitch); + position.setX(d8); + position.setY(d9); + position.setZ(d4); + position.setYaw(f); + } + + EntityPortalExitEvent event = new EntityPortalExitEvent(entity.getBukkitEntity(), from, position, before, velocity); + this.a.getServer().getPluginManager().callEvent(event); + Location to = event.getTo(); + if (event.isCancelled() || to == null || !entity.isAlive()) { + position = from; + velocity = before; } else { - return false; + position = to; + velocity = event.getAfter(); } + // CraftBukkit end } public boolean a(Entity entity) { - byte b0 = 16; + // CraftBukkit start - allow for portal creation to be based on coordinates instead of entity + return this.createPortal(entity.locX, entity.locY, entity.locZ, 16); + } + + public boolean createPortal(double x, double y, double z, int b0) { + if (this.a.getWorld().getEnvironment() == org.bukkit.World.Environment.THE_END) { + this.createEndPortal(x, y, z); + return true; + } + // CraftBukkit end double d0 = -1.0D; - int i = MathHelper.floor(entity.locX); - int j = MathHelper.floor(entity.locY); - int k = MathHelper.floor(entity.locZ); + // CraftBukkit start + int i = MathHelper.floor(x); + int j = MathHelper.floor(y); + int k = MathHelper.floor(z); + // CraftBukkit end int l = i; int i1 = j; int j1 = k; @@ -241,10 +350,10 @@ public class PortalTravelAgent { double d4; for (i2 = i - b0; i2 <= i + b0; ++i2) { - d1 = (double) i2 + 0.5D - entity.locX; + d1 = (double) i2 + 0.5D - x; // CraftBukkit for (j2 = k - b0; j2 <= k + b0; ++j2) { - d2 = (double) j2 + 0.5D - entity.locZ; + d2 = (double) j2 + 0.5D - z; // CraftBukkit label274: for (k2 = this.a.P() - 1; k2 >= 0; --k2) { @@ -275,7 +384,7 @@ public class PortalTravelAgent { } } - d3 = (double) k2 + 0.5D - entity.locY; + d3 = (double) k2 + 0.5D - y; // CraftBukkit d4 = d1 * d1 + d3 * d3 + d2 * d2; if (d0 < 0.0D || d4 < d0) { d0 = d4; @@ -292,10 +401,10 @@ public class PortalTravelAgent { if (d0 < 0.0D) { for (i2 = i - b0; i2 <= i + b0; ++i2) { - d1 = (double) i2 + 0.5D - entity.locX; + d1 = (double) i2 + 0.5D - x; // CraftBukkit for (j2 = k - b0; j2 <= k + b0; ++j2) { - d2 = (double) j2 + 0.5D - entity.locZ; + d2 = (double) j2 + 0.5D - z; // CraftBukkit label222: for (k2 = this.a.P() - 1; k2 >= 0; --k2) { @@ -319,7 +428,7 @@ public class PortalTravelAgent { } } - d3 = (double) k2 + 0.5D - entity.locY; + d3 = (double) k2 + 0.5D - y; // CraftBukkit d4 = d1 * d1 + d3 * d3 + d2 * d2; if (d0 < 0.0D || d4 < d0) { d0 = d4; diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java index b426d5d9..3f73ef97 100644 --- a/src/main/java/net/minecraft/server/WorldServer.java +++ b/src/main/java/net/minecraft/server/WorldServer.java @@ -59,7 +59,7 @@ public class WorldServer extends World implements org.bukkit.BlockChangeDelegate this.M = new TreeSet(); } - this.P = new PortalTravelAgent(this); + this.P = new org.bukkit.craftbukkit.CraftTravelAgent(this); // CraftBukkit } // CraftBukkit start |