-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
253 additions
and
1 deletion.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
...org/embeddedt/modernfix/common/mixin/perf/faster_structure_location/ServerLevelMixin.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,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; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
.../embeddedt/modernfix/common/mixin/perf/faster_structure_location/StructureCheckMixin.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,51 @@ | ||
package org.embeddedt.modernfix.common.mixin.perf.faster_structure_location; | ||
|
||
import com.llamalad7.mixinextras.injector.ModifyExpressionValue; | ||
import net.minecraft.core.Registry; | ||
import net.minecraft.world.level.ChunkPos; | ||
import net.minecraft.world.level.chunk.ChunkGeneratorStructureState; | ||
import net.minecraft.world.level.levelgen.structure.Structure; | ||
import net.minecraft.world.level.levelgen.structure.StructureCheck; | ||
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.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
@Mixin(StructureCheck.class) | ||
public class StructureCheckMixin implements IStructureCheck { | ||
@Shadow @Final private Registry<Structure> structureConfigs; | ||
|
||
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) | ||
* @reason Avoid running the canCreateStructure method (which can be expensive) if the structure placement already | ||
* forbids placing the structure in this chunk. | ||
*/ | ||
@ModifyExpressionValue(method = "checkStart", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/levelgen/structure/StructureCheck;tryLoadFromStorage(Lnet/minecraft/world/level/ChunkPos;Lnet/minecraft/world/level/levelgen/structure/Structure;ZJ)Lnet/minecraft/world/level/levelgen/structure/StructureCheckResult;")) | ||
private StructureCheckResult mfix$checkForValidPosition(StructureCheckResult storageResult, ChunkPos chunkPos, Structure structure, boolean skipKnownStructures) { | ||
if (storageResult != null) { | ||
return storageResult; | ||
} else if(mfix$structureState != null) { | ||
// Check if any of the placements allow for this structure to be in this chunk | ||
var structureHolder = this.structureConfigs.wrapAsHolder(structure); | ||
for (var placement : mfix$structureState.getPlacementsForStructure(structureHolder)) { | ||
if (placement.isStructureChunk(mfix$structureState, chunkPos.x, chunkPos.z)) { | ||
// Allowed - return null so regular check runs | ||
return null; | ||
} | ||
} | ||
// Not allowed - early exit by returning a non-null value | ||
return StructureCheckResult.START_NOT_PRESENT; | ||
} else { | ||
return null; | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
.../main/java/org/embeddedt/modernfix/common/mixin/perf/remove_spawn_chunks/EntityMixin.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,37 @@ | ||
package org.embeddedt.modernfix.common.mixin.perf.remove_spawn_chunks; | ||
|
||
import com.llamalad7.mixinextras.injector.ModifyExpressionValue; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.server.level.TicketType; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.level.ChunkPos; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
@Mixin(Entity.class) | ||
public class EntityMixin { | ||
/** | ||
* @author embeddedt | ||
* @reason If the spawn chunks are not loaded, end portals linking to the overworld will teleport entities into | ||
* the void at the spawn position, which is not ideal. To solve this, we create a PORTAL ticket if the expected | ||
* overworld chunk is missing. | ||
*/ | ||
@ModifyExpressionValue(method = "findDimensionEntryPoint", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;getSharedSpawnPos()Lnet/minecraft/core/BlockPos;"), require = 0) | ||
private BlockPos mfix$triggerChunkloadAtSpawnPos(BlockPos spawnPos, ServerLevel destination) { | ||
// Only apply this change if the overworld is the destination | ||
if (destination.dimension() == ServerLevel.OVERWORLD) { | ||
// No ticket is required if the chunk happens to already be loaded | ||
if(!destination.hasChunk(spawnPos.getX() >> 4, spawnPos.getZ() >> 4)) { | ||
// Create a portal ticket. While we could just load the chunk once, it would immediately unload on the | ||
// next tick, causing churn. The ticket will keep it loaded for a few seconds which should give high | ||
// performance for farms pumping things through portals frequently. | ||
BlockPos key = spawnPos.immutable(); | ||
destination.getChunkSource().addRegionTicket(TicketType.PORTAL, new ChunkPos(key), 3, key); | ||
// Wait for the chunk to be loaded, as adding the ticket is asynchronous | ||
destination.getChunk(key); | ||
} | ||
} | ||
return spawnPos; | ||
} | ||
} |
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
7 changes: 7 additions & 0 deletions
7
common/src/main/java/org/embeddedt/modernfix/duck/IStructureCheck.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,7 @@ | ||
package org.embeddedt.modernfix.duck; | ||
|
||
import net.minecraft.world.level.chunk.ChunkGeneratorStructureState; | ||
|
||
public interface IStructureCheck { | ||
void mfix$setStructureState(ChunkGeneratorStructureState state); | ||
} |
Oops, something went wrong.