use of net.minecraft.world.ChunkCache in project PneumaticCraft by MineMaarten.
the class AchievementHandler method checkFor9x9.
public static void checkFor9x9(EntityPlayer player, int x, int y, int z) {
ChunkCache cache = new ChunkCache(player.worldObj, x - 8, y, z - 8, x + 8, y, z + 8, 0);
ForgeDirection[] dirs = { ForgeDirection.NORTH, ForgeDirection.WEST };
for (ForgeDirection dir : dirs) {
int wallLength = 1;
int minX = x;
int minZ = z;
int maxX = x;
int maxZ = z;
int newX = x + dir.offsetX;
int newZ = z + dir.offsetZ;
while (wallLength < 9 && cache.getBlock(newX, y, newZ) == Blocks.cobblestone) {
wallLength++;
minX = Math.min(minX, newX);
minZ = Math.min(minZ, newZ);
maxX = Math.max(maxX, newX);
maxZ = Math.max(maxZ, newZ);
newX += dir.offsetX;
newZ += dir.offsetZ;
}
newX = x - dir.offsetX;
newZ = z - dir.offsetZ;
while (wallLength < 9 && cache.getBlock(newX, y, newZ) == Blocks.cobblestone) {
wallLength++;
minX = Math.min(minX, newX);
minZ = Math.min(minZ, newZ);
maxX = Math.max(maxX, newX);
maxZ = Math.max(maxZ, newZ);
newX -= dir.offsetX;
newZ -= dir.offsetZ;
}
if (wallLength == 9) {
if (checkFor9x9(cache, x, y, z, minX, minZ, maxX, maxZ)) {
giveAchievement(player, "dw9x9");
return;
}
}
}
}
use of net.minecraft.world.ChunkCache in project PneumaticCraft by MineMaarten.
the class ProgWidgetAreaItemBase method getCache.
public static IBlockAccess getCache(Collection<ChunkPosition> area, World world) {
if (area.size() == 0)
return world;
int minX, minY, minZ, maxX, maxY, maxZ;
Iterator<ChunkPosition> iterator = area.iterator();
ChunkPosition p = iterator.next();
minX = maxX = p.chunkPosX;
minY = maxY = p.chunkPosY;
minZ = maxZ = p.chunkPosZ;
while (iterator.hasNext()) {
p = iterator.next();
minX = Math.min(minX, p.chunkPosX);
minY = Math.min(minY, p.chunkPosY);
minZ = Math.min(minZ, p.chunkPosZ);
maxX = Math.max(maxX, p.chunkPosX);
maxY = Math.max(maxY, p.chunkPosY);
maxZ = Math.max(maxZ, p.chunkPosZ);
}
return new ChunkCache(world, minX, minY, minZ, maxX, maxY, maxZ, 0);
}
use of net.minecraft.world.ChunkCache in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class WorldPhysicsCollider method isBlockInWorldSolidFast.
private boolean isBlockInWorldSolidFast(final int posX, final int posY, final int posZ) {
if (posY < 0 || posY >= 256) {
return false;
}
final ChunkCache surroundingChunks = parent.getCachedSurroundingChunks();
final int relativeChunkX = (posX >> 4) - surroundingChunks.chunkX;
final int relativeChunkZ = (posZ >> 4) - surroundingChunks.chunkZ;
if (relativeChunkX < 0 || relativeChunkX >= surroundingChunks.chunkArray.length || relativeChunkZ < 0 || relativeChunkZ >= surroundingChunks.chunkArray[relativeChunkX].length) {
return false;
}
final Chunk chunk = surroundingChunks.chunkArray[relativeChunkX][relativeChunkZ];
if (chunk == null) {
return false;
}
final ExtendedBlockStorage blockStorage = chunk.storageArrays[posY >> 4];
if (blockStorage == null) {
return false;
}
final IBitOctree octree = ITerrainOctreeProvider.class.cast(blockStorage.data).getSolidOctree();
return octree.get(posX & 15, posY & 15, posZ & 15);
}
use of net.minecraft.world.ChunkCache in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class WorldPhysicsCollider method updatePotentialCollisionCache.
// TODO: The greatest physics lag starts here.
private void updatePotentialCollisionCache() {
ticksSinceCacheUpdate = 0D;
// in the same tick
if (Math.random() > .5) {
ticksSinceCacheUpdate -= .05D;
}
int oldSize = cachedPotentialHits.size();
// Resets the potential hits array in O(1) time! Isn't that something.
// cachedPotentialHits.resetQuick();
cachedPotentialHits.clear();
AxisAlignedBB shipBBOriginal = parent.getPhysicsTransformAABB();
if (shipBBOriginal == null) {
return;
}
final AxisAlignedBB shipBB = shipBBOriginal.grow(3);
// Use the physics tick collision box instead of the game tick collision box.
// We are using grow(3) on both because for some reason if we don't then ships start
// jiggling through the ground. God I can't wait for a new physics engine.
final AxisAlignedBB collisionBB = shipBB.grow(AABB_EXPANSION).expand(calculator.getLinearVelocity().x * .2, calculator.getLinearVelocity().y * .2, calculator.getLinearVelocity().z * .2);
// Ship is outside of world blockSpace, just skip this all togvalkyrium
if (collisionBB.maxY < 0 || collisionBB.minY > 255) {
return;
}
// Has a -1 on the minY value, I hope this helps with preventing things from
// falling through the floor
BlockPos min = new BlockPos(collisionBB.minX, Math.max(collisionBB.minY - 1, 0), collisionBB.minZ);
BlockPos max = new BlockPos(collisionBB.maxX, Math.min(collisionBB.maxY, 255), collisionBB.maxZ);
centerPotentialHit = new BlockPos((min.getX() + max.getX()) / 2D, (min.getY() + max.getY()) / 2D, (min.getZ() + max.getZ()) / 2D);
ChunkCache cache = parent.getCachedSurroundingChunks();
if (cache == null) {
System.err.println("VS Cached Surrounding Chunks was null! This is going to cause catastophric terrible events!!");
return;
}
int chunkMinX = min.getX() >> 4;
int chunkMaxX = (max.getX() >> 4) + 1;
int chunkMinZ = min.getZ() >> 4;
int chunkMaxZ = (max.getZ() >> 4) + 1;
// long startTime = System.nanoTime();
int minX = min.getX();
int minY = min.getY();
int minZ = min.getZ();
int maxX = max.getX();
int maxY = max.getY();
int maxZ = max.getZ();
// More multithreading!
if (VSConfig.MULTITHREADING_SETTINGS.multithreadCollisionCacheUpdate && parent.getBlockPositions().size() > 100) {
List<Triple<Integer, Integer, TIntList>> tasks = new ArrayList<>();
for (int chunkX = chunkMinX; chunkX < chunkMaxX; chunkX++) {
for (int chunkZ = chunkMinZ; chunkZ < chunkMaxZ; chunkZ++) {
tasks.add(new ImmutableTriple<>(chunkX, chunkZ, new TIntArrayList()));
}
}
Consumer<Triple<Integer, Integer, TIntList>> consumer = i -> {
// i is a Tuple<Integer, Integer>
// updateCollisionCacheParrallel(cache, cachedPotentialHits, i.getFirst(),
// i.getSecond(), minX, minY, minZ, maxX, maxY, maxZ);
updateCollisionCacheSequential(cache, i.getLeft(), i.getMiddle(), minX, minY, minZ, maxX, maxY, maxZ, shipBB, i.getRight());
};
ValkyrienSkiesMod.getPhysicsThreadPool().submit(() -> tasks.parallelStream().forEach(consumer)).join();
tasks.forEach(task -> cachedPotentialHits.addAll(task.getRight()));
} else {
// Cast to double to avoid overflow errors
double size = ((double) (chunkMaxX - chunkMinX)) * ((double) (chunkMaxZ - chunkMinZ));
if (size > 300000) {
// Sanity check; don't execute the rest of the code because we'll just freeze the physics thread.
return;
}
// TODO: VS thread freezes here.
for (int chunkX = chunkMinX; chunkX < chunkMaxX; chunkX++) {
for (int chunkZ = chunkMinZ; chunkZ < chunkMaxZ; chunkZ++) {
updateCollisionCacheSequential(cache, chunkX, chunkZ, minX, minY, minZ, maxX, maxY, maxZ, shipBB, cachedPotentialHits);
}
}
}
}
use of net.minecraft.world.ChunkCache in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class WorldWaterCollider method updatePotentialCollisionCache.
private void updatePotentialCollisionCache() {
secondsSinceCollisionCacheUpdate = 0;
// ships from all updating in the same tick
if (Math.random() > .5) {
secondsSinceCollisionCacheUpdate -= .01;
}
cachedPotentialHits.clear();
AxisAlignedBB shipBBOriginal = parent.getPhysicsTransformAABB();
if (shipBBOriginal == null) {
return;
}
// We are using grow(3) because its good.
final AxisAlignedBB shipBB = shipBBOriginal.grow(3);
final AxisAlignedBB collisionBB = shipBB.grow(AABB_EXPANSION).grow(2 * Math.ceil(RANGE_CHECK));
// Ship is outside of world blockSpace, just skip this
if (collisionBB.maxY < 0 || collisionBB.minY > 255) {
return;
}
// Has a -1 on the minY value, I hope this helps with preventing things from
// falling through the floor
final BlockPos min = new BlockPos(collisionBB.minX, Math.max(collisionBB.minY - 1, 0), collisionBB.minZ);
final BlockPos max = new BlockPos(collisionBB.maxX, Math.min(collisionBB.maxY, 255), collisionBB.maxZ);
centerPotentialHit = new BlockPos((min.getX() + max.getX()) / 2.0, (min.getY() + max.getY()) / 2.0, (min.getZ() + max.getZ()) / 2.0);
final ChunkCache cache = parent.getCachedSurroundingChunks();
if (cache == null) {
System.err.println("VS Cached Surrounding Chunks was null! This is going to cause catastophric terrible events!!");
return;
}
final int chunkMinX = min.getX() >> 4;
final int chunkMaxX = (max.getX() >> 4) + 1;
final int chunkMinZ = min.getZ() >> 4;
final int chunkMaxZ = (max.getZ() >> 4) + 1;
final int minX = min.getX();
final int minY = min.getY();
final int minZ = min.getZ();
final int maxX = max.getX();
final int maxY = max.getY();
final int maxZ = max.getZ();
// More multithreading!
if (VSConfig.MULTITHREADING_SETTINGS.multithreadCollisionCacheUpdate && parent.getBlockPositions().size() > 100) {
final List<Triple<Integer, Integer, TIntList>> tasks = new ArrayList<>();
for (int chunkX = chunkMinX; chunkX < chunkMaxX; chunkX++) {
for (int chunkZ = chunkMinZ; chunkZ < chunkMaxZ; chunkZ++) {
tasks.add(new ImmutableTriple<>(chunkX, chunkZ, new TIntArrayList()));
}
}
Consumer<Triple<Integer, Integer, TIntList>> consumer = i -> updateCollisionCacheSequential(cache, i.getLeft(), i.getMiddle(), minX, minY, minZ, maxX, maxY, maxZ, shipBB, i.getRight());
ValkyrienSkiesMod.getPhysicsThreadPool().submit(() -> tasks.parallelStream().forEach(consumer)).join();
tasks.forEach(task -> cachedPotentialHits.addAll(task.getRight()));
} else {
// Cast to double to avoid overflow errors
final double size = ((double) (chunkMaxX - chunkMinX)) * ((double) (chunkMaxZ - chunkMinZ));
if (size > 300000) {
// Sanity check; don't execute the rest of the code because we'll just freeze the physics thread.
return;
}
for (int chunkX = chunkMinX; chunkX < chunkMaxX; chunkX++) {
for (int chunkZ = chunkMinZ; chunkZ < chunkMaxZ; chunkZ++) {
updateCollisionCacheSequential(cache, chunkX, chunkZ, minX, minY, minZ, maxX, maxY, maxZ, shipBB, cachedPotentialHits);
}
}
}
}
Aggregations