Search in sources :

Example 1 with FillerEntry

use of gregtech.api.worldgen.filler.FillerEntry in project GregTech by GregTechCE.

the class GTOreInfo method findComponentBlocksAsItemStacks.

// Finds the possible blocks from the Filler definition, and returns them as ItemStacks
public List<ItemStack> findComponentBlocksAsItemStacks() {
    Collection<IBlockState> containedStates = new ArrayList<>();
    List<ItemStack> containedBlocksAsItemStacks = new ArrayList<>();
    // Find all possible states in the Filler
    // Needed because one generation option returns all possible blockStates
    List<FillerEntry> possibleStates = blockFiller.getAllPossibleStates();
    for (FillerEntry entry : possibleStates) {
        containedStates.addAll(entry.getPossibleResults());
    }
    // Check to see if we are dealing with a fluid generation case, before transforming states
    if (veinPopulator instanceof FluidSpringPopulator) {
        for (IBlockState state : containedStates) {
            Block temp = state.getBlock();
            if (temp instanceof IFluidBlock) {
                Fluid fluid = ((IFluidBlock) temp).getFluid();
                FluidStack fStack = new FluidStack(fluid, 1000);
                ItemStack stack = FluidUtil.getFilledBucket(fStack);
                containedBlocksAsItemStacks.add(stack);
            }
        }
    } else {
        // Transform the list of BlockStates to a list of ItemStacks
        for (IBlockState state : containedStates) {
            containedBlocksAsItemStacks.add(new ItemStack(state.getBlock(), 1, state.getBlock().getMetaFromState(state)));
        }
    }
    return containedBlocksAsItemStacks;
}
Also used : FillerEntry(gregtech.api.worldgen.filler.FillerEntry) IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) FluidSpringPopulator(gregtech.api.worldgen.populator.FluidSpringPopulator) ItemStack(net.minecraft.item.ItemStack)

Example 2 with FillerEntry

use of gregtech.api.worldgen.filler.FillerEntry in project GregTech by GregTechCE.

the class GTOreInfo method createOreWeightingTooltip.

// Creates a tooltip show the weighting of the individual ores in the ore vein
public List<String> createOreWeightingTooltip(int slotIndex) {
    List<String> tooltip = new ArrayList<>();
    int totalWeight = 0;
    double weight;
    List<FillerEntry> fillerEntries = blockFiller.getAllPossibleStates();
    for (FillerEntry entries : fillerEntries) {
        if (entries != null && !entries.getEntries().isEmpty()) {
            for (Pair<Integer, FillerEntry> entry : entries.getEntries()) {
                totalWeight = totalWeight + entry.getKey();
            }
        }
    }
    for (FillerEntry entry : fillerEntries) {
        if (entry.getEntries() != null && !entry.getEntries().isEmpty()) {
            Pair<Integer, FillerEntry> entryWithWeight = entry.getEntries().get(slotIndex - 2);
            weight = Math.round((entryWithWeight.getKey() / (double) totalWeight) * 100);
            tooltip.add("Weight in vein: " + weight + "%");
        }
    }
    return tooltip;
}
Also used : FillerEntry(gregtech.api.worldgen.filler.FillerEntry)

Example 3 with FillerEntry

use of gregtech.api.worldgen.filler.FillerEntry in project GregTech by GregTechCE.

the class FillerConfigUtils method createStateMatchFiller.

