From ce0d4f9bf98662e4083ab8cb01c81a62fd85cab4 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Wed, 22 Jan 2014 04:49:38 -0400 Subject: [PATCH 1/3] Updated DDTeleporter Updated DDTeleporter to have a fixed minimum chance of sending the player to the Nether when using a dungeon exit. This also allows players to reach the Nether without ever having been there before using a Nether portal - that was previously impossible since DD would not "know" that the Nether existed. Also cleaned up the code a bit and possibly fixed a bug that would cause players to get teleported into walls. --- .../mod_pocketDim/core/DDTeleporter.java | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java index 012c537..d365453 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java @@ -36,11 +36,13 @@ import StevenDimDoors.mod_pocketDim.watcher.ClientDimData; import StevenDimDoors.mod_pocketDim.world.PocketBuilder; import cpw.mods.fml.common.registry.GameRegistry; -@SuppressWarnings("deprecation") public class DDTeleporter { 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 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 START_ROOT_SHIFT_CHANCE = 0; private static final int ROOT_SHIFT_CHANCE_PER_LEVEL = 5; @@ -57,7 +59,7 @@ public class DDTeleporter * @param properties * @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 y = destination.getY(); @@ -74,10 +76,10 @@ public class DDTeleporter switch (orientation) { case 0: - point= new Point3D(MathHelper.floor_double(x - 0.5), y - 1, MathHelper.floor_double(z + 0.5)); + point = new Point3D(MathHelper.floor_double(x - 0.5), y - 1, MathHelper.floor_double(z + 0.5)); break; case 1: - point= new Point3D(MathHelper.floor_double(x + 0.5), y - 1, MathHelper.floor_double(z - 0.5)); + point = new Point3D(MathHelper.floor_double(x + 0.5), y - 1, MathHelper.floor_double(z - 0.5)); break; case 2: point = new Point3D(MathHelper.floor_double(x + 1.5), y - 1, MathHelper.floor_double(z + 0.5)); @@ -92,24 +94,23 @@ public class DDTeleporter blockIDBottom = world.getBlockId(point.getX(), point.getY(), 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())) { 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())) { return false; } } return true; - - } + private static void placeInPortal(Entity entity, WorldServer world, Point4D destination, DDProperties properties, boolean checkOrientation) { int x = destination.getX(); @@ -128,12 +129,12 @@ public class DDTeleporter orientation = -1; } - if(!CheckDestination(entity, world, destination, properties)) + if (!checkDestination(entity, world, destination, properties)) { - if(entity instanceof EntityPlayerMP) + if (entity instanceof EntityPlayerMP) { EntityPlayer player = (EntityPlayer) entity; - player.rotationYaw=(orientation * 90)+90; + player.rotationYaw = (orientation * 90) + 90; switch (orientation) { case 0: @@ -146,18 +147,15 @@ public class DDTeleporter player.setPositionAndUpdate(x + 0.5, y - 1, z + 0.5); break; case 3: - player.setPositionAndUpdate(x + 0.5, y - 1, z + .5); + player.setPositionAndUpdate(x + 0.5, y - 1, z + 0.5); break; default: player.setPositionAndUpdate(x, y - 1, z); break; } - } - - } - if (entity instanceof EntityPlayer) + else if (entity instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) entity; switch (orientation) @@ -413,8 +411,6 @@ public class DDTeleporter // 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. GameRegistry.onPlayerChangedDimension((EntityPlayer)entity); - - } DDTeleporter.placeInPortal(entity, newWorld, destination, properties, checkOrientation); return entity; @@ -448,6 +444,9 @@ public class DDTeleporter 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); } else @@ -622,6 +621,8 @@ public class DDTeleporter { // 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. + // 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()); ArrayList roots = PocketManager.getRootDimensions(); @@ -629,6 +630,10 @@ public class DDTeleporter 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++) { NewDimData selection = roots.get( random.nextInt(roots.size()) ); From 70795b64759a8c7cb6b84c64f19efd4246c4c861 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Wed, 22 Jan 2014 05:10:50 -0400 Subject: [PATCH 2/3] Minor Change Added a warning on some hacky code for sending dim data. --- .../mod_pocketDim/core/DDTeleporter.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java index d365453..fda57f6 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java @@ -317,10 +317,13 @@ public class DDTeleporter if(player != null) // Are we working with a player? { // We need to do all this special stuff to move a player between dimensions. - //Give the client the dimensionData for the destination - PocketManager.getDimwatcher().onCreated(new ClientDimData(PocketManager.getDimensionData(destination.getDimension()))); - - + //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()))); // Set the new dimension and inform the client that it's moving to a new world. player.dimension = destination.getDimension(); From 8d372fadff5a3d8775e20f8762288d98f3390d43 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Wed, 22 Jan 2014 05:57:07 -0400 Subject: [PATCH 3/3] Chunk Bug Fixes Added chunk.setChunkModified() to other classes that were missing it. We have several copies of setBlockDirectly() spread around that needed updating. Also made pockets use FoR instead of glowstone. =P --- src/main/java/StevenDimDoors/experimental/MazeBuilder.java | 1 + .../java/StevenDimDoors/mod_pocketDim/schematic/Schematic.java | 1 + .../java/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/StevenDimDoors/experimental/MazeBuilder.java b/src/main/java/StevenDimDoors/experimental/MazeBuilder.java index 37935c8..9e31e9a 100644 --- a/src/main/java/StevenDimDoors/experimental/MazeBuilder.java +++ b/src/main/java/StevenDimDoors/experimental/MazeBuilder.java @@ -230,5 +230,6 @@ public class MazeBuilder } extBlockStorage.setExtBlockID(localX, y & 15, localZ, blockID); extBlockStorage.setExtBlockMetadata(localX, y & 15, localZ, metadata); + chunk.setChunkModified(); } } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/schematic/Schematic.java b/src/main/java/StevenDimDoors/mod_pocketDim/schematic/Schematic.java index bc866fe..a746535 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/schematic/Schematic.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/schematic/Schematic.java @@ -427,6 +427,7 @@ public class Schematic { } extBlockStorage.setExtBlockID(localX, y & 15, localZ, blockID); extBlockStorage.setExtBlockMetadata(localX, y & 15, localZ, metadata); + chunk.setChunkModified(); } catch(Exception e) { diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java b/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java index 1104715..3a26038 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java @@ -475,7 +475,7 @@ public class PocketBuilder //Build the (wallThickness - 1) layers of Fabric of Reality 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); }