net.minecraft.world.gen.chunk.ChunkGenerator Java Examples

The following examples show how to use net.minecraft.world.gen.chunk.ChunkGenerator. 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: SpiderLairFeature.java    From the-hallow with MIT License 6 votes vote down vote up
@Override
public boolean generate(IWorld iWorld, ChunkGenerator<? extends ChunkGeneratorConfig> chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig defaultFeatureConfig) {
	if (iWorld.getBlockState(pos.down()).getBlock() == HallowedBlocks.DECEASED_GRASS_BLOCK) {
		setSpawner(iWorld, pos, EntityType.SPIDER);
		
		for (int i = 0; i < 64; ++i) {
			BlockPos pos_2 = pos.add(random.nextInt(6) - random.nextInt(6), random.nextInt(3) - random.nextInt(3), random.nextInt(6) - random.nextInt(6));
			if (iWorld.isAir(pos_2) || iWorld.getBlockState(pos_2).getBlock() == HallowedBlocks.DECEASED_GRASS_BLOCK) {
				iWorld.setBlockState(pos_2, Blocks.COBWEB.getDefaultState(), 2);
			}
		}
		
		BlockPos chestPos = pos.add(random.nextInt(4) - random.nextInt(4), 0, random.nextInt(4) - random.nextInt(4));
		iWorld.setBlockState(chestPos, StructurePiece.method_14916(iWorld, chestPos, Blocks.CHEST.getDefaultState()), 2);
		LootableContainerBlockEntity.setLootTable(iWorld, random, chestPos, TheHallow.id("chests/spider_lair"));
		
		return true;
	} else {
		return false;
	}
}
 
Example #2
Source File: HallowedCactusFeature.java    From the-hallow with MIT License 6 votes vote down vote up
@Override
public boolean generate(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> generator, Random random, BlockPos pos, DefaultFeatureConfig config) {
	for (int i = 0; i < 10; i++) {
		BlockPos pos2 = pos.add(random.nextInt(8) - random.nextInt(8), random.nextInt(4) - random.nextInt(4), random.nextInt(8) - random.nextInt(8));
		if (world.isAir(pos2)) {
			int height = 1 + random.nextInt(random.nextInt(3) + 1);
			
			for (int j = 0; j < height; j++) {
				if (HallowedBlocks.RESTLESS_CACTUS.getDefaultState().canPlaceAt(world, pos2)) {
					world.setBlockState(pos2.up(j), HallowedBlocks.RESTLESS_CACTUS.getDefaultState(), 2);
				}
			}
		}
	}
	
	return true;
}
 
Example #3
Source File: FeatureGenerator.java    From fabric-carpet with MIT License 6 votes vote down vote up
public static StructureStart shouldStructureStartAt(ServerWorld world, BlockPos pos, StructureFeature<?> structure, boolean computeBox)
{
    ChunkGenerator<?> generator = world.getChunkManager().getChunkGenerator();
    if (!generator.getBiomeSource().hasStructureFeature(structure))
        return null;
    BiomeAccess biomeAccess = world.getBiomeAccess().withSource(generator.getBiomeSource());
    ChunkRandom chunkRandom = new ChunkRandom();
    ChunkPos chunkPos = new ChunkPos(pos);
    Biome biome = biomeAccess.getBiome(new BlockPos(chunkPos.getStartX() + 9, 0, chunkPos.getStartZ() + 9));
    if (structure.shouldStartAt(biomeAccess, generator, chunkRandom, chunkPos.x, chunkPos.z, biome))
    {
        if (!computeBox) return StructureStart.DEFAULT;
        StructureManager manager = world.getSaveHandler().getStructureManager();
        StructureStart structureStart3 = structure.getStructureStartFactory().create(structure, chunkPos.x, chunkPos.z, BlockBox.empty(), 0, generator.getSeed());
        structureStart3.initialize(generator, manager, chunkPos.x, chunkPos.z, biome);
        if (!structureStart3.hasChildren()) return null;
        return structureStart3;
    }
    return null;
}
 
