use of ValkyrienWarfareBase.Relocation.VWChunkCache in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class PhysicsObject method assembleShip.
private void assembleShip(EntityPlayer player, SpatialDetector detector, BlockPos centerInWorld) {
MutableBlockPos pos = new MutableBlockPos();
TIntIterator iter = detector.foundSet.iterator();
int radiusNeeded = 1;
while (iter.hasNext()) {
int i = iter.next();
detector.setPosWithRespectTo(i, BlockPos.ORIGIN, pos);
int xRad = Math.abs(pos.getX() >> 4);
int zRad = Math.abs(pos.getZ() >> 4);
radiusNeeded = Math.max(Math.max(zRad, xRad), radiusNeeded + 1);
}
// radiusNeeded = Math.max(radiusNeeded, 5);
iter = detector.foundSet.iterator();
radiusNeeded = Math.min(radiusNeeded, ValkyrienWarfareMod.chunkManager.getManagerForWorld(wrapper.worldObj).maxChunkRadius);
// System.out.println(radiusNeeded);
claimNewChunks(radiusNeeded);
claimedChunks = new Chunk[(ownedChunks.radius * 2) + 1][(ownedChunks.radius * 2) + 1];
claimedChunksEntries = new PlayerChunkMapEntry[(ownedChunks.radius * 2) + 1][(ownedChunks.radius * 2) + 1];
for (int x = ownedChunks.minX; x <= ownedChunks.maxX; x++) {
for (int z = ownedChunks.minZ; z <= ownedChunks.maxZ; z++) {
Chunk chunk = new Chunk(worldObj, x, z);
injectChunkIntoWorld(chunk, x, z, true);
claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ] = chunk;
}
}
//Prevents weird shit from spawning at the edges of a ship
replaceOuterChunksWithAir();
VKChunkCache = new VWChunkCache(worldObj, claimedChunks);
int minChunkX = claimedChunks[0][0].xPosition;
int minChunkZ = claimedChunks[0][0].zPosition;
refrenceBlockPos = getRegionCenter();
centerCoord = new Vector(refrenceBlockPos.getX(), refrenceBlockPos.getY(), refrenceBlockPos.getZ());
createPhysicsCalculations();
//The ship just got build, how can it not be the latest?
physicsProcessor.isShipPastBuild90 = true;
BlockPos centerDifference = refrenceBlockPos.subtract(centerInWorld);
while (iter.hasNext()) {
int i = iter.next();
detector.setPosWithRespectTo(i, centerInWorld, pos);
IBlockState state = detector.cache.getBlockState(pos);
TileEntity worldTile = detector.cache.getTileEntity(pos);
pos.setPos(pos.getX() + centerDifference.getX(), pos.getY() + centerDifference.getY(), pos.getZ() + centerDifference.getZ());
ownedChunks.chunkOccupiedInLocal[(pos.getX() >> 4) - minChunkX][(pos.getZ() >> 4) - minChunkZ] = true;
Chunk chunkToSet = claimedChunks[(pos.getX() >> 4) - minChunkX][(pos.getZ() >> 4) - minChunkZ];
int storageIndex = pos.getY() >> 4;
if (chunkToSet.storageArrays[storageIndex] == chunkToSet.NULL_BLOCK_STORAGE) {
chunkToSet.storageArrays[storageIndex] = new ExtendedBlockStorage(storageIndex << 4, true);
}
chunkToSet.storageArrays[storageIndex].set(pos.getX() & 15, pos.getY() & 15, pos.getZ() & 15, state);
if (worldTile != null) {
NBTTagCompound tileEntNBT = new NBTTagCompound();
tileEntNBT = worldTile.writeToNBT(tileEntNBT);
// Change the Block position to be inside of the Ship
tileEntNBT.setInteger("x", pos.getX());
tileEntNBT.setInteger("y", pos.getY());
tileEntNBT.setInteger("z", pos.getZ());
//Fuck this old code
// TileEntity newInstance = VKChunkCache.getTileEntity(pos);
// newInstance.readFromNBT(tileEntNBT);
TileEntity newInstance = TileEntity.create(worldObj, tileEntNBT);
newInstance.validate();
Class tileClass = newInstance.getClass();
Field[] fields = tileClass.getDeclaredFields();
for (Field field : fields) {
try {
field.setAccessible(true);
Object o = field.get(newInstance);
if (o != null) {
if (o instanceof BlockPos) {
BlockPos inTilePos = (BlockPos) o;
int hash = detector.getHashWithRespectTo(inTilePos.getX(), inTilePos.getY(), inTilePos.getZ(), detector.firstBlock);
if (detector.foundSet.contains(hash)) {
if (!(o instanceof MutableBlockPos)) {
inTilePos = inTilePos.add(centerDifference.getX(), centerDifference.getY(), centerDifference.getZ());
field.set(newInstance, inTilePos);
} else {
MutableBlockPos mutable = (MutableBlockPos) o;
mutable.setPos(inTilePos.getX() + centerDifference.getX(), inTilePos.getY() + centerDifference.getY(), inTilePos.getZ() + centerDifference.getZ());
}
}
}
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
worldObj.setTileEntity(newInstance.getPos(), newInstance);
newInstance.markDirty();
}
// chunkCache.setBlockState(pos, state);
// worldObj.setBlockState(pos, state);
}
iter = detector.foundSet.iterator();
short[][] changes = new short[claimedChunks.length][claimedChunks[0].length];
while (iter.hasNext()) {
int i = iter.next();
// BlockPos respectTo = detector.getPosWithRespectTo(i, centerInWorld);
detector.setPosWithRespectTo(i, centerInWorld, pos);
// detector.cache.setBlockState(pos, Blocks.air.getDefaultState());
// TODO: Get this to update on clientside as well, you bastard!
TileEntity tile = worldObj.getTileEntity(pos);
if (tile != null) {
tile.invalidate();
}
worldObj.setBlockState(pos, Blocks.AIR.getDefaultState(), 2);
}
for (int x = ownedChunks.minX; x <= ownedChunks.maxX; x++) {
for (int z = ownedChunks.minZ; z <= ownedChunks.maxZ; z++) {
claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ].isTerrainPopulated = true;
// claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ].generateSkylightMap();
// claimedChunks[x-ownedChunks.minX][z-ownedChunks.minZ].checkLight();
}
}
detectBlockPositions();
//TODO: This fixes the lighting, but it adds lag; maybe remove this
for (int x = ownedChunks.minX; x <= ownedChunks.maxX; x++) {
for (int z = ownedChunks.minZ; z <= ownedChunks.maxZ; z++) {
// claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ].isTerrainPopulated = true;
claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ].generateSkylightMap();
claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ].checkLight();
}
}
coordTransform = new CoordTransformObject(this);
physicsProcessor.processInitialPhysicsData();
physicsProcessor.updateParentCenterOfMass();
}
use of ValkyrienWarfareBase.Relocation.VWChunkCache in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class PhysicsObject method loadClaimedChunks.
public void loadClaimedChunks() {
ArrayList<TileEntity> nodeTileEntitiesToUpdate = new ArrayList<TileEntity>();
claimedChunks = new Chunk[(ownedChunks.radius * 2) + 1][(ownedChunks.radius * 2) + 1];
claimedChunksEntries = new PlayerChunkMapEntry[(ownedChunks.radius * 2) + 1][(ownedChunks.radius * 2) + 1];
for (int x = ownedChunks.minX; x <= ownedChunks.maxX; x++) {
for (int z = ownedChunks.minZ; z <= ownedChunks.maxZ; z++) {
Chunk chunk = worldObj.getChunkFromChunkCoords(x, z);
if (chunk == null) {
System.out.println("Just a loaded a null chunk");
chunk = new Chunk(worldObj, x, z);
}
// Do this to get it re-integrated into the world
if (!worldObj.isRemote) {
injectChunkIntoWorld(chunk, x, z, false);
}
for (Entry<BlockPos, TileEntity> entry : chunk.chunkTileEntityMap.entrySet()) {
TileEntity tile = entry.getValue();
if (tile instanceof INodeProvider) {
nodeTileEntitiesToUpdate.add(tile);
}
}
claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ] = chunk;
}
}
VKChunkCache = new VWChunkCache(worldObj, claimedChunks);
refrenceBlockPos = getRegionCenter();
coordTransform = new CoordTransformObject(this);
if (!worldObj.isRemote) {
createPhysicsCalculations();
}
detectBlockPositions();
for (TileEntity tile : nodeTileEntitiesToUpdate) {
Node node = ((INodeProvider) tile).getNode();
if (node != null) {
node.updateBuildState();
} else {
System.err.println("How the fuck did we get a null node?");
}
}
coordTransform.updateAllTransforms();
}
Aggregations