Modified NewDimData and IDimLink
Modified how links are created so that the caller must specify a link type when the link is created, rather than setting it later. This was done to avoid having to send two link data packets following the way links would be handled logically. Turns out this was good idea overall for ensuring link integrity, because there was one case where I forgot to set the link type after creating the link.
This commit is contained in:
parent
4086e75ead
commit
efa5b3eb4c
10 changed files with 51 additions and 41 deletions
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -27,7 +27,7 @@ public abstract class NewDimData implements Serializable
|
|||
private ArrayList<IDimLink> 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<IDimLink>(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<IDimLink> 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;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue