Search in sources :

Example 1 with IDeposit

use of com.oitsjustjose.geolosys.api.world.IDeposit in project Geolosys by oitsjustjose.

the class PlutonRegistry method pick.

@Nullable
public IDeposit pick(ISeedReader reader, BlockPos pos, Random rand) {
    @SuppressWarnings("unchecked") ArrayList<IDeposit> choices = (ArrayList<IDeposit>) this.deposits.clone();
    // Dimension Filtering done here!
    choices.removeIf((dep) -> {
        ResourceLocation dim = reader.getWorld().getDimensionKey().getLocation();
        boolean isDimFilterBl = dep.isDimensionFilterBl();
        for (String dim2Raw : dep.getDimensionFilter()) {
            boolean match = new ResourceLocation(dim2Raw).equals(dim);
            if ((isDimFilterBl && match) || (!isDimFilterBl && !match)) {
                return true;
            }
        }
        return false;
    });
    if (choices.size() == 0) {
        return null;
    }
    /* 1/3 chance to lean towards a biome restricted deposit */
    if (rand.nextInt(3) == 0) {
        // Only remove the entries if there's at least one.
        if (choices.stream().anyMatch((dep) -> {
            return dep.hasBiomeRestrictions() && dep.canPlaceInBiome(reader.getBiome(pos));
        })) {
            choices.removeIf((dep) -> {
                return !(dep.hasBiomeRestrictions() && dep.canPlaceInBiome(reader.getBiome(pos)));
            });
        }
    }
    int totalWt = 0;
    for (IDeposit d : choices) {
        totalWt += d.getGenWt();
    }
    int rng = rand.nextInt(totalWt);
    for (IDeposit d : choices) {
        int wt = d.getGenWt();
        if (rng < wt) {
            return d;
        }
        rng -= wt;
    }
    Geolosys.getInstance().LOGGER.error("Could not reach decision on pluton to generate at PlutonRegistry#pick");
    return null;
}
Also used : IDeposit(com.oitsjustjose.geolosys.api.world.IDeposit) ResourceLocation(net.minecraft.util.ResourceLocation) ArrayList(java.util.ArrayList) Nullable(javax.annotation.Nullable)

Example 2 with IDeposit

use of com.oitsjustjose.geolosys.api.world.IDeposit in project Geolosys by oitsjustjose.

the class DepositFeature method generate.

@Override
@ParametersAreNonnullByDefault
public boolean generate(ISeedReader reader, ChunkGenerator generator, Random rand, BlockPos pos, NoFeatureConfig config) {
    if (generator instanceof FlatChunkGenerator) {
        return false;
    }
    IDepositCapability cap = reader.getWorld().getCapability(GeolosysAPI.GEOLOSYS_WORLD_CAPABILITY).orElse(null);
    if (cap == null) {
        Geolosys.getInstance().LOGGER.error("NULL PLUTON CAPABILITY!!!");
        return false;
    }
    boolean placedPending = placePendingBlocks(reader, cap, pos);
    ChunkPos chunkPos = new ChunkPos(pos);
    if (cap.hasPlutonGenerated(chunkPos)) {
        return false;
    }
    IDeposit pluton = GeolosysAPI.plutonRegistry.pick(reader, pos, rand);
    if (pluton == null) {
        // Could be no pluton for the dimension
        return false;
    }
    if (rand.nextInt(CommonConfig.CHUNK_SKIP_CHANCE.get()) > pluton.getGenWt()) {
        return false;
    }
    boolean anyGenerated = pluton.generate(reader, pos, cap) > 0;
    if (anyGenerated) {
        pluton.afterGen(reader, pos, cap);
        cap.setPlutonGenerated(chunkPos);
        return true;
    }
    return placedPending;
}
Also used : IDeposit(com.oitsjustjose.geolosys.api.world.IDeposit) FlatChunkGenerator(net.minecraft.world.gen.FlatChunkGenerator) ChunkPos(net.minecraft.util.math.ChunkPos) IDepositCapability(com.oitsjustjose.geolosys.common.world.capability.IDepositCapability) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Aggregations

IDeposit (com.oitsjustjose.geolosys.api.world.IDeposit)2 IDepositCapability (com.oitsjustjose.geolosys.common.world.capability.IDepositCapability)1 ArrayList (java.util.ArrayList)1 Nullable (javax.annotation.Nullable)1 ParametersAreNonnullByDefault (javax.annotation.ParametersAreNonnullByDefault)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 ChunkPos (net.minecraft.util.math.ChunkPos)1 FlatChunkGenerator (net.minecraft.world.gen.FlatChunkGenerator)1