Partially Fixed Rotation Bugs
It turns out my earlier commits didn't completely fix things because certain implementation details were missing. I had assumed they were done. Also, some of the information I had regarding the default schematic orientation was wrong. This commit remedies most of those problems with a robust rotation implementation. However, I haven't added the code for linking Warp Doors yet, and there is a bug with tile entities getting reversed in East/West oriented rooms. Not sure why that's happening.
This commit is contained in:
@@ -1,58 +1,63 @@
|
|||||||
package StevenDimDoors.mod_pocketDim;
|
package StevenDimDoors.mod_pocketDim;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
public class Point3D implements Serializable {
|
public class Point3D implements Serializable {
|
||||||
|
|
||||||
private int x;
|
private int x;
|
||||||
private int y;
|
private int y;
|
||||||
private int z;
|
private int z;
|
||||||
|
|
||||||
public Point3D(int x, int y,int z)
|
public Point3D(int x, int y,int z)
|
||||||
|
{
|
||||||
|
this.x = x;
|
||||||
{
|
this.y = y;
|
||||||
this.x = x;
|
this.z = z;
|
||||||
this.y = y;
|
}
|
||||||
this.z = z;
|
|
||||||
}
|
public int getX()
|
||||||
|
{
|
||||||
public int getX()
|
return x;
|
||||||
{
|
}
|
||||||
return x;
|
|
||||||
}
|
public int getY()
|
||||||
|
{
|
||||||
public int getY()
|
return y;
|
||||||
{
|
}
|
||||||
return y;
|
|
||||||
}
|
public int getZ()
|
||||||
|
{
|
||||||
public int getZ()
|
return z;
|
||||||
{
|
}
|
||||||
return z;
|
|
||||||
}
|
public int setY(int y)
|
||||||
|
{
|
||||||
public int setY(int y)
|
return this.y=y;
|
||||||
{
|
}
|
||||||
return this.y=y;
|
|
||||||
}
|
public int setX(int x)
|
||||||
public int setX(int x)
|
{
|
||||||
{
|
return this. x=x;
|
||||||
return this. x=x;
|
}
|
||||||
}
|
|
||||||
public int setZ(int z)
|
public int setZ(int z)
|
||||||
{
|
{
|
||||||
return this. z=z;
|
return this. z=z;
|
||||||
}
|
}
|
||||||
public boolean equals(Object other)
|
|
||||||
{
|
public Point3D clone()
|
||||||
boolean result = false;
|
{
|
||||||
if (other instanceof Point3D)
|
return new Point3D(x, y, z);
|
||||||
{
|
}
|
||||||
Point3D that = (Point3D) other;
|
|
||||||
result = (this.getX() == that.getX() && this.getY() == that.getY()&& this.getY() == that.getZ());
|
public boolean equals(Object other)
|
||||||
}
|
{
|
||||||
return result;
|
boolean result = false;
|
||||||
}
|
if (other instanceof Point3D)
|
||||||
|
{
|
||||||
|
Point3D that = (Point3D) other;
|
||||||
|
result = (this.getX() == that.getX() && this.getY() == that.getY()&& this.getY() == that.getZ());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,6 @@ import java.io.File;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
@@ -18,9 +17,9 @@ import net.minecraft.item.ItemStack;
|
|||||||
import net.minecraft.nbt.CompressedStreamTools;
|
import net.minecraft.nbt.CompressedStreamTools;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.tileentity.TileEntityChest;
|
import net.minecraft.tileentity.TileEntityChest;
|
||||||
import net.minecraft.tileentity.TileEntityDispenser;
|
import net.minecraft.tileentity.TileEntityDispenser;
|
||||||
|
import net.minecraft.util.MathHelper;
|
||||||
import net.minecraft.util.WeightedRandomChestContent;
|
import net.minecraft.util.WeightedRandomChestContent;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
@@ -32,31 +31,23 @@ import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper;
|
|||||||
import StevenDimDoors.mod_pocketDim.ticking.MobObelisk;
|
import StevenDimDoors.mod_pocketDim.ticking.MobObelisk;
|
||||||
|
|
||||||
public class SchematicLoader
|
public class SchematicLoader
|
||||||
|
|
||||||
{
|
{
|
||||||
private Random rand = new Random();
|
private final static int EAST_DOOR_METADATA = 0;
|
||||||
public HashMap<Integer,HashMap<Integer, HashMap<Integer,Integer>>> rotationMap = new HashMap<Integer,HashMap<Integer, HashMap<Integer,Integer>>>();
|
private final static int SOUTH_DOOR_METADATA = 1;
|
||||||
|
private final static int WEST_DOOR_METADATA = 2;
|
||||||
|
private final static int NORTH_DOOR_METADATA = 3;
|
||||||
|
private final static int REFERENCE_DOOR_ORIENTATION = NORTH_DOOR_METADATA;
|
||||||
|
|
||||||
public int transMeta;
|
public int transMeta;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private DDProperties properties = DDProperties.instance();
|
private DDProperties properties = DDProperties.instance();
|
||||||
|
|
||||||
public SchematicLoader() { }
|
public SchematicLoader() { }
|
||||||
|
|
||||||
public int transformMetadata(int metadata, int orientation, int blockID)
|
public int transformMetadata(int metadata, int orientation, int blockID)
|
||||||
{
|
{
|
||||||
if (DungeonHelper.instance().metadataFlipList.contains(blockID))
|
if (DungeonHelper.instance().metadataFlipList.contains(blockID))
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
switch (orientation)
|
switch (orientation)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
@@ -94,7 +85,7 @@ public class SchematicLoader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(blockID== Block.chest.blockID||blockID== Block.chestTrapped.blockID||blockID== Block.ladder.blockID)
|
else if(blockID== Block.chest.blockID||blockID== Block.chestTrapped.blockID||blockID== Block.ladder.blockID)
|
||||||
{
|
{
|
||||||
switch (metadata)
|
switch (metadata)
|
||||||
{
|
{
|
||||||
@@ -117,7 +108,7 @@ public class SchematicLoader
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(blockID==Block.vine.blockID)
|
else if(blockID==Block.vine.blockID)
|
||||||
{
|
{
|
||||||
switch (metadata)
|
switch (metadata)
|
||||||
{
|
{
|
||||||
@@ -134,16 +125,8 @@ public class SchematicLoader
|
|||||||
case 8:
|
case 8:
|
||||||
metadata = 1;
|
metadata = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
else if(blockID== Block.lever.blockID||blockID== Block.stoneButton.blockID||blockID== Block.woodenButton.blockID||blockID== Block.torchWood.blockID||blockID== Block.torchRedstoneIdle.blockID||blockID== Block.torchRedstoneActive.blockID)
|
else if(blockID== Block.lever.blockID||blockID== Block.stoneButton.blockID||blockID== Block.woodenButton.blockID||blockID== Block.torchWood.blockID||blockID== Block.torchRedstoneIdle.blockID||blockID== Block.torchRedstoneActive.blockID)
|
||||||
{
|
{
|
||||||
switch (metadata)
|
switch (metadata)
|
||||||
@@ -171,14 +154,10 @@ public class SchematicLoader
|
|||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
metadata = 1;
|
metadata = 1;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else if(blockID== Block.pistonBase.blockID||blockID==Block.pistonExtension.blockID||blockID==Block.pistonStickyBase.blockID||blockID==Block.dispenser.blockID||blockID==Block.dropper.blockID)
|
||||||
else if(blockID== Block.pistonBase.blockID||blockID==Block.pistonExtension.blockID||blockID==Block.pistonStickyBase.blockID||blockID==Block.dispenser.blockID||blockID==Block.dropper.blockID)
|
|
||||||
{
|
{
|
||||||
switch (metadata)
|
switch (metadata)
|
||||||
{
|
{
|
||||||
@@ -843,22 +822,28 @@ public class SchematicLoader
|
|||||||
}
|
}
|
||||||
|
|
||||||
World world;
|
World world;
|
||||||
Chunk chunk;
|
dimHelper.dimList.get(destDimID).hasBeenFilled = true;
|
||||||
dimHelper.dimList.get(destDimID).hasBeenFilled=true;
|
|
||||||
|
|
||||||
if(dimHelper.getWorld(destDimID)==null)
|
if (dimHelper.getWorld(destDimID) == null)
|
||||||
{
|
{
|
||||||
dimHelper.initDimension(destDimID);
|
dimHelper.initDimension(destDimID);
|
||||||
}
|
}
|
||||||
world=dimHelper.getWorld(destDimID);
|
world = dimHelper.getWorld(destDimID);
|
||||||
|
|
||||||
|
//The following Random initialization code is based on code from ChunkProviderGenerate.
|
||||||
|
//It makes our generation depend on the world seed.
|
||||||
|
Random rand = new Random(world.getSeed());
|
||||||
|
long factorA = rand.nextLong() / 2L * 2L + 1L;
|
||||||
|
long factorB = rand.nextLong() / 2L * 2L + 1L;
|
||||||
|
rand.setSeed((riftX >> 4) * factorA + (riftZ >> 4) * factorB ^ world.getSeed());
|
||||||
|
|
||||||
//coords relative to the schematic, start at 0 and increase up to max height/width/length
|
//coords relative to the schematic, start at 0 and increase up to max height/width/length
|
||||||
int x, y, z;
|
int x, y, z;
|
||||||
|
|
||||||
//relative offset between the schematic coords and world coords
|
//The real coordinates where a block will be placed
|
||||||
int offsetX = 0;
|
int realX = 0;
|
||||||
int offsetY = 0;
|
int realY = 0;
|
||||||
int offsetZ = 0;
|
int realZ = 0;
|
||||||
|
|
||||||
//first loop through the .schematic to load in all rift locations, and monolith spawn locations.
|
//first loop through the .schematic to load in all rift locations, and monolith spawn locations.
|
||||||
//also finds the incomingLink location, which determines the final position of the generated .schematic
|
//also finds the incomingLink location, which determines the final position of the generated .schematic
|
||||||
@@ -868,7 +853,6 @@ public class SchematicLoader
|
|||||||
{
|
{
|
||||||
for ( z = 0; z < length; ++z)
|
for ( z = 0; z < length; ++z)
|
||||||
{
|
{
|
||||||
|
|
||||||
int index = y * width * length + z * width + x;
|
int index = y * width * length + z * width + x;
|
||||||
|
|
||||||
int blockToReplace=blocks[index];
|
int blockToReplace=blocks[index];
|
||||||
@@ -894,50 +878,48 @@ public class SchematicLoader
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(blockToReplace==Block.endPortalFrame.blockID)
|
else if (blockToReplace == Block.endPortalFrame.blockID)
|
||||||
{
|
{
|
||||||
monolithSpawns.add(new Point3D(x,y,z));
|
monolithSpawns.add(new Point3D(x,y,z));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Compute the Y-axis translation that places our structure correctly
|
//Compute the Y-axis translation that places our structure correctly
|
||||||
offsetY = riftY - entrance.getY();
|
int offsetY = riftY - entrance.getY();
|
||||||
|
|
||||||
//Loop to actually place the blocks
|
//Loop to actually place the blocks
|
||||||
for ( x = 0; x < width; x++)
|
for (x = 0; x < width; x++)
|
||||||
{
|
{
|
||||||
for ( z = 0; z < length; z++)
|
for (z = 0; z < length; z++)
|
||||||
{
|
{
|
||||||
//Compute the X-axis and Z-axis translations that will shift
|
//Compute the X-axis and Z-axis translations that will shift
|
||||||
//and rotate our structure properly.
|
//and rotate our structure properly.
|
||||||
switch (orientation)
|
switch (orientation)
|
||||||
{
|
{
|
||||||
case 0: //South
|
case REFERENCE_DOOR_ORIENTATION:
|
||||||
offsetX = entrance.getZ() + riftX;
|
realX = (x - entrance.getX()) + riftX;
|
||||||
offsetZ = -entrance.getX() + riftZ;
|
realZ = (z - entrance.getZ()) + riftZ;
|
||||||
break;
|
break;
|
||||||
case 1: //West
|
case (REFERENCE_DOOR_ORIENTATION + 1) % 4: //270 degree CCW rotation
|
||||||
offsetX = entrance.getX() + riftX;
|
realX = (z - entrance.getZ()) + riftX;
|
||||||
offsetZ = entrance.getZ() + riftZ;
|
realZ = -(x - entrance.getX()) + riftZ;
|
||||||
break;
|
break;
|
||||||
case 2: //North
|
case (REFERENCE_DOOR_ORIENTATION + 2) % 4: //180 degree rotation
|
||||||
offsetX = -entrance.getZ() + riftX;
|
realX = -(x - entrance.getX()) + riftX;
|
||||||
offsetZ = entrance.getX() + riftZ;
|
realZ = -(z - entrance.getZ()) + riftZ;
|
||||||
break;
|
break;
|
||||||
case 3: //East
|
case (REFERENCE_DOOR_ORIENTATION + 3) % 4: //90 degree CCW rotation
|
||||||
offsetX = -entrance.getX() + riftX;
|
realX = -(z - entrance.getZ()) + riftX;
|
||||||
offsetZ = -entrance.getZ() + riftZ;
|
realZ = (x - entrance.getX()) + riftZ;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( y = 0; y < height; y++)
|
for (y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
|
|
||||||
int index = y * width * length + z * width + x;
|
int index = y * width * length + z * width + x;
|
||||||
|
realY = y + offsetY;
|
||||||
|
|
||||||
int blockToReplace=blocks[index];
|
int blockToReplace=blocks[index];
|
||||||
int blockMetaData=blockData[index];
|
int blockMetaData=blockData[index];
|
||||||
@@ -962,15 +944,15 @@ public class SchematicLoader
|
|||||||
//convert vanilla doors to dim doors, then place vanilla blocks
|
//convert vanilla doors to dim doors, then place vanilla blocks
|
||||||
if(blockToReplace==Block.doorIron.blockID)
|
if(blockToReplace==Block.doorIron.blockID)
|
||||||
{
|
{
|
||||||
setBlockDirectly(world,x+offsetX,y+offsetY,z+offsetZ,properties.DimensionalDoorID, transMeta );
|
setBlockDirectly(world,realX, realY, realZ,properties.DimensionalDoorID, transMeta );
|
||||||
}
|
}
|
||||||
else if(blockToReplace==Block.doorWood.blockID)
|
else if(blockToReplace==Block.doorWood.blockID)
|
||||||
{
|
{
|
||||||
setBlockDirectly(world,x+offsetX,y+offsetY,z+offsetZ,properties.WarpDoorID, transMeta );
|
setBlockDirectly(world,realX, realY, realZ,properties.WarpDoorID, transMeta );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setBlockDirectly(world,x+offsetX,y+offsetY,z+offsetZ,blockToReplace, transMeta );
|
setBlockDirectly(world,realX, realY, realZ,blockToReplace, transMeta );
|
||||||
}
|
}
|
||||||
|
|
||||||
//generate container inventories
|
//generate container inventories
|
||||||
@@ -986,17 +968,17 @@ public class SchematicLoader
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
//fill chests
|
//fill chests
|
||||||
if(world.getBlockTileEntity(x+offsetX, y+offsetY, z+offsetZ) instanceof TileEntityChest)
|
if(world.getBlockTileEntity(realX, realY, realZ) instanceof TileEntityChest)
|
||||||
{
|
{
|
||||||
TileEntityChest chest = (TileEntityChest) world.getBlockTileEntity(x+offsetX, y+offsetY, z+offsetZ);
|
TileEntityChest chest = (TileEntityChest) world.getBlockTileEntity(realX, realY, realZ);
|
||||||
ChestGenHooks info = DDLoot.DungeonChestInfo;
|
ChestGenHooks info = DDLoot.DungeonChestInfo;
|
||||||
WeightedRandomChestContent.generateChestContents(rand, info.getItems(rand), (TileEntityChest)world.getBlockTileEntity(x+offsetX, y+offsetY, z+offsetZ), info.getCount(rand));
|
WeightedRandomChestContent.generateChestContents(rand, info.getItems(rand), (TileEntityChest)world.getBlockTileEntity(realX, realY, realZ), info.getCount(rand));
|
||||||
}
|
}
|
||||||
|
|
||||||
//fill dispensers
|
//fill dispensers
|
||||||
if(world.getBlockTileEntity(x+offsetX, y+offsetY, z+offsetZ) instanceof TileEntityDispenser)
|
if(world.getBlockTileEntity(realX, realY, realZ) instanceof TileEntityDispenser)
|
||||||
{
|
{
|
||||||
TileEntityDispenser dispenser = (TileEntityDispenser) world.getBlockTileEntity(x+offsetX, y+offsetY, z+offsetZ);
|
TileEntityDispenser dispenser = (TileEntityDispenser) world.getBlockTileEntity(realX, realY, realZ);
|
||||||
dispenser.addItem(new ItemStack(Item.arrow, 64));
|
dispenser.addItem(new ItemStack(Item.arrow, 64));
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1006,46 +988,45 @@ public class SchematicLoader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//generate the LinkData defined by the door placement, Iron Dim doors first
|
//Set up variables to use transformPoint()
|
||||||
|
Point3D pocketOrigin = new Point3D(riftX, riftY, riftZ);
|
||||||
|
Point3D zeroPoint = new Point3D(0, 0, 0);
|
||||||
|
|
||||||
|
//Generate the LinkData defined by the door placement, Iron Dim doors first
|
||||||
for(Point3D point : sideLinks)
|
for(Point3D point : sideLinks)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
int depth = dimHelper.instance.getDimDepth(originDimID);
|
int depth = dimHelper.instance.getDimDepth(originDimID);
|
||||||
int xNoise = 0;
|
int forwardNoise = MathHelper.getRandomIntegerInRange(rand, -50 * (depth + 1), 150 * (depth + 1));
|
||||||
int zNoise =0;
|
int sidewaysNoise = MathHelper.getRandomIntegerInRange(rand, -10 * (depth + 1), 10 * (depth + 1));
|
||||||
switch(world.getBlockMetadata(point.getX()+offsetX, point.getY()+offsetY-1, point.getZ()+offsetZ))
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
xNoise = (int)rand.nextInt(depth+1*200)+depth*50;
|
|
||||||
zNoise = (int)rand.nextInt(depth+1*20)-(10)*depth;
|
|
||||||
|
|
||||||
break;
|
//Transform doorLocation to the pocket coordinate system.
|
||||||
case 1:
|
Point3D doorLocation = point.clone();
|
||||||
xNoise = (int)rand.nextInt(depth+1*20)-(10)*depth;
|
transformPoint(doorLocation, entrance, orientation - REFERENCE_DOOR_ORIENTATION, pocketOrigin);
|
||||||
zNoise = (int) rand.nextInt(depth+1*200)+depth*50;
|
int blockDirection = world.getBlockMetadata(doorLocation.getX(), doorLocation.getY() - 1, doorLocation.getZ());
|
||||||
|
|
||||||
break;
|
//Rotate the link destination noise to point in the same direction as the door exit
|
||||||
case 2:
|
//and add it to the door's location. Use EAST as the reference orientation since linkDestination
|
||||||
xNoise = - (rand.nextInt(depth+1*200)+depth*50);
|
//is constructed as if pointing East.
|
||||||
zNoise = (int)rand.nextInt(depth+1*20)-(10)*depth;
|
Point3D linkDestination = new Point3D(forwardNoise, 0, sidewaysNoise);
|
||||||
|
transformPoint(linkDestination, zeroPoint, blockDirection - EAST_DOOR_METADATA, doorLocation);
|
||||||
break;
|
|
||||||
case 3:
|
//Create the link between our current door and its intended exit in destination pocket
|
||||||
xNoise = (int)rand.nextInt(depth+1*20)-(10)*depth;
|
LinkData sideLink = new LinkData(destDimID, 0,
|
||||||
zNoise = -(rand.nextInt(depth+1*200)+depth*50);
|
doorLocation.getX(),
|
||||||
|
doorLocation.getY(),
|
||||||
break;
|
doorLocation.getZ(),
|
||||||
}
|
linkDestination.getX(),
|
||||||
|
linkDestination.getY() + 1,
|
||||||
LinkData sideLink = new LinkData(destDimID,0,point.getX()+offsetX, point.getY()+offsetY, point.getZ()+offsetZ,xNoise+point.getX()+offsetX, point.getY()+offsetY+1, zNoise+point.getZ()+offsetZ,true,world.getBlockMetadata(point.getX()+offsetX, point.getY()+offsetY-1, point.getZ()+offsetZ));
|
linkDestination.getZ(),
|
||||||
|
true, blockDirection);
|
||||||
dimHelper.instance.createPocket(sideLink, true, true);
|
dimHelper.instance.createPocket(sideLink, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//generate linkData for wooden dim doors leading to the overworld
|
//generate linkData for wooden dim doors leading to the overworld
|
||||||
for(Point3D point : exitLinks)
|
for(Point3D point : exitLinks)
|
||||||
{
|
{
|
||||||
try
|
//DISABLED FOR TESTING
|
||||||
|
/*try
|
||||||
{
|
{
|
||||||
LinkData randomLink=dimHelper.instance.getRandomLinkData(false);
|
LinkData randomLink=dimHelper.instance.getRandomLinkData(false);
|
||||||
LinkData sideLink = new LinkData(destDimID,dimHelper.dimList.get(originDimID).exitDimLink.destDimID,point.getX()+offsetX, point.getY()+offsetY, point.getZ()+offsetZ,point.getX()+offsetX, 0, point.getZ()+offsetZ,true,world.getBlockMetadata(point.getX()+offsetX, point.getY()+offsetY-1, point.getZ()+offsetZ));
|
LinkData sideLink = new LinkData(destDimID,dimHelper.dimList.get(originDimID).exitDimLink.destDimID,point.getX()+offsetX, point.getY()+offsetY, point.getZ()+offsetZ,point.getX()+offsetX, 0, point.getZ()+offsetZ,true,world.getBlockMetadata(point.getX()+offsetX, point.getY()+offsetY-1, point.getZ()+offsetZ));
|
||||||
@@ -1084,17 +1065,82 @@ public class SchematicLoader
|
|||||||
catch(Exception E)
|
catch(Exception E)
|
||||||
{
|
{
|
||||||
E.printStackTrace();
|
E.printStackTrace();
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
//spawn monoliths
|
//spawn monoliths
|
||||||
for(Point3D point : monolithSpawns)
|
for(Point3D point : monolithSpawns)
|
||||||
{
|
{
|
||||||
|
//Transform the frame block's location to the pocket coordinate system
|
||||||
|
Point3D frameLocation = point.clone();
|
||||||
|
transformPoint(frameLocation, entrance, orientation - REFERENCE_DOOR_ORIENTATION, pocketOrigin);
|
||||||
|
|
||||||
Entity mob = new MobObelisk(world);
|
Entity mob = new MobObelisk(world);
|
||||||
mob.setLocationAndAngles(point.getX()+offsetX,point.getY()+offsetY, point.getZ()+offsetZ, 1, 1);
|
mob.setLocationAndAngles(frameLocation.getX(), frameLocation.getY(), frameLocation.getZ(), 1, 1); //TODO: Why not set the angles to 0? @.@ ~SenseiKiwi
|
||||||
world.spawnEntityInWorld(mob);
|
world.spawnEntityInWorld(mob);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void transformPoint(Point3D position, Point3D srcOrigin, int angle, Point3D destOrigin)
|
||||||
|
{
|
||||||
|
//This function receives a position (e.g. point in schematic space), translates it relative
|
||||||
|
//to a source coordinate system (e.g. the point that will be the center of a schematic),
|
||||||
|
//then rotates and translates it to obtain the corresponding point in a destination
|
||||||
|
//coordinate system (e.g. the location of the entry rift in the pocket being generated).
|
||||||
|
//The result is returned by overwriting the original position so that new object references
|
||||||
|
//aren't needed. That way, repeated use of this function will not incur as much overhead.
|
||||||
|
|
||||||
|
//Position is only overwritten at the end, so it's okay to provide it as srcOrigin or destOrigin as well.
|
||||||
|
|
||||||
|
int tx = position.getX() - srcOrigin.getX();
|
||||||
|
int ty = position.getY() - srcOrigin.getY();
|
||||||
|
int tz = position.getZ() - srcOrigin.getZ();
|
||||||
|
|
||||||
|
//"int angle" specifies a rotation consistent with Minecraft's orientation system.
|
||||||
|
//That means each increment of 1 in angle would be a 90-degree clockwise turn.
|
||||||
|
//Given a starting direction A and a destination direction B, the rotation would be
|
||||||
|
//calculated by (B - A).
|
||||||
|
|
||||||
|
//Adjust angle into the expected range
|
||||||
|
if (angle < 0)
|
||||||
|
{
|
||||||
|
int correction = -(angle / 4);
|
||||||
|
angle = angle + 4 * (correction + 1);
|
||||||
|
}
|
||||||
|
angle = angle % 4;
|
||||||
|
|
||||||
|
//Rotations are considered in counterclockwise form because coordinate systems are
|
||||||
|
//often assumed to be right-handed and convenient formulas are available for
|
||||||
|
//common counterclockwise rotations.
|
||||||
|
//Reference: http://en.wikipedia.org/wiki/Rotation_matrix#Common_rotations
|
||||||
|
int rx;
|
||||||
|
int rz;
|
||||||
|
switch (angle)
|
||||||
|
{
|
||||||
|
case 0: //No rotation
|
||||||
|
rx = tx;
|
||||||
|
rz = tz;
|
||||||
|
break;
|
||||||
|
case 1: //270 degrees counterclockwise
|
||||||
|
rx = tz;
|
||||||
|
rz = -tx;
|
||||||
|
break;
|
||||||
|
case 2: //180 degrees
|
||||||
|
rx = -tx;
|
||||||
|
rz = -tz;
|
||||||
|
break;
|
||||||
|
case 3: //90 degrees counterclockwise
|
||||||
|
rx = -tz;
|
||||||
|
rz = tx;
|
||||||
|
break;
|
||||||
|
default: //This should never happen.
|
||||||
|
throw new IllegalStateException("Invalid angle value. This should never happen!");
|
||||||
|
}
|
||||||
|
|
||||||
|
position.setX( rx + destOrigin.getX() );
|
||||||
|
position.setY( ty + destOrigin.getY() );
|
||||||
|
position.setZ( rz + destOrigin.getZ() );
|
||||||
|
}
|
||||||
|
|
||||||
public void generateDungeonPocket(LinkData link)
|
public void generateDungeonPocket(LinkData link)
|
||||||
{
|
{
|
||||||
@@ -1113,40 +1159,35 @@ public class SchematicLoader
|
|||||||
|
|
||||||
public void setBlockDirectly(World world, int x, int y, int z,int id, int metadata)
|
public void setBlockDirectly(World world, int x, int y, int z,int id, int metadata)
|
||||||
{
|
{
|
||||||
if(Block.blocksList[id]==null)
|
if (Block.blocksList[id] == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cX;
|
int cX = x >> 4;
|
||||||
int cZ;
|
int cZ = z >> 4;
|
||||||
int cY;
|
int cY = y >> 4;
|
||||||
|
|
||||||
Chunk chunk;
|
Chunk chunk;
|
||||||
cX = x >> 4;
|
|
||||||
cZ = z >> 4;
|
|
||||||
cY=y >>4;
|
|
||||||
|
|
||||||
int chunkX=(x % 16)< 0 ? ((x) % 16)+16 : ((x) % 16);
|
//TODO: This really seems odd to me. Like it's wrong. ~SenseiKiwi
|
||||||
int chunkZ=((z) % 16)< 0 ? ((z) % 16)+16 : ((z) % 16);
|
int chunkX=(x % 16)< 0 ? ((x) % 16)+16 : ((x) % 16);
|
||||||
|
int chunkZ=((z) % 16)< 0 ? ((z) % 16)+16 : ((z) % 16);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
chunk = world.getChunkFromChunkCoords(cX, cZ);
|
||||||
|
if (chunk.getBlockStorageArray()[cY] == null)
|
||||||
|
{
|
||||||
|
chunk.getBlockStorageArray()[cY] = new ExtendedBlockStorage(cY << 4, !world.provider.hasNoSky);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// this.chunk=new EmptyChunk(world,cX, cZ);
|
chunk.getBlockStorageArray()[cY].setExtBlockID(chunkX, (y) & 15, chunkZ, id);
|
||||||
try
|
chunk.getBlockStorageArray()[cY].setExtBlockMetadata(chunkX, (y) & 15, chunkZ, metadata);
|
||||||
{
|
}
|
||||||
chunk=world.getChunkFromChunkCoords(cX, cZ);
|
catch(Exception e)
|
||||||
if (chunk.getBlockStorageArray()[cY] == null)
|
{
|
||||||
{
|
e.printStackTrace();
|
||||||
chunk.getBlockStorageArray()[cY] = new ExtendedBlockStorage(cY << 4, !world.provider.hasNoSky);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
chunk.getBlockStorageArray()[cY].setExtBlockID(chunkX, (y) & 15, chunkZ, id);
|
|
||||||
chunk.getBlockStorageArray()[cY].setExtBlockMetadata(chunkX, (y) & 15, chunkZ, metadata);
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user