Java Code Examples for net.minecraft.world.chunk.Chunk#getBlockState()
The following examples show how to use
net.minecraft.world.chunk.Chunk#getBlockState() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChunkCacheSchematic.java From litematica with GNU Lesser General Public License v3.0 | 6 votes |
@Override public IBlockState getBlockState(BlockPos pos) { if (pos.getY() >= 0 && pos.getY() < 256) { int cx = (pos.getX() >> 4) - this.chunkStartX; int cz = (pos.getZ() >> 4) - this.chunkStartZ; if (cx >= 0 && cx < this.chunkArray.length && cz >= 0 && cz < this.chunkArray[cx].length) { Chunk chunk = this.chunkArray[cx][cz]; if (chunk != null) { return chunk.getBlockState(pos); } } } return AIR; }
Example 2
Source File: SchematicVerifier.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
private boolean verifyChunk(Chunk chunkClient, Chunk chunkSchematic, IntBoundingBox box) { LayerRange range = DataManager.getRenderLayerRange(); EnumFacing.Axis axis = range.getAxis(); boolean ranged = this.schematicPlacement.getSchematicVerifierType() == BlockInfoListType.RENDER_LAYERS; final int startX = ranged && axis == EnumFacing.Axis.X ? Math.max(box.minX, range.getLayerMin()) : box.minX; final int startY = ranged && axis == EnumFacing.Axis.Y ? Math.max(box.minY, range.getLayerMin()) : box.minY; final int startZ = ranged && axis == EnumFacing.Axis.Z ? Math.max(box.minZ, range.getLayerMin()) : box.minZ; final int endX = ranged && axis == EnumFacing.Axis.X ? Math.min(box.maxX, range.getLayerMax()) : box.maxX; final int endY = ranged && axis == EnumFacing.Axis.Y ? Math.min(box.maxY, range.getLayerMax()) : box.maxY; final int endZ = ranged && axis == EnumFacing.Axis.Z ? Math.min(box.maxZ, range.getLayerMax()) : box.maxZ; for (int y = startY; y <= endY; ++y) { for (int z = startZ; z <= endZ; ++z) { for (int x = startX; x <= endX; ++x) { MUTABLE_POS.setPos(x, y, z); IBlockState stateClient = chunkClient.getBlockState(x, y, z).getActualState(chunkClient.getWorld(), MUTABLE_POS); IBlockState stateSchematic = chunkSchematic.getBlockState(x, y, z); this.checkBlockStates(x, y, z, stateSchematic, stateClient); if (stateSchematic != AIR) { this.schematicBlocks++; } if (stateClient != AIR) { this.clientBlocks++; } } } } return true; }
Example 3
Source File: MoonSurfaceBuilder.java From Galacticraft-Rewoven with MIT License | 4 votes |
public void generate(Random random, Chunk chunk, Biome biome, int x, int z, int height, double noise, BlockState defaultBlock, BlockState fluidBlock, int seaLevel, long seed, TernarySurfaceConfig ternarySurfaceConfig) { BlockState blockState = ternarySurfaceConfig.getTopMaterial(); BlockState blockState2 = ternarySurfaceConfig.getUnderMaterial(); BlockPos.Mutable mutable = new BlockPos.Mutable(); int i = -1; int j = (int) (noise / 3.0D + 3.0D + random.nextDouble() * 0.25D); int k = x & 15; int l = z & 15; for (int m = height; m >= 0; --m) { mutable.set(k, m, l); BlockState blockState3 = chunk.getBlockState(mutable); if (blockState3.isAir()) { i = -1; } else if (blockState3.isOf(defaultBlock.getBlock())) { if (i == -1) { if (j <= 0) { blockState = Blocks.AIR.getDefaultState(); blockState2 = defaultBlock; } else if (m >= seaLevel - 4 && m <= seaLevel + 1) { blockState = ternarySurfaceConfig.getTopMaterial(); blockState2 = ternarySurfaceConfig.getUnderMaterial(); } if (m < seaLevel && (blockState == null || blockState.isAir())) { if (biome.getTemperature(mutable.set(x, m, z)) < 0.15F) { blockState = Blocks.ICE.getDefaultState(); } else { blockState = fluidBlock; } mutable.set(k, m, l); } i = j; if (m >= seaLevel - 1) { chunk.setBlockState(mutable, blockState, false); } else if (m < seaLevel - 7 - j) { blockState = Blocks.AIR.getDefaultState(); blockState2 = defaultBlock; chunk.setBlockState(mutable, ternarySurfaceConfig.getUnderwaterMaterial(), false); } else { chunk.setBlockState(mutable, blockState2, false); } } else if (i > 0) { --i; chunk.setBlockState(mutable, blockState2, false); if (i == 0 && blockState2.isOf(GalacticraftBlocks.MOON_TURF) && j > 1) { i = random.nextInt(4) + Math.max(0, m - 63); blockState2 = GalacticraftBlocks.MOON_ROCK.getDefaultState(); } } } } }
Example 4
Source File: MultiBlockSurfaceBuilder.java From Galacticraft-Rewoven with MIT License | 4 votes |
protected void generate(Random random, Chunk chunk, Biome biome, int x, int z, int height, double noise, BlockState defaultBlock, BlockState fluidBlock, MultiBlockSurfaceConfig multiBlockSurfaceConfig, int seaLevel) { BlockState blockState = multiBlockSurfaceConfig.getTopMaterial(); BlockState blockState2 = multiBlockSurfaceConfig.getUnderMaterial(); BlockPos.Mutable mutable = new BlockPos.Mutable(); int i = -1; int j = (int) (noise / 3.0D + 3.0D + random.nextDouble() * 0.25D); int k = x & 15; int l = z & 15; for (int m = height; m >= 0; --m) { mutable.set(k, m, l); BlockState blockState3 = chunk.getBlockState(mutable); if (blockState3.isAir()) { i = -1; } else if (blockState3.getBlock() == defaultBlock.getBlock()) { if (i == -1) { if (j <= 0) { blockState = Blocks.AIR.getDefaultState(); blockState2 = multiBlockSurfaceConfig.getUnderMaterial(); } else if (m >= seaLevel - 4 && m <= seaLevel + 1) { blockState = multiBlockSurfaceConfig.getTopMaterial(); blockState2 = multiBlockSurfaceConfig.getUnderMaterial(); } if (m < seaLevel && (blockState == null || blockState.isAir())) { if (biome.getTemperature(mutable.set(x, m, z)) < 0.15F) { blockState = Blocks.ICE.getDefaultState(); } else { blockState = fluidBlock; } mutable.set(k, m, l); } i = j; if (m >= seaLevel - 1) { chunk.setBlockState(mutable, blockState, false); } else if (m < seaLevel - 7 - j) { blockState = Blocks.AIR.getDefaultState(); blockState2 = multiBlockSurfaceConfig.getTopMaterial(); chunk.setBlockState(mutable, multiBlockSurfaceConfig.getUnderwaterMaterial(), false); } else { chunk.setBlockState(mutable, blockState2, false); } } else if (i > 0) { --i; chunk.setBlockState(mutable, blockState2, false); if (i == 0 && blockState2.getBlock() == Blocks.SAND && j > 1) { i = random.nextInt(4) + Math.max(0, m - 63); blockState2 = blockState2.getBlock() == Blocks.RED_SAND ? Blocks.RED_SANDSTONE.getDefaultState() : Blocks.SANDSTONE.getDefaultState(); } } } } }
Example 5
Source File: TaskPasteSchematicPerChunkCommand.java From litematica with GNU Lesser General Public License v3.0 | 4 votes |
protected boolean processBox(ChunkPos pos, IntBoundingBox box, WorldSchematic worldSchematic, WorldClient worldClient, EntityPlayerSP player) { BlockPos.MutableBlockPos posMutable = new BlockPos.MutableBlockPos(); Chunk chunkSchematic = worldSchematic.getChunkProvider().getLoadedChunk(pos.x, pos.z); Chunk chunkClient = worldClient.getChunkProvider().getLoadedChunk(pos.x, pos.z); if (this.boxInProgress == false) { this.currentX = box.minX; this.currentY = box.minY; this.currentZ = box.minZ; this.boxVolume = (box.maxX - box.minX + 1) * (box.maxY - box.minY + 1) * (box.maxZ - box.minZ + 1); this.currentIndex = 0; this.boxInProgress = true; } while (this.currentIndex < this.boxVolume) { posMutable.setPos(this.currentX, this.currentY, this.currentZ); if (++this.currentY > box.maxY) { this.currentY = box.minY; if (++this.currentX > box.maxX) { this.currentX = box.minX; ++this.currentZ; } } ++this.currentIndex; IBlockState stateSchematicOrig = chunkSchematic.getBlockState(posMutable); IBlockState stateClient = chunkClient.getBlockState(posMutable); if (stateSchematicOrig.getBlock() != Blocks.AIR || stateClient.getBlock() != Blocks.AIR) { // Discard the non-meta state info, as it depends on neighbor blocks which will // be synced with some delay from the server. TODO 1.13 remove this @SuppressWarnings("deprecation") IBlockState stateSchematic = stateSchematicOrig.getBlock().getStateFromMeta(stateSchematicOrig.getBlock().getMetaFromState(stateSchematicOrig)); if (this.changedBlockOnly == false || stateClient != stateSchematic) { if ((this.replace == ReplaceBehavior.NONE && stateClient.getMaterial() != Material.AIR) || (this.replace == ReplaceBehavior.WITH_NON_AIR && stateSchematicOrig.getMaterial() == Material.AIR)) { continue; } this.sendSetBlockCommand(posMutable.getX(), posMutable.getY(), posMutable.getZ(), stateSchematicOrig, player); if (++this.sentCommandsThisTick >= this.maxCommandsPerTick) { break; } } } } if (this.currentIndex >= this.boxVolume) { this.summonEntities(box, worldSchematic, player); this.boxInProgress = false; return true; } return false; }
Example 6
Source File: ShipCollisionTask.java From Valkyrien-Skies with Apache License 2.0 | 4 votes |
public void checkPosition(int x, int y, int z, int positionHash) { final Chunk chunkIn = toTask.getParent() .getChunkAt(x >> 4, z >> 4); y = Math.max(0, Math.min(y, 255)); ExtendedBlockStorage storage = chunkIn.storageArrays[y >> 4]; if (storage != null) { IBitOctreeProvider provider = (IBitOctreeProvider) storage.data; IBitOctree octree = provider.getBitOctree(); if (octree.get(x & 15, y & 15, z & 15)) { IBlockState inLocalState = chunkIn.getBlockState(x, y, z); // Only if you want to stop short // foundPairs.add(positionHash); // foundPairs.add(x); // foundPairs.add(y); // foundPairs.add(z); inLocalPos.setPos(x, y, z); AxisAlignedBB inLocalBB = new AxisAlignedBB(inLocalPos.getX(), inLocalPos.getY(), inLocalPos.getZ(), inLocalPos.getX() + 1, inLocalPos.getY() + 1, inLocalPos.getZ() + 1); AxisAlignedBB inGlobalBB = new AxisAlignedBB(mutablePos.getX(), mutablePos.getY(), mutablePos.getZ(), mutablePos.getX() + 1, mutablePos.getY() + 1, mutablePos.getZ() + 1); // This changes the box bounding box to the real bounding box, not sure if this // is better or worse for this mod // List<AxisAlignedBB> colBB = worldObj.getCollisionBoxes(inLocalBB); // inLocalBB = colBB.get(0); Polygon shipInWorld = new Polygon(inLocalBB, toTask.getParent().getShipTransformationManager().getCurrentPhysicsTransform(), TransformType.SUBSPACE_TO_GLOBAL); Polygon worldPoly = new Polygon(inGlobalBB); // TODO: Remove the normals crap PhysPolygonCollider collider = new PhysPolygonCollider(shipInWorld, worldPoly, toTask.getParent().getShipTransformationManager().normals); if (!collider.seperated) { // return handleActualCollision(collider, mutablePos, inLocalPos, inWorldState, // inLocalState); CollisionInformationHolder holder = new CollisionInformationHolder(collider, mutablePos.getX(), mutablePos.getY(), mutablePos.getZ(), inLocalPos.getX(), inLocalPos.getY(), inLocalPos.getZ(), inWorldState, inLocalState); collisionInformationGenerated.add(holder); } } } }
Example 7
Source File: BiomeHandler.java From AdvancedRocketry with MIT License | 3 votes |
public static void changeBiome(World world, int biomeId, Chunk chunk, BlockPos pos) { Biome biome = world.getBiome(pos); Biome biomeTo = Biome.getBiome(biomeId); int x = pos.getX(); int z = pos.getZ(); if(biome == biomeTo) return; int y = 60; if(biome.topBlock != biomeTo.topBlock) { int yy = chunk.getHeightValue(x & 15, z & 15); while(!world.getBlockState(new BlockPos(x, yy - 1, z)).isOpaqueCube() && yy > 0) yy--; if(yy == 0) return; if(chunk.getBlockState(x & 15, yy - 1, z & 15) == biome.topBlock) chunk.setBlockState(new BlockPos(x & 15, yy - 1, z & 15), biomeTo.topBlock); y = (short)yy; } byte[] biomeArr = chunk.getBiomeArray(); biomeArr[(x & 15) + (z & 15)*16] = (byte)biomeId; //PacketHandler.sendToNearby(new PacketBiomeIDChange(chunk, world, new BlockPosition(x, y, z)), world.provider.dimensionId, x, y, z, 256); }