Search in sources :

Example 1 with ExtendedBlockStorage

use of net.minecraft.world.chunk.storage.ExtendedBlockStorage 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();
}
Also used : TIntIterator(gnu.trove.iterator.TIntIterator) VWChunkCache(ValkyrienWarfareBase.Relocation.VWChunkCache) IBlockState(net.minecraft.block.state.IBlockState) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) SPacketUnloadChunk(net.minecraft.network.play.server.SPacketUnloadChunk) Chunk(net.minecraft.world.chunk.Chunk) ExtendedBlockStorage(net.minecraft.world.chunk.storage.ExtendedBlockStorage) TileEntity(net.minecraft.tileentity.TileEntity) Field(java.lang.reflect.Field) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) Vector(ValkyrienWarfareBase.API.Vector)

Example 2 with ExtendedBlockStorage

use of net.minecraft.world.chunk.storage.ExtendedBlockStorage 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);
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState) ChunkCache(net.minecraft.world.ChunkCache) BlockPos(net.minecraft.util.math.BlockPos) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) Chunk(net.minecraft.world.chunk.Chunk) ExtendedBlockStorage(net.minecraft.world.chunk.storage.ExtendedBlockStorage) Vector(ValkyrienWarfareBase.API.Vector) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Example 3 with ExtendedBlockStorage

use of net.minecraft.world.chunk.storage.ExtendedBlockStorage in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class WorldPhysicsCollider method processPotentialCollisionsAccurately.

