use of net.minecraft.world.ChunkCache in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class WorldPhysicsCollider method updatePotentialCollisionCache.
private void updatePotentialCollisionCache() {
final AxisAlignedBB collisionBB = parent.collisionBB.expand(expansion, expansion, expansion).addCoord(calculator.linearMomentum.X * calculator.invMass, calculator.linearMomentum.Y * calculator.invMass, calculator.linearMomentum.Z * calculator.invMass);
ticksSinceCacheUpdate = 0D;
//in the same tick
if (Math.random() > .5) {
ticksSinceCacheUpdate -= .05D;
}
// cachedPotentialHits = new ArrayList<BlockPos>();
cachedPotentialHits = new TIntArrayList();
// Ship is outside of world blockSpace, just skip this all together
if (collisionBB.maxY < 0 || collisionBB.minY > 255) {
// internalCachedPotentialHits = new BlockPos[0];
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()) / 2D, (min.getY() + max.getY()) / 2D, (min.getZ() + max.getZ()) / 2D);
final ChunkCache cache = parent.surroundingWorldChunksCache;
final Vector inLocal = new Vector();
int maxX, maxY, maxZ, localX, localY, localZ, x, y, z, chunkX, chunkZ;
double rangeCheck = 1.8D;
if (ValkyrienWarfareMod.highAccuracyCollisions) {
rangeCheck = 3D;
}
Chunk chunk, chunkIn;
ExtendedBlockStorage extendedblockstorage;
IBlockState state, localState;
int chunkMinX = min.getX() >> 4;
int chunkMaxX = (max.getX() >> 4) + 1;
int storageMinY = min.getY() >> 4;
int storageMaxY = (max.getY() >> 4) + 1;
int chunkMinZ = min.getZ() >> 4;
int chunkMaxZ = (max.getZ() >> 4) + 1;
int storageY;
int mmX = min.getX(), mmY = min.getY(), mmZ = min.getZ(), mxX = max.getX(), mxY = max.getY(), mxZ = max.getZ();
Vector inBody = new Vector();
Vector speedInBody = new Vector();
for (chunkX = chunkMinX; chunkX < chunkMaxX; chunkX++) {
for (chunkZ = chunkMinZ; chunkZ < chunkMaxZ; chunkZ++) {
int arrayChunkX = chunkX - cache.chunkX;
int arrayChunkZ = chunkZ - cache.chunkZ;
if (!(arrayChunkX < 0 || arrayChunkZ < 0 || arrayChunkX > cache.chunkArray.length - 1 || arrayChunkZ > cache.chunkArray[0].length - 1)) {
chunk = cache.chunkArray[arrayChunkX][arrayChunkZ];
for (storageY = storageMinY; storageY < storageMaxY; storageY++) {
extendedblockstorage = chunk.storageArrays[storageY];
if (extendedblockstorage != null) {
int minStorageX = chunkX << 4;
int minStorageY = storageY << 4;
int minStorageZ = chunkZ << 4;
int maxStorageX = minStorageX + 16;
int maxStorageY = minStorageY + 16;
int maxStorageZ = minStorageZ + 16;
minStorageX = Math.max(minStorageX, mmX);
minStorageY = Math.max(minStorageY, mmY);
minStorageZ = Math.max(minStorageZ, mmZ);
maxStorageX = Math.min(maxStorageX, mxX);
maxStorageY = Math.min(maxStorageY, mxY);
maxStorageZ = Math.min(maxStorageZ, mxZ);
for (x = minStorageX; x < maxStorageX; x++) {
for (y = minStorageY; y < maxStorageY; y++) {
for (z = minStorageZ; z < maxStorageZ; z++) {
state = extendedblockstorage.get(x & 15, y & 15, z & 15);
if (state.getMaterial().isSolid()) {
inLocal.X = x + .5D;
inLocal.Y = y + .5D;
inLocal.Z = z + .5D;
parent.coordTransform.fromGlobalToLocal(inLocal);
inBody.setSubtraction(inLocal, parent.centerCoord);
parent.physicsProcessor.setVectorToVelocityAtPoint(inBody, speedInBody);
speedInBody.multiply(-parent.physicsProcessor.physRawSpeed);
if (ValkyrienWarfareMod.highAccuracyCollisions) {
speedInBody.multiply(20D);
}
// System.out.println(speedInBody);
int minX, minY, minZ;
if (speedInBody.X > 0) {
minX = MathHelper.floor_double(inLocal.X - rangeCheck);
maxX = MathHelper.floor_double(inLocal.X + rangeCheck + speedInBody.X);
} else {
minX = MathHelper.floor_double(inLocal.X - rangeCheck + speedInBody.X);
maxX = MathHelper.floor_double(inLocal.X + rangeCheck);
}
if (speedInBody.Y > 0) {
minY = MathHelper.floor_double(inLocal.Y - rangeCheck);
maxY = MathHelper.floor_double(inLocal.Y + rangeCheck + speedInBody.Y);
} else {
minY = MathHelper.floor_double(inLocal.Y - rangeCheck + speedInBody.Y);
maxY = MathHelper.floor_double(inLocal.Y + rangeCheck);
}
if (speedInBody.Z > 0) {
minZ = MathHelper.floor_double(inLocal.Z - rangeCheck);
maxZ = MathHelper.floor_double(inLocal.Z + rangeCheck + speedInBody.Z);
} else {
minZ = MathHelper.floor_double(inLocal.Z - rangeCheck + speedInBody.Z);
maxZ = MathHelper.floor_double(inLocal.Z + rangeCheck);
}
/** The Old Way of doing things; approx. 33% slower overall when running this code instead of new
for (localX = minX; localX < maxX; localX++) {
for (localZ = minZ; localZ < maxZ; localZ++) {
for (localY = minY; localY < maxY; localY++) {
if (parent.ownsChunk(localX >> 4, localZ >> 4)) {
chunkIn = parent.VKChunkCache.getChunkAt(localX >> 4, localZ >> 4);
localState = chunkIn.getBlockState(localX, localY, localZ);
if (localState.getMaterial().isSolid()) {
cachedPotentialHits.add(SpatialDetector.getHashWithRespectTo(x, y, z, centerPotentialHit));
localX = localY = localZ = Integer.MAX_VALUE - 420;
}
}
}
}
}
**/
int shipChunkMinX = minX >> 4;
int shipChunkMinY = Math.max(minY >> 4, 0);
int shipChunkMinZ = minZ >> 4;
int shipChunkMaxX = maxX >> 4;
int shipChunkMaxY = Math.min(maxY >> 4, 15);
int shipChunkMaxZ = maxZ >> 4;
shipChunkMaxX++;
shipChunkMaxY++;
shipChunkMaxZ++;
if (shipChunkMaxZ - shipChunkMinZ > 200 || shipChunkMaxX - shipChunkMinX > 200) {
System.err.println("Wtf. This fucking error");
return;
}
testForNearbyBlocks: for (int shipChunkX = shipChunkMinX; shipChunkX < shipChunkMaxX; shipChunkX++) {
for (int shipChunkZ = shipChunkMinZ; shipChunkZ < shipChunkMaxZ; shipChunkZ++) {
if (parent.ownsChunk(shipChunkX, shipChunkZ)) {
chunkIn = parent.VKChunkCache.getChunkAt(shipChunkX, shipChunkZ);
for (int shipChunkYStorage = shipChunkMinY; shipChunkYStorage < shipChunkMaxY; shipChunkYStorage++) {
ExtendedBlockStorage storage = chunkIn.storageArrays[shipChunkYStorage];
if (storage != null) {
int shipStorageMinX = shipChunkX << 4;
int shipStorageMinY = shipChunkYStorage << 4;
int shipStorageMinZ = shipChunkZ << 4;
int shipStorageMaxX = shipStorageMinX + 16;
int shipStorageMaxY = shipStorageMinY + 16;
int shipStorageMaxZ = shipStorageMinZ + 16;
shipStorageMinX = Math.max(shipStorageMinX, minX);
shipStorageMinY = Math.max(shipStorageMinY, minY);
shipStorageMinZ = Math.max(shipStorageMinZ, minZ);
shipStorageMaxX = Math.min(shipStorageMaxX, maxX);
shipStorageMaxY = Math.min(shipStorageMaxY, maxY);
shipStorageMaxZ = Math.min(shipStorageMaxZ, maxZ);
for (localX = shipStorageMinX; localX < shipStorageMaxX; localX++) {
for (localY = shipStorageMinY; localY < shipStorageMaxY; localY++) {
for (localZ = shipStorageMinZ; localZ < shipStorageMaxZ; localZ++) {
localState = chunkIn.getBlockState(localX, localY, localZ);
if (localState.getMaterial().isSolid()) {
cachedPotentialHits.add(SpatialDetector.getHashWithRespectTo(x, y, z, centerPotentialHit));
break testForNearbyBlocks;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
/**
for (x = min.getX(); x <= max.getX(); x++) {
for (z = min.getZ(); z < max.getZ(); z++) {
chunkX = (x >> 4) - cache.chunkX;
chunkZ = (z >> 4) - cache.chunkZ;
if (!(chunkX < 0 || chunkZ < 0 || chunkX > cache.chunkArray.length - 1 || chunkZ > cache.chunkArray[0].length - 1)) {
chunk = cache.chunkArray[chunkX][chunkZ];
for (y = min.getY(); y < max.getY(); y++) {
extendedblockstorage = chunk.storageArrays[y >> 4];
if (extendedblockstorage != null) {
state = extendedblockstorage.get(x & 15, y & 15, z & 15);
if (state.getMaterial().isSolid()) {
inLocal.X = x + .5D;
inLocal.Y = y + .5D;
inLocal.Z = z + .5D;
parent.coordTransform.fromGlobalToLocal(inLocal);
maxX = (int) Math.floor(inLocal.X + rangeCheck);
maxY = (int) Math.floor(inLocal.Y + rangeCheck);
maxZ = (int) Math.floor(inLocal.Z + rangeCheck);
for (localX = MathHelper.floor_double(inLocal.X - rangeCheck); localX < maxX; localX++) {
for (localZ = MathHelper.floor_double(inLocal.Z - rangeCheck); localZ < maxZ; localZ++) {
for (localY = MathHelper.floor_double(inLocal.Y - rangeCheck); localY < maxY; localY++) {
if (parent.ownsChunk(localX >> 4, localZ >> 4)) {
chunkIn = parent.VKChunkCache.getChunkAt(localX >> 4, localZ >> 4);
localState = chunkIn.getBlockState(localX, localY, localZ);
if (localState.getMaterial().isSolid()) {
cachedPotentialHits.add(SpatialDetector.getHashWithRespectTo(x, y, z, centerPotentialHit));
localX = localY = localZ = Integer.MAX_VALUE - 420;
}
}
}
}
}
}
}
}
}
}
}
**/
cachedPotentialHits.shuffle(rand);
}
use of net.minecraft.world.ChunkCache in project BetterWithAddons by DaedalusGame.
the class BlockRopePost method getExtendedState.
@Override
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
TileEntity te = world instanceof ChunkCache ? ((ChunkCache) world).getTileEntity(pos, Chunk.EnumCreateEntityType.CHECK) : world.getTileEntity(pos);
if (te instanceof TileEntityRopePost) {
TileEntityRopePost tile = (TileEntityRopePost) te;
IExtendedBlockState withplanks = ((IExtendedBlockState) state).withProperty(HELD_WORLD, world).withProperty(HELD_POS, pos).withProperty(HELD_STATE, tile.getFenceState()).withProperty(HELD_PLANKS, tile.getPlanks());
return withplanks;
} else {
return state;
}
}
use of net.minecraft.world.ChunkCache in project RFTools by McJty.
the class CoalGeneratorBlock method getActualState.
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
TileEntity te = world instanceof ChunkCache ? ((ChunkCache) world).getTileEntity(pos, Chunk.EnumCreateEntityType.CHECK) : world.getTileEntity(pos);
boolean working = false;
if (te instanceof CoalGeneratorTileEntity) {
working = ((CoalGeneratorTileEntity) te).isWorking();
}
return state.withProperty(WORKING, working);
}
use of net.minecraft.world.ChunkCache in project RFTools by McJty.
the class ModularStorageBlock method getActualState.
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
TileEntity tileEntity = world instanceof ChunkCache ? ((ChunkCache) world).getTileEntity(pos, Chunk.EnumCreateEntityType.CHECK) : world.getTileEntity(pos);
if (tileEntity instanceof ModularStorageTileEntity) {
ModularStorageTileEntity te = (ModularStorageTileEntity) tileEntity;
ItemStack stack = te.getInventoryHelper().getStackInSlot(ModularStorageContainer.SLOT_TYPE_MODULE);
int level = te.getRenderLevel();
int remoteId = te.getRemoteId();
ModularAmountOverlay p = AMOUNT_NONE;
if (remoteId > 0) {
switch(level) {
case -1:
p = AMOUNT_NONE;
break;
case 0:
p = AMOUNT_R0;
break;
case 1:
p = AMOUNT_R1;
break;
case 2:
p = AMOUNT_R2;
break;
case 3:
p = AMOUNT_R3;
break;
case 4:
p = AMOUNT_R4;
break;
case 5:
p = AMOUNT_R5;
break;
case 6:
p = AMOUNT_R6;
break;
case 7:
p = AMOUNT_R7;
break;
}
} else {
switch(level) {
case -1:
p = AMOUNT_NONE;
break;
case 0:
p = AMOUNT_G0;
break;
case 1:
p = AMOUNT_G1;
break;
case 2:
p = AMOUNT_G2;
break;
case 3:
p = AMOUNT_G3;
break;
case 4:
p = AMOUNT_G4;
break;
case 5:
p = AMOUNT_G5;
break;
case 6:
p = AMOUNT_G6;
break;
case 7:
p = AMOUNT_G7;
break;
}
}
IBlockState newstate = state.withProperty(AMOUNT, p);
if (stack.isEmpty()) {
return newstate.withProperty(TYPEMODULE, TYPE_NONE);
} else if (stack.getItem() == ModularStorageSetup.genericTypeItem) {
return newstate.withProperty(TYPEMODULE, TYPE_GENERIC);
} else if (stack.getItem() == ModularStorageSetup.oreDictTypeItem) {
return newstate.withProperty(TYPEMODULE, TYPE_ORE);
}
return newstate.withProperty(TYPEMODULE, TYPE_NONE);
} else {
return super.getActualState(state, world, pos);
}
}
use of net.minecraft.world.ChunkCache in project RFTools by McJty.
the class MatterBeamerBlock method getActualState.
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
TileEntity te = world instanceof ChunkCache ? ((ChunkCache) world).getTileEntity(pos, Chunk.EnumCreateEntityType.CHECK) : world.getTileEntity(pos);
boolean working = false;
if (te instanceof MatterBeamerTileEntity) {
working = ((MatterBeamerTileEntity) te).isGlowing();
}
return state.withProperty(WORKING, working);
}
Aggregations