Merge pull request #131 from SenseiKiwi/master

Updated DDTeleporter
This commit is contained in:
StevenRS11
2014-01-22 02:00:31 -08:00
4 changed files with 33 additions and 23 deletions

View File

@@ -230,5 +230,6 @@ public class MazeBuilder
} }
extBlockStorage.setExtBlockID(localX, y & 15, localZ, blockID); extBlockStorage.setExtBlockID(localX, y & 15, localZ, blockID);
extBlockStorage.setExtBlockMetadata(localX, y & 15, localZ, metadata); extBlockStorage.setExtBlockMetadata(localX, y & 15, localZ, metadata);
chunk.setChunkModified();
} }
} }

View File

@@ -36,11 +36,13 @@ import StevenDimDoors.mod_pocketDim.watcher.ClientDimData;
import StevenDimDoors.mod_pocketDim.world.PocketBuilder; import StevenDimDoors.mod_pocketDim.world.PocketBuilder;
import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry;
@SuppressWarnings("deprecation")
public class DDTeleporter public class DDTeleporter
{ {
private static final Random random = new Random(); private static final Random random = new Random();
private static final int NETHER_DIMENSION_ID = -1;
private static final int END_DIMENSION_ID = 1; private static final int END_DIMENSION_ID = 1;
private static final int MAX_NETHER_EXIT_CHANCE = 100;
private static final int NETHER_EXIT_CHANCE = 20; //20% chance to compensate for frequent exit failures - the Nether often doesn't have enough space for an exit
private static final int MAX_ROOT_SHIFT_CHANCE = 100; private static final int MAX_ROOT_SHIFT_CHANCE = 100;
private static final int START_ROOT_SHIFT_CHANCE = 0; private static final int START_ROOT_SHIFT_CHANCE = 0;
private static final int ROOT_SHIFT_CHANCE_PER_LEVEL = 5; private static final int ROOT_SHIFT_CHANCE_PER_LEVEL = 5;
@@ -57,7 +59,7 @@ public class DDTeleporter
* @param properties * @param properties
* @return * @return
*/ */
public static boolean CheckDestination(Entity entity, WorldServer world, Point4D destination,DDProperties properties) private static boolean checkDestination(Entity entity, WorldServer world, Point4D destination,DDProperties properties)
{ {
int x = destination.getX(); int x = destination.getX();
int y = destination.getY(); int y = destination.getY();
@@ -92,14 +94,14 @@ public class DDTeleporter
blockIDBottom = world.getBlockId(point.getX(), point.getY(), point.getZ()); blockIDBottom = world.getBlockId(point.getX(), point.getY(), point.getZ());
blockIDTop = world.getBlockId(point.getX(), point.getY()+1, point.getZ()); blockIDTop = world.getBlockId(point.getX(), point.getY()+1, point.getZ());
if(!(Block.blocksList[blockIDBottom]==null)) if (Block.blocksList[blockIDBottom] != null)
{ {
if(!Block.blocksList[blockIDBottom].isBlockReplaceable(world, point.getX(), point.getY(), point.getZ())) if(!Block.blocksList[blockIDBottom].isBlockReplaceable(world, point.getX(), point.getY(), point.getZ()))
{ {
return false; return false;
} }
} }
if(!(Block.blocksList[blockIDTop]==null)) if (Block.blocksList[blockIDTop] != null)
{ {
if (!Block.blocksList[blockIDTop].isBlockReplaceable(world, point.getX(), point.getY()+1, point.getZ())) if (!Block.blocksList[blockIDTop].isBlockReplaceable(world, point.getX(), point.getY()+1, point.getZ()))
{ {
@@ -107,9 +109,8 @@ public class DDTeleporter
} }
} }
return true; return true;
} }
private static void placeInPortal(Entity entity, WorldServer world, Point4D destination, DDProperties properties, boolean checkOrientation) private static void placeInPortal(Entity entity, WorldServer world, Point4D destination, DDProperties properties, boolean checkOrientation)
{ {
int x = destination.getX(); int x = destination.getX();
@@ -128,7 +129,7 @@ public class DDTeleporter
orientation = -1; orientation = -1;
} }
if(!CheckDestination(entity, world, destination, properties)) if (!checkDestination(entity, world, destination, properties))
{ {
if (entity instanceof EntityPlayerMP) if (entity instanceof EntityPlayerMP)
{ {
@@ -146,16 +147,13 @@ public class DDTeleporter
player.setPositionAndUpdate(x + 0.5, y - 1, z + 0.5); player.setPositionAndUpdate(x + 0.5, y - 1, z + 0.5);
break; break;
case 3: case 3:
player.setPositionAndUpdate(x + 0.5, y - 1, z + .5); player.setPositionAndUpdate(x + 0.5, y - 1, z + 0.5);
break; break;
default: default:
player.setPositionAndUpdate(x, y - 1, z); player.setPositionAndUpdate(x, y - 1, z);
break; break;
} }
} }
} }
else if (entity instanceof EntityPlayer) else if (entity instanceof EntityPlayer)
{ {
@@ -320,10 +318,13 @@ public class DDTeleporter
{ {
// We need to do all this special stuff to move a player between dimensions. // We need to do all this special stuff to move a player between dimensions.
//Give the client the dimensionData for the destination //Give the client the dimensionData for the destination
// FIXME: This violates the way we assume PocketManager works. DimWatcher should not be exposed
// to prevent us from doing bad things. Moreover, no dimension is being created, so if we ever
// tie code to that, it could cause confusing bugs.
// No hacky for you! ~SenseiKiwi
PocketManager.getDimwatcher().onCreated(new ClientDimData(PocketManager.getDimensionData(destination.getDimension()))); PocketManager.getDimwatcher().onCreated(new ClientDimData(PocketManager.getDimensionData(destination.getDimension())));
// Set the new dimension and inform the client that it's moving to a new world. // Set the new dimension and inform the client that it's moving to a new world.
player.dimension = destination.getDimension(); player.dimension = destination.getDimension();
player.playerNetServerHandler.sendPacketToPlayer(new Packet9Respawn(player.dimension, (byte)player.worldObj.difficultySetting, newWorld.getWorldInfo().getTerrainType(), newWorld.getHeight(), player.theItemInWorldManager.getGameType())); player.playerNetServerHandler.sendPacketToPlayer(new Packet9Respawn(player.dimension, (byte)player.worldObj.difficultySetting, newWorld.getWorldInfo().getTerrainType(), newWorld.getHeight(), player.theItemInWorldManager.getGameType()));
@@ -413,8 +414,6 @@ public class DDTeleporter
// Tell Forge we're moving its players so everyone else knows. // Tell Forge we're moving its players so everyone else knows.
// Let's try doing this down here in case this is what's killing NEI. // Let's try doing this down here in case this is what's killing NEI.
GameRegistry.onPlayerChangedDimension((EntityPlayer)entity); GameRegistry.onPlayerChangedDimension((EntityPlayer)entity);
} }
DDTeleporter.placeInPortal(entity, newWorld, destination, properties, checkOrientation); DDTeleporter.placeInPortal(entity, newWorld, destination, properties, checkOrientation);
return entity; return entity;
@@ -448,6 +447,9 @@ public class DDTeleporter
if (cooldown == 0 || entity instanceof EntityPlayer) if (cooldown == 0 || entity instanceof EntityPlayer)
{ {
// According to Steven, we increase the cooldown by a random amount so that if someone
// makes a loop with doors and throws items in them, the slamming sounds won't all
// sync up and be very loud. The cooldown itself prevents server-crashing madness.
cooldown = 2 + random.nextInt(2); cooldown = 2 + random.nextInt(2);
} }
else else
@@ -622,6 +624,8 @@ public class DDTeleporter
{ {
// A dungeon exit acts the same as a safe exit, but has the chance of // A dungeon exit acts the same as a safe exit, but has the chance of
// taking the user to any non-pocket dimension, excluding Limbo and The End. // taking the user to any non-pocket dimension, excluding Limbo and The End.
// There is a chance of choosing the Nether first before other root dimensions
// to compensate for servers with many Mystcraft ages or other worlds.
NewDimData current = PocketManager.getDimensionData(link.link.point.getDimension()); NewDimData current = PocketManager.getDimensionData(link.link.point.getDimension());
ArrayList<NewDimData> roots = PocketManager.getRootDimensions(); ArrayList<NewDimData> roots = PocketManager.getRootDimensions();
@@ -629,6 +633,10 @@ public class DDTeleporter
if (random.nextInt(MAX_ROOT_SHIFT_CHANCE) < shiftChance) if (random.nextInt(MAX_ROOT_SHIFT_CHANCE) < shiftChance)
{ {
if (random.nextInt(MAX_NETHER_EXIT_CHANCE) < NETHER_EXIT_CHANCE)
{
return generateSafeExit(PocketManager.getDimensionData(NETHER_DIMENSION_ID), link, properties);
}
for (int attempts = 0; attempts < 10; attempts++) for (int attempts = 0; attempts < 10; attempts++)
{ {
NewDimData selection = roots.get( random.nextInt(roots.size()) ); NewDimData selection = roots.get( random.nextInt(roots.size()) );

View File

@@ -427,6 +427,7 @@ public class Schematic {
} }
extBlockStorage.setExtBlockID(localX, y & 15, localZ, blockID); extBlockStorage.setExtBlockID(localX, y & 15, localZ, blockID);
extBlockStorage.setExtBlockMetadata(localX, y & 15, localZ, metadata); extBlockStorage.setExtBlockMetadata(localX, y & 15, localZ, metadata);
chunk.setChunkModified();
} }
catch(Exception e) catch(Exception e)
{ {

View File

@@ -475,7 +475,7 @@ public class PocketBuilder
//Build the (wallThickness - 1) layers of Fabric of Reality //Build the (wallThickness - 1) layers of Fabric of Reality
for (int layer = 1; layer < wallThickness; layer++) for (int layer = 1; layer < wallThickness; layer++)
{ {
buildBox(world, center.getX(), center.getY(), center.getZ(), (size / 2) - layer, Block.glowStone.blockID, buildBox(world, center.getX(), center.getY(), center.getZ(), (size / 2) - layer, properties.FabricBlockID,
layer < (wallThickness - 1) && properties.TNFREAKINGT_Enabled, properties.NonTntWeight); layer < (wallThickness - 1) && properties.TNFREAKINGT_Enabled, properties.NonTntWeight);
} }