// Runs through the cache ArrayList, checking each possible BlockPos for SOLID blocks that can collide, if it finds any it will
// move to the next method
//TODO: Optimize from here, this is taking 10x the processing time of updating collision cache!
private void processPotentialCollisionsAccurately() {
    final MutableBlockPos localCollisionPos = new MutableBlockPos();
    final Vector inWorld = new Vector();
    int minX, minY, minZ, maxX, maxY, maxZ, x, y, z;
    final double rangeCheck = .65D;
    TIntIterator intIterator = cachedPotentialHits.iterator();
    while (intIterator.hasNext()) {
        // Converts the int to a mutablePos
        SpatialDetector.setPosWithRespectTo(intIterator.next(), centerPotentialHit, mutablePos);
        inWorld.X = mutablePos.getX() + .5;
        inWorld.Y = mutablePos.getY() + .5;
        inWorld.Z = mutablePos.getZ() + .5;
        parent.coordTransform.fromGlobalToLocal(inWorld);
        minX = MathHelper.floor_double(inWorld.X - rangeCheck);
        minY = MathHelper.floor_double(inWorld.Y - rangeCheck);
        minZ = MathHelper.floor_double(inWorld.Z - rangeCheck);
        maxX = MathHelper.floor_double(inWorld.X + rangeCheck);
        maxY = MathHelper.floor_double(inWorld.Y + rangeCheck);
        maxZ = MathHelper.floor_double(inWorld.Z + rangeCheck);
        /**
			 * Something here is causing the game to freeze :/
			 */
        int minChunkX = minX >> 4;
        int minChunkY = minY >> 4;
        int minChunkZ = minZ >> 4;
        int maxChunkX = maxX >> 4;
        int maxChunkY = maxY >> 4;
        int maxChunkZ = maxZ >> 4;
        entireLoop: if (!(minChunkY > 15 || maxChunkY < 0)) {
            for (int chunkX = minChunkX; chunkX <= maxChunkX; chunkX++) {
                for (int chunkZ = minChunkZ; chunkZ <= maxChunkZ; chunkZ++) {
                    if (parent.ownsChunk(chunkX, chunkZ)) {
                        final Chunk chunkIn = parent.VKChunkCache.getChunkAt(chunkX, chunkZ);
                        int minXToCheck = chunkX << 4;
                        int maxXToCheck = minXToCheck + 15;
                        int minZToCheck = chunkZ << 4;
                        int maxZToCheck = minZToCheck + 15;
                        minXToCheck = Math.max(minXToCheck, minX);
                        maxXToCheck = Math.min(maxXToCheck, maxX);
                        minZToCheck = Math.max(minZToCheck, minZ);
                        maxZToCheck = Math.min(maxZToCheck, maxZ);
                        for (int chunkY = minChunkY; chunkY <= maxChunkY; chunkY++) {
                            ExtendedBlockStorage storage = chunkIn.storageArrays[chunkY];
                            if (storage != null) {
                                int minYToCheck = chunkY << 4;
                                int maxYToCheck = minYToCheck + 15;
                                minYToCheck = Math.max(minYToCheck, minY);
                                maxYToCheck = Math.min(maxYToCheck, maxY);
                                for (x = minXToCheck; x <= maxXToCheck; x++) {
                                    for (z = minZToCheck; z <= maxZToCheck; z++) {
                                        for (y = minYToCheck; y <= maxYToCheck; y++) {
                                            final IBlockState state = storage.get(x & 15, y & 15, z & 15);
                                            if (state.getMaterial().isSolid()) {
                                                localCollisionPos.setPos(x, y, z);
                                                boolean brokeAWorldBlock = handleLikelyCollision(mutablePos, localCollisionPos, parent.surroundingWorldChunksCache.getBlockState(mutablePos), state);
                                                if (brokeAWorldBlock) {
                                                    int positionRemoved = SpatialDetector.getHashWithRespectTo(mutablePos.getX(), mutablePos.getY(), mutablePos.getZ(), centerPotentialHit);
                                                    cachedHitsToRemove.add(positionRemoved);
                                                    break entireLoop;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    //The old way of doing things
    /*for (x = minX; x <= maxX; x++) {
				for (z = minZ; z <= maxZ; z++) {
					if (parent.ownsChunk(x >> 4, z >> 4)) {
						for (y = minY; y <= maxY; y++) {
							final Chunk chunkIn = parent.VKChunkCache.getChunkAt(x >> 4, z >> 4);
							final IBlockState state = chunkIn.getBlockState(x, y, z);
							if (state.getMaterial().isSolid()) {
								localCollisionPos.setPos(x, y, z);

								handleLikelyCollision(mutablePos, localCollisionPos, parent.surroundingWorldChunksCache.getBlockState(mutablePos), state);
							}
						}
					}
				}
			}*/
    }
}
Also used : TIntIterator(gnu.trove.iterator.TIntIterator) IBlockState(net.minecraft.block.state.IBlockState) Chunk(net.minecraft.world.chunk.Chunk) ExtendedBlockStorage(net.minecraft.world.chunk.storage.ExtendedBlockStorage) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) Vector(ValkyrienWarfareBase.API.Vector)

Example 4 with ExtendedBlockStorage

use of net.minecraft.world.chunk.storage.ExtendedBlockStorage in project Engine by VoltzEngine-Project.

the class AbstractChunkProvider method setBlock.

/**
     * Places a block inside of the chunks extends block storage
     * <p>
     * This will also set the light level if the block has a light level.
     *
     * @param chunk - chunk to edit
     * @param y     - y level to place the block at
     * @param x     - chunk internal x pos 0 to 15
     * @param z     - chunk internal z pos 0 to 15
     * @param block - block to place
     * @param meta  - meta to place
     */
protected final void setBlock(Chunk chunk, int x, int y, int z, Block block, int meta) {
    final int l = y >> 4;
    ExtendedBlockStorage extendedblockstorage = chunk.getBlockStorageArray()[l];
    if (extendedblockstorage == null) {
        extendedblockstorage = new ExtendedBlockStorage((y / 16) * 16, !this.worldObj.provider.hasNoSky);
        chunk.getBlockStorageArray()[l] = extendedblockstorage;
    }
    extendedblockstorage.func_150818_a(x, y & 15, z, block);
    if (meta >= 0 && meta < 16) {
        extendedblockstorage.setExtBlockMetadata(x, y & 15, z, meta);
    }
    if (block.getLightValue() > 0) {
        extendedblockstorage.setExtBlocklightValue(x, y & 15, z, block.getLightValue());
    }
}
Also used : ExtendedBlockStorage(net.minecraft.world.chunk.storage.ExtendedBlockStorage)

Example 5 with ExtendedBlockStorage

use of net.minecraft.world.chunk.storage.ExtendedBlockStorage in project Engine by VoltzEngine-Project.

the class ChunkProviderEmpty method provideChunk.

/**
     * Will return back a chunk, if it doesn't exist and its not a MP client it will generates all the blocks for the
     * specified chunk from the map seed and chunk seed
     */
@Override
public Chunk provideChunk(int chunkX, int chunkZ) {
    Chunk chunk = new Chunk(this.worldObj, chunkX, chunkZ);
    int spawnChunkX = this.worldObj.getSpawnPoint().posX >> 4;
    int spawnChunkZ = this.worldObj.getSpawnPoint().posZ >> 4;
    int y_base = 70;
    //Init spawn if it has not already been created
    if (spawnChunkX == chunkX && spawnChunkZ == chunkZ) {
        generateSpawnCenter(chunk, chunkX, chunkZ, y_base);
    } else if (spawnChunkX + 1 == chunkX && spawnChunkZ == chunkZ || spawnChunkX - 1 == chunkX && spawnChunkZ == chunkZ) {
        generateXBridge(chunk, chunkX, chunkZ, y_base);
    } else if (spawnChunkX == chunkX && spawnChunkZ + 1 == chunkZ || spawnChunkX == chunkX && spawnChunkZ - 1 == chunkZ) {
        generateZBridge(chunk, chunkX, chunkZ, y_base);
    } else if (spawnChunkX + 2 == chunkX && spawnChunkZ == chunkZ) {
        generatePlatform(chunk, chunkX, chunkZ, y_base);
        ExtendedBlockStorage extendedblockstorage = chunk.getBlockStorageArray()[y_base >> 4];
        extendedblockstorage.func_150818_a(15, (y_base + 11) & 15, 8, Blocks.command_block);
    } else if (spawnChunkX - 2 == chunkX && spawnChunkZ == chunkZ) {
        generatePlatform(chunk, chunkX, chunkZ, y_base);
        ExtendedBlockStorage extendedblockstorage = chunk.getBlockStorageArray()[y_base >> 4];
        extendedblockstorage.func_150818_a(0, (y_base + 11) & 15, 8, Blocks.command_block);
    } else if (spawnChunkX == chunkX && spawnChunkZ + 2 == chunkZ) {
        generatePlatform(chunk, chunkX, chunkZ, y_base);
        ExtendedBlockStorage extendedblockstorage = chunk.getBlockStorageArray()[y_base >> 4];
        extendedblockstorage.func_150818_a(8, (y_base + 11) & 15, 15, Blocks.command_block);
    } else if (spawnChunkX == chunkX && spawnChunkZ - 2 == chunkZ) {
        generatePlatform(chunk, chunkX, chunkZ, y_base);
        ExtendedBlockStorage extendedblockstorage = chunk.getBlockStorageArray()[y_base >> 4];
        extendedblockstorage.func_150818_a(8, (y_base + 11) & 15, 0, Blocks.command_block);
    } else if (spawnChunkX + 4 == chunkX && spawnChunkZ == chunkZ) {
        lazyGenerateIsland("chunkFlat", chunkX << 4, y_base, chunkZ << 4);
    } else if (spawnChunkX - 4 == chunkX && spawnChunkZ == chunkZ) {
        lazyGenerateIsland("tree", chunkX << 4, y_base, chunkZ << 4);
    } else if (spawnChunkX == chunkX && spawnChunkZ + 4 == chunkZ) {
        lazyGenerateIsland("stonebrickPlatform", chunkX << 4, y_base, chunkZ << 4);
    } else if (spawnChunkX == chunkX && spawnChunkZ - 4 == chunkZ) {
    //lazyGenerateIsland("chunkFlat", chunkX << 4, 33, chunkZ << 4);
    }
    //Not sure if we need to call this before biome
    chunk.generateSkylightMap();
    //Set biome ID for chunk
    byte[] abyte1 = chunk.getBiomeArray();
    Arrays.fill(abyte1, (byte) 1);
    chunk.generateSkylightMap();
    return chunk;
}
Also used : Chunk(net.minecraft.world.chunk.Chunk) ExtendedBlockStorage(net.minecraft.world.chunk.storage.ExtendedBlockStorage)

Aggregations

ExtendedBlockStorage (net.minecraft.world.chunk.storage.ExtendedBlockStorage)12 Chunk (net.minecraft.world.chunk.Chunk)7 MutableBlockPos (net.minecraft.util.math.BlockPos.MutableBlockPos)4 Vector (ValkyrienWarfareBase.API.Vector)3 IBlockState (net.minecraft.block.state.IBlockState)3 BlockPos (net.minecraft.util.math.BlockPos)3 TIntIterator (gnu.trove.iterator.TIntIterator)2 SPacketUnloadChunk (net.minecraft.network.play.server.SPacketUnloadChunk)2 VWChunkCache (ValkyrienWarfareBase.Relocation.VWChunkCache)1 Pos (com.builtbroken.mc.imp.transform.vector.Pos)1 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 Field (java.lang.reflect.Field)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 TileEntity (net.minecraft.tileentity.TileEntity)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 ChunkCache (net.minecraft.world.ChunkCache)1