Skip to content

Commit

Permalink
1.16.2 port
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Young committed Aug 24, 2020
1 parent c969add commit 335a9ab
Show file tree
Hide file tree
Showing 23 changed files with 101 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ archivesBaseName = modFileName
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.

repositories {
// Put remote maven repositories here
maven {
url 'https://www.dogforce-games.com/maven/'
}
}

minecraft {
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ modName = YUNG's Better Caves
modAuthor = YUNGNICKYOUNG

# A description of the mod, to be displayed in mcmod.info
modDescription = YUNG's Better Caves overhauls Vanilla Minecraft's cave generation, making caves much more structurally diverse and exciting!
modDescription = Overhauled cave generation, underground lakes and rivers, lava oceans, and more! This is the most powerful and customizable Minecraft cave mod, with dozens of options and support for dimension-specific configurability.

# Credits to be displayed in the mcmod.info
modCredits = Special thanks to kilo from the Rebirth of the Night team!
modCredits = Thanks so much to all my supporters, and special shoutout to kilo from the Rebirth of the Night team!

# The version of Minecraft we are modding for
modMinecraftVersion = 1.16.1
modMinecraftVersion = 1.16.2

# The MCP Mappings the source code of the mod will be built against
# MCP Mappings are in the format
Expand All @@ -41,7 +41,7 @@ modMinecraftVersion = 1.16.1
# (and the modMcpMappingsChannel property if you're switching in between stable and snapshot)
# and then refresh the gradle project in your IDE
modMcpMappingsChannel = snapshot
modMcpMappingsVersion = 20200514-1.16
modMcpMappingsVersion = 20200813-1.16.1

# The Forge version the mod is being made for
modForgeVersion = 32.0.47
modForgeVersion = 33.0.20
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
import com.yungnickyoung.minecraft.bettercaves.init.BCModConfig;
import com.yungnickyoung.minecraft.bettercaves.init.BCFeature;
import com.yungnickyoung.minecraft.bettercaves.world.carver.BetterCavesCarver;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.carver.ConfiguredCarver;
import net.minecraft.world.gen.feature.Feature;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -15,6 +20,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;

/**
* Entry point for Better Caves
Expand All @@ -38,8 +44,8 @@ public class BetterCaves {
* Better Caves deletes these and wraps them in its feature so that they can be
* used for dimensions in which Better Caves is disabled.
*/
public static Map<Class<? extends Biome>, List<ConfiguredCarver<?>>> defaultBiomeAirCarvers = new HashMap<>();
public static Map<Class<? extends Biome>, List<ConfiguredCarver<?>>> defaultBiomeLiquidCarvers = new HashMap<>();
public static Map<String, List<Supplier<ConfiguredCarver<?>>>> defaultBiomeAirCarvers = new HashMap<>();
public static Map<String, List<Supplier<ConfiguredCarver<?>>>> defaultBiomeLiquidCarvers = new HashMap<>();

/** File referring to the overarching directory for custom dimension configs **/
public static File customConfigDir;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,50 @@
package com.yungnickyoung.minecraft.bettercaves.init;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.yungnickyoung.minecraft.bettercaves.BetterCaves;
import com.yungnickyoung.minecraft.bettercaves.config.BCSettings;
import com.yungnickyoung.minecraft.bettercaves.config.Configuration;
import com.yungnickyoung.minecraft.bettercaves.world.feature.CarverFeature;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.WorldGenRegistries;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.GenerationStage;
import net.minecraft.world.gen.carver.ConfiguredCarver;
import net.minecraft.world.gen.feature.*;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.DeferredWorkQueue;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Collectors;

public class BCFeature {
private static final DeferredRegister<Feature<?>> FEATURES = DeferredRegister.create(ForgeRegistries.FEATURES, BCSettings.MOD_ID);
public static final CarverFeature BETTERCAVES_CARVER = new CarverFeature(NoFeatureConfig.field_236558_a_);
public static final RegistryObject<Feature<?>> BETTERCAVES_CARVER_FEATURE = FEATURES.register("bettercave", () -> BETTERCAVES_CARVER);
public static final CarverFeature BETTERCAVES_FEATURE = new CarverFeature(NoFeatureConfig.field_236558_a_);
public static final ConfiguredFeature<?, ?> CONFIGURED_BETTERCAVES_FEATURE = new ConfiguredFeature<>(BETTERCAVES_FEATURE, new NoFeatureConfig());

/**
* Register
*/
public static void init() {
FEATURES.register(FMLJavaModLoadingContext.get().getModEventBus());
FMLJavaModLoadingContext.get().getModEventBus().addListener(BCFeature::commonSetup);
FMLJavaModLoadingContext.get().getModEventBus().addListener(BCFeature::configChanged);
FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(Feature.class, BCFeature::registerFeature);
MinecraftForge.EVENT_BUS.addListener(BCFeature::worldUnload);
}

public static void registerFeature(final RegistryEvent.Register<Feature<?>> event) {
Registry.register(Registry.FEATURE, new ResourceLocation(BCSettings.MOD_ID, "bettercaves"), BETTERCAVES_FEATURE);
}

/**
* Iterates over all biomes, removing their carvers and adding the Better Caves feature
* (which wraps all the pre-existing carvers) to the front of their feature lists
Expand All @@ -53,26 +59,29 @@ public static void commonSetup(FMLCommonSetupEvent event) {
private static void lateSetup() {
BetterCaves.LOGGER.info("Replacing biome carvers with Better Caves carvers...");

// Get all registered biomes
Set<Map.Entry<ResourceLocation, Biome>> biomesList = ForgeRegistries.BIOMES.getEntries();

// Replace biome carvers with Better Caves carvers
for (Map.Entry<ResourceLocation, Biome> e : biomesList) {
Biome biome = e.getValue();
for (Biome biome : WorldGenRegistries.field_243657_i) {
convertImmutableFeatures(biome);

// Save all pre-existing carvers for biome.
// These will be used in dimensions where Better Caves is not whitelisted.
List<ConfiguredCarver<?>> defaultAirCarvers = biome.getCarvers(GenerationStage.Carving.AIR);
List<ConfiguredCarver<?>> defaultLiquidCarvers = biome.getCarvers(GenerationStage.Carving.LIQUID);
BetterCaves.defaultBiomeAirCarvers.put(biome.getClass(), defaultAirCarvers);
BetterCaves.defaultBiomeLiquidCarvers.put(biome.getClass(), defaultLiquidCarvers);
List<Supplier<ConfiguredCarver<?>>> defaultAirCarvers = biome.func_242440_e().func_242489_a(GenerationStage.Carving.AIR);
List<Supplier<ConfiguredCarver<?>>> defaultLiquidCarvers = biome.func_242440_e().func_242489_a(GenerationStage.Carving.LIQUID);
BetterCaves.defaultBiomeAirCarvers.put(biome.toString(), defaultAirCarvers);
BetterCaves.defaultBiomeLiquidCarvers.put(biome.toString(), defaultLiquidCarvers);

// Use Access Transformer to make carvers field public so we can replace with empty list
biome.carvers = Maps.newHashMap();
biome.func_242440_e().field_242483_e = Maps.newHashMap();

// Use Access Transformer to make features field public so we can put our carver
// at the front of the list to give it guaranteed priority.
biome.features.get(GenerationStage.Decoration.RAW_GENERATION).add(0, new ConfiguredFeature<>(new CarverFeature(NoFeatureConfig.field_236558_a_), new NoFeatureConfig()));
List<List<Supplier<ConfiguredFeature<?, ?>>>> biomeFeatures = biome.func_242440_e().field_242484_f;
while (biomeFeatures.size() <= GenerationStage.Decoration.RAW_GENERATION.ordinal()) {
biomeFeatures.add(Lists.newArrayList());
}
biomeFeatures.get(GenerationStage.Decoration.RAW_GENERATION.ordinal()).add(0,
() -> CONFIGURED_BETTERCAVES_FEATURE
);
}
}

Expand All @@ -82,7 +91,7 @@ private static void lateSetup() {
public static void worldUnload(WorldEvent.Unload event) {
BetterCaves.LOGGER.debug("UNLOADING WORLD");
try {
String key = Objects.requireNonNull(((World) event.getWorld()).func_234923_W_().func_240901_a_()).toString();
String key = Objects.requireNonNull(((World) event.getWorld()).getDimensionKey().func_240901_a_()).toString();
BetterCaves.activeCarversMap.remove(key);
} catch (NullPointerException e) {
BetterCaves.LOGGER.error("ERROR: Unable to unload carver for dimension!");
Expand Down Expand Up @@ -116,4 +125,10 @@ public static void configChanged(ModConfig.ModConfigEvent event) {
BetterCaves.whitelistedDimensions = whitelistedDimensions;
}
}

private static void convertImmutableFeatures(Biome biome) {
if (biome.func_242440_e().field_242484_f instanceof ImmutableList) {
biome.func_242440_e().field_242484_f = biome.func_242440_e().field_242484_f.stream().map(Lists::newArrayList).collect(Collectors.toList());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.yungnickyoung.minecraft.bettercaves.config.BCSettings;
import com.yungnickyoung.minecraft.bettercaves.util.Vector3f;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import net.minecraft.world.IWorld;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.IChunk;
import net.minecraft.world.gen.WorldGenRegion;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import net.minecraft.world.chunk.IChunk;
import net.minecraft.world.gen.GenerationStage;
import net.minecraft.world.gen.Heightmap;
import net.minecraft.world.gen.WorldGenRegion;

import java.util.*;

Expand Down Expand Up @@ -89,7 +88,7 @@ public void initialize(ISeedReader worldIn) {
String dimensionName = "";

try {
dimensionName = Objects.requireNonNull(((WorldGenRegion) world).getWorld().func_234923_W_().func_240901_a_()).toString();
dimensionName = Objects.requireNonNull(world.getWorld().getDimensionKey().func_240901_a_()).toString();
} catch (NullPointerException e) {
BetterCaves.LOGGER.error("ERROR: Unable to get dimension name! This could be a problem...");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public static void carveBlock(IChunk chunkIn, BlockPos blockPos, BlockState airB
BlockPos blockPosBelow = blockPos.down();

Biome biome = chunkIn.getBiomes().getNoiseBiome(blockPos.getX(), blockPos.getY(), blockPos.getZ());
BlockState biomeTopBlockState = biome.getSurfaceBuilderConfig().getTop();
BlockState biomeFillerBlockState = biome.getSurfaceBuilderConfig().getUnder();
BlockState biomeTopBlockState = biome.func_242440_e().func_242502_e().getTop();
BlockState biomeFillerBlockState = biome.func_242440_e().func_242502_e().getUnder();
BlockState blockState = chunkIn.getBlockState(blockPos);
BlockState blockStateAbove = chunkIn.getBlockState(blockPosAbove);
BlockState blockStateBelow = chunkIn.getBlockState(blockPosBelow);
Expand Down Expand Up @@ -130,8 +130,8 @@ public static void carveFloodedBlock(IChunk chunkIn, Random rand, BlockPos.Mutab

// Dig flooded block
Biome biome = chunkIn.getBiomes().getNoiseBiome(blockPos.getX(), blockPos.getY(), blockPos.getZ());
BlockState biomeTopBlockState = biome.getSurfaceBuilderConfig().getTop();
BlockState biomeFillerBlockState = biome.getSurfaceBuilderConfig().getUnder();
BlockState biomeTopBlockState = biome.func_242440_e().func_242502_e().getTop();
BlockState biomeFillerBlockState = biome.func_242440_e().func_242502_e().getUnder();
BlockState blockState = chunkIn.getBlockState(blockPos);
BlockState blockStateAbove = chunkIn.getBlockState(blockPos.up());
if (!canReplaceLiquidBlock(blockState, blockStateAbove) && blockState != biomeTopBlockState && blockState != biomeFillerBlockState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void carveColumn(IChunk chunk, ColPos colPos, int topY, NoiseColumn noise
}
else if (digBlock) {
if (flooded) {
CarverUtils.carveFloodedBlock(chunk, new Random(), blockPos.func_239590_i_(), liquidBlock, settings.getLiquidAltitude(), settings.isReplaceFloatingGravel(), carvingMask);
CarverUtils.carveFloodedBlock(chunk, new Random(), blockPos.toMutable(), liquidBlock, settings.getLiquidAltitude(), settings.isReplaceFloatingGravel(), carvingMask);
} else {
CarverUtils.carveBlock(chunk, blockPos, liquidBlock, settings.getLiquidAltitude(), settings.isReplaceFloatingGravel(), carvingMask);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void carveColumn(IChunk chunk, ColPos colPos, int topY, float smoothAmp,
CarverUtils.debugCarveBlock(chunk, blockPos, settings.getDebugBlock(), digBlock);
} else if (digBlock) {
if (flooded) {
CarverUtils.carveFloodedBlock(chunk, new Random(), blockPos.func_239590_i_(), liquidBlock, settings.getLiquidAltitude(), settings.isReplaceFloatingGravel(), carvingMask);
CarverUtils.carveFloodedBlock(chunk, new Random(), blockPos.toMutable(), liquidBlock, settings.getLiquidAltitude(), settings.isReplaceFloatingGravel(), carvingMask);
} else {
CarverUtils.carveBlock(chunk, blockPos, liquidBlock, settings.getLiquidAltitude(), settings.isReplaceFloatingGravel(), carvingMask);
} }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ public class RavineController {
private boolean isRavinesEnabled;
private boolean isDebugViewEnabled;

private ConfiguredCarver<ProbabilityConfig> ravineCarver;
private ConfiguredCarver<ProbabilityConfig> configuredCarver;
private RavineCarver ravineCarver;

public RavineController(ISeedReader worldIn, ConfigHolder config) {
this.world = worldIn;
this.isRavinesEnabled = config.enableVanillaRavines.get();
this.isDebugViewEnabled = config.debugVisualizer.get();

this.ravineCarver = new ConfiguredCarver<>(new RavineCarver(world, config, ProbabilityConfig.field_236576_b_), new ProbabilityConfig(.02f));
this.ravineCarver = new RavineCarver(world, config, ProbabilityConfig.field_236576_b_);
this.configuredCarver = new ConfiguredCarver<>(ravineCarver, new ProbabilityConfig(.02f));
}

public void carveChunk(IChunk chunkIn, int chunkX, int chunkZ, BlockState[][] liquidBlocks, Map<Long, Biome> biomeMap, BitSet airCarvingMask, BitSet liquidCarvingMask) {
Expand All @@ -43,15 +45,15 @@ public void carveChunk(IChunk chunkIn, int chunkX, int chunkZ, BlockState[][] li
for (int currChunkX = chunkX - 8; currChunkX <= chunkX + 8; currChunkX++) {
for (int currChunkZ = chunkZ - 8; currChunkZ <= chunkZ + 8; currChunkZ++) {
random.setLargeFeatureSeed(this.world.getSeed(), currChunkX, currChunkZ);
if (ravineCarver.shouldCarve(random, chunkX, chunkZ)) {
((RavineCarver) ravineCarver.carver).carve(chunkIn, random, world.getSeaLevel(), currChunkX, currChunkZ, chunkX, chunkZ, liquidBlocks, biomeMap, airCarvingMask, liquidCarvingMask);
if (configuredCarver.shouldCarve(random, chunkX, chunkZ)) {
ravineCarver.carve(chunkIn, random, world.getSeaLevel(), currChunkX, currChunkZ, chunkX, chunkZ, liquidBlocks, biomeMap, airCarvingMask, liquidCarvingMask);
}
}
}
}

public void setWorld(ISeedReader worldIn) {
this.world = worldIn;
((RavineCarver)this.ravineCarver.carver).setWorld(worldIn);
this.ravineCarver.setWorld(worldIn);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.minecraft.block.Blocks;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.ISeedReader;
import net.minecraft.world.gen.WorldGenRegion;
import net.minecraftforge.registries.ForgeRegistries;

import java.util.Objects;
Expand All @@ -32,7 +31,7 @@ public class WaterRegionController {

public WaterRegionController(ISeedReader worldIn, ConfigHolder config) {
this.world = worldIn;
this.dimensionName = Objects.requireNonNull(((WorldGenRegion) world).getWorld().func_234923_W_().func_240901_a_()).toString();
this.dimensionName = Objects.requireNonNull(world.getWorld().getDimensionKey().func_240901_a_()).toString();
this.rand = new Random();

// Vars from config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ private void digBlock(IWorld worldIn, IChunk chunkIn, int chunkX, int chunkZ, in

// Carve block
if (flooded) {
CarverUtils.carveFloodedBlock(chunkIn, rand, blockPos.func_239590_i_(), liquidBlockState, liquidAltitude, liquidCarvingMask);
CarverUtils.carveFloodedBlock(chunkIn, rand, blockPos.toMutable(), liquidBlockState, liquidAltitude, liquidCarvingMask);
}
else {
CarverUtils.carveBlock(chunkIn, blockPos, liquidBlockState, this.liquidAltitude, this.isReplaceGravelEnabled, airCarvingMask);
Expand Down
Loading

0 comments on commit 335a9ab

Please sign in to comment.