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