Skip to content

Commit

Permalink
Twilight Forest compatibility (#963)
Browse files Browse the repository at this point in the history
* Compat fix for twilight forest

* Add mixins to prevent structure generation

---------

Co-authored-by: StewStrong <[email protected]>
  • Loading branch information
Ictoan42 and StewStrong authored Sep 27, 2024
1 parent fe1b77d commit 5beb174
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ subprojects {
name = 'tterrag maven'
url = 'https://maven.tterrag.com/'
}
maven { url = "https://modmaven.dev/" } // Twilight Forest
maven { url = "https://api.modrinth.com/maven" } // LazyDFU, Suggestion Tweaker, Create Big Cannons
maven { url = "https://maven.shedaniel.me/" } // Cloth Config, REI
maven { url "https://maven.architectury.dev/" }
Expand Down
3 changes: 3 additions & 0 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ dependencies {
//modCompileOnly("curse.maven:rubidium-574856:4024781")
modCompileOnly("maven.modrinth:embeddium:${embeddium_version}")

// Twilight Forest
modImplementation("teamtwilight:twilightforest:${twilightforest_version}:universal")

// Create compat
modImplementation("com.simibubi.create:create-${minecraft_version}:${create_version}:slim") { transitive = false }
modImplementation("com.jozufozu.flywheel:flywheel-forge-${minecraft_version}:${flywheel_version}")
Expand Down
3 changes: 3 additions & 0 deletions forge/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ cloth_config_version = 11.1.106
create_version = 0.5.1.e-22
flywheel_version = 0.6.10-7
registrate_version = MC1.20-1.3.3

# https://modmaven.dev/teamtwilight/twilightforest/
twilightforest_version = 4.3.2145
cc_tweaked_version = 1.109.0-forge
#Extra
# https://modrinth.com/mod/tis3d/version/MC1.19.2-forge-1.7.4
Expand Down
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);
}
}
}
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.
1 change: 1 addition & 0 deletions forge/src/main/resources/valkyrienskies-forge.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"compat.tfc.MixinTFCChunkGenerator",
"compat.thermalexpansion.MixinTileCoFH",
"compat.tis3d.MixinInfraredPacketEntity",
"compat.twilightforest.ChunkGeneratorTwilightMixin",
"feature.forge_interact.MixinIForgePlayer",
"feature.water_in_ships_entity.MixinEntity",
"feature.shipyard_entities.MixinPersistentEntitySectionManager",
Expand Down

0 comments on commit 5beb174

Please sign in to comment.