From b18fe877debe1de1796657f0580c55a88f6fe535 Mon Sep 17 00:00:00 2001 From: StevenRS11 Date: Tue, 12 Nov 2013 13:16:54 -0500 Subject: [PATCH] Fixed commands and rift orientation --- .../mod_pocketDim/DDProperties.java | 8 +- .../mod_pocketDim/blocks/TransTrapdoor.java | 2 +- .../commands/CommandCreateDungeonRift.java | 24 ++- .../mod_pocketDim/core/NewDimData.java | 4 - .../mod_pocketDim/core/PocketManager.java | 33 +-- .../mod_pocketDim/helpers/Compactor.java | 6 +- .../mod_pocketDim/watcher/ClientLinkData.java | 38 ++++ .../mod_pocketDim/watcher/IUpdateSource.java | 2 +- .../mod_pocketDim/world/GatewayGenerator.java | 4 +- .../mod_pocketDim/world/PocketBuilder.java | 193 +++++++++++------- .../ClientPacketHandler.java | 9 +- 11 files changed, 207 insertions(+), 116 deletions(-) create mode 100644 StevenDimDoors/mod_pocketDim/watcher/ClientLinkData.java diff --git a/StevenDimDoors/mod_pocketDim/DDProperties.java b/StevenDimDoors/mod_pocketDim/DDProperties.java index 182dde20..fb6bd176 100644 --- a/StevenDimDoors/mod_pocketDim/DDProperties.java +++ b/StevenDimDoors/mod_pocketDim/DDProperties.java @@ -230,13 +230,13 @@ public class DDProperties "Sets the chance (out of " + MonolithSpawner.MAX_MONOLITH_SPAWNING_CHANCE + ") that Monoliths will " + "spawn in a given Limbo chunk. The default chance is 28.").getInt(); - ClusterGenerationChance = config.get(Configuration.CATEGORY_GENERAL, "Cluster Generation Chance", 3, + ClusterGenerationChance = config.get(Configuration.CATEGORY_GENERAL, "Cluster Generation Chance", 2, "Sets the chance (out of " + GatewayGenerator.MAX_CLUSTER_GENERATION_CHANCE + ") that a cluster of rifts will " + - "generate in a given chunk. The default chance is 3.").getInt(); + "generate in a given chunk. The default chance is 2.").getInt(); - GatewayGenerationChance = config.get(Configuration.CATEGORY_GENERAL, "Gateway Generation Chance", 10, + GatewayGenerationChance = config.get(Configuration.CATEGORY_GENERAL, "Gateway Generation Chance", 15, "Sets the chance (out of " + GatewayGenerator.MAX_GATEWAY_GENERATION_CHANCE + ") that a Rift Gateway will " + - "generate in a given chunk. The default chance is 10.").getInt(); + "generate in a given chunk. The default chance is 15.").getInt(); LimboBiomeID = config.get(CATEGORY_BIOME, "Limbo Biome ID", 251).getInt(); PocketBiomeID = config.get(CATEGORY_BIOME, "Pocket Biome ID", 250).getInt(); diff --git a/StevenDimDoors/mod_pocketDim/blocks/TransTrapdoor.java b/StevenDimDoors/mod_pocketDim/blocks/TransTrapdoor.java index 20815034..1ff68132 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/TransTrapdoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/TransTrapdoor.java @@ -96,7 +96,7 @@ public class TransTrapdoor extends BlockTrapDoor implements IDimDoor, ITileEntit DimLink link = dimension.getLink(x, y, z); if (link == null && dimension.isPocketDimension()) { - dimension.createLink(x, y, z, LinkTypes.UNSAFE_EXIT); + dimension.createLink(x, y, z, LinkTypes.UNSAFE_EXIT,0); } } } diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java b/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java index 86e12bf5..2475b269 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java @@ -7,6 +7,7 @@ import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.dungeon.DungeonData; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; +import StevenDimDoors.mod_pocketDim.world.PocketBuilder; import java.util.Collection; @@ -73,7 +74,7 @@ public class CommandCreateDungeonRift extends DDCommandBase { dimension = PocketManager.getDimensionData(sender.worldObj); - link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON); + link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON,orientation); sender.worldObj.setBlock(x, y + 1, z,mod_pocketDim.blockRift.blockID,0,3); sendChat(sender,("Created a rift to a random dungeon.")); @@ -86,16 +87,17 @@ public class CommandCreateDungeonRift extends DDCommandBase result = findDungeonByPartialName(command[0], dungeonHelper.getUntaggedDungeons()); } //Check if we found any matches - if (result != null) - { - //Create a rift to our selected dungeon and notify the player - //TODO currently crashes, need to create the dimension first - dimension = PocketManager.getDimensionData(sender.worldObj); - link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON); - PocketManager.getDimensionData(link.destination().getDimension()).initializeDungeon(x, y + 1, z, orientation,link, result); - sender.worldObj.setBlock(x, y + 1, z,mod_pocketDim.blockRift.blockID,0,3); - sendChat(sender,("Created a rift to \"" + result.schematicName() + "\" dungeon (Dimension ID = " + link.destination().getDimension() + ").")); - } + if (result != null) + { + //Create a rift to our selected dungeon and notify the player + //TODO currently crashes, need to create the dimension first + dimension = PocketManager.getDimensionData(sender.worldObj); + link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON,orientation); + PocketBuilder.generateSelectedDungeonPocket(link, mod_pocketDim.properties, result); + + sender.worldObj.setBlock(x, y + 1, z,mod_pocketDim.blockRift.blockID,0,3); + sendChat(sender,("Created a rift to \"" + result.schematicName() + "\" dungeon (Dimension ID = " + link.destination().getDimension() + ").")); + } else { //No matches! diff --git a/StevenDimDoors/mod_pocketDim/core/NewDimData.java b/StevenDimDoors/mod_pocketDim/core/NewDimData.java index 4562252e..8cf98a79 100644 --- a/StevenDimDoors/mod_pocketDim/core/NewDimData.java +++ b/StevenDimDoors/mod_pocketDim/core/NewDimData.java @@ -245,10 +245,6 @@ public abstract class NewDimData { return Math.abs(i) + Math.abs(j) + Math.abs(k); } - public DimLink createLink(int x, int y, int z, int linkType) - { - return createLink(new Point4D(x, y, z, id), linkType,0); - } public DimLink createLink(int x, int y, int z, int linkType,int orientation) { return createLink(new Point4D(x, y, z, id), linkType,orientation); diff --git a/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/StevenDimDoors/mod_pocketDim/core/PocketManager.java index b42d888b..b8435fee 100644 --- a/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -27,6 +27,7 @@ import StevenDimDoors.mod_pocketDim.saving.PackedLinkData; import StevenDimDoors.mod_pocketDim.saving.PackedLinkTail; import StevenDimDoors.mod_pocketDim.util.Point4D; import StevenDimDoors.mod_pocketDim.watcher.ClientDimData; +import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData; import StevenDimDoors.mod_pocketDim.watcher.IUpdateSource; import StevenDimDoors.mod_pocketDim.watcher.IUpdateWatcher; import StevenDimDoors.mod_pocketDim.watcher.UpdateWatcherProxy; @@ -154,22 +155,24 @@ public class PocketManager } } - private static class ClientLinkWatcher implements IUpdateWatcher - { - @Override - public void onCreated(Point4D source) - { - NewDimData dimension = getDimensionData(source.getDimension()); - dimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.CLIENT_SIDE); - } + private static class ClientLinkWatcher implements IUpdateWatcher + { + @Override + public void onCreated(ClientLinkData link) + { + Point4D source = link.point; + NewDimData dimension = getDimensionData(source.getDimension()); + dimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.CLIENT_SIDE,link.orientation); + } - @Override - public void onDeleted(Point4D source) - { - NewDimData dimension = getDimensionData(source.getDimension()); - dimension.deleteLink(source.getX(), source.getY(), source.getZ()); - } - } + @Override + public void onDeleted(ClientLinkData link) + { + Point4D source = link.point; + NewDimData dimension = getDimensionData(source.getDimension()); + dimension.deleteLink(source.getX(), source.getY(), source.getZ()); + } + } private static class ClientDimWatcher implements IUpdateWatcher { diff --git a/StevenDimDoors/mod_pocketDim/helpers/Compactor.java b/StevenDimDoors/mod_pocketDim/helpers/Compactor.java index 611fe99d..fcff7738 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/Compactor.java +++ b/StevenDimDoors/mod_pocketDim/helpers/Compactor.java @@ -12,6 +12,7 @@ import StevenDimDoors.mod_pocketDim.core.IDimRegistrationCallback; import StevenDimDoors.mod_pocketDim.core.LinkTypes; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.util.Point4D; +import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData; public class Compactor { @@ -76,8 +77,9 @@ public class Compactor int linkCount = input.readInt(); for (int h = 0; h < linkCount; h++) { - Point4D source = Point4D.read(input); - dimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.CLIENT_SIDE); + ClientLinkData link = ClientLinkData.read(input); + Point4D source = link.point; + dimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.CLIENT_SIDE,link.orientation); } } } diff --git a/StevenDimDoors/mod_pocketDim/watcher/ClientLinkData.java b/StevenDimDoors/mod_pocketDim/watcher/ClientLinkData.java new file mode 100644 index 00000000..cfecad5c --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/watcher/ClientLinkData.java @@ -0,0 +1,38 @@ +package StevenDimDoors.mod_pocketDim.watcher; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +import StevenDimDoors.mod_pocketDim.core.DimLink; +import StevenDimDoors.mod_pocketDim.util.Point4D; + +public class ClientLinkData +{ + public Point4D point; + public int orientation; + + public ClientLinkData(DimLink link) + { + this.point= link.source(); + this.orientation=link.orientation(); + } + + public ClientLinkData(Point4D point, int orientation) + { + this.point = point; + this.orientation=orientation; + } + + public void write(DataOutputStream output) throws IOException + { + Point4D.write(point, output); + output.writeInt(orientation); + } + + public static ClientLinkData read(DataInputStream input) throws IOException + { + return new ClientLinkData(Point4D.read(input), input.readInt()); + } + +} \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/watcher/IUpdateSource.java b/StevenDimDoors/mod_pocketDim/watcher/IUpdateSource.java index 98e260e8..f8dd4045 100644 --- a/StevenDimDoors/mod_pocketDim/watcher/IUpdateSource.java +++ b/StevenDimDoors/mod_pocketDim/watcher/IUpdateSource.java @@ -4,5 +4,5 @@ import StevenDimDoors.mod_pocketDim.util.Point4D; public interface IUpdateSource { - public void registerWatchers(IUpdateWatcher dimWatcher, IUpdateWatcher linkWatcher); + public void registerWatchers(IUpdateWatcher dimWatcher, IUpdateWatcher linkWatcher); } diff --git a/StevenDimDoors/mod_pocketDim/world/GatewayGenerator.java b/StevenDimDoors/mod_pocketDim/world/GatewayGenerator.java index 6b0dd0ad..fc260a8a 100644 --- a/StevenDimDoors/mod_pocketDim/world/GatewayGenerator.java +++ b/StevenDimDoors/mod_pocketDim/world/GatewayGenerator.java @@ -101,7 +101,7 @@ public class GatewayGenerator implements IWorldGenerator if (link == null) { dimension = PocketManager.getDimensionData(world); - link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON); + link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON,0); } else { @@ -136,7 +136,7 @@ public class GatewayGenerator implements IWorldGenerator { //Create a partial link to a dungeon. dimension = PocketManager.getDimensionData(world); - link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON); + link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON,0); //If the current dimension isn't Limbo, build a Rift Gateway out of Stone Bricks if (dimension.id() != properties.LimboDimensionID) diff --git a/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java b/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java index b1dd1f93..0bb054c5 100644 --- a/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java +++ b/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java @@ -119,79 +119,128 @@ public class PocketBuilder } - public static boolean generateNewDungeonPocket(DimLink link, DDProperties properties) - { - if (link == null) - { - throw new IllegalArgumentException("link cannot be null."); - } - if (properties == null) - { - throw new IllegalArgumentException("properties cannot be null."); - } - - if (link.hasDestination()) - { - throw new IllegalArgumentException("link cannot have a destination assigned already."); - } - + private static boolean buildDungeonPocket(DungeonData dungeon, NewDimData dimension, DimLink link, DungeonSchematic schematic,World world, DDProperties properties) + { - try - { - //Register a new dimension - NewDimData parent = PocketManager.getDimensionData(link.source().getDimension()); - NewDimData dimension = PocketManager.registerPocket(parent, true); - - //Load a world - World world = PocketManager.loadDimension(dimension.id()); - - if (world == null || world.provider == null) - { - System.err.println("Could not initialize dimension for a dungeon!"); - return false; - } - - //Choose a dungeon to generate - Pair pair = selectDungeon(dimension, random, properties); - if (pair == null) - { - System.err.println("Could not select a dungeon for generation!"); - return false; - } - DungeonData dungeon = pair.getFirst(); - DungeonSchematic schematic = pair.getSecond(); - - //Calculate the destination point - DungeonPackConfig packConfig = dungeon.dungeonType().Owner != null ? dungeon.dungeonType().Owner.getConfig() : null; - Point4D source = link.source(); - int orientation = getDoorOrientation(source, properties); - Point3D destination; - - if (packConfig != null && packConfig.doDistortDoorCoordinates()) - { - destination = calculateNoisyDestination(source, dimension, dungeon, orientation); - } - else - { - destination = new Point3D(source.getX(), source.getY(), source.getZ()); - } - - destination.setY( yCoordHelper.adjustDestinationY(destination.getY(), world.getHeight(), schematic.getEntranceDoorLocation().getY(), schematic.getHeight()) ); - - //Generate the dungeon - schematic.copyToWorld(world, destination, orientation, link, random); - - //Finish up destination initialization - dimension.initializeDungeon(destination.getX(), destination.getY(), destination.getZ(), orientation, link, dungeon); - dimension.setFilled(true); - return true; - } - catch (Exception e) - { - e.printStackTrace(); - return false; - } - } + //Calculate the destination point + DungeonPackConfig packConfig = dungeon.dungeonType().Owner != null ? dungeon.dungeonType().Owner.getConfig() : null; + Point4D source = link.source(); + int orientation = link.orientation(); + Point3D destination; + + if (packConfig != null && packConfig.doDistortDoorCoordinates()) + { + destination = calculateNoisyDestination(source, dimension, dungeon, orientation); + } + else + { + destination = new Point3D(source.getX(), source.getY(), source.getZ()); + } + + destination.setY( yCoordHelper.adjustDestinationY(destination.getY(), world.getHeight(), schematic.getEntranceDoorLocation().getY(), schematic.getHeight()) ); + + //Generate the dungeon + schematic.copyToWorld(world, destination, orientation, link, random); + + //Finish up destination initialization + dimension.initializeDungeon(destination.getX(), destination.getY(), destination.getZ(), orientation, link, dungeon); + dimension.setFilled(true); + return true; + + + } + + public static boolean generateSelectedDungeonPocket(DimLink link, DDProperties properties,DungeonData data) + { + if (link == null) + { + throw new IllegalArgumentException("link cannot be null."); + } + if (properties == null) + { + throw new IllegalArgumentException("properties cannot be null."); + } + + if (link.hasDestination()) + { + throw new IllegalArgumentException("link cannot have a destination assigned already."); + } + + + + //Register a new dimension + NewDimData parent = PocketManager.getDimensionData(link.source().getDimension()); + NewDimData dimension = PocketManager.registerPocket(parent, true); + + //Load a world + World world = PocketManager.loadDimension(dimension.id()); + + if (world == null || world.provider == null) + { + System.err.println("Could not initialize dimension for a dungeon!"); + return false; + } + + DungeonData dungeon = null; + DungeonSchematic schematic = null; + + dungeon = data; + if (data == null) + { + System.err.println("Could not select a dungeon for generation!"); + return false; + } + schematic = loadAndValidateDungeon(dungeon,properties); + + return PocketBuilder.buildDungeonPocket(dungeon, dimension, link, schematic, world, properties); + + } + + + public static boolean generateNewDungeonPocket(DimLink link, DDProperties properties) + { + if (link == null) + { + throw new IllegalArgumentException("link cannot be null."); + } + if (properties == null) + { + throw new IllegalArgumentException("properties cannot be null."); + } + + if (link.hasDestination()) + { + throw new IllegalArgumentException("link cannot have a destination assigned already."); + } + + + + //Register a new dimension + NewDimData parent = PocketManager.getDimensionData(link.source().getDimension()); + NewDimData dimension = PocketManager.registerPocket(parent, true); + + //Load a world + World world = PocketManager.loadDimension(dimension.id()); + + if (world == null || world.provider == null) + { + System.err.println("Could not initialize dimension for a dungeon!"); + return false; + } + + //Choose a dungeon to generate + Pair pair = selectDungeon(dimension, random, properties); + if (pair == null) + { + System.err.println("Could not select a dungeon for generation!"); + return false; + } + DungeonData dungeon = pair.getFirst(); + DungeonSchematic schematic = pair.getSecond(); + + return buildDungeonPocket(dungeon, dimension, link, schematic, world, properties); + } + private static Point3D calculateNoisyDestination(Point4D source, NewDimData dimension, DungeonData dungeon, int orientation) { diff --git a/StevenDimDoors/mod_pocketDimClient/ClientPacketHandler.java b/StevenDimDoors/mod_pocketDimClient/ClientPacketHandler.java index 5e6be4d6..b9057f40 100644 --- a/StevenDimDoors/mod_pocketDimClient/ClientPacketHandler.java +++ b/StevenDimDoors/mod_pocketDimClient/ClientPacketHandler.java @@ -4,6 +4,7 @@ import StevenDimDoors.mod_pocketDim.PacketConstants; import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.util.Point4D; import StevenDimDoors.mod_pocketDim.watcher.ClientDimData; +import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData; import StevenDimDoors.mod_pocketDim.watcher.IUpdateSource; import StevenDimDoors.mod_pocketDim.watcher.IUpdateWatcher; @@ -20,7 +21,7 @@ import net.minecraft.server.integrated.IntegratedServer; public class ClientPacketHandler implements IPacketHandler, IUpdateSource { - private IUpdateWatcher linkWatcher; + private IUpdateWatcher linkWatcher; private IUpdateWatcher dimWatcher; public ClientPacketHandler() @@ -29,7 +30,7 @@ public class ClientPacketHandler implements IPacketHandler, IUpdateSource } @Override - public void registerWatchers(IUpdateWatcher dimWatcher, IUpdateWatcher linkWatcher) + public void registerWatchers(IUpdateWatcher dimWatcher, IUpdateWatcher linkWatcher) { this.dimWatcher = dimWatcher; this.linkWatcher = linkWatcher; @@ -59,13 +60,13 @@ public class ClientPacketHandler implements IPacketHandler, IUpdateSource dimWatcher.onCreated( ClientDimData.read(input) ); break; case PacketConstants.CREATE_LINK_PACKET_ID: - linkWatcher.onCreated( Point4D.read(input) ); + linkWatcher.onCreated( ClientLinkData.read(input) ); break; case PacketConstants.DELETE_DIM_PACKET_ID: dimWatcher.onDeleted( ClientDimData.read(input) ); break; case PacketConstants.DELETE_LINK_PACKET_ID: - linkWatcher.onDeleted( Point4D.read(input) ); + linkWatcher.onDeleted( ClientLinkData.read(input) ); break; } }