Example #4
Source File: HallowedOreFeature.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public boolean generate(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> chunkGenerator, Random random, BlockPos blockPos, HallowedOreFeatureConfig oreFeatureConfig) {
	float randomNumberFromZeroToPi = random.nextFloat() * 3.1415927F;
	float dividedSize = (float) oreFeatureConfig.size / 8.0F;
	int ceilSize = MathHelper.ceil(((float) oreFeatureConfig.size / 16.0F * 2.0F + 1.0F) / 2.0F);
	double positiveX = (blockPos.getX() + MathHelper.sin(randomNumberFromZeroToPi) * dividedSize);
	double negativeX = (blockPos.getX() - MathHelper.sin(randomNumberFromZeroToPi) * dividedSize);
	double positiveZ = (blockPos.getZ() + MathHelper.cos(randomNumberFromZeroToPi) * dividedSize);
	double negativeZ = (blockPos.getZ() - MathHelper.cos(randomNumberFromZeroToPi) * dividedSize);
	double positiveY = (blockPos.getY() + random.nextInt(3) - 2);
	double negativeY = (blockPos.getY() + random.nextInt(3) - 2);
	int startX = blockPos.getX() - MathHelper.ceil(dividedSize) - ceilSize;
	int y = blockPos.getY() - 2 - ceilSize;
	int startZ = blockPos.getZ() - MathHelper.ceil(dividedSize) - ceilSize;
	int xSize = 2 * (MathHelper.ceil(dividedSize) + ceilSize);
	int int_7 = 2 * (2 + ceilSize);
	
	for (int x = startX; x <= startX + xSize; ++x) {
		for (int z = startZ; z <= startZ + xSize; ++z) {
			if (y <= world.getTopY(Type.OCEAN_FLOOR_WG, x, z)) {
				return this.generateVeinPart(world, random, oreFeatureConfig, positiveX, negativeX, positiveZ, negativeZ, positiveY, negativeY, startX, y, startZ, xSize, int_7);
			}
		}
	}
	
	return false;
}
 
Example #5
Source File: StructureFeatureMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
private StructureStart forceStructureStart(IWorld worldIn, ChunkGenerator <? extends ChunkGeneratorConfig > generator, Random rand, long packedChunkPos)
{
    ChunkPos chunkpos = new ChunkPos(packedChunkPos);
    StructureStart structurestart;

    Chunk ichunk = worldIn.getChunk(chunkpos.x, chunkpos.z, ChunkStatus.STRUCTURE_STARTS, false);

    if (ichunk != null)
    {
        structurestart = ichunk.getStructureStart(this.getName());

        if (structurestart != null && structurestart != StructureStart.DEFAULT)
        {
            return structurestart;
        }
    }
    Biome biome_1 = generator.getBiomeSource().getBiomeForNoiseGen((chunkpos.getStartX() + 9) >> 2, 0, (chunkpos.getStartZ() + 9) >> 2 );
    StructureStart structurestart1 = getStructureStartFactory().create((StructureFeature)(Object)this, chunkpos.x, chunkpos.z, BlockBox.empty(),0,generator.getSeed());
    structurestart1.initialize(generator, ((ServerWorld)worldIn).getStructureManager() , chunkpos.x, chunkpos.z, biome_1);
    structurestart = structurestart1.hasChildren() ? structurestart1 : StructureStart.DEFAULT;

    if (structurestart.hasChildren())
    {
        worldIn.getChunk(chunkpos.x, chunkpos.z).setStructureStart(this.getName(), structurestart);
    }

    //long2objectmap.put(packedChunkPos, structurestart);
    return structurestart;
}
 
