-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vForge-12. Add deep copy dimension noise settings on world load.
- Loading branch information
Nicholas Young
committed
Aug 4, 2021
1 parent
152281c
commit db2baa8
Showing
6 changed files
with
106 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/com/yungnickyoung/minecraft/yungsapi/init/YAModWorldgen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.yungnickyoung.minecraft.yungsapi.init; | ||
|
||
import com.yungnickyoung.minecraft.yungsapi.mixin.ChunkGeneratorAccessor; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraft.util.registry.Registry; | ||
import net.minecraft.world.gen.ChunkGenerator; | ||
import net.minecraft.world.gen.settings.DimensionStructuresSettings; | ||
import net.minecraft.world.gen.settings.StructureSpreadSettings; | ||
import net.minecraft.world.server.ServerWorld; | ||
import net.minecraftforge.common.MinecraftForge; | ||
import net.minecraftforge.event.world.WorldEvent; | ||
|
||
import java.util.Optional; | ||
|
||
public class YAModWorldgen { | ||
public static void init() { | ||
MinecraftForge.EVENT_BUS.addListener(YAModWorldgen::deepCopyDimensionalSpacing); | ||
} | ||
|
||
/** | ||
* Deep copying the noise settings prevents bugs related to modded dimensions that use | ||
* the same noise settings as existing dimensions. | ||
* Credits to TelepathicGrunt. | ||
*/ | ||
private static void deepCopyDimensionalSpacing(final WorldEvent.Load event) { | ||
if (event.getWorld() instanceof ServerWorld) { | ||
ServerWorld serverWorld = (ServerWorld) event.getWorld(); | ||
|
||
// Workaround for Terraforged | ||
ResourceLocation chunkGenResourceLocation = Registry.CHUNK_GENERATOR_CODEC.getKey(((ChunkGeneratorAccessor) serverWorld.getChunkProvider().generator).yungsapi_getCodec()); | ||
if (chunkGenResourceLocation != null && chunkGenResourceLocation.getNamespace().equals("terraforged")) { | ||
return; | ||
} | ||
|
||
ChunkGenerator chunkGenerator = serverWorld.getChunkProvider().generator; | ||
|
||
// Grab old copy of stronghold spacing settings | ||
StructureSpreadSettings oldStrongholdSettings = chunkGenerator.func_235957_b_().func_236199_b_(); | ||
|
||
// Make a deep copy and wrap it in an optional as DimensionStructuresSettings requires an optional | ||
Optional<StructureSpreadSettings> newStrongholdSettings = oldStrongholdSettings == null ? | ||
Optional.empty() : | ||
Optional.of(new StructureSpreadSettings( | ||
oldStrongholdSettings.func_236660_a_(), | ||
oldStrongholdSettings.func_236662_b_(), | ||
oldStrongholdSettings.func_236663_c_())); | ||
|
||
// Create new deep copied DimensionStructuresSettings | ||
// We do not need to create a new structure spacing map instance here as our patch into | ||
// DimensionStructuresSettings will already create the new map instance for us. | ||
DimensionStructuresSettings newSettings = new DimensionStructuresSettings(newStrongholdSettings, chunkGenerator.func_235957_b_().func_236195_a_()); | ||
|
||
((ChunkGeneratorAccessor) chunkGenerator).yungsapi_setSettings(newSettings); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/yungnickyoung/minecraft/yungsapi/mixin/ChunkGeneratorAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.yungnickyoung.minecraft.yungsapi.mixin; | ||
|
||
import com.mojang.serialization.Codec; | ||
import net.minecraft.world.gen.ChunkGenerator; | ||
import net.minecraft.world.gen.settings.DimensionStructuresSettings; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
import org.spongepowered.asm.mixin.gen.Invoker; | ||
|
||
@Mixin(ChunkGenerator.class) | ||
public interface ChunkGeneratorAccessor { | ||
@Accessor("settings") | ||
void yungsapi_setSettings(DimensionStructuresSettings dimensionStructuresSettings); | ||
|
||
@Invoker("func_230347_a_") | ||
Codec<ChunkGenerator> yungsapi_getCodec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"required": true, | ||
"package": "com.yungnickyoung.minecraft.yungsapi.mixin", | ||
"compatibilityLevel": "JAVA_8", | ||
"refmap": "yungsapi.refmap.json", | ||
"mixins": [ | ||
"ChunkGeneratorAccessor" | ||
], | ||
"injectors": { | ||
"defaultRequire": 1 | ||
}, | ||
"minVersion": "0.8" | ||
} |