Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #5

Merged
merged 2 commits into from
Dec 8, 2023
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.4]

### Added
* Added new config setting `replaceColdBiomesOnly`, default true
* When true, only cold biomes near spawn will be replaced (as before), when false _all_ biomes will be replaced
* Other changes: `replaceColdBiomeId` is now `replaceBiomeId`, and `replaceColdBiomesNearSpawn` is now `replaceBiomesNearSpawn`

## [1.1.3]

### Added
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ minecraft_version=1.19.2
forge_version=1.19.2-43.2.4

# Mod Properties
mod_version=1.1.3
mod_version=1.1.4
maven_group=dev.ftb.mods
archives_base_name=ftb-team-dimensions
mod_id=ftbteamdimensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ public static class CategoryCommonGeneral {
public final ForgeConfigSpec.EnumValue<ChunkGenerators> chunkGenerator;
public final ForgeConfigSpec.BooleanValue teamSpecificNetherEntryPoint;
public final ForgeConfigSpec.BooleanValue placeEntitiesInStartStructure;
public final ForgeConfigSpec.IntValue replaceColdBiomesNearSpawn;
public final ForgeConfigSpec.BooleanValue replaceColdBiomesOnly;
public final ForgeConfigSpec.IntValue replaceBiomesNearSpawn;
public final ForgeConfigSpec.EnumValue<GameType> lobbyGameMode;
public final ForgeConfigSpec.BooleanValue allowLobbyDamages;
public final ForgeConfigSpec.ConfigValue<String> replaceColdBiomeId;
public final ForgeConfigSpec.ConfigValue<String> replaceBiomeId;

public CategoryCommonGeneral() {
COMMON_BUILDER.push("general");
Expand Down Expand Up @@ -107,13 +108,17 @@ public CategoryCommonGeneral() {
.comment("If true, then any entities saved in the starting structure NBT will be included when the structure is generated")
.define("placeEntitiesInStartStructure", true);

this.replaceColdBiomesNearSpawn = COMMON_BUILDER
.comment("If > 0, any chunk closer than this distance from spawn, with a cold biome (i.e. water can freeze) in its X/Z midpoint, will have its biome replaced with the biome defined in 'replaceColdBiomeId'. Set to 0 to disable all replacement.")
.defineInRange("replaceColdBiomesNearSpawn", 64, 0, Integer.MAX_VALUE);
this.replaceBiomesNearSpawn = COMMON_BUILDER
.comment("If > 0, any chunk closer than this distance from spawn will have its biome replaced with the biome defined in 'replaceBiomeId'. Set to 0 to disable all replacement.")
.defineInRange("replaceColdBiomesNearSpawn", 0, 0, Integer.MAX_VALUE);

this.replaceColdBiomeId = COMMON_BUILDER
.comment("Id of the biome which will be used to replace cold biomes near spawn (see 'replaceColdBiomesNearSpawn')")
.define("replaceColdBiomeId", "minecraft:plains");
this.replaceColdBiomesOnly = COMMON_BUILDER
.comment("If true (and 'replaceBiomesNearSpawn' > 0), only cold biomes near spawn (i.e. water can freeze) will be replaced with the biome defined in 'replaceBiomeId'.")
.define("replaceColdBiomesOnly", true);

this.replaceBiomeId = COMMON_BUILDER
.comment("Id of the biome which will be used to replace biomes near spawn (see 'replaceBiomesNearSpawn')")
.define("replaceBiomeId", "minecraft:plains");

COMMON_BUILDER.pop();
}
Expand Down
27 changes: 16 additions & 11 deletions src/main/java/dev/ftb/mods/ftbteamdimensions/FTBTeamDimensions.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,26 +137,31 @@ private void onLevelLoad(LevelEvent.Load event) {
}

private void onChunkLoad(ChunkEvent.Load event) {
if (event.getLevel() instanceof ServerLevel level && DimensionUtils.isTeamDimension(level) && FTBDimensionsConfig.COMMON_GENERAL.replaceColdBiomesNearSpawn.get() > 0) {
FTBDimensionsConfig.CategoryCommonGeneral general = FTBDimensionsConfig.COMMON_GENERAL;
if (event.getLevel() instanceof ServerLevel level && DimensionUtils.isTeamDimension(level) && general.replaceBiomesNearSpawn.get() > 0) {
BlockPos spawnPos = DimensionStorage.get(level.getServer()).getDimensionSpawnLocation(level.dimension().location());
if (spawnPos != null) {
ChunkPos chunkPos = event.getChunk().getPos();
BlockPos pos1 = chunkPos.getMiddleBlockPosition(spawnPos.getY());
int threshold = (int) Math.pow(FTBDimensionsConfig.COMMON_GENERAL.replaceColdBiomesNearSpawn.get(), 2);
if (pos1.distSqr(spawnPos) < threshold && level.getBiome(pos1).value().coldEnoughToSnow(pos1)) {
ResourceKey<Biome> biomeKey = ResourceKey.create(Registry.BIOME_REGISTRY,
new ResourceLocation(FTBDimensionsConfig.COMMON_GENERAL.replaceColdBiomeId.get()));
Holder<Biome> replacement = level.registryAccess().registry(Registry.BIOME_REGISTRY).orElseThrow().getHolderOrThrow(biomeKey);
BlockPos from = new BlockPos(chunkPos.getMinBlockX(), level.getMinBuildHeight(), chunkPos.getMinBlockZ());
BlockPos to = new BlockPos(chunkPos.getMaxBlockX(), level.getMaxBuildHeight(), chunkPos.getMaxBlockZ());
level.getServer().executeIfPossible(() ->
BiomeReplacementUtils.replaceBiome(level, event.getChunk(), from , to, replacement)
);
int threshold = (int) Math.pow(general.replaceBiomesNearSpawn.get(), 2);
if (pos1.distSqr(spawnPos) < threshold && (!general.replaceColdBiomesOnly.get() || level.getBiome(pos1).value().coldEnoughToSnow(pos1))) {
doReplacement(event, level, chunkPos);
}
}
}
}

private static void doReplacement(ChunkEvent.Load event, ServerLevel level, ChunkPos chunkPos) {
ResourceKey<Biome> biomeKey = ResourceKey.create(Registry.BIOME_REGISTRY,
new ResourceLocation(FTBDimensionsConfig.COMMON_GENERAL.replaceBiomeId.get()));
Holder<Biome> replacement = level.registryAccess().registry(Registry.BIOME_REGISTRY).orElseThrow().getHolderOrThrow(biomeKey);
BlockPos from = new BlockPos(chunkPos.getMinBlockX(), level.getMinBuildHeight(), chunkPos.getMinBlockZ());
BlockPos to = new BlockPos(chunkPos.getMaxBlockX(), level.getMaxBuildHeight(), chunkPos.getMaxBlockZ());
level.getServer().executeIfPossible(() ->
BiomeReplacementUtils.replaceBiome(level, event.getChunk(), from , to, replacement)
);
}

private void onSleepFinished(final SleepFinishedTimeEvent event) {
if (event.getLevel() instanceof ServerLevel level && level.dimension().location().getNamespace().equals(MOD_ID)) {
// player has slept in a dynamic dimension
Expand Down