Java Code Examples for net.minecraft.world.chunk.Chunk#setBlockState()

The following examples show how to use net.minecraft.world.chunk.Chunk#setBlockState() . 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: MoonChunkGenerator.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
private void makeCrater(int craterX, int craterZ, int chunkX, int chunkZ, int size, Chunk chunk) {
    for (int x = 0; x < 16; x++) {
        for (int z = 0; z < 16; z++) {
            double xDev = craterX - (chunkX + x);
            double zDev = craterZ - (chunkZ + z);
            if (xDev * xDev + zDev * zDev < size * size) {
                xDev /= size;
                zDev /= size;
                final double sqrtY = xDev * xDev + zDev * zDev;
                final double yDev = 5 - (sqrtY * sqrtY * 6);
                int helper = 0;
                for (int y = 127; y > 0; y--) {
                    if (!chunk.getBlockState(new BlockPos(x, y, z)).isAir() && helper <= yDev) {
                        chunk.setBlockState(new BlockPos(x, y, z), Blocks.AIR.getDefaultState(), false);
                        helper++;
                    }
                    if (helper > yDev) {
                        break;
                    }
                }
            }
        }
    }
}
 
Example 2
Source File: MoonChunkGenerator.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
public void buildBedrock(Chunk chunk, Random random) {
    BlockPos.Mutable mutable = new BlockPos.Mutable();
    int i = chunk.getPos().getStartX();
    int j = chunk.getPos().getStartZ();
    int k = this.chunkGeneratorType.getBedrockFloorY();
    int l = this.field_24779 - 1 - this.chunkGeneratorType.getBedrockCeilingY();
    boolean bl = l + 4 >= 0 && l < this.field_24779;
    boolean bl2 = k + 4 >= 0 && k < this.field_24779;
    if (bl || bl2) {
        Iterator<BlockPos> var11 = BlockPos.iterate(i, 0, j, i + 15, 0, j + 15).iterator();

        while (true) {
            BlockPos blockPos;
            int o;
            do {
                if (!var11.hasNext()) {
                    return;
                }

                blockPos = var11.next();
                if (bl) {
                    for (o = 0; o < 5; ++o) {
                        if (o <= random.nextInt(5)) {
                            chunk.setBlockState(mutable.set(blockPos.getX(), l - o, blockPos.getZ()), Blocks.BEDROCK.getDefaultState(), false);
                        }
                    }
                }
            } while (!bl2);

            for (o = 4; o >= 0; --o) {
                if (o <= random.nextInt(5)) {
                    chunk.setBlockState(mutable.set(blockPos.getX(), k + o, blockPos.getZ()), Blocks.BEDROCK.getDefaultState(), false);
                }
            }
        }
    }
}
 
Example 3
Source File: MoonSurfaceBuilder.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
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 vote down vote up
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: GTEventPopulateChunk.java    From GT-Classic with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SubscribeEvent(priority = EventPriority.NORMAL)
	public void onEvent(PopulateChunkEvent.Post event) {
		if (!event.getWorld().provider.getDimensionType().equals(DimensionType.OVERWORLD)) {
			return;
		}
		if (GTConfig.general.replaceOceanGravelWithSand) {
			Chunk chunk = event.getWorld().getChunkFromChunkCoords(event.getChunkX(), event.getChunkZ());
			for (int x = 0; x < 16; ++x) {
				for (int z = 0; z < 16; ++z) {
					Biome biomegenbase = event.getWorld().getBiome(new BlockPos(chunk.x * 16 + x, 128, chunk.z * 16
							+ z));
					if (BiomeDictionary.hasType(biomegenbase, Type.OCEAN)
							|| BiomeDictionary.hasType(biomegenbase, Type.BEACH)) {
						for (int y = 30; y < 60; ++y) {
							if (chunk.getBlockState(x, y, z).getBlock() == BLOCK_GRAVEL) {
								chunk.setBlockState(new BlockPos(x, y, z), BLOCK_SAND.getDefaultState());
							}
						}
					}
				}
			}
			chunk.markDirty();
		}
//		if (GTConfig.general.redSandInForestsAndPlains) {
//			Chunk chunk = event.getWorld().getChunkFromChunkCoords(event.getChunkX(), event.getChunkZ());
//			for (int x = 0; x < 16; ++x) {
//				for (int z = 0; z < 16; ++z) {
//					Biome biomegenbase = event.getWorld().getBiome(new BlockPos(chunk.x * 16 + x, 128, chunk.z * 16
//							+ z));
//					if (BiomeDictionary.hasType(biomegenbase, Type.FOREST)
//							|| BiomeDictionary.hasType(biomegenbase, Type.PLAINS)) {
//						for (int y = 30; y < 80; ++y) {
//							if (chunk.getBlockState(x, y, z).getBlock() == BLOCK_SAND) {
//								chunk.setBlockState(new BlockPos(x, y, z), BLOCKSTATE_RED_SAND);
//							}
//						}
//					}
//				}
//			}
//			chunk.markDirty();
//		}
	}
 
Example 6
Source File: WorldGenLargeCrystal.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
public void setBlockState(World world, BlockPos pos, IBlockState state) {
	Chunk chunk = world.getChunkFromBlockCoords(pos);
	chunk.setBlockState(pos, state);
}
 
Example 7
Source File: BiomeHandler.java    From AdvancedRocketry with MIT License 3 votes vote down vote up
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);
	}