Improved DDTeleporter

Made a minor change to DDTeleporter - added a flag so that we can
specify that entities must be teleported to the destination without
trying to shift them around based on destination orientation. This is
important for the trapdoor, since otherwise entities might get shoved
into walls. Also cleaned up some code in DDTeleporter. It's much more
readable now. These changes are in preparation for completing Trans
Trapdoor destination selection.
This commit is contained in:
SenseiKiwi
2013-09-08 21:01:38 -04:00
parent fc6dd63573
commit 156c61a772
5 changed files with 102 additions and 93 deletions

View File

@@ -10,11 +10,11 @@ import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingFallEvent; import net.minecraftforge.event.entity.living.LivingFallEvent;
import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.event.world.WorldEvent;
import StevenDimDoors.mod_pocketDim.core.DDTeleporter; import StevenDimDoors.mod_pocketDim.core.DDTeleporter;
import StevenDimDoors.mod_pocketDim.core.NewDimData;
import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.core.PocketManager;
import StevenDimDoors.mod_pocketDim.ticking.RiftRegenerator; import StevenDimDoors.mod_pocketDim.ticking.RiftRegenerator;
import StevenDimDoors.mod_pocketDim.util.Point4D; import StevenDimDoors.mod_pocketDim.util.Point4D;
import StevenDimDoors.mod_pocketDim.world.LimboProvider; import StevenDimDoors.mod_pocketDim.world.LimboProvider;
import StevenDimDoors.mod_pocketDim.world.PocketProvider;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
@@ -69,8 +69,11 @@ public class EventHookContainer
public boolean LivingDeathEvent(LivingDeathEvent event) public boolean LivingDeathEvent(LivingDeathEvent event)
{ {
Entity entity = event.entity; Entity entity = event.entity;
if (entity instanceof EntityPlayer && entity.worldObj.provider instanceof PocketProvider
&& properties.LimboEnabled) if (entity instanceof EntityPlayer && properties.LimboEnabled)
{
NewDimData dimension = PocketManager.getDimensionData(entity.worldObj);
if (dimension.isDungeon())
{ {
EntityPlayer player = (EntityPlayer) entity; EntityPlayer player = (EntityPlayer) entity;
if (!properties.LimboReturnsInventoryEnabled) if (!properties.LimboReturnsInventoryEnabled)
@@ -78,11 +81,13 @@ public class EventHookContainer
player.inventory.clearInventory(-1, -1); player.inventory.clearInventory(-1, -1);
} }
ChunkCoordinates coords = LimboProvider.getLimboSkySpawn(player.worldObj.rand); ChunkCoordinates coords = LimboProvider.getLimboSkySpawn(player.worldObj.rand);
DDTeleporter.teleportEntity(player, new Point4D(coords.posX, coords.posY, coords.posZ, mod_pocketDim.properties.LimboDimensionID)); Point4D destination = new Point4D(coords.posX, coords.posY, coords.posZ, mod_pocketDim.properties.LimboDimensionID);
DDTeleporter.teleportEntity(player, destination, false);
player.setEntityHealth(player.getMaxHealth()); player.setEntityHealth(player.getMaxHealth());
event.setCanceled(true); event.setCanceled(true);
return false; return false;
} }
}
return true; return true;
} }

View File

@@ -67,7 +67,7 @@ public class BlockDimWallPerm extends Block
//FIXME: Shouldn't we make the player's destination safe BEFORE teleporting him?! //FIXME: Shouldn't we make the player's destination safe BEFORE teleporting him?!
//player.setPositionAndUpdate( x, y, z ); //player.setPositionAndUpdate( x, y, z );
Point4D destination = new Point4D(destinationX, destinationY, destinationZ, 0); Point4D destination = new Point4D(destinationX, destinationY, destinationZ, 0);
DDTeleporter.teleportEntity(player, destination); DDTeleporter.teleportEntity(player, destination, false);
//player.setPositionAndUpdate( x, y, z ); //player.setPositionAndUpdate( x, y, z );

View File

