use of net.minecraft.util.math.BlockPos in project Witchworks by Um-Mitternacht.
the class CropThistle method trySpread.
private void trySpread(World world, BlockPos center, Random rand) {
BlockPos I = center.add(-1, -1, -1);
BlockPos F = center.add(1, 1, 1);
BlockPos.getAllInBox(I, F).forEach(pos -> {
if (rand.nextBoolean() && canSustainBush(world.getBlockState(pos.down())) && (world.isAirBlock(pos) || world.getBlockState(pos).getBlock().isReplaceable(world, pos))) {
world.setBlockState(pos, getDefaultState(), 2);
}
});
}
use of net.minecraft.util.math.BlockPos in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class CoordTransformObject method updateParentAABB.
// TODO: FinishME
public void updateParentAABB() {
double mnX = 0, mnY = 0, mnZ = 0, mxX = 0, mxY = 0, mxZ = 0;
Vector currentLocation = new Vector();
mnX = mxX = parent.wrapper.posX;
mnY = mxY = parent.wrapper.posY;
mnZ = mxZ = parent.wrapper.posZ;
for (BlockPos pos : parent.blockPositions) {
currentLocation.X = pos.getX() + .5D;
currentLocation.Y = pos.getY() + .5D;
currentLocation.Z = pos.getZ() + .5D;
fromLocalToGlobal(currentLocation);
if (currentLocation.X < mnX) {
mnX = currentLocation.X;
}
if (currentLocation.X > mxX) {
mxX = currentLocation.X;
}
if (currentLocation.Y < mnY) {
mnY = currentLocation.Y;
}
if (currentLocation.Y > mxY) {
mxY = currentLocation.Y;
}
if (currentLocation.Z < mnZ) {
mnZ = currentLocation.Z;
}
if (currentLocation.Z > mxZ) {
mxZ = currentLocation.Z;
}
}
AxisAlignedBB enclosingBB = new AxisAlignedBB(mnX, mnY, mnZ, mxX, mxY, mxZ).expand(.6D, .6D, .6D);
parent.collisionBB = enclosingBB;
}
use of net.minecraft.util.math.BlockPos in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class PhysicsObject method processChunkClaims.
/*
* Generates the new chunks
*/
public void processChunkClaims(EntityPlayer player) {
BlockPos centerInWorld = new BlockPos(wrapper.posX, wrapper.posY, wrapper.posZ);
SpatialDetector detector = DetectorManager.getDetectorFor(detectorID, centerInWorld, worldObj, ValkyrienWarfareMod.maxShipSize + 1, true);
if (detector.foundSet.size() > ValkyrienWarfareMod.maxShipSize || detector.cleanHouse) {
if (player != null) {
player.addChatComponentMessage(new TextComponentString("Ship construction canceled because its exceeding the ship size limit (Raise with /physSettings maxShipSize <number>) ; Or because it's attatched to bedrock)"));
}
wrapper.setDead();
return;
}
assembleShip(player, detector, centerInWorld);
}
use of net.minecraft.util.math.BlockPos 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 net.minecraft.util.math.BlockPos in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class SpatialDetector method getBlockPosArrayList.
public ArrayList<BlockPos> getBlockPosArrayList() {
ArrayList<BlockPos> detectedBlockPos = new ArrayList<BlockPos>();
TIntIterator intIter = foundSet.iterator();
while (intIter.hasNext()) {
int hash = (Integer) intIter.next();
BlockPos fromHash = getPosWithRespectTo(hash, firstBlock);
if (fromHash.getY() + 128 - firstBlock.getY() < 0) {
System.err.println("I really hope this doesnt happen");
return new ArrayList<BlockPos>();
}
detectedBlockPos.add(fromHash);
}
return detectedBlockPos;
}
Aggregations