Improved DDTeleporter
Made various changes to clarify code in DDTeleporter. For instance, we had a whole switch block that was used to give the same outcome on every case except the default. I rewrote the code there to remove the block. Also changed DDTeleporter.checkDestination() since it was redoing the destination orientation checks unnecessarily, changing the entity's yaw when it shouldn't have side effects, and some other little things.
This commit is contained in:
@@ -51,41 +51,31 @@ public class DDTeleporter
|
||||
|
||||
private DDTeleporter() { }
|
||||
|
||||
/**Checks if the destination supplied is valid, ie, filled by any non-replaceable block.
|
||||
*
|
||||
* @param entity
|
||||
* @param world
|
||||
* @param destination
|
||||
* @param properties
|
||||
* @return
|
||||
/**
|
||||
* Checks if the destination supplied is safe (i.e. filled by any replaceable or non-opaque blocks)
|
||||
*/
|
||||
private static boolean checkDestination(Entity entity, WorldServer world, Point4D destination,DDProperties properties)
|
||||
private static boolean checkDestination(WorldServer world, Point4D destination, int orientation)
|
||||
{
|
||||
int x = destination.getX();
|
||||
int y = destination.getY();
|
||||
int z = destination.getZ();
|
||||
int blockIDTop;
|
||||
int blockIDBottom;
|
||||
|
||||
Point3D point;
|
||||
|
||||
int orientation;
|
||||
|
||||
orientation = getDestinationOrientation(destination, properties);
|
||||
entity.rotationYaw = (orientation * 90) + 90;
|
||||
switch (orientation)
|
||||
{
|
||||
case 0:
|
||||
point = new Point3D(MathHelper.floor_double(x - 0.5), y - 1, MathHelper.floor_double(z + 0.5));
|
||||
point = new Point3D(x - 1, y - 1, z);
|
||||
break;
|
||||
case 1:
|
||||
point = new Point3D(MathHelper.floor_double(x + 0.5), y - 1, MathHelper.floor_double(z - 0.5));
|
||||
point = new Point3D(x, y - 1, z - 1);
|
||||
break;
|
||||
case 2:
|
||||
point = new Point3D(MathHelper.floor_double(x + 1.5), y - 1, MathHelper.floor_double(z + 0.5));
|
||||
point = new Point3D(x + 1, y - 1, z);
|
||||
break;
|
||||
case 3:
|
||||
point = new Point3D(MathHelper.floor_double(x + 0.5), y - 1, MathHelper.floor_double(z + 1.5));
|
||||
point = new Point3D(x, y - 1, z + 1);
|
||||
break;
|
||||
default:
|
||||
point = new Point3D(x, y - 1, z);
|
||||
@@ -129,35 +119,11 @@ public class DDTeleporter
|
||||
orientation = -1;
|
||||
}
|
||||
|
||||
if (!checkDestination(entity, world, destination, properties))
|
||||
{
|
||||
if (entity instanceof EntityPlayerMP)
|
||||
if (entity instanceof EntityPlayer)
|
||||
{
|
||||
EntityPlayer player = (EntityPlayer) entity;
|
||||
player.rotationYaw = (orientation * 90) + 90;
|
||||
switch (orientation)
|
||||
if (checkDestination(world, destination, orientation))
|
||||
{
|
||||
case 0:
|
||||
player.setPositionAndUpdate(x + 0.5, y - 1, z + 0.5);
|
||||
break;
|
||||
case 1:
|
||||
player.setPositionAndUpdate(x + 0.5, y - 1, z + 0.5);
|
||||
break;
|
||||
case 2:
|
||||
player.setPositionAndUpdate(x + 0.5, y - 1, z + 0.5);
|
||||
break;
|
||||
case 3:
|
||||
player.setPositionAndUpdate(x + 0.5, y - 1, z + 0.5);
|
||||
break;
|
||||
default:
|
||||
player.setPositionAndUpdate(x, y - 1, z);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (entity instanceof EntityPlayer)
|
||||
{
|
||||
EntityPlayer player = (EntityPlayer) entity;
|
||||
switch (orientation)
|
||||
{
|
||||
case 0:
|
||||
@@ -177,6 +143,11 @@ public class DDTeleporter
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player.setPositionAndUpdate(x + 0.5, y - 1, z + 0.5);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof EntityMinecart)
|
||||
{
|
||||
entity.motionX = 0;
|
||||
|
||||
Reference in New Issue
Block a user