Example #6
Source File: CarpetExpression.java    From fabric-carpet with MIT License 5 votes vote down vote up
private void BooYah(ChunkGenerator generator)
{
    synchronized (generator)
    {
        if (generator.getSeed() != lastSeed)
        {
            StructureFeatures.STRONGHOLD.shouldStartAt(null, generator, null, 0, 0, null);
            lastSeed = generator.getSeed();
        }
    }
}
 
Example #7
Source File: FeatureGenerator.java    From fabric-carpet with MIT License 5 votes vote down vote up
private static Thing setupCustomStructure(StructureFeature structure, FeatureConfig conf, Biome biome, boolean wireOnly)
    {
    //if (1+2==3)
    //    throw new RuntimeException("rebuild me");
    return (w, p) -> {
        ChunkGenerator chunkgen = new OverworldChunkGenerator(w, w.getChunkManager().getChunkGenerator().getBiomeSource(), new OverworldChunkGeneratorConfig()) //  BiomeSourceType.VANILLA_LAYERED.applyConfig((BiomeSourceType.VANILLA_LAYERED.getConfig())), ChunkGeneratorType.SURFACE.createSettings())
        {
            @Override
            public <C extends FeatureConfig> C getStructureConfig(Biome biome_1, StructureFeature<C> structureFeature_1)
            {
                return (C)conf;
            }

            @Override
            public BiomeSource getBiomeSource()
            {
                return new VanillaLayeredBiomeSource(new VanillaLayeredBiomeSourceConfig(w.getLevelProperties()))
                {
                    @Override
                    public Biome getBiomeForNoiseGen(int i, int j, int k)
                    {
                        return biome;
                    }

                    @Override
                    public Set<Biome> getBiomesInArea(int int_1, int int_2, int int_3, int int_4)
                    {
                        return Sets.newHashSet(biome);
                    }
                };
            }
        };


        return ((StructureFeatureInterface)structure).plopAnywhere(w, p, chunkgen, wireOnly);
    };
}
 
