-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Twilight Forest compatibility (#963)
* Compat fix for twilight forest * Add mixins to prevent structure generation --------- Co-authored-by: StewStrong <[email protected]>
- Loading branch information
1 parent
fe1b77d
commit 5beb174
Showing
6 changed files
with
94 additions
and
0 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
79 changes: 79 additions & 0 deletions
79
...org/valkyrienskies/mod/forge/mixin/compat/twilightforest/ChunkGeneratorTwilightMixin.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,79 @@ | ||
package org.valkyrienskies.mod.forge.mixin.compat.twilightforest; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.Executor; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Holder; | ||
import net.minecraft.core.HolderSet; | ||
import net.minecraft.core.RegistryAccess; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.server.level.WorldGenRegion; | ||
import net.minecraft.world.level.ChunkPos; | ||
import net.minecraft.world.level.LevelHeightAccessor; | ||
import net.minecraft.world.level.NoiseColumn; | ||
import net.minecraft.world.level.StructureManager; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.chunk.ChunkAccess; | ||
import net.minecraft.world.level.chunk.ChunkGeneratorStructureState; | ||
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings; | ||
import net.minecraft.world.level.levelgen.NoiseSettings; | ||
import net.minecraft.world.level.levelgen.RandomState; | ||
import net.minecraft.world.level.levelgen.blending.Blender; | ||
import net.minecraft.world.level.levelgen.structure.Structure; | ||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplateManager; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
import org.valkyrienskies.mod.common.VS2ChunkAllocator; | ||
import twilightforest.world.components.chunkgenerators.ChunkGeneratorTwilight; | ||
|
||
@Mixin(ChunkGeneratorTwilight.class) | ||
public class ChunkGeneratorTwilightMixin { | ||
@Shadow | ||
@Final | ||
protected Holder<NoiseGeneratorSettings> noiseGeneratorSettings; | ||
|
||
@Inject(method = "getBaseColumn", at = @At("HEAD"), cancellable = true) | ||
private void preGetBaseColumn(int x, int y, LevelHeightAccessor level, RandomState random, CallbackInfoReturnable<NoiseColumn> cir) { | ||
if (VS2ChunkAllocator.INSTANCE.isChunkInShipyardCompanion(x, y)) { | ||
final NoiseSettings ns = this.noiseGeneratorSettings.value().noiseSettings(); | ||
final int k = Math.max(ns.minY(), level.getMinBuildHeight()); | ||
cir.setReturnValue(new NoiseColumn(k, new BlockState[0])); | ||
} | ||
} | ||
|
||
@Inject(method = "buildSurface", at = @At("HEAD"), cancellable = true) | ||
private void preBuildSurface(WorldGenRegion world, StructureManager manager, RandomState random, ChunkAccess chunk, CallbackInfo ci) { | ||
final ChunkPos chunkPos = chunk.getPos(); | ||
if (VS2ChunkAllocator.INSTANCE.isChunkInShipyardCompanion(chunkPos.x, chunkPos.z)) { | ||
ci.cancel(); | ||
} | ||
} | ||
|
||
@Inject(method = "fillFromNoise", at = @At("HEAD"), cancellable = true) | ||
private void preFillFromNoise(Executor executor, Blender blender, RandomState random, StructureManager structureManager, ChunkAccess chunk, CallbackInfoReturnable<CompletableFuture<ChunkAccess>> cir) { | ||
final ChunkPos chunkPos = chunk.getPos(); | ||
if (VS2ChunkAllocator.INSTANCE.isChunkInShipyardCompanion(chunkPos.x, chunkPos.z)) { | ||
cir.setReturnValue(CompletableFuture.completedFuture(chunk)); | ||
} | ||
} | ||
|
||
@Inject(method = "createStructures", at = @At("HEAD"), cancellable = true) | ||
private void preCreateStructures(RegistryAccess access, ChunkGeneratorStructureState state, StructureManager manager, ChunkAccess chunk, StructureTemplateManager templateManager, CallbackInfo ci) { | ||
final ChunkPos chunkPos = chunk.getPos(); | ||
if (VS2ChunkAllocator.INSTANCE.isChunkInShipyardCompanion(chunkPos.x, chunkPos.z)) { | ||
ci.cancel(); | ||
} | ||
} | ||
|
||
@Inject(method = "findNearestMapStructure", at = @At("HEAD"), cancellable = true) | ||
private void preFindNearestMapStructure(ServerLevel level, HolderSet<Structure> targetStructures, BlockPos pos, int searchRadius, boolean skipKnownStructures, CallbackInfoReturnable cir) { | ||
if (VS2ChunkAllocator.INSTANCE.isChunkInShipyardCompanion(pos.getX() >> 4, pos.getZ() >> 4)) { | ||
cir.setReturnValue(null); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...rc/main/java/org/valkyrienskies/mod/forge/mixin/compat/twilightforest/README.MD
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,7 @@ | ||
Just a smidgen of compatibility code for twilight forest | ||
|
||
- ChunkGeneratorTwilightMixin | ||
- Fixes world generation not being cancelled within the shipyard in the | ||
twilight forest. TF uses its own ChunkGenerator implementation but it has | ||
all the same methods as the vanilla NoiseBasedChunkGenerator so the same | ||
mixins work. |
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