@@ -39,37 +39,44 @@ public class DDTeleporter
private DDTeleporter() { } private DDTeleporter() { }
private static void placeInPortal(Entity entity, WorldServer world, Point4D destination, DDProperties properties) private static void placeInPortal(Entity entity, WorldServer world, Point4D destination, DDProperties properties, boolean checkOrientation)
{ {
int x = destination.getX(); int x = destination.getX();
int y = destination.getY(); int y = destination.getY();
int z = destination.getZ(); int z = destination.getZ();
int orientation = getDestinationOrientation(destination, properties); int orientation;
if (checkOrientation)
{
orientation = getDestinationOrientation(destination, properties);
entity.rotationYaw = (orientation * 90) + 90;
}
else
{
//Teleport the entity to the precise destination point
orientation = -1;
}
if (entity instanceof EntityPlayer) if (entity instanceof EntityPlayer)
{ {
EntityPlayer player = (EntityPlayer) entity; EntityPlayer player = (EntityPlayer) entity;
player.rotationYaw=(orientation*90)+90; switch (orientation)
if(orientation==2||orientation==6)
{
player.setPositionAndUpdate( x+1.5, y-1, z+.5 );
}
else if(orientation==3||orientation==7)
{
player.setPositionAndUpdate( x+.5, y-1, z+1.5 );
}
else if(orientation==0||orientation==4)
{
player.setPositionAndUpdate(x-.5, y-1, z+.5);
}
else if(orientation==1||orientation==5)
{
player.setPositionAndUpdate(x+.5, y-1, z-.5);
}
else
{ {
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 + 1.5, y - 1, z + 0.5);
break;
case 3:
player.setPositionAndUpdate(x + 0.5, y - 1, z + 1.5);
break;
default:
player.setPositionAndUpdate(x, y - 1, z); player.setPositionAndUpdate(x, y - 1, z);
break;
} }
} }
else if (entity instanceof EntityMinecart) else if (entity instanceof EntityMinecart)
@@ -77,60 +84,53 @@ public class DDTeleporter
entity.motionX = 0; entity.motionX = 0;
entity.motionZ = 0; entity.motionZ = 0;
entity.motionY = 0; entity.motionY = 0;
entity.rotationYaw=(orientation*90)+90;
if(orientation==2||orientation==6) switch (orientation)
{ {
DDTeleporter.setEntityPosition(entity, x+1.5, y, z+.5 ); case 0:
entity.motionX =.39; DDTeleporter.setEntityPosition(entity, x - 0.5, y, z + 0.5);
entity.motionX = -0.39;
entity.worldObj.updateEntityWithOptionalForce(entity, false); entity.worldObj.updateEntityWithOptionalForce(entity, false);
break;
case 1:
DDTeleporter.setEntityPosition(entity, x + 0.5, y, z - 0.5);
entity.motionZ = -0.39;
entity.worldObj.updateEntityWithOptionalForce(entity, false);
break;
case 2:
DDTeleporter.setEntityPosition(entity, x + 1.5, y, z + 0.5);
entity.motionX = 0.39;
entity.worldObj.updateEntityWithOptionalForce(entity, false);
break;
case 3:
DDTeleporter.setEntityPosition(entity, x + 0.5, y, z + 1.5 );
entity.motionZ = 0.39;
entity.worldObj.updateEntityWithOptionalForce(entity, false);
break;
default:
DDTeleporter.setEntityPosition(entity, x, y, z);
break;
} }
else if(orientation==3||orientation==7)
{
DDTeleporter.setEntityPosition(entity, x+.5, y, z+1.5 );
entity.motionZ =.39;
entity.worldObj.updateEntityWithOptionalForce(entity, false);
}
else if(orientation==0||orientation==4)
{
DDTeleporter.setEntityPosition(entity,x-.5, y, z+.5);
entity.motionX =-.39;
entity.worldObj.updateEntityWithOptionalForce(entity, false);
}
else if(orientation==1||orientation==5)
{
DDTeleporter.setEntityPosition(entity,x+.5, y, z-.5);
entity.motionZ =-.39;
entity.worldObj.updateEntityWithOptionalForce(entity, false);
} }
else else
{ {
DDTeleporter.setEntityPosition(entity,x, y, z); switch (orientation)
}
}
else if (entity instanceof Entity)
{ {
entity.rotationYaw=(orientation*90)+90; case 0:
if(orientation==2||orientation==6) setEntityPosition(entity, x - 0.5, y, z + 0.5);
{ break;
DDTeleporter.setEntityPosition(entity, x+1.5, y, z+.5 ); case 1:
} setEntityPosition(entity, x + 0.5, y, z - 0.5);
else if(orientation==3||orientation==7) break;
{ case 2:
setEntityPosition(entity, x + 1.5, y, z + 0.5);
DDTeleporter.setEntityPosition(entity, x+.5, y, z+1.5 ); break;
} case 3:
else if(orientation==0||orientation==4) setEntityPosition(entity, x + 0.5, y, z + 1.5);
{ break;
DDTeleporter.setEntityPosition(entity,x-.5, y, z+.5); default:
} setEntityPosition(entity, x, y, z);
else if(orientation==1||orientation==5) break;
{
DDTeleporter.setEntityPosition(entity,x+.5, y, z-.5);
}
else
{
DDTeleporter.setEntityPosition(entity,x, y, z);
} }
} }
} }
@@ -164,7 +164,7 @@ public class DDTeleporter
return world.getBlockMetadata(door.getX(), door.getY() - 1, door.getZ()) & 3; return world.getBlockMetadata(door.getX(), door.getY() - 1, door.getZ()) & 3;
} }
public static Entity teleportEntity(Entity entity, Point4D destination) public static Entity teleportEntity(Entity entity, Point4D destination, boolean checkOrientation)
{ {
if (entity == null) if (entity == null)
{ {
@@ -185,7 +185,7 @@ public class DDTeleporter
// Is something riding? Handle it first. // Is something riding? Handle it first.
if (entity.riddenByEntity != null) if (entity.riddenByEntity != null)
{ {
return teleportEntity(entity.riddenByEntity, destination); return teleportEntity(entity.riddenByEntity, destination, checkOrientation);
} }
// Are we riding something? Dismount and tell the mount to go first. // Are we riding something? Dismount and tell the mount to go first.
@@ -193,7 +193,7 @@ public class DDTeleporter
if (cart != null) if (cart != null)
{ {
entity.mountEntity(null); entity.mountEntity(null);
cart = teleportEntity(cart, destination); cart = teleportEntity(cart, destination, checkOrientation);
// We keep track of both so we can remount them on the other side. // We keep track of both so we can remount them on the other side.
} }
@@ -211,7 +211,7 @@ public class DDTeleporter
// GreyMaria: What is this even accomplishing? We're doing the exact same thing at the end of this all. // GreyMaria: What is this even accomplishing? We're doing the exact same thing at the end of this all.
// TODO Check to see if this is actually vital. // TODO Check to see if this is actually vital.
DDTeleporter.placeInPortal(entity, newWorld, destination, properties); DDTeleporter.placeInPortal(entity, newWorld, destination, properties, checkOrientation);
if (difDest) // Are we moving our target to a new dimension? if (difDest) // Are we moving our target to a new dimension?
{ {
@@ -306,7 +306,7 @@ public class DDTeleporter
GameRegistry.onPlayerChangedDimension((EntityPlayer)entity); GameRegistry.onPlayerChangedDimension((EntityPlayer)entity);
} }
DDTeleporter.placeInPortal(entity, newWorld, destination, properties); DDTeleporter.placeInPortal(entity, newWorld, destination, properties, checkOrientation);
return entity; return entity;
} }
@@ -355,13 +355,13 @@ public class DDTeleporter
Point4D randomDestination = getRandomDestination(); Point4D randomDestination = getRandomDestination();
if (randomDestination != null) if (randomDestination != null)
{ {
entity = teleportEntity(entity, randomDestination); entity = teleportEntity(entity, randomDestination, true);
entity.worldObj.playSoundEffect(entity.posX, entity.posY, entity.posZ, "mob.endermen.portal", 1.0F, 1.0F); entity.worldObj.playSoundEffect(entity.posX, entity.posY, entity.posZ, "mob.endermen.portal", 1.0F, 1.0F);
} }
} }
else else
{ {
entity = teleportEntity(entity, link.destination()); entity = teleportEntity(entity, link.destination(), link.linkType() != LinkTypes.UNSAFE_EXIT);
entity.worldObj.playSoundEffect(entity.posX, entity.posY, entity.posZ, "mob.endermen.portal", 1.0F, 1.0F); entity.worldObj.playSoundEffect(entity.posX, entity.posY, entity.posZ, "mob.endermen.portal", 1.0F, 1.0F);
} }
} }

