类net.minecraft.world.gen.chunk.ChunkGenerator源码实例Demo

下面列出了怎么用net.minecraft.world.gen.chunk.ChunkGenerator的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: the-hallow   文件: SpiderLairFeature.java
@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;
	}
}
 
源代码2 项目: the-hallow   文件: HallowedCactusFeature.java
@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;
}
 
源代码3 项目: fabric-carpet   文件: FeatureGenerator.java
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;
}
 
源代码4 项目: Galacticraft-Rewoven   文件: GCOreFeature.java
@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;
}
 
源代码5 项目: the-hallow   文件: DeaderBushFeature.java
@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;
}
 
源代码6 项目: the-hallow   文件: DeceasedWildCropFeature.java
@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;
}
 
源代码7 项目: the-hallow   文件: RandomizedWildCropFeature.java
@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;
}
 
源代码8 项目: the-hallow   文件: HallowedOreFeature.java
@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;
}
 
源代码9 项目: patchwork-api   文件: MixinServerWorld.java
@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();
	}
}
 
源代码10 项目: fabric-carpet   文件: FeatureGenerator.java
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);
    };
}
 
源代码11 项目: fabric-carpet   文件: CarpetExpression.java
private void BooYah(ChunkGenerator generator)
{
    synchronized (generator)
    {
        if (generator.getSeed() != lastSeed)
        {
            StructureFeatures.STRONGHOLD.shouldStartAt(null, generator, null, 0, 0, null);
            lastSeed = generator.getSeed();
        }
    }
}
 
源代码12 项目: fabric-carpet   文件: StructureFeatureMixin.java
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;
}
 
源代码13 项目: Galacticraft-Rewoven   文件: MoonVillageStart.java
@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();
}
 
源代码14 项目: the-hallow   文件: StoneCircleFeature.java
@Override
public boolean generate(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> chunkGenerator, Random rand, BlockPos pos, DefaultFeatureConfig config) {
	return this.generate(world, rand, pos);
}
 
源代码15 项目: the-hallow   文件: WitchWellFeature.java
@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;
}
 
源代码16 项目: the-hallow   文件: BarrowFeature.java
@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());
}
 
源代码17 项目: patchwork-api   文件: IForgeWorldType.java
default ChunkGenerator<?> createChunkGenerator(World world) {
	return world.dimension.createChunkGenerator();
}
 
源代码18 项目: patchwork-api   文件: MixinSpawnHelper.java
@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);
}
 
源代码19 项目: patchwork-api   文件: MixinSpawnHelper.java
@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);
}
 
源代码20 项目: fabric-carpet   文件: StructureFeatureMixin.java
@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;
}
 
源代码21 项目: fabric-carpet   文件: StructureFeatureInterface.java
boolean plopAnywhere(ServerWorld world, BlockPos pos, ChunkGenerator<? extends ChunkGeneratorConfig> generator, boolean wireOnly); 
 类所在包
 类方法
 同包方法