I've either fixed going to The End, or made it worse. I'm sure we'll find out soon!

This commit is contained in:
Nathan Adams 2011-11-24 20:00:55 +00:00
parent 61edd36378
commit 47b4406b7e
3 changed files with 85 additions and 59 deletions

View File

@ -3,8 +3,13 @@ package net.minecraft.server;
import java.util.Random; import java.util.Random;
// CraftBukkit start // CraftBukkit start
import org.bukkit.event.world.PortalCreateEvent; /*
import org.bukkit.Bukkit; * 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.
*
*/
// CraftBukkit end // CraftBukkit end
public class PortalTravelAgent { public class PortalTravelAgent {
@ -247,53 +252,6 @@ public class PortalTravelAgent {
boolean flag; boolean flag;
// CraftBukkit start - portal create event
java.util.Collection<org.bukkit.block.Block> blocks = new java.util.HashSet<org.bukkit.block.Block>();
// Find out what blocks the portal is going to modify, duplicated from below
org.bukkit.World bworld = world.getWorld();
if (d0 < 0.0D) {
if (i1 < 70) {
i1 = 70;
}
if (i1 > world.height - 10) {
i1 = world.height - 10;
}
j5 = i1;
for (l2 = -1; l2 <= 1; ++l2) {
for (k2 = 1; k2 < 3; ++k2) {
for (j3 = -1; j3 < 3; ++j3) {
i3 = i5 + (k2 - 1) * k5 + l2 * l5;
l3 = j5 + j3;
k3 = j2 + (k2 - 1) * l5 - l2 * k5;
blocks.add(bworld.getBlockAt(i3, l3, k3));
}
}
}
}
for (l2 = 0; l2 < 4; ++l2) {
for (k2 = 0; k2 < 4; ++k2) {
for (j3 = -1; j3 < 4; ++j3) {
i3 = i5 + (k2 - 1) * k5;
l3 = j5 + j3;
k3 = j2 + (k2 - 1) * l5;
blocks.add(bworld.getBlockAt(i3, l3, k3));
}
}
}
PortalCreateEvent event = new PortalCreateEvent(blocks, bworld);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return true;
}
// CraftBukkit end
if (d0 < 0.0D) { if (d0 < 0.0D) {
if (i1 < 70) { if (i1 < 70) {
i1 = 70; i1 = 70;

View File

@ -305,7 +305,7 @@ public class ServerConfigurationManager {
public void a(EntityPlayer entityplayer, int i) { public void a(EntityPlayer entityplayer, int i) {
// CraftBukkit start -- Replaced the standard handling of portals with a more customised method. // CraftBukkit start -- Replaced the standard handling of portals with a more customised method.
int dimension = entityplayer.dimension; int dimension = i;
WorldServer fromWorld = this.server.getWorldServer(dimension); WorldServer fromWorld = this.server.getWorldServer(dimension);
WorldServer toWorld = null; WorldServer toWorld = null;
if (dimension < 10) { if (dimension < 10) {
@ -315,13 +315,28 @@ public class ServerConfigurationManager {
} }
} }
} }
double blockRatio = dimension == -1 ? 8 : 0.125;
Location fromLocation = new Location(fromWorld.getWorld(), entityplayer.locX, entityplayer.locY, entityplayer.locZ, entityplayer.yaw, entityplayer.pitch); Location fromLocation = new Location(fromWorld.getWorld(), entityplayer.locX, entityplayer.locY, entityplayer.locZ, entityplayer.yaw, entityplayer.pitch);
Location toLocation = toWorld == null ? null : new Location(toWorld.getWorld(), (entityplayer.locX * blockRatio), entityplayer.locY, (entityplayer.locZ * blockRatio), entityplayer.yaw, entityplayer.pitch); Location toLocation = null;
if (toWorld != null) {
if ((dimension == -1) || (dimension == 0)) {
double blockRatio = dimension == 0 ? 8 : 0.125;
toLocation = toWorld == null ? null : new Location(toWorld.getWorld(), (entityplayer.locX * blockRatio), entityplayer.locY, (entityplayer.locZ * blockRatio), entityplayer.yaw, entityplayer.pitch);
} else {
ChunkCoordinates coords = toWorld.d();
toLocation = new Location(toWorld.getWorld(), coords.x, coords.y, coords.z, 90, 0);
}
}
org.bukkit.craftbukkit.PortalTravelAgent pta = new org.bukkit.craftbukkit.PortalTravelAgent(); org.bukkit.craftbukkit.PortalTravelAgent pta = new org.bukkit.craftbukkit.PortalTravelAgent();
PlayerPortalEvent event = new PlayerPortalEvent((Player) entityplayer.getBukkitEntity(), fromLocation, toLocation, pta); PlayerPortalEvent event = new PlayerPortalEvent((Player) entityplayer.getBukkitEntity(), fromLocation, toLocation, pta);
if (entityplayer.dimension == 1) {
event.useTravelAgent(false);
}
Bukkit.getServer().getPluginManager().callEvent(event); Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled() || event.getTo() == null) { if (event.isCancelled() || event.getTo() == null) {
return; return;

View File

@ -3,11 +3,13 @@ package org.bukkit.craftbukkit;
import java.util.Random; import java.util.Random;
import net.minecraft.server.Block; import net.minecraft.server.Block;
import net.minecraft.server.MathHelper;
import net.minecraft.server.WorldServer; import net.minecraft.server.WorldServer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.TravelAgent; import org.bukkit.TravelAgent;
import org.bukkit.World.Environment;
import org.bukkit.event.world.PortalCreateEvent; import org.bukkit.event.world.PortalCreateEvent;
public class PortalTravelAgent implements TravelAgent { public class PortalTravelAgent implements TravelAgent {
@ -43,6 +45,32 @@ public class PortalTravelAgent implements TravelAgent {
public Location findPortal(Location location) { public Location findPortal(Location location) {
net.minecraft.server.World world = ((CraftWorld) location.getWorld()).getHandle(); net.minecraft.server.World world = ((CraftWorld) location.getWorld()).getHandle();
if (location.getWorld().getEnvironment() == Environment.THE_END) {
int i = MathHelper.floor(location.getBlockX());
int j = MathHelper.floor(location.getBlockY()) - 1;
int k = MathHelper.floor(location.getBlockZ());
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 (world.getTypeId(k1, l1, i2) != (flag ? Block.OBSIDIAN.id : 0)) {
return null;
}
}
}
}
return location;
}
// short short1 = 128; // short short1 = 128;
double d0 = -1.0D; double d0 = -1.0D;
int i = 0; int i = 0;
@ -59,7 +87,7 @@ public class PortalTravelAgent implements TravelAgent {
for (int k1 = i1 - this.searchRadius; k1 <= i1 + this.searchRadius; ++k1) { for (int k1 = i1 - this.searchRadius; k1 <= i1 + this.searchRadius; ++k1) {
double d3 = (double) k1 + 0.5D - location.getZ(); double d3 = (double) k1 + 0.5D - location.getZ();
for (int l1 = 127; l1 >= 0; --l1) { for (int l1 = world.height - 1; l1 >= 0; --l1) {
if (world.getTypeId(j1, l1, k1) == Block.PORTAL.id) { if (world.getTypeId(j1, l1, k1) == Block.PORTAL.id) {
while (world.getTypeId(j1, l1 - 1, k1) == Block.PORTAL.id) { while (world.getTypeId(j1, l1 - 1, k1) == Block.PORTAL.id) {
--l1; --l1;
@ -108,6 +136,31 @@ public class PortalTravelAgent implements TravelAgent {
public boolean createPortal(Location location) { public boolean createPortal(Location location) {
net.minecraft.server.World world = ((CraftWorld) location.getWorld()).getHandle(); net.minecraft.server.World world = ((CraftWorld) location.getWorld()).getHandle();
if (location.getWorld().getEnvironment() == Environment.THE_END) {
int i = MathHelper.floor(location.getBlockX());
int j = MathHelper.floor(location.getBlockY()) - 1;
int k = MathHelper.floor(location.getBlockZ());
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;
world.setTypeId(k1, l1, i2, flag ? Block.OBSIDIAN.id : 0);
}
}
}
return true;
}
// byte b0 = 16; // byte b0 = 16;
double d0 = -1.0D; double d0 = -1.0D;
int i = location.getBlockX(); int i = location.getBlockX();
@ -142,7 +195,7 @@ public class PortalTravelAgent implements TravelAgent {
d2 = (double) j2 + 0.5D - location.getZ(); d2 = (double) j2 + 0.5D - location.getZ();
label271: label271:
for (l2 = 127; l2 >= 0; --l2) { for (l2 = world.height - 1; l2 >= 0; --l2) {
if (world.isEmpty(i2, l2, j2)) { if (world.isEmpty(i2, l2, j2)) {
while (l2 > 0 && world.isEmpty(i2, l2 - 1, j2)) { while (l2 > 0 && world.isEmpty(i2, l2 - 1, j2)) {
--l2; --l2;
@ -193,7 +246,7 @@ public class PortalTravelAgent implements TravelAgent {
d2 = (double) j2 + 0.5D - location.getZ(); d2 = (double) j2 + 0.5D - location.getZ();
label219: label219:
for (l2 = 127; l2 >= 0; --l2) { for (l2 = world.height - 1; l2 >= 0; --l2) {
if (world.isEmpty(i2, l2, j2)) { if (world.isEmpty(i2, l2, j2)) {
while (l2 > 0 && world.isEmpty(i2, l2 - 1, j2)) { while (l2 > 0 && world.isEmpty(i2, l2 - 1, j2)) {
--l2; --l2;
@ -254,8 +307,8 @@ public class PortalTravelAgent implements TravelAgent {
i1 = 70; i1 = 70;
} }
if (i1 > 118) { if (i1 > world.height - 10) {
i1 = 118; i1 = world.height - 10;
} }
j5 = i1; j5 = i1;
@ -301,8 +354,8 @@ public class PortalTravelAgent implements TravelAgent {
i1 = 70; i1 = 70;
} }
if (i1 > 118) { if (i1 > world.height - 10) {
i1 = 118; i1 = world.height - 10;
} }
j5 = i1; j5 = i1;