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;
}
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;
}
Aggregations