Skip to content

Commit

Permalink
Compat fix for twilight forest
Browse files Browse the repository at this point in the history
  • Loading branch information
Ictoan42 committed Sep 19, 2024
1 parent a9ed052 commit e28f968
Show file tree
Hide file tree
Showing 6 changed files with 71 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
2 changes: 2 additions & 0 deletions forge/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ create_version = 0.5.1.e-22
flywheel_version = 0.6.10-7
registrate_version = MC1.20-1.3.3
cc_tweaked_version = 1.109.0
# https://modmaven.dev/teamtwilight/twilightforest/
twilightforest_version = 4.3.2145
#Extra
# https://modrinth.com/mod/tis3d/version/MC1.19.2-forge-1.7.4
tis3d_version = MC1.20.1-forge-1.7.5
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.valkyrienskies.mod.forge.mixin.compat.twilightforest;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import net.minecraft.core.Holder;
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.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 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));
}
}
}
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 @@ -13,6 +13,7 @@
"compat.tfc.MixinTFCChunkGenerator",
"compat.thermalexpansion.MixinTileCoFH",
"compat.tis3d.MixinInfraredPacketEntity",
"compat.twilightforest.ChunkGeneratorTwilightMixin",
"feature.forge_interact.MixinIForgePlayer",
"feature.water_in_ships_entity.MixinEntity",
"world.level.block.FireMixin"
Expand Down

0 comments on commit e28f968

Please sign in to comment.