use of com.ferreusveritas.dynamictrees.trees.Species in project DynamicTrees by DynamicTreesTeam.
the class JsonMath method processElement.
private MathOperator processElement(String key, JsonElement value) {
EnumMathFunction op = EnumMathFunction.getFunction(key);
ArrayList<MathOperator> paramList = new ArrayList<>();
Species speciesArg = Species.NULLSPECIES;
// If the value is an array then these are the parameters for this operation
if (value.isJsonArray()) {
for (JsonElement parameter : value.getAsJsonArray()) {
MathOperator m = null;
if (parameter.isJsonObject()) {
Entry<String, JsonElement> entry = parameter.getAsJsonObject().entrySet().iterator().next();
m = processElement(entry.getKey(), entry.getValue());
} else if (parameter.isJsonPrimitive()) {
if (parameter.getAsJsonPrimitive().isNumber()) {
m = new Const(parameter.getAsFloat());
} else if (parameter.getAsJsonPrimitive().isString()) {
String name = parameter.getAsString();
MathOperator var = getVariable(name);
if (var != null) {
m = var;
} else if (TreeRegistry.findSpeciesSloppy(name) != Species.NULLSPECIES) {
speciesArg = TreeRegistry.findSpeciesSloppy(name);
}
}
}
if (m != null) {
paramList.add(m);
}
}
}
MathOperator[] paramArray = paramList.toArray(new MathOperator[0]);
switch(op) {
case NOISE:
return new Noise();
case RAND:
return new Rand();
case TREES:
return new Trees(biome);
case RADIUS:
return new Radius();
case ADD:
return new Adder(paramArray);
case SUB:
return new Subtractor(paramArray);
case MUL:
return new Multiplier(paramArray);
case DIV:
return new Divider(paramArray);
case MAX:
return new Maximum(paramArray);
case MIN:
return new Minimum(paramArray);
case IFGT:
return new IfGreaterThan(paramArray);
case SPECIES:
return speciesArg != Species.NULLSPECIES ? new IfSpecies(speciesArg, paramArray) : null;
case DEBUG:
return new Debug(paramArray);
default:
return null;
}
}
use of com.ferreusveritas.dynamictrees.trees.Species in project DynamicTrees-BYG by DynamicTreesTeam.
the class BYGHugeMushroomGenFeature method postGenerate.
@Override
protected boolean postGenerate(GenFeatureConfiguration configuration, PostGenerationContext context) {
IWorld world = context.world();
BlockPos rootPos = context.pos();
Species species = context.species();
if (!(world instanceof ISeedReader))
return false;
Random rand = world.getRandom();
MushroomType mushroomType = getType(world, rootPos, species, context.biome());
int count = configuration.get(MAX_COUNT);
int magnitude = (int) (context.radius() * 0.75);
if (magnitude <= 2)
return false;
magnitude++;
for (int i = 0; i < configuration.get(MAX_ATTEMPTS); i++) {
if (rand.nextFloat() < configuration.get(PLACE_CHANCE) * mushroomType.getChanceMult()) {
double angle = rand.nextFloat() * (2 * Math.PI);
Vector2f offsetVec = new Vector2f((float) (magnitude * Math.cos(angle)), (float) (magnitude * Math.sin(angle)));
Vector3i offsetVecInt = new Vector3i(Math.ceil(offsetVec.x), 0, Math.ceil(offsetVec.y));
BlockPos shroomPos = findFloor(species, world, rootPos.offset(offsetVecInt));
if (shroomPos != BlockPos.ZERO && SoilHelper.isSoilAcceptable(world.getBlockState(shroomPos), SoilHelper.getSoilFlags(fungusSoils))) {
ConfiguredFeature<?, ?> feature = mushroomType.getFeature(rand, configuration);
feature.place((ISeedReader) world, null, rand, shroomPos);
count--;
if (count == 0)
return true;
}
}
}
return count != configuration.get(MAX_COUNT);
}
use of com.ferreusveritas.dynamictrees.trees.Species in project DynamicTrees-BYG by DynamicTreesTeam.
the class MangrovelingsGenFeature method postGenerate.
@Override
protected boolean postGenerate(GenFeatureConfiguration configuration, PostGenerationContext context) {
IWorld world = context.world();
Species species = context.species();
int[] angles = new int[2];
angles[0] = angles[1] = world.getRandom().nextInt(6);
while (angles[0] == angles[1]) {
angles[1] = world.getRandom().nextInt(6);
}
anglesLoop: for (int a : angles) {
double angle = Math.toRadians(a * 60.0f);
float distance = 3.0f + world.getRandom().nextFloat() * 2.0f;
BlockPos offPos = context.pos().offset(new Vector3i(Math.sin(angle) * distance, 0, Math.cos(angle) * distance));
if (context.bounds().inBounds(offPos, true)) {
if (species.isAcceptableSoil(world, offPos, world.getBlockState(offPos))) {
if (!(world.isEmptyBlock(offPos.above(1)) && world.isEmptyBlock(offPos.above(2)))) {
continue;
}
for (Direction hor : CoordUtils.HORIZONTALS) {
BlockPos offPos2 = offPos.offset(hor.getNormal());
if (!(world.isEmptyBlock(offPos2.above(1)) && world.isEmptyBlock(offPos2.above(2)))) {
continue anglesLoop;
}
}
species.placeRootyDirtBlock(world, offPos, 0);
species.getFamily().getBranch().ifPresent(branch -> branch.setRadius(world, offPos.above(1), 1, Direction.DOWN, 0));
if (world.getRandom().nextInt(2) == 0) {
world.setBlock(offPos.above(2), species.getLeavesProperties().getDynamicLeavesState(1), 3);
} else {
species.getFamily().getBranch().ifPresent(branch -> branch.setRadius(world, offPos.above(2), 1, Direction.DOWN, 0));
if (world.isEmptyBlock(offPos.above(3))) {
world.setBlock(offPos.above(3), species.getLeavesProperties().getDynamicLeavesState(1), 3);
}
}
}
}
}
return false;
}
use of com.ferreusveritas.dynamictrees.trees.Species in project DynamicTrees-BYG by DynamicTreesTeam.
the class AncientLogic method populateDirectionProbabilityMap.
@Override
public int[] populateDirectionProbabilityMap(GrowthLogicKitConfiguration configuration, DirectionManipulationContext context) {
final GrowSignal signal = context.signal();
final int[] probMap = context.probMap();
final World world = context.world();
final BlockPos pos = context.pos();
final Species species = context.species();
Direction originDir = signal.dir.getOpposite();
int treeHash = CoordUtils.coordHashCode(signal.rootPos, 2);
// Down is always disallowed
probMap[0] = 0;
if (signal.energy > configuration.get(CANOPY_ENERGY)) {
// not canopy
// Alter probability map for direction change
probMap[1] = species.getUpProbability();
// Start by disabling probability on the sides
probMap[2] = probMap[3] = probMap[4] = probMap[5] = 0;
if (signal.isInTrunk()) {
if (signal.delta.getY() <= configuration.getLowestBranchHeight(context) + 1) {
// midway
int sideHash = treeHash % 16;
probMap[2] = sideHash % 2 < 1 ? 1 : 0;
probMap[3] = sideHash % 4 < 2 ? 1 : 0;
probMap[4] = sideHash % 8 < 4 ? 1 : 0;
probMap[5] = sideHash < 8 ? 1 : 0;
}
} else {
branchTwisting(world, pos, signal, probMap);
}
} else
// it is canopy so dark oak logic is used
darkOakCanopy(signal, probMap);
// Disable the direction we came from
probMap[originDir.ordinal()] = 0;
return probMap;
}
use of com.ferreusveritas.dynamictrees.trees.Species in project DynamicTrees-BYG by DynamicTreesTeam.
the class EbonyLogic method populateDirectionProbabilityMap.
@Override
public int[] populateDirectionProbabilityMap(GrowthLogicKitConfiguration configuration, DirectionManipulationContext context) {
final Species species = context.species();
final GrowSignal signal = context.signal();
final int[] probMap = context.probMap();
Direction originDir = signal.dir.getOpposite();
probMap[0] = species.getUpProbability();
probMap[1] = signal.isInTrunk() && signal.energy > configuration.getLowestBranchHeight(context) ? 0 : probMap[0];
probMap[2] = probMap[3] = probMap[4] = probMap[5] = 4;
if (!signal.isInTrunk())
probMap[signal.dir.ordinal()] += 2;
// Disable the direction we came from
probMap[originDir.ordinal()] = 0;
return probMap;
}
Aggregations