Merging Canvox's patch #105

Merged
StevenRS11 merged 31 commits from master into master 2013-12-17 01:52:53 +00:00
11 changed files with 207 additions and 116 deletions
Showing only changes of commit b18fe877de - Show all commits

View File

@@ -230,13 +230,13 @@ public class DDProperties
"Sets the chance (out of " + MonolithSpawner.MAX_MONOLITH_SPAWNING_CHANCE + ") that Monoliths will " + "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(); "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 " + "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 " + "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(); LimboBiomeID = config.get(CATEGORY_BIOME, "Limbo Biome ID", 251).getInt();
PocketBiomeID = config.get(CATEGORY_BIOME, "Pocket Biome ID", 250).getInt(); PocketBiomeID = config.get(CATEGORY_BIOME, "Pocket Biome ID", 250).getInt();

View File

@@ -96,7 +96,7 @@ public class TransTrapdoor extends BlockTrapDoor implements IDimDoor, ITileEntit
DimLink link = dimension.getLink(x, y, z); DimLink link = dimension.getLink(x, y, z);
if (link == null && dimension.isPocketDimension()) if (link == null && dimension.isPocketDimension())
{ {
dimension.createLink(x, y, z, LinkTypes.UNSAFE_EXIT); dimension.createLink(x, y, z, LinkTypes.UNSAFE_EXIT,0);
} }
} }
} }

View File

@@ -7,6 +7,7 @@ import StevenDimDoors.mod_pocketDim.core.NewDimData;
import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.core.PocketManager;
import StevenDimDoors.mod_pocketDim.dungeon.DungeonData; import StevenDimDoors.mod_pocketDim.dungeon.DungeonData;
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
import StevenDimDoors.mod_pocketDim.world.PocketBuilder;
import java.util.Collection; import java.util.Collection;
@@ -73,7 +74,7 @@ public class CommandCreateDungeonRift extends DDCommandBase
{ {
dimension = PocketManager.getDimensionData(sender.worldObj); 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); 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."));
@@ -86,16 +87,17 @@ public class CommandCreateDungeonRift extends DDCommandBase
result = findDungeonByPartialName(command[0], dungeonHelper.getUntaggedDungeons()); result = findDungeonByPartialName(command[0], dungeonHelper.getUntaggedDungeons());
} }
//Check if we found any matches //Check if we found any matches
if (result != null) if (result != null)
{ {
//Create a rift to our selected dungeon and notify the player //Create a rift to our selected dungeon and notify the player
//TODO currently crashes, need to create the dimension first //TODO currently crashes, need to create the dimension first
dimension = PocketManager.getDimensionData(sender.worldObj); dimension = PocketManager.getDimensionData(sender.worldObj);
link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON); link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON,orientation);
PocketManager.getDimensionData(link.destination().getDimension()).initializeDungeon(x, y + 1, z, orientation,link, result); 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() + ").")); 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 else
{ {
//No matches! //No matches!

View File

@@ -245,10 +245,6 @@ public abstract class NewDimData
{ {
return Math.abs(i) + Math.abs(j) + Math.abs(k); 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) public DimLink createLink(int x, int y, int z, int linkType,int orientation)
{ {
return createLink(new Point4D(x, y, z, id), linkType,orientation); return createLink(new Point4D(x, y, z, id), linkType,orientation);

View File

@@ -27,6 +27,7 @@ import StevenDimDoors.mod_pocketDim.saving.PackedLinkData;
import StevenDimDoors.mod_pocketDim.saving.PackedLinkTail; import StevenDimDoors.mod_pocketDim.saving.PackedLinkTail;
import StevenDimDoors.mod_pocketDim.util.Point4D; import StevenDimDoors.mod_pocketDim.util.Point4D;
import StevenDimDoors.mod_pocketDim.watcher.ClientDimData; import StevenDimDoors.mod_pocketDim.watcher.ClientDimData;
import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData;
import StevenDimDoors.mod_pocketDim.watcher.IUpdateSource; import StevenDimDoors.mod_pocketDim.watcher.IUpdateSource;
import StevenDimDoors.mod_pocketDim.watcher.IUpdateWatcher; import StevenDimDoors.mod_pocketDim.watcher.IUpdateWatcher;
import StevenDimDoors.mod_pocketDim.watcher.UpdateWatcherProxy; import StevenDimDoors.mod_pocketDim.watcher.UpdateWatcherProxy;
@@ -154,22 +155,24 @@ public class PocketManager
} }
} }
private static class ClientLinkWatcher implements IUpdateWatcher<Point4D> private static class ClientLinkWatcher implements IUpdateWatcher<ClientLinkData>
{ {
@Override @Override
public void onCreated(Point4D source) public void onCreated(ClientLinkData link)
{ {
NewDimData dimension = getDimensionData(source.getDimension()); Point4D source = link.point;
dimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.CLIENT_SIDE); NewDimData dimension = getDimensionData(source.getDimension());
} dimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.CLIENT_SIDE,link.orientation);
}
@Override @Override
public void onDeleted(Point4D source) public void onDeleted(ClientLinkData link)
{ {
NewDimData dimension = getDimensionData(source.getDimension()); Point4D source = link.point;
dimension.deleteLink(source.getX(), source.getY(), source.getZ()); NewDimData dimension = getDimensionData(source.getDimension());
} dimension.deleteLink(source.getX(), source.getY(), source.getZ());
} }
}
private static class ClientDimWatcher implements IUpdateWatcher<ClientDimData> private static class ClientDimWatcher implements IUpdateWatcher<ClientDimData>
{ {

View File

@@ -12,6 +12,7 @@ import StevenDimDoors.mod_pocketDim.core.IDimRegistrationCallback;
import StevenDimDoors.mod_pocketDim.core.LinkTypes; import StevenDimDoors.mod_pocketDim.core.LinkTypes;
import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.NewDimData;
import StevenDimDoors.mod_pocketDim.util.Point4D; import StevenDimDoors.mod_pocketDim.util.Point4D;
import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData;
public class Compactor public class Compactor
{ {
@@ -76,8 +77,9 @@ public class Compactor
int linkCount = input.readInt(); int linkCount = input.readInt();
for (int h = 0; h < linkCount; h++) for (int h = 0; h < linkCount; h++)
{ {
Point4D source = Point4D.read(input); ClientLinkData link = ClientLinkData.read(input);
dimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.CLIENT_SIDE); Point4D source = link.point;
dimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.CLIENT_SIDE,link.orientation);
} }
} }
} }

