diff --git a/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java b/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java index 1d0cd0d7..fbd0281a 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java @@ -172,7 +172,7 @@ public class DimensionalDoor extends BlockContainer IDimLink link = dimension.getLink(x, y, z); if (link == null) { - dimension.createLink(x, y, z).setLinkType(IDimLink.TYPE_POCKET); + dimension.createLink(x, y, z, IDimLink.TYPE_POCKET); } } world.setBlockTileEntity(x, y, z, this.createNewTileEntity(world)); diff --git a/StevenDimDoors/mod_pocketDim/blocks/UnstableDoor.java b/StevenDimDoors/mod_pocketDim/blocks/UnstableDoor.java index 74a0f738..d53e5762 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/UnstableDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/UnstableDoor.java @@ -54,7 +54,7 @@ public class UnstableDoor extends DimensionalDoor if (!world.isRemote && world.getBlockId(x, y - 1, z) == this.blockID) { NewDimData dimension = PocketManager.getDimensionData(world); - dimension.createLink(x, y, z).setLinkType(IDimLink.TYPE_RANDOM); + dimension.createLink(x, y, z, IDimLink.TYPE_RANDOM); } } } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java b/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java index cbe51590..410a0525 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java @@ -41,7 +41,7 @@ public class WarpDoor extends DimensionalDoor IDimLink link = dimension.getLink(x, y, z); if (link == null) { - dimension.createLink(x, y, z).setLinkType(IDimLink.TYPE_SAFE_EXIT); + dimension.createLink(x, y, z, IDimLink.TYPE_SAFE_EXIT); } } world.setBlockTileEntity(x, y, z, this.createNewTileEntity(world)); diff --git a/StevenDimDoors/mod_pocketDim/core/IDimLink.java b/StevenDimDoors/mod_pocketDim/core/IDimLink.java index 34d2f9ba..cb62dc38 100644 --- a/StevenDimDoors/mod_pocketDim/core/IDimLink.java +++ b/StevenDimDoors/mod_pocketDim/core/IDimLink.java @@ -27,5 +27,4 @@ public interface IDimLink extends Serializable public IDimLink parent(); public int linkType(); public IDimLink setDestination(int x, int y, int z, NewDimData dimension); - public IDimLink setLinkType(int linkType); } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/core/NewDimData.java b/StevenDimDoors/mod_pocketDim/core/NewDimData.java index f8c9941c..40c3333f 100644 --- a/StevenDimDoors/mod_pocketDim/core/NewDimData.java +++ b/StevenDimDoors/mod_pocketDim/core/NewDimData.java @@ -27,7 +27,7 @@ public abstract class NewDimData implements Serializable private ArrayList children; public DimLink(Point4D source, DimLink parent) - { + { this.parent = parent; this.source = source; this.tail = parent.tail; @@ -35,11 +35,16 @@ public abstract class NewDimData implements Serializable parent.children.add(this); } - public DimLink(Point4D source) + public DimLink(Point4D source, int linkType) { + if (linkType < IDimLink.TYPE_ENUM_MIN || linkType > IDimLink.TYPE_ENUM_MAX) + { + throw new IllegalArgumentException("The specified link type is invalid."); + } + this.parent = null; this.source = source; - this.tail = new LinkTail(0, null); + this.tail = new LinkTail(linkType, null); this.children = new ArrayList(EXPECTED_CHILDREN); } @@ -72,18 +77,6 @@ public abstract class NewDimData implements Serializable tail.setDestination(new Point4D(x, y, z, dimension.id())); return this; } - - @Override - public IDimLink setLinkType(int linkType) - { - if (linkType < IDimLink.TYPE_ENUM_MIN || linkType > IDimLink.TYPE_ENUM_MAX) - { - throw new IllegalArgumentException("The specified link type is invalid."); - } - - tail.setLinkType(linkType); - return this; - } @Override public Iterable children() @@ -131,6 +124,11 @@ public abstract class NewDimData implements Serializable public void overwrite(DimLink nextParent) { + if (nextParent == null) + { + throw new IllegalArgumentException("nextParent cannot be null."); + } + if (this == nextParent) { //Ignore this request silently @@ -152,15 +150,28 @@ public abstract class NewDimData implements Serializable //Attach to new parent parent = nextParent; + tail = nextParent.tail; + nextParent.children.add(this); + } + + public void overwrite(int linkType) + { + //Release children + for (IDimLink child : children) + { + ((DimLink) child).parent = null; + } + children.clear(); + + //Release parent if (parent != null) { - tail = parent.tail; - parent.children.add(this); - } - else - { - tail = new LinkTail(0, null); + parent.children.remove(this); } + + //Attach to new parent + parent = null; + tail = new LinkTail(linkType, null); } @Override @@ -224,7 +235,7 @@ public abstract class NewDimData implements Serializable public IDimLink findNearestRift(World world, int range, int x, int y, int z) { - //TODO: Rewrite this later to use an octtree, remove World parameter + //TODO: Rewrite this later to use an octtree //Sanity check... if (world.provider.dimensionId != id) @@ -271,24 +282,24 @@ public abstract class NewDimData implements Serializable return Math.abs(i) + Math.abs(j) + Math.abs(k); } - public IDimLink createLink(int x, int y, int z) + public IDimLink createLink(int x, int y, int z, int linkType) { - return createLink(new Point4D(x, y, z, id)); + return createLink(new Point4D(x, y, z, id), linkType); } - private IDimLink createLink(Point4D source) - { + private IDimLink createLink(Point4D source, int linkType) + { //Return an existing link if there is one to avoid creating multiple links starting at the same point. DimLink link = linkMapping.get(source); if (link == null) { - link = new DimLink(source); + link = new DimLink(source, linkType); linkMapping.put(source, link); linkList.add(link); } else { - link.overwrite(null); + link.overwrite(linkType); } return link; } diff --git a/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java b/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java index ab6013a9..1c0663da 100644 --- a/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java +++ b/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java @@ -284,7 +284,7 @@ public class DungeonSchematic extends Schematic { private static void createEntranceReverseLink(NewDimData dimension, Point3D pocketCenter, IDimLink entryLink) { - IDimLink link = dimension.createLink(pocketCenter.getX(), pocketCenter.getY(), pocketCenter.getZ()); + IDimLink link = dimension.createLink(pocketCenter.getX(), pocketCenter.getY(), pocketCenter.getZ(), IDimLink.TYPE_NORMAL); Point4D destination = link.source(); link.setDestination(destination.getX(), destination.getY(), destination.getZ(), PocketManager.getDimensionData(destination.getDimension())); @@ -295,7 +295,7 @@ public class DungeonSchematic extends Schematic { //Transform the door's location to the pocket coordinate system Point3D location = point.clone(); BlockRotator.transformPoint(location, entrance, rotation, pocketCenter); - dimension.createLink(location.getX(), location.getY(), location.getZ()).setLinkType(IDimLink.TYPE_DUNGEON_EXIT); + dimension.createLink(location.getX(), location.getY(), location.getZ(), IDimLink.TYPE_DUNGEON_EXIT); } private static void createDimensionalDoorLink(NewDimData dimension, Point3D point, Point3D entrance, int rotation, Point3D pocketCenter) @@ -303,7 +303,7 @@ public class DungeonSchematic extends Schematic { //Transform the door's location to the pocket coordinate system Point3D location = point.clone(); BlockRotator.transformPoint(location, entrance, rotation, pocketCenter); - dimension.createLink(location.getX(), location.getY(), location.getZ()).setLinkType(IDimLink.TYPE_DUNGEON); + dimension.createLink(location.getX(), location.getY(), location.getZ(), IDimLink.TYPE_DUNGEON); } private static void spawnMonolith(World world, Point3D point, Point3D entrance, int rotation, Point3D pocketCenter) diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index 39139327..cc9cfdb5 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -278,7 +278,7 @@ public class DungeonHelper { //Create a link above the specified position. Link to a new pocket dimension. NewDimData dimension = PocketManager.getDimensionData(world); - IDimLink link = dimension.createLink(x, y + 1, z).setLinkType(IDimLink.TYPE_POCKET); + IDimLink link = dimension.createLink(x, y + 1, z, IDimLink.TYPE_POCKET); //Place a Warp Door linked to that pocket ItemDimensionalDoor.placeDoorBlock(world, x, y, z, 3, mod_pocketDim.warpDoor); diff --git a/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java b/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java index 727fc24c..c6eec69d 100644 --- a/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java +++ b/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java @@ -187,7 +187,7 @@ public class ItemRiftBlade extends ItemSword NewDimData dimension = PocketManager.getDimensionData(world); if (!dimension.isPocketDimension() && dimension.getLink(x, y + 1, z) == null) { - dimension.createLink(x, y + 1, z).setLinkType(IDimLink.TYPE_POCKET); + dimension.createLink(x, y + 1, z, IDimLink.TYPE_POCKET); player.worldObj.playSoundAtEntity(player,"mods.DimDoors.sfx.riftDoor", 0.6f, 1); ItemDimensionalDoor.placeDoorBlock(world, x, y, z, orientation, mod_pocketDim.transientDoor); } diff --git a/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java b/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java index bd3c74bd..fc521bfa 100644 --- a/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java +++ b/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java @@ -66,8 +66,8 @@ public class ItemRiftSignature extends Item //The link was used before and already has an endpoint stored. Create links connecting the two endpoints. NewDimData sourceDimension = PocketManager.getDimensionData(source.getDimension()); NewDimData destinationDimension = PocketManager.getDimensionData(world); - IDimLink link = sourceDimension.createLink(source.getX(), source.getY(), source.getZ()).setLinkType(IDimLink.TYPE_NORMAL); - IDimLink reverse = destinationDimension.createLink(x, y, z).setLinkType(IDimLink.TYPE_NORMAL); + IDimLink link = sourceDimension.createLink(source.getX(), source.getY(), source.getZ(), IDimLink.TYPE_NORMAL); + IDimLink reverse = destinationDimension.createLink(x, y, z, IDimLink.TYPE_NORMAL); link.setDestination(x, y, z, destinationDimension); reverse.setDestination(source.getX(), source.getY(), source.getZ(), sourceDimension); diff --git a/StevenDimDoors/mod_pocketDim/world/GatewayGenerator.java b/StevenDimDoors/mod_pocketDim/world/GatewayGenerator.java index 5bc6fb0c..2a2e0f07 100644 --- a/StevenDimDoors/mod_pocketDim/world/GatewayGenerator.java +++ b/StevenDimDoors/mod_pocketDim/world/GatewayGenerator.java @@ -97,7 +97,7 @@ public class GatewayGenerator implements IWorldGenerator if (link == null) { dimension = PocketManager.getDimensionData(world); - link = dimension.createLink(x, y + 1, z).setLinkType(IDimLink.TYPE_POCKET); + link = dimension.createLink(x, y + 1, z, IDimLink.TYPE_POCKET); } else { @@ -132,7 +132,7 @@ public class GatewayGenerator implements IWorldGenerator { //Create a partial link to a dungeon. dimension = PocketManager.getDimensionData(world); - link = dimension.createLink(x, y + 1, z).setLinkType(IDimLink.TYPE_DUNGEON); + link = dimension.createLink(x, y + 1, z, IDimLink.TYPE_DUNGEON); //If the current dimension isn't Limbo, build a Rift Gateway out of Stone Bricks if (dimension.id() != properties.LimboDimensionID)