Fixed DungeonSchematic

Modified DungeonSchematic to use the new link and dimension classes.
This commit is contained in:
SenseiKiwi 2013-08-30 10:57:08 -04:00
parent 934dcfde3d
commit 8e8346864e

View file

@ -14,19 +14,19 @@ import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.DDProperties;
import StevenDimDoors.mod_pocketDim.Point3D;
import StevenDimDoors.mod_pocketDim.core.NewLinkData;
import StevenDimDoors.mod_pocketDim.core.IDimLink;
import StevenDimDoors.mod_pocketDim.core.NewDimData;
import StevenDimDoors.mod_pocketDim.core.PocketManager;
import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper;
import StevenDimDoors.mod_pocketDim.schematic.BlockRotator;
import StevenDimDoors.mod_pocketDim.schematic.CompoundFilter;
import StevenDimDoors.mod_pocketDim.schematic.InvalidSchematicException;
import StevenDimDoors.mod_pocketDim.schematic.ReplacementFilter;
import StevenDimDoors.mod_pocketDim.schematic.Schematic;
import StevenDimDoors.mod_pocketDim.ticking.MobMonolith;
import StevenDimDoors.mod_pocketDim.util.Point4D;
public class DungeonSchematic extends Schematic {
@ -167,10 +167,10 @@ public class DungeonSchematic extends Schematic {
return new DungeonSchematic(Schematic.copyFromWorld(world, x, y, z, width, height, length, doCompactBounds));
}
public void copyToWorld(World world, Point3D pocketCenter, int dungeonOrientation, int originDimID, int destDimID, boolean doDistortCoordinates)
public void copyToWorld(World world, Point3D pocketCenter, int dungeonOrientation, IDimLink entryLink)
{
//TODO: This function is an improvised solution so we can get the release moving. In the future,
//we should generalize block tranformations and implement support for them at the level of Schematic,
//we should generalize block transformations and implement support for them at the level of Schematic,
//then just use that support from DungeonSchematic instead of making this local fix.
//It might be easiest to support transformations using a WorldOperation
@ -222,10 +222,10 @@ public class DungeonSchematic extends Schematic {
world.setBlockTileEntity(pocketPoint.getX(), pocketPoint.getY(), pocketPoint.getZ(), TileEntity.createAndLoadEntity(tileTag));
}
setUpDungeon(world, pocketCenter, turnAngle, originDimID, destDimID, doDistortCoordinates);
setUpDungeon(PocketManager.getDimensionData(world), world, pocketCenter, turnAngle, entryLink);
}
private void setUpDungeon(World world, Point3D pocketCenter, int turnAngle, int originDimID, int destDimID, boolean doDistortCoordinates)
private void setUpDungeon(NewDimData dimension, World world, Point3D pocketCenter, int turnAngle, IDimLink entryLink)
{
//The following Random initialization code is based on code from ChunkProviderGenerate.
//It makes our generation depend on the world seed.
@ -244,18 +244,18 @@ public class DungeonSchematic extends Schematic {
filler.apply(world, minCorner, maxCorner);
//Set up entrance door rift
setUpEntranceDoorLink(world, entranceDoorLocation, turnAngle, pocketCenter);
createEntranceReverseLink(dimension, pocketCenter, entryLink);
//Set up link data for dimensional doors
for (Point3D location : dimensionalDoorLocations)
{
setUpDimensionalDoorLink(world, location, entranceDoorLocation, turnAngle, pocketCenter, originDimID, destDimID, doDistortCoordinates, random);
createDimensionalDoorLink(dimension, location, entranceDoorLocation, turnAngle, pocketCenter);
}
//Set up link data for exit door
for (Point3D location : exitDoorLocations)
{
setUpExitDoorLink(world, location, entranceDoorLocation, turnAngle, pocketCenter, originDimID, destDimID, random);
createExitDoorLink(dimension, location, entranceDoorLocation, turnAngle, pocketCenter);
}
//Remove end portal frames and spawn Monoliths
@ -290,130 +290,28 @@ public class DungeonSchematic extends Schematic {
}
}
private static void setUpEntranceDoorLink(World world, Point3D entrance, int rotation, Point3D pocketCenter)
private static void createEntranceReverseLink(NewDimData dimension, Point3D pocketCenter, IDimLink entryLink)
{
//Set the orientation of the rift exit
Point3D entranceRiftLocation = entrance.clone();
BlockRotator.transformPoint(entranceRiftLocation, entrance, rotation, pocketCenter);
NewLinkData sideLink = PocketManager.instance.getLinkDataFromCoords(
entranceRiftLocation.getX(),
entranceRiftLocation.getY(),
entranceRiftLocation.getZ(),
world);
sideLink.linkOrientation = world.getBlockMetadata(
entranceRiftLocation.getX(),
entranceRiftLocation.getY() - 1,
entranceRiftLocation.getZ());
IDimLink link = dimension.createLink(pocketCenter.getX(), pocketCenter.getY(), pocketCenter.getZ());
Point4D destination = link.source();
link.setDestination(destination.getX(), destination.getY(), destination.getZ(),
PocketManager.getDimensionData(destination.getDimension()));
}
private static void setUpExitDoorLink(World world, Point3D point, Point3D entrance, int rotation, Point3D pocketCenter, int originDimID, int destDimID, Random random)
private static void createExitDoorLink(NewDimData dimension, Point3D point, Point3D entrance, int rotation, Point3D pocketCenter)
{
try
{
//TODO: Hax, remove this later
DDProperties properties = DDProperties.instance();
//Transform doorLocation to the pocket coordinate system.
Point3D location = point.clone();
BlockRotator.transformPoint(location, entrance, rotation, pocketCenter);
int blockDirection = world.getBlockMetadata(location.getX(), location.getY() - 1, location.getZ());
Point3D linkDestination = location.clone();
NewLinkData randomLink = PocketManager.instance.getRandomLinkData(false);
NewLinkData sideLink = new NewLinkData(destDimID,
PocketManager.instance.getDimData(originDimID).exitDimLink.destDimID,
location.getX(),
location.getY(),
location.getZ(),
linkDestination.getX(),
linkDestination.getY() + 1,
linkDestination.getZ(),
true, blockDirection);
if (sideLink.destDimID == properties.LimboDimensionID)
{
sideLink.destDimID = 0;
}
else if ((random.nextBoolean() && randomLink != null))
{
sideLink.destDimID = randomLink.locDimID;
}
sideLink.destYCoord = yCoordHelper.getFirstUncovered(sideLink.destDimID, linkDestination.getX(), linkDestination.getY(), linkDestination.getZ())-1;
if (sideLink.destYCoord < 5)
{
sideLink.destYCoord = 70;
}
sideLink.linkOrientation = world.getBlockMetadata(linkDestination.getX(), linkDestination.getY() - 1, linkDestination.getZ());
PocketManager.instance.createLink(sideLink);
/**dimHelper.instance.createLink(sideLink.destDimID ,
sideLink.locDimID,
sideLink.destXCoord,
sideLink.destYCoord,
sideLink.destZCoord,
sideLink.locXCoord,
sideLink.locYCoord,
sideLink.locZCoord,
BlockRotator.transformMetadata(sideLink.linkOrientation, 2, Block.doorWood.blockID));
**/
if (world.getBlockId(linkDestination.getX(), linkDestination.getY() - 3, linkDestination.getZ()) == properties.FabricBlockID)
{
setBlockDirectly(world, linkDestination.getX(), linkDestination.getY() - 2, linkDestination.getZ(), Block.stoneBrick.blockID, 0);
}
else
{
setBlockDirectly(world,linkDestination.getX(), linkDestination.getY() - 2, linkDestination.getZ(),
world.getBlockId(linkDestination.getX(), linkDestination.getY() - 3, linkDestination.getZ()),
world.getBlockMetadata(linkDestination.getX(), linkDestination.getY() - 3, linkDestination.getZ()));
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
private static void setUpDimensionalDoorLink(World world, Point3D point, Point3D entrance, int rotation, Point3D pocketCenter, int originDimID, int destDimID, boolean applyNoise, Random random)
{
int depth = PocketManager.instance.getDimDepth(originDimID) + 1;
int forwardNoise;
int sidewaysNoise;
if (applyNoise)
{
forwardNoise = MathHelper.getRandomIntegerInRange(random, -50 * depth, 150 * depth);
sidewaysNoise = MathHelper.getRandomIntegerInRange(random, -10 * depth, 10 * depth);
}
else
{
forwardNoise = 0;
sidewaysNoise = 0;
}
//Transform doorLocation to the pocket coordinate system
//Transform the door's location to the pocket coordinate system
Point3D location = point.clone();
BlockRotator.transformPoint(location, entrance, rotation, pocketCenter);
int blockDirection = world.getBlockMetadata(location.getX(), location.getY() - 1, location.getZ());
//Rotate the link destination noise to point in the same direction as the door exit
//and add it to the door's location. Use EAST as the reference orientation since linkDestination
//is constructed as if pointing East.
Point3D linkDestination = new Point3D(forwardNoise, 0, sidewaysNoise);
Point3D zeroPoint = new Point3D(0, 0, 0);
BlockRotator.transformPoint(linkDestination, zeroPoint, blockDirection - BlockRotator.EAST_DOOR_METADATA, location);
//Create the link between our current door and its intended exit in destination pocket
NewLinkData sideLink = new NewLinkData(destDimID, 0,
location.getX(),
location.getY(),
location.getZ(),
linkDestination.getX(),
linkDestination.getY() + 1,
linkDestination.getZ(),
true, blockDirection);
PocketManager.instance.createPocket(sideLink, true, true);
dimension.createLink(location.getX(), location.getY(), location.getZ()).setLinkType(IDimLink.TYPE_DUNGEON_EXIT);
}
private static void createDimensionalDoorLink(NewDimData dimension, Point3D point, Point3D entrance, int rotation, Point3D pocketCenter)
{
//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);
}
private static void spawnMonolith(World world, Point3D point, Point3D entrance, int rotation, Point3D pocketCenter)