View File

@@ -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());
}
}

View File

@@ -4,5 +4,5 @@ import StevenDimDoors.mod_pocketDim.util.Point4D;
public interface IUpdateSource public interface IUpdateSource
{ {
public void registerWatchers(IUpdateWatcher<ClientDimData> dimWatcher, IUpdateWatcher<Point4D> linkWatcher); public void registerWatchers(IUpdateWatcher<ClientDimData> dimWatcher, IUpdateWatcher<ClientLinkData> linkWatcher);
} }

View File

@@ -101,7 +101,7 @@ public class GatewayGenerator implements IWorldGenerator
if (link == null) if (link == null)
{ {
dimension = PocketManager.getDimensionData(world); dimension = PocketManager.getDimensionData(world);
link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON); link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON,0);
} }
else else
{ {
@@ -136,7 +136,7 @@ public class GatewayGenerator implements IWorldGenerator
{ {
//Create a partial link to a dungeon. //Create a partial link to a dungeon.
dimension = PocketManager.getDimensionData(world); 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 the current dimension isn't Limbo, build a Rift Gateway out of Stone Bricks
if (dimension.id() != properties.LimboDimensionID) if (dimension.id() != properties.LimboDimensionID)

View File

@@ -119,79 +119,128 @@ public class PocketBuilder
} }
public static boolean generateNewDungeonPocket(DimLink link, DDProperties properties) private static boolean buildDungeonPocket(DungeonData dungeon, NewDimData dimension, DimLink link, DungeonSchematic schematic,World world, 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()) //Calculate the destination point
{ DungeonPackConfig packConfig = dungeon.dungeonType().Owner != null ? dungeon.dungeonType().Owner.getConfig() : null;
throw new IllegalArgumentException("link cannot have a destination assigned already."); 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;
try }
{
//Register a new dimension
NewDimData parent = PocketManager.getDimensionData(link.source().getDimension());
NewDimData dimension = PocketManager.registerPocket(parent, true);
//Load a world public static boolean generateSelectedDungeonPocket(DimLink link, DDProperties properties,DungeonData data)
World world = PocketManager.loadDimension(dimension.id()); {
if (link == null)
{
throw new IllegalArgumentException("link cannot be null.");
}
if (properties == null)
{
throw new IllegalArgumentException("properties cannot be null.");
}
if (world == null || world.provider == null) if (link.hasDestination())
{ {
System.err.println("Could not initialize dimension for a dungeon!"); throw new IllegalArgumentException("link cannot have a destination assigned already.");
return false; }
}
//Choose a dungeon to generate
Pair<DungeonData, DungeonSchematic> 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()) //Register a new dimension
{ NewDimData parent = PocketManager.getDimensionData(link.source().getDimension());
destination = calculateNoisyDestination(source, dimension, dungeon, orientation); NewDimData dimension = PocketManager.registerPocket(parent, true);
}
else
{
destination = new Point3D(source.getX(), source.getY(), source.getZ());
}
destination.setY( yCoordHelper.adjustDestinationY(destination.getY(), world.getHeight(), schematic.getEntranceDoorLocation().getY(), schematic.getHeight()) ); //Load a world
World world = PocketManager.loadDimension(dimension.id());
//Generate the dungeon if (world == null || world.provider == null)
schematic.copyToWorld(world, destination, orientation, link, random); {
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<DungeonData, DungeonSchematic> 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);
}
//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;
}
}
private static Point3D calculateNoisyDestination(Point4D source, NewDimData dimension, DungeonData dungeon, int orientation) private static Point3D calculateNoisyDestination(Point4D source, NewDimData dimension, DungeonData dungeon, int orientation)
{ {

View File

@@ -4,6 +4,7 @@ import StevenDimDoors.mod_pocketDim.PacketConstants;
import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.core.PocketManager;
import StevenDimDoors.mod_pocketDim.util.Point4D; import StevenDimDoors.mod_pocketDim.util.Point4D;
import StevenDimDoors.mod_pocketDim.watcher.ClientDimData; import StevenDimDoors.mod_pocketDim.watcher.ClientDimData;
import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData;
import StevenDimDoors.mod_pocketDim.watcher.IUpdateSource; import StevenDimDoors.mod_pocketDim.watcher.IUpdateSource;
import StevenDimDoors.mod_pocketDim.watcher.IUpdateWatcher; import StevenDimDoors.mod_pocketDim.watcher.IUpdateWatcher;
@@ -20,7 +21,7 @@ import net.minecraft.server.integrated.IntegratedServer;
public class ClientPacketHandler implements IPacketHandler, IUpdateSource public class ClientPacketHandler implements IPacketHandler, IUpdateSource
{ {
private IUpdateWatcher<Point4D> linkWatcher; private IUpdateWatcher<ClientLinkData> linkWatcher;
private IUpdateWatcher<ClientDimData> dimWatcher; private IUpdateWatcher<ClientDimData> dimWatcher;
public ClientPacketHandler() public ClientPacketHandler()
@@ -29,7 +30,7 @@ public class ClientPacketHandler implements IPacketHandler, IUpdateSource
} }
@Override @Override
public void registerWatchers(IUpdateWatcher<ClientDimData> dimWatcher, IUpdateWatcher<Point4D> linkWatcher) public void registerWatchers(IUpdateWatcher<ClientDimData> dimWatcher, IUpdateWatcher<ClientLinkData> linkWatcher)
{ {
this.dimWatcher = dimWatcher; this.dimWatcher = dimWatcher;
this.linkWatcher = linkWatcher; this.linkWatcher = linkWatcher;
@@ -59,13 +60,13 @@ public class ClientPacketHandler implements IPacketHandler, IUpdateSource
dimWatcher.onCreated( ClientDimData.read(input) ); dimWatcher.onCreated( ClientDimData.read(input) );
break; break;
case PacketConstants.CREATE_LINK_PACKET_ID: case PacketConstants.CREATE_LINK_PACKET_ID:
linkWatcher.onCreated( Point4D.read(input) ); linkWatcher.onCreated( ClientLinkData.read(input) );
break; break;
case PacketConstants.DELETE_DIM_PACKET_ID: case PacketConstants.DELETE_DIM_PACKET_ID:
dimWatcher.onDeleted( ClientDimData.read(input) ); dimWatcher.onDeleted( ClientDimData.read(input) );
break; break;
case PacketConstants.DELETE_LINK_PACKET_ID: case PacketConstants.DELETE_LINK_PACKET_ID:
linkWatcher.onDeleted( Point4D.read(input) ); linkWatcher.onDeleted( ClientLinkData.read(input) );
break; break;
} }
} }