Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
package gregtech.api.worldgen.config;

import com.google.gson.JsonObject;
import crafttweaker.annotations.ZenRegister;
import crafttweaker.api.minecraft.CraftTweakerMC;
import crafttweaker.api.world.IBiome;
import gregtech.api.GTValues;
import gregtech.api.util.GTLog;
import gregtech.api.worldgen.bedrockFluids.BedrockFluidVeinHandler;
import net.minecraft.world.WorldProvider;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fml.common.Optional;
import org.apache.commons.lang3.ArrayUtils;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenGetter;
import stanhebben.zenscript.annotations.ZenMethod;

import javax.annotation.Nonnull;
import java.util.function.Function;
import java.util.function.Predicate;

@ZenClass("mods.gregtech.ore.BedrockFluidDepositDefinition")
@ZenRegister
public class BedrockFluidDepositDefinition implements IWorldgenDefinition { //todo re-balance depletion rates of default veins

private final String depositName;
Expand Down Expand Up @@ -91,57 +79,46 @@ public boolean initializeFromConfig(@Nonnull JsonObject configRoot) {

//This is the file name
@Override
@ZenGetter("depositName")
public String getDepositName() {
return depositName;
}

@ZenGetter("assignedName")
public String getAssignedName() {
return assignedName;
}

@ZenGetter("description")
public String getDescription() {
return description;
}

@ZenGetter("weight")
public int getWeight() {
return weight;
}

@ZenMethod
public int[] getProductionRates() {
return productionRates;
}

@ZenGetter("minimumProduction")
public int getMinimumProductionRate() {
return productionRates[0];
}

@ZenGetter("maximumProduction")
public int getMaximumProductionRate() {
return productionRates[1];
}

@ZenGetter
public int getDepletionAmount() {
return depletionAmount;
}

@ZenGetter
public int getDepletionChance() {
return depletionChance;
}

@ZenGetter
public int getDepletedProductionRate() {
return depletedProductionRate;
}

@ZenGetter
public Fluid getStoredFluid() {
return storedFluid;
}
Expand All @@ -154,21 +131,6 @@ public Predicate<WorldProvider> getDimensionFilter() {
return dimensionFilter;
}

@ZenMethod("getBiomeWeightModifier")
@Optional.Method(modid = GTValues.MODID_CT)
public int ctGetBiomeWeightModifier(IBiome biome) {
int biomeIndex = ArrayUtils.indexOf(CraftTweakerMC.biomes, biome);
Biome mcBiome = Biome.REGISTRY.getObjectById(biomeIndex);
return mcBiome == null ? 0 : getBiomeWeightModifier().apply(mcBiome);
}

@ZenMethod("checkDimension")
@Optional.Method(modid = GTValues.MODID_CT)
public boolean ctCheckDimension(int dimensionId) {
WorldProvider worldProvider = DimensionManager.getProvider(dimensionId);
return worldProvider != null && getDimensionFilter().test(worldProvider);
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof BedrockFluidDepositDefinition))
Expand Down
114 changes: 114 additions & 0 deletions src/main/java/gregtech/api/worldgen/config/FillerConfigUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,28 @@ private static FillerEntry createWeightRandomStateFiller(JsonObject object) {
return new WeightRandomMatcherEntry(randomList);
}

public static LayeredFillerEntry createLayeredFiller(JsonObject object) {
JsonArray values = object.get("values").getAsJsonArray();
Preconditions.checkArgument(values.size() == 4, "Invalid number of ores in a Layered vein (should be 4, is actually %d", values.size());

return new LayeredFillerEntry(
readLayerFiller(values.get(0).getAsJsonObject(), "primary"),
readLayerFiller(values.get(1).getAsJsonObject(), "secondary"),
readLayerFiller(values.get(2).getAsJsonObject(), "between"),
createBlockStateFiller(values.get(3).getAsJsonObject().get("sporadic"))
);
}

private static Pair<FillerEntry, Integer> readLayerFiller(JsonObject object, String layerType) {
FillerEntry filler = createBlockStateFiller(object.get(layerType));
JsonElement layerElement = object.get("layers");
int layers = -1;
if (layerElement != null) {
layers = layerElement.getAsInt();
}
return Pair.of(filler, layers);
}

private static class OreFilterEntry implements FillerEntry {

private final Map<StoneType, IBlockState> blockStateMap;
Expand Down Expand Up @@ -225,4 +247,96 @@ public List<Pair<Integer, FillerEntry>> getEntries() {
return randomList;
}
}

public static class LayeredFillerEntry implements FillerEntry {

private final FillerEntry primary;
private final FillerEntry secondary;
private final FillerEntry between;
private final FillerEntry sporadic;

private final int betweenLayers;

// Provided for readability
private final int sporadicDivisor;
private final int startPrimary;
private final int startBetween;

private final ImmutableList<FillerEntry> subEntries;
private final ImmutableList<IBlockState> blockStates;

public LayeredFillerEntry(Pair<FillerEntry, Integer> primary, Pair<FillerEntry, Integer> secondary, Pair<FillerEntry, Integer> between, FillerEntry sporadic) {
this.primary = primary.getLeft();
this.secondary = secondary.getLeft();
this.between = between.getLeft();
this.sporadic = sporadic;

int primaryLayers = primary.getRight() == -1 ? 4 : primary.getRight();
int secondaryLayers = secondary.getRight() == -1 ? 3 : secondary.getRight();
this.betweenLayers = between.getRight() == -1 ? 3 : between.getRight();

// Ensure "between" is not more than the total primary and secondary layers
// TODO Comment
Preconditions.checkArgument(primaryLayers + secondaryLayers >= betweenLayers, "");

this.sporadicDivisor = primaryLayers + secondaryLayers - 1;
this.startPrimary = secondaryLayers;
this.startBetween = secondaryLayers - betweenLayers / 2;

this.subEntries = ImmutableList.of(this.primary, this.secondary, this.between, this.sporadic);
this.blockStates = ImmutableList.<IBlockState>builder()
.addAll(this.primary.getPossibleResults())
.addAll(this.secondary.getPossibleResults())
.addAll(this.between.getPossibleResults())
.addAll(this.sporadic.getPossibleResults())
.build();
}

@Override
public IBlockState apply(IBlockState source, IBlockAccess blockAccess, BlockPos blockPos) {
// should never be called, but just to be safe...
return apply(source, blockAccess, blockPos, 1.0, new Random(), 0);
}

public IBlockState apply(IBlockState source, IBlockAccess blockAccess, BlockPos blockPos, double density, Random random, int layer) {
// First try to spawn "between"
if (layer >= startBetween && layer - startBetween + 1 <= betweenLayers) {
if (random.nextFloat() <= density / 2) {
return between.apply(source, blockAccess, blockPos);
}
}

// Then try primary/secondary
if (layer >= startPrimary) {
if (random.nextFloat() <= density) {
return primary.apply(source, blockAccess, blockPos);
}
} else {
if (random.nextFloat() <= density) {
return secondary.apply(source, blockAccess, blockPos);
}
}

// Then lastly, try sporadic
if (random.nextFloat() <= density / sporadicDivisor) {
return sporadic.apply(source, blockAccess, blockPos);
}
return source;
}

@Override
public List<FillerEntry> getSubEntries() {
return subEntries;
}

@Override
public Collection<IBlockState> getPossibleResults() {
return blockStates;
}

@Override
public List<Pair<Integer, FillerEntry>> getEntries() {
return Collections.emptyList(); // todo
}
}
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,18 @@
package gregtech.api.worldgen.config;

import com.google.gson.JsonObject;
import crafttweaker.annotations.ZenRegister;
import crafttweaker.api.minecraft.CraftTweakerMC;
import crafttweaker.api.world.IBiome;
import gregtech.api.GTValues;
import gregtech.api.unification.ore.StoneType;
import gregtech.api.util.WorldBlockPredicate;
import gregtech.api.worldgen.filler.BlockFiller;
import gregtech.api.worldgen.populator.IVeinPopulator;
import gregtech.api.worldgen.shape.ShapeGenerator;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.WorldProvider;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.fml.common.Optional.Method;
import org.apache.commons.lang3.ArrayUtils;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenGetter;
import stanhebben.zenscript.annotations.ZenMethod;

import javax.annotation.Nonnull;
import java.util.function.Function;
import java.util.function.Predicate;

@ZenClass("mods.gregtech.ore.OreDepositDefinition")
@ZenRegister
public class OreDepositDefinition implements IWorldgenDefinition {

public static final Function<Biome, Integer> NO_BIOME_INFLUENCE = biome -> 0;
Expand Down Expand Up @@ -102,57 +87,46 @@ public boolean initializeFromConfig(@Nonnull JsonObject configRoot) {

//This is the file name
@Override
@ZenGetter("depositName")
public String getDepositName() {
return depositName;
}

@ZenGetter("assignedName")
public String getAssignedName() {
return assignedName;
}

@ZenGetter("description")
public String getDescription() {
return description;
}

@ZenGetter("weight")
public int getWeight() {
return weight;
}

@ZenGetter("density")
public float getDensity() {
return density;
}

@ZenGetter("priority")
public int getPriority() {
return priority;
}

@ZenGetter("isVein")
public boolean isVein() {
return countAsVein;
}

@ZenMethod
public boolean checkInHeightLimit(int yLevel) {
return yLevel >= heightLimit[0] && yLevel <= heightLimit[1];
}

@ZenMethod
public int[] getHeightLimit() {
return heightLimit;
}

@ZenGetter("minimumHeight")
public int getMinimumHeight() {
return heightLimit[0];
}

@ZenGetter("maximumHeight")
public int getMaximumHeight() {
return heightLimit[1];
}
Expand All @@ -173,34 +147,10 @@ public IVeinPopulator getVeinPopulator() {
return veinPopulator;
}

@ZenMethod("getBiomeWeightModifier")
@Method(modid = GTValues.MODID_CT)
public int ctGetBiomeWeightModifier(IBiome biome) {
int biomeIndex = ArrayUtils.indexOf(CraftTweakerMC.biomes, biome);
Biome mcBiome = Biome.REGISTRY.getObjectById(biomeIndex);
return mcBiome == null ? 0 : getBiomeWeightModifier().apply(mcBiome);
}

@ZenMethod("checkDimension")
@Method(modid = GTValues.MODID_CT)
public boolean ctCheckDimension(int dimensionId) {
WorldProvider worldProvider = DimensionManager.getProvider(dimensionId);
return worldProvider != null && getDimensionFilter().test(worldProvider);
}

@ZenMethod("canGenerateIn")
@Method(modid = GTValues.MODID_CT)
public boolean ctCanGenerateIn(crafttweaker.api.block.IBlockState blockState, crafttweaker.api.world.IBlockAccess blockAccess, crafttweaker.api.world.IBlockPos blockPos) {
IBlockState mcBlockState = CraftTweakerMC.getBlockState(blockState);
return getGenerationPredicate().test(mcBlockState, (IBlockAccess) blockAccess.getInternal(), (BlockPos) blockPos.getInternal());
}

@ZenGetter("filter")
public BlockFiller getBlockFiller() {
return blockFiller;
}

@ZenGetter("shape")
public ShapeGenerator getShapeGenerator() {
return shapeGenerator;
}
Expand Down
Loading