Fixed Eager Dimension Data Creation

1. Fixed a design flaw in PocketManager. We originally assumed that all
requests to PocketManager.getDimensionData() had to be legitimate
requests for dimensions that existed. That was true in most cases, but
for things like processing user commands, it was dangerously optimistic.
It was possible that a flaw in DD's usage of that function could be
exploited by a player to trick the mod into pre-registering dimension
data for a non-existent dimension. That would declare the dimension as a
root. DD would crash later if Forge ever allocated that ID for a pocket
dimension. The new implementation is almost the same as the old one, but
allows us to differentiate between cases when we can eagerly create
dimension data, and cases in which the absence of a dimension should
cause a crash to alert us of a design flaw.
2. Remove the pocket regeneration code from PocketBuilder. We simply
don't support pocket regeneration and it's unlikely it'll ever be
implemented because it's a difficult issue. Wiping out pockets
completely is easier. We can always recover the code from this commit if
it's needed later.
3. Minor changes: removed some debug prints from PocketManager and
changed some static accesses in PocketBuilder.
This commit is contained in:
SenseiKiwi 2014-07-13 20:03:00 -04:00
parent 8544aa17ee
commit e793493331
32 changed files with 85 additions and 179 deletions

View file

@ -1,17 +1,11 @@
package StevenDimDoors.mod_pocketDim; package StevenDimDoors.mod_pocketDim;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.INetworkManager; import net.minecraft.network.INetworkManager;
import net.minecraft.network.NetLoginHandler; import net.minecraft.network.NetLoginHandler;
import net.minecraft.network.packet.NetHandler; import net.minecraft.network.packet.NetHandler;
import net.minecraft.network.packet.Packet1Login; import net.minecraft.network.packet.Packet1Login;
import net.minecraft.network.packet.Packet250CustomPayload; import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.integrated.IntegratedServer;
import net.minecraftforge.common.DimensionManager; import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.network.ForgePacket; import net.minecraftforge.common.network.ForgePacket;
import net.minecraftforge.common.network.packet.DimensionRegisterPacket; import net.minecraftforge.common.network.packet.DimensionRegisterPacket;
@ -65,7 +59,8 @@ public class ConnectionHandler implements IConnectionHandler
@Override @Override
public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager) public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager)
{ {
PocketManager.getDimwatcher().onCreated(new ClientDimData(PocketManager.getDimensionData(0))); // Hax... please don't do this! >_<
PocketManager.getDimwatcher().onCreated(new ClientDimData(PocketManager.createDimensionDataDangerously(0)));
} }
} }

View file