Example #8
Source File: MixinServerWorld.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Redirect(method = "method_14168", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/dimension/Dimension;createChunkGenerator()Lnet/minecraft/world/gen/chunk/ChunkGenerator;"))
private static ChunkGenerator<?> createChunkGenerator(Dimension dimension, WorldSaveHandler saveHandler, Executor executor, MinecraftServer minecraftServer, WorldGenerationProgressListener progressListener, World world, Dimension dimensionArg) {
	LevelGeneratorType generatorType = world.getLevelProperties().getGeneratorType();

	if (generatorType instanceof PatchworkLevelGeneratorType) {
		return ((IForgeWorldType) generatorType).createChunkGenerator(world);
	} else {
		return dimension.createChunkGenerator();
	}
}
 
Example #9
Source File: RandomizedWildCropFeature.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public boolean generate(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> chunkGenerator, Random random, BlockPos blockPos, DefaultFeatureConfig defaultFeatureConfig) {
	int numCrop = 0;

	for (int i = 0; i < 64; ++i) {
		BlockPos randomBlockPos = blockPos.add(random.nextInt(8) - random.nextInt(8), random.nextInt(4) - random.nextInt(4), random.nextInt(8) - random.nextInt(8));
		if (world.isAir(randomBlockPos) && world.getBlockState(randomBlockPos.down()).getBlock() == HallowedBlocks.DECEASED_GRASS_BLOCK) {
			world.setBlockState(randomBlockPos, this.choiceSelector.getSelection(random, randomBlockPos), 2);
			++numCrop;
		}
	}

	return numCrop > 0;
}
 
Example #10
Source File: DeceasedWildCropFeature.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public boolean generate(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> chunkGenerator, Random random, BlockPos blockPos, DefaultFeatureConfig defaultFeatureConfig) {
	int numCrop = 0;
	
	for (int i = 0; i < 64; ++i) {
		BlockPos randomBlockPos = blockPos.add(random.nextInt(8) - random.nextInt(8), random.nextInt(4) - random.nextInt(4), random.nextInt(8) - random.nextInt(8));
		if (world.isAir(randomBlockPos) && world.getBlockState(randomBlockPos.down()).getBlock() == HallowedBlocks.DECEASED_GRASS_BLOCK) {
			world.setBlockState(randomBlockPos, this.crop, 2);
			++numCrop;
		}
	}
	
	return numCrop > 0;
}
 
Example #11
Source File: DeaderBushFeature.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public boolean generate(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> generator, Random random, BlockPos pos, DefaultFeatureConfig config) {
	for (BlockState state1 = world.getBlockState(pos); (state1.isAir() || state1.matches(BlockTags.LEAVES)) && pos.getY() > 0; state1 = world.getBlockState(pos)) {
		pos = pos.down();
	}
	
	for (int int_1 = 0; int_1 < 4; ++int_1) {
		BlockPos pos2 = pos.add(random.nextInt(8) - random.nextInt(8), random.nextInt(4) - random.nextInt(4), random.nextInt(8) - random.nextInt(8));
		if (world.isAir(pos2) && state.canPlaceAt(world, pos2)) {
			world.setBlockState(pos2, state, 2);
		}
	}
	
	return true;
}
 
Example #12
Source File: GCOreFeature.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public boolean generate(ServerWorldAccess serverWorldAccess, StructureAccessor structureAccessor, ChunkGenerator chunkGenerator, Random random, BlockPos blockPos, GCOreFeatureConfig oreFeatureConfig) {
    float f = random.nextFloat() * 3.1415927F;
    float g = (float) oreFeatureConfig.size / 8.0F;
    int i = MathHelper.ceil(((float) oreFeatureConfig.size / 16.0F * 2.0F + 1.0F) / 2.0F);
    double d = (float) blockPos.getX() + MathHelper.sin(f) * g;
    double e = (float) blockPos.getX() - MathHelper.sin(f) * g;
    double h = (float) blockPos.getZ() + MathHelper.cos(f) * g;
    double j = (float) blockPos.getZ() - MathHelper.cos(f) * g;
    double l = blockPos.getY() + random.nextInt(3) - 2;
    double m = blockPos.getY() + random.nextInt(3) - 2;
    int n = blockPos.getX() - MathHelper.ceil(g) - i;
    int o = blockPos.getY() - 2 - i;
    int p = blockPos.getZ() - MathHelper.ceil(g) - i;
    int q = 2 * (MathHelper.ceil(g) + i);
    int r = 2 * (2 + i);

    for (int s = n; s <= n + q; ++s) {
        for (int t = p; t <= p + q; ++t) {
            if (o <= serverWorldAccess.getTopY(Heightmap.Type.OCEAN_FLOOR_WG, s, t)) {
                return this.generateVeinPart(serverWorldAccess, random, oreFeatureConfig, d, e, h, j, l, m, n, o, p, q, r);
            }
        }
    }

    return false;
}
 
Example #13
Source File: WitchWellFeature.java    From the-hallow with MIT License 4 votes vote down vote up
@Override
public boolean generate(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> gen, Random random, BlockPos pos, DefaultFeatureConfig config) {
	pos = pos.up();
	while (world.isAir(pos) && pos.getY() > 2) {
		pos = pos.down();
	}
	
	if (!CAN_GENERATE.test(world.getBlockState(pos))) {
		return false;
	}
	
	// Check for solid ground
	for (int x = -2; x <= 2; ++x) {
		for (int z = -2; z <= 2; ++z) {
			if (world.isAir(pos.add(x, -1, z)) && world.isAir(pos.add(x, -2, z))) {
				return false;
			}
		}
	}
	
	//System.out.println("Generating at " + pos);
	
	// Below-ground layer
	for (int y = -1; y <= 0; ++y) {
		for (int x = -2; x <= 2; ++x) {
			for (int z = -2; z <= 2; ++z) {
				world.setBlockState(pos.add(x, y, z), this.wall, 2);
			}
		}
	}
	
	// Fluid
	world.setBlockState(pos, this.fluid, 2);
	for (Direction direction : Direction.Type.HORIZONTAL) {
		world.setBlockState(pos.offset(direction), this.fluid, 2);
	}
	
	// Above-ground layer
	for (int x = -2; x <= 2; ++x) {
		for (int z = -2; z <= 2; ++z) {
			if (x == -2 || x == 2 || z == -2 || z == 2) {
				world.setBlockState(pos.add(x, 1, z), this.wall, 2);
			}
		}
	}
	
	// Slabs in the above-ground layer
	world.setBlockState(pos.add(2, 1, 0), this.slab, 2);
	world.setBlockState(pos.add(-2, 1, 0), this.slab, 2);
	world.setBlockState(pos.add(0, 1, 2), this.slab, 2);
	world.setBlockState(pos.add(0, 1, -2), this.slab, 2);
	
	// Witched pumpkin
	int pumpkinX = random.nextBoolean() ? -2 : 2;
	int pumpkinZ = random.nextBoolean() ? -2 : 2;
	Direction pumpkinFacing = Direction.fromHorizontal(random.nextInt(4));
	world.setBlockState(pos.add(pumpkinX, 2, pumpkinZ), getPumpkin(pumpkinFacing), 2);
	world.setBlockState(pos.add(0, 3, 0), this.lantern, 2);
	
	// Roof
	for (int x = -1; x <= 1; ++x) {
		for (int z = -1; z <= 1; ++z) {
			if (x == 0 && z == 0) {
				world.setBlockState(pos.add(x, 4, z), this.wall, 2);
			} else {
				world.setBlockState(pos.add(x, 4, z), this.slab, 2);
			}
		}
	}
	
	// Pillars
	for (int y = 1; y <= 3; ++y) {
		world.setBlockState(pos.add(-1, y, -1), this.wall, 2);
		world.setBlockState(pos.add(-1, y, 1), this.wall, 2);
		world.setBlockState(pos.add(1, y, -1), this.wall, 2);
		world.setBlockState(pos.add(1, y, 1), this.wall, 2);
	}
	
	return true;
}
 
Example #14
Source File: BarrowFeature.java    From the-hallow with MIT License 4 votes vote down vote up
@Override
public boolean generate(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> chunkGenerator, Random rand, BlockPos pos, DefaultFeatureConfig config) {
	//final BiomeSource source = chunkGenerator.getBiomeSource();
	
	return this.generate(world, rand, pos, (blockpos) -> world.getBiome(blockpos).getSurfaceConfig());
}
 
Example #15
Source File: MoonVillageStart.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
@Override
public void init(ChunkGenerator chunkGenerator, StructureManager structureManager, int x, int z, Biome biome, StructurePoolFeatureConfig featureConfig) {
    StructurePoolBasedGenerator.addPieces(BASE_POOL, 6, MoonVillagePiece::new, chunkGenerator, structureManager, new BlockPos(x * 16, 70, z * 16), this.children, random, true, true);
    this.setBoundingBoxFromChildren();
}
 
Example #16
Source File: IForgeWorldType.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
default ChunkGenerator<?> createChunkGenerator(World world) {
	return world.dimension.createChunkGenerator();
}
 
Example #17
Source File: MixinSpawnHelper.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@ModifyVariable(method = "method_8664", at = @At(value = "INVOKE", target = "java/util/List.isEmpty ()Z", shift = At.Shift.BEFORE))
private static List<Biome.SpawnEntry> hookRandomSpawn(List<Biome.SpawnEntry> oldSpawns, ChunkGenerator<?> chunkGenerator, EntityCategory entityCategory, Random random, BlockPos blockPos) {
	IWorld world = ((MixinChunkGenerator) chunkGenerator).getWorld();

	return WorldEvents.getPotentialSpawns(world, entityCategory, blockPos, oldSpawns);
}
 
Example #18
Source File: MixinSpawnHelper.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@ModifyVariable(method = "method_8659", at = @At(value = "INVOKE", target = "java/util/List.isEmpty ()Z", shift = At.Shift.BEFORE))
private static List<Biome.SpawnEntry> hookCanSpawn(List<Biome.SpawnEntry> oldSpawns, ChunkGenerator<?> chunkGenerator, EntityCategory entityCategory, Biome.SpawnEntry spawnEntry, BlockPos blockPos) {
	IWorld world = ((MixinChunkGenerator) chunkGenerator).getWorld();

	return WorldEvents.getPotentialSpawns(world, entityCategory, blockPos, oldSpawns);
}
 
Example #19
Source File: StoneCircleFeature.java    From the-hallow with MIT License 4 votes vote down vote up
@Override
public boolean generate(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> chunkGenerator, Random rand, BlockPos pos, DefaultFeatureConfig config) {
	return this.generate(world, rand, pos);
}
 
Example #20
Source File: StructureFeatureMixin.java    From fabric-carpet with MIT License 4 votes vote down vote up
@Override
public boolean plopAnywhere(ServerWorld world, BlockPos pos, ChunkGenerator<? extends ChunkGeneratorConfig> generator, boolean wireOnly)
{
    if (world.isClient())
        return false;
    CarpetSettings.skipGenerationChecks = true;
    try
    {
        Random rand = new Random(world.getRandom().nextInt());
        int j = pos.getX() >> 4;
        int k = pos.getZ() >> 4;
        long chId = ChunkPos.toLong(j, k);
        StructureStart structurestart = forceStructureStart(world, generator, rand, chId);
        if (structurestart == StructureStart.DEFAULT)
        {
            return false;
        }
        //generator.ge   getStructurePositionToReferenceMap(this).computeIfAbsent(chId,
        //    (x) -> new LongOpenHashSet()).add(chId);
        world.getChunk(j, k).addStructureReference(this.getName(), chId);  //, ChunkStatus.STRUCTURE_STARTS

        BlockBox box = structurestart.getBoundingBox();
        if (!wireOnly)
        {
            structurestart.generateStructure(world, generator, rand,
                new BlockBox(
                            pos.getX() - this.getRadius() * 16,
                            pos.getZ() - this.getRadius() * 16,
                            pos.getX() + (this.getRadius() + 1) * 16,
                            pos.getZ() + (1 + this.getRadius()) * 16),
                    new ChunkPos(j, k)
            );
        }
        //structurestart.notifyPostProcessAt(new ChunkPos(j, k));

        int i = getRadius();
        for (int k1 = j - i; k1 <= j + i; ++k1)
        {
            for (int l1 = k - i; l1 <= k + i; ++l1)
            {
                if (k1 == j && l1 == k) continue;
                long nbchkid = ChunkPos.toLong(k1, l1);
                if (box.intersectsXZ(k1<<4, l1<<4, (k1<<4) + 15, (l1<<4) + 15))
                {
                    //generator.getStructurePositionToReferenceMap(this).computeIfAbsent(nbchkid, (__) -> new LongOpenHashSet()).add(chId);
                    world.getChunk(k1, l1).addStructureReference(this.getName(), chId); //, ChunkStatus.STRUCTURE_STARTS
                    //structurestart.  notifyPostProcessAt(new ChunkPos(k1, l1));
                }
            }
        }
    }
    catch (Exception booboo)
    {
        CarpetSettings.LOG.error("Unknown Exception while plopping structure: "+booboo);
        booboo.printStackTrace();
        return false;
    }
    finally
    {
        CarpetSettings.skipGenerationChecks = false;
    }
    return true;
}
 
Example #21
Source File: StructureFeatureInterface.java    From fabric-carpet with MIT License votes vote down vote up
boolean plopAnywhere(ServerWorld world, BlockPos pos, ChunkGenerator<? extends ChunkGeneratorConfig> generator, boolean wireOnly);