Search in sources :

Example 26 with Species

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;
    }
}
Also used : ArrayList(java.util.ArrayList) JsonElement(com.google.gson.JsonElement) Species(com.ferreusveritas.dynamictrees.trees.Species)

Example 27 with Species

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);
}
Also used : Random(java.util.Random) IWorld(net.minecraft.world.IWorld) Vector2f(net.minecraft.util.math.vector.Vector2f) Vector3i(net.minecraft.util.math.vector.Vector3i) BlockPos(net.minecraft.util.math.BlockPos) ISeedReader(net.minecraft.world.ISeedReader) Species(com.ferreusveritas.dynamictrees.trees.Species)

Example 28 with Species

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;
}
Also used : PostGenerationContext(com.ferreusveritas.dynamictrees.systems.genfeatures.context.PostGenerationContext) CoordUtils(com.ferreusveritas.dynamictrees.util.CoordUtils) GenFeatureConfiguration(com.ferreusveritas.dynamictrees.systems.genfeatures.GenFeatureConfiguration) ResourceLocation(net.minecraft.util.ResourceLocation) Vector3i(net.minecraft.util.math.vector.Vector3i) IWorld(net.minecraft.world.IWorld) BlockPos(net.minecraft.util.math.BlockPos) Species(com.ferreusveritas.dynamictrees.trees.Species) Direction(net.minecraft.util.Direction) GenFeature(com.ferreusveritas.dynamictrees.systems.genfeatures.GenFeature) IWorld(net.minecraft.world.IWorld) Vector3i(net.minecraft.util.math.vector.Vector3i) BlockPos(net.minecraft.util.math.BlockPos) Species(com.ferreusveritas.dynamictrees.trees.Species) Direction(net.minecraft.util.Direction)

Example 29 with Species

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;
}
Also used : GrowSignal(com.ferreusveritas.dynamictrees.systems.GrowSignal) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Species(com.ferreusveritas.dynamictrees.trees.Species) Direction(net.minecraft.util.Direction)

Example 30 with Species

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;
}
Also used : GrowSignal(com.ferreusveritas.dynamictrees.systems.GrowSignal) Species(com.ferreusveritas.dynamictrees.trees.Species) Direction(net.minecraft.util.Direction)

Aggregations

Species (com.ferreusveritas.dynamictrees.trees.Species)56 BlockPos (net.minecraft.util.math.BlockPos)24 IBlockState (net.minecraft.block.state.IBlockState)19 ItemStack (net.minecraft.item.ItemStack)12 GrowSignal (com.ferreusveritas.dynamictrees.systems.GrowSignal)9 Direction (net.minecraft.util.Direction)9 ResourceLocation (net.minecraft.util.ResourceLocation)8 World (net.minecraft.world.World)8 TileEntitySpecies (com.ferreusveritas.dynamictrees.tileentity.TileEntitySpecies)6 EnumFacing (net.minecraft.util.EnumFacing)6 MapSignal (com.ferreusveritas.dynamictrees.api.network.MapSignal)5 BlockRooty (com.ferreusveritas.dynamictrees.blocks.BlockRooty)4 ArrayList (java.util.ArrayList)4 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)4 WrongUsageException (net.minecraft.command.WrongUsageException)4 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)4 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)4 ITreePart (com.ferreusveritas.dynamictrees.api.treedata.ITreePart)3 BlockBonsaiPot (com.ferreusveritas.dynamictrees.blocks.BlockBonsaiPot)3 TreeFamily (com.ferreusveritas.dynamictrees.trees.TreeFamily)3