@ -236,7 +236,7 @@ public class EventHookContainer
Chunk chunk = event.getChunk(); Chunk chunk = event.getChunk();
if (!chunk.worldObj.isRemote && PocketManager.isLoaded()) if (!chunk.worldObj.isRemote && PocketManager.isLoaded())
{ {
NewDimData dimension = PocketManager.getDimensionData(chunk.worldObj); NewDimData dimension = PocketManager.createDimensionData(chunk.worldObj);
for (DimLink link : dimension.getChunkLinks(chunk.xPosition, chunk.zPosition)) for (DimLink link : dimension.getChunkLinks(chunk.xPosition, chunk.zPosition))
{ {
regenerator.scheduleSlowRegeneration(link); regenerator.scheduleSlowRegeneration(link);

View file

@ -25,7 +25,7 @@ public class BlockGoldDimDoor extends BaseDimDoor
{ {
if (!world.isRemote && world.getBlockId(x, y - 1, z) == this.blockID) if (!world.isRemote && world.getBlockId(x, y - 1, z) == this.blockID)
{ {
NewDimData dimension = PocketManager.getDimensionData(world); NewDimData dimension = PocketManager.createDimensionData(world);
DimLink link = dimension.getLink(x, y, z); DimLink link = dimension.getLink(x, y, z);
if (link == null) if (link == null)
{ {

View file

@ -22,7 +22,7 @@ public class DimensionalDoor extends BaseDimDoor
{ {
if (!world.isRemote && world.getBlockId(x, y - 1, z) == this.blockID) if (!world.isRemote && world.getBlockId(x, y - 1, z) == this.blockID)
{ {
NewDimData dimension = PocketManager.getDimensionData(world); NewDimData dimension = PocketManager.createDimensionData(world);
DimLink link = dimension.getLink(x, y, z); DimLink link = dimension.getLink(x, y, z);
if (link == null) if (link == null)
{ {

View file

@ -76,7 +76,7 @@ public class TransTrapdoor extends BlockTrapDoor implements IDimDoor, ITileEntit
{ {
if (!world.isRemote) if (!world.isRemote)
{ {
NewDimData dimension = PocketManager.getDimensionData(world); NewDimData dimension = PocketManager.createDimensionData(world);
DimLink link = dimension.getLink(x, y, z); DimLink link = dimension.getLink(x, y, z);
if (link == null && dimension.isPocketDimension()) if (link == null && dimension.isPocketDimension())
{ {

View file

@ -64,7 +64,7 @@ public class TransientDoor extends BaseDimDoor
{ {
if (!world.isRemote && world.getBlockId(x, y - 1, z) == this.blockID) if (!world.isRemote && world.getBlockId(x, y - 1, z) == this.blockID)
{ {
NewDimData dimension = PocketManager.getDimensionData(world); NewDimData dimension = PocketManager.createDimensionData(world);
DimLink link = dimension.getLink(x, y, z); DimLink link = dimension.getLink(x, y, z);
if (link == null && dimension.isPocketDimension()) if (link == null && dimension.isPocketDimension())
{ {

View file

@ -21,7 +21,7 @@ public class UnstableDoor extends BaseDimDoor
{ {
if (!world.isRemote && world.getBlockId(x, y - 1, z) == this.blockID) if (!world.isRemote && world.getBlockId(x, y - 1, z) == this.blockID)
{ {
NewDimData dimension = PocketManager.getDimensionData(world); NewDimData dimension = PocketManager.createDimensionData(world);
dimension.createLink(x, y, z, LinkTypes.RANDOM,world.getBlockMetadata(x, y - 1, z)); dimension.createLink(x, y, z, LinkTypes.RANDOM,world.getBlockMetadata(x, y - 1, z));
} }
} }

View file

@ -22,7 +22,7 @@ public class WarpDoor extends BaseDimDoor
{ {
if (!world.isRemote && world.getBlockId(x, y - 1, z) == this.blockID) if (!world.isRemote && world.getBlockId(x, y - 1, z) == this.blockID)
{ {
NewDimData dimension = PocketManager.getDimensionData(world); NewDimData dimension = PocketManager.createDimensionData(world);
DimLink link = dimension.getLink(x, y, z); DimLink link = dimension.getLink(x, y, z);
if (link == null && dimension.isPocketDimension()) if (link == null && dimension.isPocketDimension())
{ {

View file

@ -61,7 +61,7 @@ public class CommandCreateDungeonRift extends DDCommandBase
// Check if we found any matches // Check if we found any matches
if (result != null) if (result != null)
{ {
dimension = PocketManager.getDimensionData(sender.worldObj); dimension = PocketManager.createDimensionData(sender.worldObj);
link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON, orientation); link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON, orientation);
if (PocketBuilder.generateSelectedDungeonPocket(link, mod_pocketDim.properties, result)) if (PocketBuilder.generateSelectedDungeonPocket(link, mod_pocketDim.properties, result))
{ {

View file

@ -53,7 +53,7 @@ public class CommandCreateRandomRift extends DDCommandBase
if (command.length == 0) if (command.length == 0)
{ {
dimension = PocketManager.getDimensionData(sender.worldObj); dimension = PocketManager.createDimensionData(sender.worldObj);
link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON, orientation); link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON, orientation);
sender.worldObj.setBlock(x, y + 1, z,mod_pocketDim.blockRift.blockID, 0, 3); sender.worldObj.setBlock(x, y + 1, z,mod_pocketDim.blockRift.blockID, 0, 3);
sendChat(sender, "Created a rift to a random dungeon."); sendChat(sender, "Created a rift to a random dungeon.");
@ -69,7 +69,7 @@ public class CommandCreateRandomRift extends DDCommandBase
// Check if we found any matches // Check if we found any matches
if (result != null) if (result != null)
{ {
dimension = PocketManager.getDimensionData(sender.worldObj); dimension = PocketManager.createDimensionData(sender.worldObj);
link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON, orientation); link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON, orientation);
if (PocketBuilder.generateSelectedDungeonPocket(link, mod_pocketDim.properties, result)) if (PocketBuilder.generateSelectedDungeonPocket(link, mod_pocketDim.properties, result))
{ {

View file

@ -63,7 +63,7 @@ public class CommandDeleteRifts extends DDCommandBase
int y; int y;
int z; int z;
Point4D location; Point4D location;
NewDimData dimension = PocketManager.getDimensionData(targetDimension); NewDimData dimension = PocketManager.createDimensionData(world);
ArrayList<DimLink> links = dimension.getAllLinks(); ArrayList<DimLink> links = dimension.getAllLinks();
for (DimLink link : links) for (DimLink link : links)
{ {

View file

@ -80,7 +80,6 @@ public class CommandTeleportPlayer extends DDCommandBase
else else
{ {
dimensionID = targetPlayer.worldObj.provider.dimensionId; dimensionID = targetPlayer.worldObj.provider.dimensionId;
// SenseiKiwi: Will not be used, but I prefer not to leave 'world' as null
world = targetPlayer.worldObj; world = targetPlayer.worldObj;
} }
@ -95,7 +94,7 @@ public class CommandTeleportPlayer extends DDCommandBase
if (command.length == 2) if (command.length == 2)
{ {
// Check if the destination is a pocket dimension // Check if the destination is a pocket dimension
dimension = PocketManager.getDimensionData(dimensionID); dimension = PocketManager.createDimensionData(world);
if (dimension.isPocketDimension()) if (dimension.isPocketDimension())
{ {
// The destination is a pocket dimension. // The destination is a pocket dimension.

View file

@ -227,7 +227,7 @@ public class DDTeleporter
&& blockID != properties.GoldenDimensionalDoorID) && blockID != properties.GoldenDimensionalDoorID)
{ {
//Return the pocket's orientation instead //Return the pocket's orientation instead
return PocketManager.getDimensionData(door.getDimension()).orientation(); return PocketManager.createDimensionData(world).orientation();
} }
//Return the orientation portion of its metadata //Return the orientation portion of its metadata
@ -294,7 +294,7 @@ public class DDTeleporter
// to prevent us from doing bad things. Moreover, no dimension is being created, so if we ever // 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. // tie code to that, it could cause confusing bugs.
// No hacky for you! ~SenseiKiwi // No hacky for you! ~SenseiKiwi
PocketManager.getDimwatcher().onCreated(new ClientDimData(PocketManager.getDimensionData(destination.getDimension()))); PocketManager.getDimwatcher().onCreated(new ClientDimData(PocketManager.createDimensionData(newWorld)));
// 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();
@ -552,7 +552,7 @@ public class DDTeleporter
// To avoid loops, don't generate a destination if the player is // To avoid loops, don't generate a destination if the player is
// already in a non-pocket dimension. // already in a non-pocket dimension.
NewDimData current = PocketManager.getDimensionData(link.link.point.getDimension()); NewDimData current = PocketManager.getDimensionData(link.source().getDimension());
if (current.isPocketDimension()) if (current.isPocketDimension())
{ {
Point4D source = link.source(); Point4D source = link.source();
@ -606,9 +606,10 @@ public class DDTeleporter
} }
} }
} }
private static boolean generateSafeExit(DimLink link, DDProperties properties) private static boolean generateSafeExit(DimLink link, DDProperties properties)
{ {
NewDimData current = PocketManager.getDimensionData(link.link.point.getDimension()); NewDimData current = PocketManager.getDimensionData(link.source().getDimension());
return generateSafeExit(current.root(), link, properties); return generateSafeExit(current.root(), link, properties);
} }
@ -619,7 +620,7 @@ public class DDTeleporter
// There is a chance of choosing the Nether first before other root dimensions // There is a chance of choosing the Nether first before other root dimensions
// to compensate for servers with many Mystcraft ages or other worlds. // to compensate for servers with many Mystcraft ages or other worlds.
NewDimData current = PocketManager.getDimensionData(link.link.point.getDimension()); NewDimData current = PocketManager.getDimensionData(link.source().getDimension());
ArrayList<NewDimData> roots = PocketManager.getRootDimensions(); ArrayList<NewDimData> roots = PocketManager.getRootDimensions();
int shiftChance = START_ROOT_SHIFT_CHANCE + ROOT_SHIFT_CHANCE_PER_LEVEL * (current.packDepth() - 1); int shiftChance = START_ROOT_SHIFT_CHANCE + ROOT_SHIFT_CHANCE_PER_LEVEL * (current.packDepth() - 1);
@ -627,11 +628,11 @@ public class DDTeleporter
{ {
if (current.root().id() != OVERWORLD_DIMENSION_ID && random.nextInt(MAX_OVERWORLD_EXIT_CHANCE) < OVERWORLD_EXIT_CHANCE) if (current.root().id() != OVERWORLD_DIMENSION_ID && random.nextInt(MAX_OVERWORLD_EXIT_CHANCE) < OVERWORLD_EXIT_CHANCE)
{ {
return generateSafeExit(PocketManager.getDimensionData(OVERWORLD_DIMENSION_ID), link, properties); return generateSafeExit(PocketManager.createDimensionDataDangerously(OVERWORLD_DIMENSION_ID), link, properties);
} }
if (current.root().id() != NETHER_DIMENSION_ID && random.nextInt(MAX_NETHER_EXIT_CHANCE) < NETHER_EXIT_CHANCE) if (current.root().id() != NETHER_DIMENSION_ID && random.nextInt(MAX_NETHER_EXIT_CHANCE) < NETHER_EXIT_CHANCE)
{ {
return generateSafeExit(PocketManager.getDimensionData(NETHER_DIMENSION_ID), link, properties); return generateSafeExit(PocketManager.createDimensionDataDangerously(NETHER_DIMENSION_ID), link, properties);
} }
for (int attempts = 0; attempts < 10; attempts++) for (int attempts = 0; attempts < 10; attempts++)
{ {
@ -735,7 +736,7 @@ public class DDTeleporter
// Create a reverse link for returning // Create a reverse link for returning
int orientation = getDestinationOrientation(source, properties); int orientation = getDestinationOrientation(source, properties);
NewDimData sourceDim = PocketManager.getDimensionData(link.source().getDimension()); NewDimData sourceDim = PocketManager.getDimensionData(link.source().getDimension());
DimLink reverse = destinationDim.createLink(x, y + 2, z, LinkTypes.REVERSE,orientation); DimLink reverse = destinationDim.createLink(x, y + 2, z, LinkTypes.REVERSE, orientation);
sourceDim.setLinkDestination(reverse, source.getX(), source.getY(), source.getZ()); sourceDim.setLinkDestination(reverse, source.getX(), source.getY(), source.getZ());
// Set up the warp door at the destination // Set up the warp door at the destination

View file

@ -163,15 +163,15 @@ public class PocketManager
public void onCreated(ClientLinkData link) public void onCreated(ClientLinkData link)
{ {
Point4D source = link.point; Point4D source = link.point;
NewDimData dimension = getDimensionData(source.getDimension()); NewDimData dimension = createDimensionData(source.getDimension());
dimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.CLIENT_SIDE,link.orientation); dimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.CLIENT_SIDE, link.orientation);
} }
@Override @Override
public void onDeleted(ClientLinkData link) public void onDeleted(ClientLinkData link)
{ {
Point4D source = link.point; Point4D source = link.point;
getDimensionData(source.getDimension()).deleteLink(source); createDimensionData(source.getDimension()).deleteLink(source);
} }
} }
@ -270,7 +270,6 @@ public class PocketManager
public static boolean registerPackedDimData(PackedDimData packedData) public static boolean registerPackedDimData(PackedDimData packedData)
{ {
InnerDimData dimData; InnerDimData dimData;
//register roots //register roots
if(packedData.ID==packedData.ParentID) if(packedData.ID==packedData.ParentID)
@ -290,7 +289,7 @@ public class PocketManager
dimData = new InnerDimData(packedData.ID, test,true, packedData.IsDungeon, linkWatcher); dimData = new InnerDimData(packedData.ID, test,true, packedData.IsDungeon, linkWatcher);
dimData.isFilled=packedData.IsFilled; dimData.isFilled=packedData.IsFilled;
dimData.origin = new Point4D(packedData.Origin.getX(),packedData.Origin.getY(),packedData.Origin.getZ(),packedData.ID); dimData.origin = new Point4D(packedData.Origin.getX(),packedData.Origin.getY(),packedData.Origin.getZ(),packedData.ID);
dimData.root=PocketManager.getDimensionData(packedData.RootID); dimData.root = PocketManager.createDimensionData(packedData.RootID);
if(packedData.DungeonData!=null) if(packedData.DungeonData!=null)
{ {
@ -413,8 +412,6 @@ public class PocketManager
*/ */
private static void loadInternal() private static void loadInternal()
{ {
//System.out.println(!FMLCommonHandler.instance().getSide().isClient());
File saveDir = DimensionManager.getCurrentSaveRootDirectory(); File saveDir = DimensionManager.getCurrentSaveRootDirectory();
if (saveDir != null) if (saveDir != null)
{ {
@ -501,11 +498,6 @@ public class PocketManager
return world; return world;
} }
public static NewDimData registerDimension(World world)
{
return registerDimension(world.provider.dimensionId, null, false, false);
}
public static NewDimData registerPocket(NewDimData parent, boolean isDungeon) public static NewDimData registerPocket(NewDimData parent, boolean isDungeon)
{ {
if (parent == null) if (parent == null)
@ -518,6 +510,7 @@ public class PocketManager
DimensionManager.registerDimension(dimensionID, properties.PocketProviderID); DimensionManager.registerDimension(dimensionID, properties.PocketProviderID);
return registerDimension(dimensionID, (InnerDimData) parent, true, isDungeon); return registerDimension(dimensionID, (InnerDimData) parent, true, isDungeon);
} }
/** /**
* Registers a dimension with DD but NOT with forge. * Registers a dimension with DD but NOT with forge.
* @param dimensionID * @param dimensionID
@ -548,16 +541,16 @@ public class PocketManager
} }
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
private static NewDimData registerClientDimension(int dimensionID, int rootID) protected static NewDimData registerClientDimension(int dimensionID, int rootID)
{ {
System.out.println("Registered dim "+dimensionID+" on the client."); // No need to raise events heres since this code should only run on the
// No need to raise events heres since this code should only run on the client side // client side. createDimensionData() always handles root dimensions
// getDimensionData() always handles root dimensions properly, even if the weren't defined before // properly, even if they weren't defined before.
// SenseiKiwi: I'm a little worried about how getDimensionData will raise // SenseiKiwi: I'm a little worried about how createDimensionData will raise
// an event when it creates any root dimensions... Needs checking later. // an event when it creates any root dimensions... Needs checking later.
InnerDimData root = (InnerDimData) getDimensionData(rootID); InnerDimData root = (InnerDimData) createDimensionData(rootID);
InnerDimData dimension; InnerDimData dimension;
if (rootID != dimensionID) if (rootID != dimensionID)
@ -573,7 +566,7 @@ public class PocketManager
{ {
dimension = root; dimension = root;
} }
if(dimension.isPocketDimension()&&!DimensionManager.isDimensionRegistered(dimension.id())) if (dimension.isPocketDimension() && !DimensionManager.isDimensionRegistered(dimension.id()))
{ {
//Im registering pocket dims here. I *think* we can assume that if its a pocket and we are //Im registering pocket dims here. I *think* we can assume that if its a pocket and we are
//registering its dim data, we also need to register it with forge. //registering its dim data, we also need to register it with forge.
@ -585,25 +578,28 @@ public class PocketManager
return dimension; return dimension;
} }
public static NewDimData getDimensionData(World world)
{
return getDimensionData(world.provider.dimensionId);
}
public static NewDimData getDimensionData(int dimensionID) public static NewDimData getDimensionData(int dimensionID)
{ {
//Retrieve the data for a dimension. If we don't have a record for that dimension, return PocketManager.dimensionData.get(dimensionID);
//assume it's a non-pocket dimension that hasn't been initialized with us before
//and create a NewDimData instance for it.
//Any pocket dimension must be listed with PocketManager to have a dimension ID
//assigned, so it's safe to assume that any unknown dimensions don't belong to us.
//FIXME: What's the point of this condition? Most calls to this function will crash anyway! ~SenseiKiwi
if(PocketManager.dimensionData == null)
{
System.out.println("Something odd happend during shutdown");
return null;
} }
public static NewDimData createDimensionData(World world)
{
return createDimensionData(world.provider.dimensionId);
}
public static NewDimData createDimensionDataDangerously(int dimensionID)
{
// Same as createDimensionData(int), but public. Meant to discourage anyone from
// using it unless absolutely needed! We'll probably phase this out eventually.
return createDimensionData(dimensionID);
}
protected static NewDimData createDimensionData(int dimensionID)
{
// Retrieve the data for a dimension. If we don't have a record for that dimension,
// assume it's a non-pocket dimension that hasn't been initialized with us before
// and create a NewDimData instance for it.
NewDimData dimension = PocketManager.dimensionData.get(dimensionID); NewDimData dimension = PocketManager.dimensionData.get(dimensionID);
if (dimension == null) if (dimension == null)
{ {

View file

@ -247,7 +247,7 @@ public class DungeonSchematic extends Schematic {
world.setBlockTileEntity(pocketPoint.getX(), pocketPoint.getY(), pocketPoint.getZ(), TileEntity.createAndLoadEntity(tileTag)); world.setBlockTileEntity(pocketPoint.getX(), pocketPoint.getY(), pocketPoint.getZ(), TileEntity.createAndLoadEntity(tileTag));
} }
setUpDungeon(PocketManager.getDimensionData(world), world, pocketCenter, turnAngle, entryLink, random, properties, blockSetter); setUpDungeon(PocketManager.createDimensionData(world), world, pocketCenter, turnAngle, entryLink, random, properties, blockSetter);
} }
private void setUpDungeon(NewDimData dimension, World world, Point3D pocketCenter, int turnAngle, DimLink entryLink, Random random, DDProperties properties, IBlockSetter blockSetter) private void setUpDungeon(NewDimData dimension, World world, Point3D pocketCenter, int turnAngle, DimLink entryLink, Random random, DDProperties properties, IBlockSetter blockSetter)

View file

@ -263,7 +263,7 @@ public class DungeonHelper
public DimLink createCustomDungeonDoor(World world, int x, int y, int z) public DimLink createCustomDungeonDoor(World world, int x, int y, int z)
{ {
//Create a link above the specified position. Link to a new pocket dimension. //Create a link above the specified position. Link to a new pocket dimension.
NewDimData dimension = PocketManager.getDimensionData(world); NewDimData dimension = PocketManager.createDimensionData(world);
DimLink link = dimension.createLink(x, y + 1, z, LinkTypes.POCKET, 3); DimLink link = dimension.createLink(x, y + 1, z, LinkTypes.POCKET, 3);
//Place a Warp Door linked to that pocket //Place a Warp Door linked to that pocket

View file

@ -74,7 +74,7 @@ public class ItemRiftSignature extends Item
// The link was used before and already has an endpoint stored. // The link was used before and already has an endpoint stored.
// Create links connecting the two endpoints. // Create links connecting the two endpoints.
NewDimData sourceDimension = PocketManager.getDimensionData(source.getDimension()); NewDimData sourceDimension = PocketManager.getDimensionData(source.getDimension());
NewDimData destinationDimension = PocketManager.getDimensionData(world); NewDimData destinationDimension = PocketManager.createDimensionData(world);
DimLink link = sourceDimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.NORMAL,source.getOrientation()); DimLink link = sourceDimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.NORMAL,source.getOrientation());
DimLink reverse = destinationDimension.createLink(x, adjustedY, z, LinkTypes.NORMAL,orientation); DimLink reverse = destinationDimension.createLink(x, adjustedY, z, LinkTypes.NORMAL,orientation);
destinationDimension.setLinkDestination(link, x, adjustedY, z); destinationDimension.setLinkDestination(link, x, adjustedY, z);
@ -99,7 +99,7 @@ public class ItemRiftSignature extends Item
else else
{ {
//The link signature has not been used. Store its current target as the first location. //The link signature has not been used. Store its current target as the first location.
setSource(stack, x, adjustedY, z,orientation, PocketManager.getDimensionData(world)); setSource(stack, x, adjustedY, z, orientation, PocketManager.createDimensionData(world));
mod_pocketDim.sendChat(player,("Location Stored in Rift Signature")); mod_pocketDim.sendChat(player,("Location Stored in Rift Signature"));
world.playSoundAtEntity(player,mod_pocketDim.modid+":riftStart", 0.6f, 1); world.playSoundAtEntity(player,mod_pocketDim.modid+":riftStart", 0.6f, 1);
} }

View file

@ -53,7 +53,7 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature
{ {
// Yes, it's initialized. // Yes, it's initialized.
NewDimData sourceDimension = PocketManager.getDimensionData(source.getDimension()); NewDimData sourceDimension = PocketManager.getDimensionData(source.getDimension());
NewDimData destinationDimension = PocketManager.getDimensionData(world); NewDimData destinationDimension = PocketManager.createDimensionData(world);
DimLink reverse = destinationDimension.getLink(x, adjustedY, z); DimLink reverse = destinationDimension.getLink(x, adjustedY, z);
DimLink link; DimLink link;
@ -104,7 +104,7 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature
else else
{ {
// The link signature has not been used. Store its current target as the first location. // The link signature has not been used. Store its current target as the first location.
setSource(stack, x, adjustedY, z, orientation, PocketManager.getDimensionData(world)); setSource(stack, x, adjustedY, z, orientation, PocketManager.createDimensionData(world));
mod_pocketDim.sendChat(player, "Location Stored in Stabilized Rift Signature"); mod_pocketDim.sendChat(player, "Location Stored in Stabilized Rift Signature");
world.playSoundAtEntity(player, "mods.DimDoors.sfx.riftStart", 0.6f, 1); world.playSoundAtEntity(player, "mods.DimDoors.sfx.riftStart", 0.6f, 1);
} }
@ -129,7 +129,7 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature
if (source != null) if (source != null)
{ {
NewDimData sourceDimension = PocketManager.getDimensionData(source.getDimension()); NewDimData sourceDimension = PocketManager.getDimensionData(source.getDimension());
NewDimData destinationDimension = PocketManager.getDimensionData(world); NewDimData destinationDimension = PocketManager.createDimensionData(world);
DimLink reverse = destinationDimension.getLink(x, adjustedY, z); DimLink reverse = destinationDimension.getLink(x, adjustedY, z);
DimLink link; DimLink link;

View file

@ -54,7 +54,7 @@ public class itemRiftRemover extends Item
int hx = hit.blockX; int hx = hit.blockX;
int hy = hit.blockY; int hy = hit.blockY;
int hz = hit.blockZ; int hz = hit.blockZ;
NewDimData dimension = PocketManager.getDimensionData(world); NewDimData dimension = PocketManager.createDimensionData(world);
DimLink link = dimension.getLink(hx, hy, hz); DimLink link = dimension.getLink(hx, hy, hz);
if (world.getBlockId(hx, hy, hz) == mod_pocketDim.blockRift.blockID && link != null && if (world.getBlockId(hx, hy, hz) == mod_pocketDim.blockRift.blockID && link != null &&
player.canPlayerEdit(hx, hy, hz, hit.sideHit, stack)) player.canPlayerEdit(hx, hy, hz, hit.sideHit, stack))
@ -85,7 +85,7 @@ public class itemRiftRemover extends Item
y = hit.blockY; y = hit.blockY;
z = hit.blockZ; z = hit.blockZ;
NewDimData dimension = PocketManager.getDimensionData(world); NewDimData dimension = PocketManager.createDimensionData(world);
DimLink link = dimension.getLink(x, y, z); DimLink link = dimension.getLink(x, y, z);
if (world.getBlockId(x, y, z) == mod_pocketDim.blockRift.blockID && link != null && if (world.getBlockId(x, y, z) == mod_pocketDim.blockRift.blockID && link != null &&
player.canPlayerEdit(x, y, z, side, stack)) player.canPlayerEdit(x, y, z, side, stack))

View file

@ -189,7 +189,7 @@ public class DDSaveHandler
{ {
if(packedLink.parent.equals(fakePoint)) if(packedLink.parent.equals(fakePoint))
{ {
NewDimData data = PocketManager.getDimensionData(packedLink.source.getDimension()); NewDimData data = PocketManager.createDimensionDataDangerously(packedLink.source.getDimension());
int linkType = packedLink.tail.linkType; int linkType = packedLink.tail.linkType;
if((linkType < LinkTypes.ENUM_MIN || linkType > LinkTypes.ENUM_MAX) && linkType != LinkTypes.CLIENT_SIDE) if((linkType < LinkTypes.ENUM_MIN || linkType > LinkTypes.ENUM_MAX) && linkType != LinkTypes.CLIENT_SIDE)
@ -201,7 +201,7 @@ public class DDSaveHandler
Point4D destination = packedLink.tail.destination; Point4D destination = packedLink.tail.destination;
if(destination!=null) if(destination!=null)
{ {
PocketManager.getDimensionData(destination.getDimension()).setLinkDestination(link, destination.getX(),destination.getY(),destination.getZ()); PocketManager.createDimensionDataDangerously(destination.getDimension()).setLinkDestination(link, destination.getX(),destination.getY(),destination.getZ());
} }
unpackedLinks.add(packedLink); unpackedLinks.add(packedLink);
} }
@ -213,7 +213,7 @@ public class DDSaveHandler
{ {
for(PackedLinkData packedLink : linksToUnpack) for(PackedLinkData packedLink : linksToUnpack)
{ {
NewDimData data = PocketManager.getDimensionData(packedLink.source.getDimension()); NewDimData data = PocketManager.createDimensionDataDangerously(packedLink.source.getDimension());
if(data.getLink(packedLink.parent)!=null) if(data.getLink(packedLink.parent)!=null)
{ {
data.createChildLink(packedLink.source.getX(), packedLink.source.getY(), packedLink.source.getZ(), data.getLink(packedLink.parent)); data.createChildLink(packedLink.source.getX(), packedLink.source.getY(), packedLink.source.getZ(), data.getLink(packedLink.parent));

View file

@ -46,7 +46,7 @@ public class TileEntityDimDoorGold extends TileEntityDimDoor implements IChunkLo
// link associated with it. // link associated with it.
if (!worldObj.isRemote) if (!worldObj.isRemote)
{ {
NewDimData dimension = PocketManager.getDimensionData(worldObj); NewDimData dimension = PocketManager.createDimensionData(worldObj);
// Check whether a ticket has already been assigned to this door // Check whether a ticket has already been assigned to this door
if (chunkTicket == null) if (chunkTicket == null)

View file

@ -137,7 +137,7 @@ public class TileEntityRift extends DDTileEntityBase
private void closeRift() private void closeRift()
{ {
NewDimData dimension = PocketManager.getDimensionData(worldObj); NewDimData dimension = PocketManager.createDimensionData(worldObj);
if (closeTimer == CLOSING_PERIOD / 2) if (closeTimer == CLOSING_PERIOD / 2)
{ {
for (DimLink riftLink : dimension.findRiftsInRange(worldObj, 6, xCoord, yCoord, zCoord)) for (DimLink riftLink : dimension.findRiftsInRange(worldObj, 6, xCoord, yCoord, zCoord))
@ -167,7 +167,7 @@ public class TileEntityRift extends DDTileEntityBase
public boolean updateNearestRift() public boolean updateNearestRift()
{ {
Point4D previousNearest = nearestRiftLocation; Point4D previousNearest = nearestRiftLocation;
DimLink nearestRiftLink = PocketManager.getDimensionData(worldObj).findNearestRift( DimLink nearestRiftLink = PocketManager.createDimensionData(worldObj).findNearestRift(
worldObj, RIFT_INTERACTION_RANGE, xCoord, yCoord, zCoord); worldObj, RIFT_INTERACTION_RANGE, xCoord, yCoord, zCoord);
nearestRiftLocation = (nearestRiftLink == null) ? null : nearestRiftLink.source(); nearestRiftLocation = (nearestRiftLink == null) ? null : nearestRiftLink.source();
@ -221,7 +221,7 @@ public class TileEntityRift extends DDTileEntityBase
return; return;
} }
NewDimData dimension = PocketManager.getDimensionData(worldObj); NewDimData dimension = PocketManager.createDimensionData(worldObj);
DimLink link = dimension.getLink(xCoord, yCoord, zCoord); DimLink link = dimension.getLink(xCoord, yCoord, zCoord);
if (link.childCount() >= MAX_CHILD_LINKS || countAncestorLinks(link) >= MAX_ANCESTOR_LINKS) if (link.childCount() >= MAX_CHILD_LINKS || countAncestorLinks(link) >= MAX_ANCESTOR_LINKS)

View file

@ -3,6 +3,7 @@ package StevenDimDoors.mod_pocketDim.world;
import java.util.Random; import java.util.Random;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.item.ItemDoor;
import net.minecraft.util.MathHelper; import net.minecraft.util.MathHelper;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.Chunk;
@ -21,7 +22,6 @@ import StevenDimDoors.mod_pocketDim.dungeon.DungeonSchematic;
import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPackConfig; import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPackConfig;
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper; import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper;
import StevenDimDoors.mod_pocketDim.items.ItemDimensionalDoor;
import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; import StevenDimDoors.mod_pocketDim.schematic.BlockRotator;
import StevenDimDoors.mod_pocketDim.util.Pair; import StevenDimDoors.mod_pocketDim.util.Pair;
import StevenDimDoors.mod_pocketDim.util.Point4D; import StevenDimDoors.mod_pocketDim.util.Point4D;
@ -40,87 +40,6 @@ public class PocketBuilder
private PocketBuilder() { } private PocketBuilder() { }
/**
* Method that takes an arbitrary link into a dungeon pocket and tries to regenerate it. First uses the origin to find that link,
* then uses that link to find the link that originally created the dungeon. If it cant find any of these, it
* instead makes the link that lead to this point into an exit door style link, sending the player to the overworld.
* @param dimension The dungeon to be regenerated
* @param linkIn The link leading somewhere into the dungeon.
* @param properties
* @return
*/
public static boolean regenerateDungeonPocket(NewDimData dimension, DimLink linkIn, DDProperties properties)
{
if (linkIn == null)
{
throw new IllegalArgumentException("link cannot be null.");
}
if (properties == null)
{
throw new IllegalArgumentException("properties cannot be null.");
}
//The link that is at the origin of the dungeon
DimLink originLink = dimension.getLink(dimension.origin());
Point4D oldLinkPos = linkIn.source();
if(originLink==null)
{
int orientation = linkIn.orientation();
originLink=dimension.createLink(oldLinkPos, LinkTypes.SAFE_EXIT, (orientation+2)%4);
return false;
}
//The link that originally created the dungeon on the way in
DimLink incomingLink = PocketManager.getLink(originLink.destination());
if(incomingLink==null||incomingLink.linkType()!=LinkTypes.DUNGEON||!(originLink.linkType()==LinkTypes.REVERSE))
{
int orientation = linkIn.orientation();
dimension.deleteLink(originLink);
dimension.createLink(oldLinkPos, LinkTypes.SAFE_EXIT, (orientation+2)%4);
return false;
}
NewDimData parent = PocketManager.getDimensionData(incomingLink.source().getDimension());
if (!dimension.isDungeon())
{
throw new IllegalArgumentException("destination must be dungeon");
}
if (dimension.isFilled())
{
throw new IllegalArgumentException("destination must be empty");
}
if (!dimension.isInitialized())
{
throw new IllegalArgumentException("destination must already exist");
}
try
{
//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;
}
DungeonSchematic schematic = loadAndValidateDungeon(dimension.dungeon(), properties);
if (schematic == null)
{
return false;
}
Point3D destination = new Point3D(incomingLink.destination());
schematic.copyToWorld(world, destination, originLink.orientation(), incomingLink, random, properties, false);
dimension.setFilled(true);
return true;
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
}
private static boolean buildDungeonPocket(DungeonData dungeon, NewDimData dimension, DimLink link, DungeonSchematic schematic, World world, DDProperties properties) private static boolean buildDungeonPocket(DungeonData dungeon, NewDimData dimension, DimLink link, DungeonSchematic schematic, World world, DDProperties properties)
{ {
//Calculate the destination point //Calculate the destination point
@ -479,7 +398,7 @@ public class PocketBuilder
//Build the door //Build the door
int doorOrientation = BlockRotator.transformMetadata(BlockRotator.EAST_DOOR_METADATA, orientation - BlockRotator.EAST_DOOR_METADATA + 2, properties.DimensionalDoorID); int doorOrientation = BlockRotator.transformMetadata(BlockRotator.EAST_DOOR_METADATA, orientation - BlockRotator.EAST_DOOR_METADATA + 2, properties.DimensionalDoorID);
ItemDimensionalDoor.placeDoorBlock(world, x, y - 1, z, doorOrientation, doorBlock); ItemDoor.placeDoorBlock(world, x, y - 1, z, doorOrientation, doorBlock);
} }
private static void buildBox(World world, int centerX, int centerY, int centerZ, int radius, int blockID, boolean placeTnt, int nonTntWeight) private static void buildBox(World world, int centerX, int centerY, int centerZ, int radius, int blockID, boolean placeTnt, int nonTntWeight)

View file

@ -68,7 +68,7 @@ public class PocketGenerator extends ChunkProviderGenerate
@Override @Override
public List getPossibleCreatures(EnumCreatureType var1, int var2, int var3, int var4) public List getPossibleCreatures(EnumCreatureType var1, int var2, int var3, int var4)
{ {
NewDimData dimension = PocketManager.getDimensionData(this.worldObj); NewDimData dimension = PocketManager.createDimensionData(this.worldObj);
if (dimension != null && dimension.dungeon() != null && !dimension.dungeon().isOpen()) if (dimension != null && dimension.dungeon() != null && !dimension.dungeon().isOpen())
{ {
return this.worldObj.getBiomeGenForCoords(var2, var3).getSpawnableList(var1); return this.worldObj.getBiomeGenForCoords(var2, var3).getSpawnableList(var1);

View file

@ -7,7 +7,6 @@ import net.minecraft.world.WorldProvider;
import net.minecraft.world.biome.WorldChunkManagerHell; import net.minecraft.world.biome.WorldChunkManagerHell;
import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.chunk.IChunkProvider;
import net.minecraftforge.client.IRenderHandler; import net.minecraftforge.client.IRenderHandler;
import net.minecraftforge.common.DimensionManager;
import StevenDimDoors.mod_pocketDim.CloudRenderBlank; import StevenDimDoors.mod_pocketDim.CloudRenderBlank;
import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.config.DDProperties; import StevenDimDoors.mod_pocketDim.config.DDProperties;
@ -103,11 +102,8 @@ public class PocketProvider extends WorldProvider
{ {
respawnDim = PocketManager.getDimensionData(this.dimensionId).root().id(); respawnDim = PocketManager.getDimensionData(this.dimensionId).root().id();
} }
// TODO: Are we sure we need to load the dimension as well? Why can't the game handle that?
if (DimensionManager.getWorld(respawnDim) == null) PocketManager.loadDimension(respawnDim);
{
DimensionManager.initDimension(respawnDim);
}
return respawnDim; return respawnDim;
} }

View file

@ -154,7 +154,7 @@ public class ComponentNetherGateway extends StructureComponent
if (bounds.isVecInside(x, y, z) && bounds.isVecInside(x, y + 1, z)) if (bounds.isVecInside(x, y, z) && bounds.isVecInside(x, y + 1, z))
{ {
orientation = this.getMetadataWithOffset(Block.doorWood.blockID, 1); orientation = this.getMetadataWithOffset(Block.doorWood.blockID, 1);
dimension = PocketManager.getDimensionData(world); dimension = PocketManager.createDimensionData(world);
link = dimension.getLink(x, y + 1, z); link = dimension.getLink(x, y + 1, z);
if (link == null) if (link == null)
{ {

View file

@ -44,7 +44,7 @@ public abstract class BaseSchematicGateway extends BaseGateway
this.generateRandomBits(world, x, y, z); this.generateRandomBits(world, x, y, z);
// Generate a dungeon link in the door // Generate a dungeon link in the door
PocketManager.getDimensionData(world).createLink(x, y + doorLocation.getY(), z, LinkTypes.DUNGEON, orientation); PocketManager.createDimensionData(world).createLink(x, y + doorLocation.getY(), z, LinkTypes.DUNGEON, orientation);
return true; return true;
} }

View file

@ -106,7 +106,7 @@ public class GatewayGenerator implements IWorldGenerator
//Create a link. If this is not the first time, create a child link and connect it to the first link. //Create a link. If this is not the first time, create a child link and connect it to the first link.
if (link == null) if (link == null)
{ {
dimension = PocketManager.getDimensionData(world); dimension = PocketManager.createDimensionData(world);
link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON,0); link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON,0);
} }
else else

View file

@ -30,7 +30,7 @@ public class GatewayLimbo extends BaseGateway
world.setBlock(x, y + 1, z - 1, blockID, 0, 3); world.setBlock(x, y + 1, z - 1, blockID, 0, 3);
world.setBlock(x, y + 1, z + 1, blockID, 0, 3); world.setBlock(x, y + 1, z + 1, blockID, 0, 3);
PocketManager.getDimensionData(world).createLink(x, y + 2, z, LinkTypes.DUNGEON, 0); PocketManager.createDimensionData(world).createLink(x, y + 2, z, LinkTypes.DUNGEON, 0);
ItemDoor.placeDoorBlock(world, x, y + 1, z, 0, mod_pocketDim.transientDoor); ItemDoor.placeDoorBlock(world, x, y + 1, z, 0, mod_pocketDim.transientDoor);
return true; return true;
} }

View file

@ -100,7 +100,7 @@ public class ClosingRiftFX extends EntityFX
float var15 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * par2 - interpPosZ); float var15 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * par2 - interpPosZ);
float var16 = 0.8F; float var16 = 0.8F;
if (PocketManager.getDimensionData(worldObj).isPocketDimension()) if (PocketManager.createDimensionData(worldObj).isPocketDimension())
{ {
var16 = 0.4F; var16 = 0.4F;
} }

View file

@ -54,7 +54,7 @@ public class GoggleRiftFX extends EntityFireworkSparkFX
float var15 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * par2 - interpPosZ); float var15 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * par2 - interpPosZ);
float var16 = .0F; float var16 = .0F;
if (PocketManager.getDimensionData(worldObj).isPocketDimension()) if (PocketManager.createDimensionData(worldObj).isPocketDimension())
{ {
var16 = .7F; var16 = .7F;
} }

View file

@ -111,7 +111,7 @@ public class RiftFX extends EntityFX
float f13 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * par2 - interpPosZ); float f13 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * par2 - interpPosZ);
float f14 = 0F; float f14 = 0F;
if (PocketManager.getDimensionData(worldObj).isPocketDimension()) if (PocketManager.createDimensionData(worldObj).isPocketDimension())
{ {
f14 = 0.7F; f14 = 0.7F;
} }