private static FillerEntry createStateMatchFiller(JsonObject object) {
    JsonArray valuesArray = object.get("values").getAsJsonArray();
    JsonElement defaultElement = object.get("default");
    ArrayList<Pair<WorldBlockPredicate, FillerEntry>> matchers = new ArrayList<>();
    for (JsonElement valueDefinition : valuesArray) {
        Preconditions.checkArgument(valueDefinition.isJsonObject(), "Found invalid value definition: %s", valueDefinition.toString());
        JsonObject valueObject = valueDefinition.getAsJsonObject();
        WorldBlockPredicate predicate = PredicateConfigUtils.createBlockStatePredicate(valueObject.get("predicate"));
        FillerEntry filler = createBlockStateFiller(valueObject.get("value"));
        matchers.add(Pair.of(predicate, filler));
    }
    if (!defaultElement.isJsonNull()) {
        FillerEntry filler = createBlockStateFiller(defaultElement);
        WorldBlockPredicate predicate = (state, world, pos) -> true;
        matchers.add(Pair.of(predicate, filler));
    } else {
        WorldBlockPredicate predicate = (state, world, pos) -> true;
        FillerEntry fillerEntry = matchers.iterator().next().getRight();
        matchers.add(Pair.of(predicate, fillerEntry));
    }
    return new BlockStateMatcherEntry(matchers);
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) WorldBlockPredicate(gregtech.api.util.WorldBlockPredicate) java.util(java.util) ImmutableSet(com.google.common.collect.ImmutableSet) Blocks(net.minecraft.init.Blocks) XSTR(gregtech.api.util.XSTR) FillerEntry(gregtech.api.worldgen.filler.FillerEntry) BlockPos(net.minecraft.util.math.BlockPos) FluidRegistry(net.minecraftforge.fluids.FluidRegistry) StoneType(gregtech.api.unification.ore.StoneType) JsonElement(com.google.gson.JsonElement) IBlockState(net.minecraft.block.state.IBlockState) JsonArray(com.google.gson.JsonArray) StoneTypes(gregtech.api.unification.ore.StoneTypes) ImmutableList(com.google.common.collect.ImmutableList) Block(net.minecraft.block.Block) Pair(org.apache.commons.lang3.tuple.Pair) Fluid(net.minecraftforge.fluids.Fluid) Preconditions(com.google.common.base.Preconditions) JsonPrimitive(com.google.gson.JsonPrimitive) GTUtility(gregtech.api.util.GTUtility) IBlockAccess(net.minecraft.world.IBlockAccess) FillerEntry(gregtech.api.worldgen.filler.FillerEntry) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) Pair(org.apache.commons.lang3.tuple.Pair) WorldBlockPredicate(gregtech.api.util.WorldBlockPredicate)

Example 4 with FillerEntry

use of gregtech.api.worldgen.filler.FillerEntry in project GregTech by GregTechCE.

the class FillerConfigUtils method createWeightRandomStateFiller.

private static FillerEntry createWeightRandomStateFiller(JsonObject object) {
    JsonArray values = object.get("values").getAsJsonArray();
    ArrayList<Pair<Integer, FillerEntry>> randomList = new ArrayList<>();
    for (JsonElement randomElement : values) {
        JsonObject randomObject = randomElement.getAsJsonObject();
        int weight = randomObject.get("weight").getAsInt();
        Preconditions.checkArgument(weight > 0, "Invalid weight: %d", weight);
        FillerEntry filler = createBlockStateFiller(randomObject.get("value"));
        randomList.add(Pair.of(weight, filler));
    }
    return new WeightRandomMatcherEntry(randomList);
}
Also used : JsonArray(com.google.gson.JsonArray) FillerEntry(gregtech.api.worldgen.filler.FillerEntry) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

FillerEntry (gregtech.api.worldgen.filler.FillerEntry)4 JsonArray (com.google.gson.JsonArray)2 JsonElement (com.google.gson.JsonElement)2 JsonObject (com.google.gson.JsonObject)2 Block (net.minecraft.block.Block)2 IBlockState (net.minecraft.block.state.IBlockState)2 Pair (org.apache.commons.lang3.tuple.Pair)2 Preconditions (com.google.common.base.Preconditions)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 StoneType (gregtech.api.unification.ore.StoneType)1 StoneTypes (gregtech.api.unification.ore.StoneTypes)1 GTUtility (gregtech.api.util.GTUtility)1 WorldBlockPredicate (gregtech.api.util.WorldBlockPredicate)1 XSTR (gregtech.api.util.XSTR)1 FluidSpringPopulator (gregtech.api.worldgen.populator.FluidSpringPopulator)1 java.util (java.util)1 Blocks (net.minecraft.init.Blocks)1 ItemStack (net.minecraft.item.ItemStack)1