Skip to content

Commit

Permalink
TFC mixin compat
Browse files Browse the repository at this point in the history
  • Loading branch information
ewoudje committed Nov 29, 2023
1 parent 5fcbc72 commit 6248cbd
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

@Mixin(ChunkGenerator.class)
public class MixinChunkGenerator {
// TODO its pretty standard to extend this class, if they do super.whatever, these mixins will not work correctly
// tfc in forge part of the mod has a bandaid solution, if this is fixed please remove that

@Inject(method = "findNearestMapFeature", at = @At("HEAD"), cancellable = true)
private void preFindNearestMapFeature(ServerLevel serverLevel, HolderSet<ConfiguredStructureFeature<?, ?>> holderSet, BlockPos blockPos, int i, boolean bl, final CallbackInfoReturnable<Pair<BlockPos, Holder<ConfiguredStructureFeature<?, ?>>>> cir) {
if (VS2ChunkAllocator.INSTANCE.isChunkInShipyardCompanion(blockPos.getX() >> 4, blockPos.getZ() >> 4)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package org.valkyrienskies.mod.forge.mixin.compat.tfc;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import net.minecraft.core.RegistryAccess;
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.StructureFeatureManager;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.biome.BiomeManager;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.levelgen.GenerationStep;
import net.minecraft.world.level.levelgen.blending.Blender;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
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;

@Pseudo
@Mixin(targets = "net.dries007.tfc.world.TFCChunkGenerator")
public class MixinTFCChunkGenerator {

@Inject(method = "m_183372_", at = @At("HEAD"), cancellable = true)
private void preApplyBiomeDecoration(
final WorldGenLevel worldGenLevel, final ChunkAccess chunkAccess,
final StructureFeatureManager structureFeatureManager, final CallbackInfo callbackInfo
) {
final ChunkPos chunkPos = chunkAccess.getPos();
if (VS2ChunkAllocator.INSTANCE.isChunkInShipyardCompanion(chunkPos.x, chunkPos.z)) {
callbackInfo.cancel();
}
}

@Inject(method = "m_62199_", at = @At("HEAD"), cancellable = true)
private void preCreateStructures(
final RegistryAccess registryAccess,
final StructureFeatureManager structureFeatureManager, final ChunkAccess chunkAccess,
final StructureManager structureManager, final long l, final CallbackInfo callbackInfo
) {
final ChunkPos chunkPos = chunkAccess.getPos();
if (VS2ChunkAllocator.INSTANCE.isChunkInShipyardCompanion(chunkPos.x, chunkPos.z)) {
callbackInfo.cancel();
}
}

@Inject(method = "m_62177_", at = @At("HEAD"), cancellable = true)
private void preCreateReferences(
final WorldGenLevel worldGenLevel, final StructureFeatureManager structureFeatureManager,
final ChunkAccess chunkAccess, final CallbackInfo callbackInfo
) {
final ChunkPos chunkPos = chunkAccess.getPos();
if (VS2ChunkAllocator.INSTANCE.isChunkInShipyardCompanion(chunkPos.x, chunkPos.z)) {
callbackInfo.cancel();
}
}

@Inject(method = "m_141914_", at = @At("HEAD"), cancellable = true)
private void preGetBaseColumn(int i, int j, LevelHeightAccessor levelHeightAccessor, CallbackInfoReturnable<NoiseColumn> cir) {
if (VS2ChunkAllocator.INSTANCE.isChunkInShipyardCompanion(i, j)) {
cir.setReturnValue(new NoiseColumn(0, new BlockState[0]));
}
}

@Inject(method = "m_183621_", at = @At("HEAD"), cancellable = true)
private void preBuildSurface(WorldGenRegion worldGenRegion, StructureFeatureManager structureFeatureManager, ChunkAccess chunkAccess, CallbackInfo ci) {
final ChunkPos chunkPos = chunkAccess.getPos();
if (VS2ChunkAllocator.INSTANCE.isChunkInShipyardCompanion(chunkPos.x, chunkPos.z)) {
ci.cancel();
}
}

@Inject(method = "m_183516_", at = @At("HEAD"), cancellable = true)
private void preApplyCarvers(WorldGenRegion worldGenRegion, long l, BiomeManager biomeManager, StructureFeatureManager structureFeatureManager, ChunkAccess chunkAccess, GenerationStep.Carving carving, CallbackInfo ci) {
final ChunkPos chunkPos = chunkAccess.getPos();
if (VS2ChunkAllocator.INSTANCE.isChunkInShipyardCompanion(chunkPos.x, chunkPos.z)) {
ci.cancel();
}
}

@Inject(method = "m_183489_", at = @At("HEAD"), cancellable = true)
private void preFillFromNoise(Executor executor, Blender blender, StructureFeatureManager structureFeatureManager, ChunkAccess chunkAccess, CallbackInfoReturnable<CompletableFuture<ChunkAccess>> cir) {
final ChunkPos chunkPos = chunkAccess.getPos();
if (VS2ChunkAllocator.INSTANCE.isChunkInShipyardCompanion(chunkPos.x, chunkPos.z)) {
cir.setReturnValue(CompletableFuture.completedFuture(chunkAccess));
}
}

@Inject(method = "m_6929_", at = @At("HEAD"), cancellable = true)
private void preSpawnOriginalMobs(WorldGenRegion worldGenRegion, CallbackInfo ci) {
final ChunkPos chunkPos = worldGenRegion.getCenter();
if (VS2ChunkAllocator.INSTANCE.isChunkInShipyardCompanion(chunkPos.x, chunkPos.z)) {
ci.cancel();
}
}
}
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 @@ -12,6 +12,7 @@
"compat.create.MixinBlocks",
"compat.create.MixinControlledContraptionEntity",
"compat.immersivengineering.MixinBlockEntityInventory",
"compat.tfc.MixinTFCChunkGenerator",
"compat.thermalexpansion.MixinTileCoFH",
"compat.tis3d.MixinInfraredPacketEntity",
"compat.modular_routers.MixinContainerModularRouter",
Expand Down

0 comments on commit 6248cbd

Please sign in to comment.