Update optimization to 1.20
This commit is contained in:
parent
473c74e63b
commit
90848b8972
|
|
@ -1,17 +0,0 @@
|
||||||
package org.embeddedt.modernfix.common.mixin.perf.faster_structure_location;
|
|
||||||
|
|
||||||
import net.minecraft.core.Holder;
|
|
||||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
|
||||||
import net.minecraft.world.level.levelgen.RandomState;
|
|
||||||
import net.minecraft.world.level.levelgen.structure.Structure;
|
|
||||||
import net.minecraft.world.level.levelgen.structure.placement.StructurePlacement;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Mixin(ChunkGenerator.class)
|
|
||||||
public interface ChunkGeneratorAccessor {
|
|
||||||
@Invoker("getPlacementsForStructure")
|
|
||||||
List<StructurePlacement> invokeGetPlacementsForStructure(Holder<Structure> structure, RandomState random);
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
package org.embeddedt.modernfix.common.mixin.perf.faster_structure_location;
|
||||||
|
|
||||||
|
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
|
||||||
|
import net.minecraft.server.level.ServerChunkCache;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.level.levelgen.structure.StructureCheck;
|
||||||
|
import org.embeddedt.modernfix.duck.IStructureCheck;
|
||||||
|
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;
|
||||||
|
|
||||||
|
@Mixin(ServerLevel.class)
|
||||||
|
public class ServerLevelMixin {
|
||||||
|
@Shadow @Final private ServerChunkCache chunkSource;
|
||||||
|
|
||||||
|
@ModifyExpressionValue(method = "<init>", at = @At(value = "NEW", target = "(Lnet/minecraft/world/level/chunk/storage/ChunkScanAccess;Lnet/minecraft/core/RegistryAccess;Lnet/minecraft/world/level/levelgen/structure/templatesystem/StructureTemplateManager;Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/world/level/chunk/ChunkGenerator;Lnet/minecraft/world/level/levelgen/RandomState;Lnet/minecraft/world/level/LevelHeightAccessor;Lnet/minecraft/world/level/biome/BiomeSource;JLcom/mojang/datafixers/DataFixer;)Lnet/minecraft/world/level/levelgen/structure/StructureCheck;", ordinal = 0))
|
||||||
|
private StructureCheck attachGeneratorState(StructureCheck check) {
|
||||||
|
((IStructureCheck)check).mfix$setStructureState(this.chunkSource.getGeneratorState());
|
||||||
|
return check;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,22 +3,26 @@ package org.embeddedt.modernfix.common.mixin.perf.faster_structure_location;
|
||||||
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
|
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.world.level.ChunkPos;
|
import net.minecraft.world.level.ChunkPos;
|
||||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
import net.minecraft.world.level.chunk.ChunkGeneratorStructureState;
|
||||||
import net.minecraft.world.level.levelgen.RandomState;
|
|
||||||
import net.minecraft.world.level.levelgen.structure.Structure;
|
import net.minecraft.world.level.levelgen.structure.Structure;
|
||||||
import net.minecraft.world.level.levelgen.structure.StructureCheck;
|
import net.minecraft.world.level.levelgen.structure.StructureCheck;
|
||||||
import net.minecraft.world.level.levelgen.structure.StructureCheckResult;
|
import net.minecraft.world.level.levelgen.structure.StructureCheckResult;
|
||||||
|
import org.embeddedt.modernfix.duck.IStructureCheck;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
|
||||||
@Mixin(StructureCheck.class)
|
@Mixin(StructureCheck.class)
|
||||||
public class StructureCheckMixin {
|
public class StructureCheckMixin implements IStructureCheck {
|
||||||
@Shadow @Final private ChunkGenerator chunkGenerator;
|
|
||||||
@Shadow @Final private long seed;
|
|
||||||
@Shadow @Final private Registry<Structure> structureConfigs;
|
@Shadow @Final private Registry<Structure> structureConfigs;
|
||||||
@Shadow @Final private RandomState randomState;
|
|
||||||
|
private ChunkGeneratorStructureState mfix$structureState;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mfix$setStructureState(ChunkGeneratorStructureState state) {
|
||||||
|
mfix$structureState = state;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author embeddedt (inspired by 24w04a and Bytzo's comment on https://bugs.mojang.com/browse/MC-249136)
|
* @author embeddedt (inspired by 24w04a and Bytzo's comment on https://bugs.mojang.com/browse/MC-249136)
|
||||||
|
|
@ -29,17 +33,19 @@ public class StructureCheckMixin {
|
||||||
private StructureCheckResult mfix$checkForValidPosition(StructureCheckResult storageResult, ChunkPos chunkPos, Structure structure, boolean skipKnownStructures) {
|
private StructureCheckResult mfix$checkForValidPosition(StructureCheckResult storageResult, ChunkPos chunkPos, Structure structure, boolean skipKnownStructures) {
|
||||||
if (storageResult != null) {
|
if (storageResult != null) {
|
||||||
return storageResult;
|
return storageResult;
|
||||||
} else {
|
} else if(mfix$structureState != null) {
|
||||||
// Check if any of the placements allow for this structure to be in this chunk
|
// Check if any of the placements allow for this structure to be in this chunk
|
||||||
var structureHolder = this.structureConfigs.getHolder(this.structureConfigs.getId(structure)).orElseThrow();
|
var structureHolder = this.structureConfigs.wrapAsHolder(structure);
|
||||||
for (var placement : ((ChunkGeneratorAccessor)this.chunkGenerator).invokeGetPlacementsForStructure(structureHolder, this.randomState)) {
|
for (var placement : mfix$structureState.getPlacementsForStructure(structureHolder)) {
|
||||||
if (placement.isStructureChunk(this.chunkGenerator, this.randomState, this.seed, chunkPos.x, chunkPos.z)) {
|
if (placement.isStructureChunk(mfix$structureState, chunkPos.x, chunkPos.z)) {
|
||||||
// Allowed - return null so regular check runs
|
// Allowed - return null so regular check runs
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Not allowed - early exit by returning a non-null value
|
// Not allowed - early exit by returning a non-null value
|
||||||
return StructureCheckResult.START_NOT_PRESENT;
|
return StructureCheckResult.START_NOT_PRESENT;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package org.embeddedt.modernfix.duck;
|
||||||
|
|
||||||
|
import net.minecraft.world.level.chunk.ChunkGeneratorStructureState;
|
||||||
|
|
||||||
|
public interface IStructureCheck {
|
||||||
|
void mfix$setStructureState(ChunkGeneratorStructureState state);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user