View File

@@ -439,6 +439,10 @@ public abstract class NewDimData
{ {
throw new IllegalStateException("The dimension has already been initialized."); throw new IllegalStateException("The dimension has already been initialized.");
} }
if (orientation < 0 || orientation > 3)
{
throw new IllegalArgumentException("orientation must be between 0 and 3, inclusive.");
}
setDestination(incoming, originX, originY, originZ); setDestination(incoming, originX, originY, originZ);
this.origin = incoming.destination(); this.origin = incoming.destination();

View File

@@ -150,7 +150,7 @@ public class MobMonolith extends EntityFlying implements IMob
(int) this.posY + 500, (int) this.posY + 500,
(int) this.posZ + MathHelper.getRandomIntegerInRange(rand, -250, 250), (int) this.posZ + MathHelper.getRandomIntegerInRange(rand, -250, 250),
properties.LimboDimensionID); properties.LimboDimensionID);
DDTeleporter.teleportEntity(entityPlayer, destination); DDTeleporter.teleportEntity(entityPlayer, destination, false);
this.aggro = 0; this.aggro = 0;
entityPlayer.worldObj.playSoundAtEntity(entityPlayer,"mods.DimDoors.sfx.crack",13, 1); entityPlayer.worldObj.playSoundAtEntity(entityPlayer,"mods.DimDoors.sfx.crack",13, 1);