-
Notifications
You must be signed in to change notification settings - Fork 290
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
1 parent
df1dcb6
commit 7687628
Showing
6 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
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
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
77 changes: 77 additions & 0 deletions
77
src/main/java/org/violetmoon/quark/mixin/mixins/ChunkGeneratorMixin.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,77 @@ | ||
package org.violetmoon.quark.mixin.mixins; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import com.llamalad7.mixinextras.sugar.Local; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Holder; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.util.RandomSource; | ||
import net.minecraft.world.level.chunk.ProtoChunk; | ||
import net.minecraft.world.level.levelgen.structure.Structure; | ||
import net.minecraft.world.level.levelgen.structure.pools.EmptyPoolElement; | ||
import net.minecraft.world.level.levelgen.structure.pools.JigsawPlacement; | ||
import net.minecraft.world.level.levelgen.structure.pools.StructurePoolElement; | ||
import net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.violetmoon.quark.content.experimental.module.GameNerfsModule; | ||
import org.violetmoon.quark.mixin.mixins.accessor.AccessorChunkAccess; | ||
import org.violetmoon.quark.mixin.mixins.accessor.AccessorSinglePoolElement; | ||
|
||
import java.util.Optional; | ||
|
||
@Mixin(JigsawPlacement.class) | ||
public class ChunkGeneratorMixin { | ||
|
||
@WrapOperation(method = "addPieces(Lnet/minecraft/world/level/levelgen/structure/Structure$GenerationContext;Lnet/minecraft/core/Holder;Ljava/util/Optional;ILnet/minecraft/core/BlockPos;ZLjava/util/Optional;I)Ljava/util/Optional;", | ||
at = @At(value = "INVOKE", | ||
target = "Lnet/minecraft/world/level/levelgen/structure/pools/StructureTemplatePool;getRandomTemplate(Lnet/minecraft/util/RandomSource;)Lnet/minecraft/world/level/levelgen/structure/pools/StructurePoolElement;")) | ||
private static StructurePoolElement quark$reduceVillagesFrequency( | ||
StructureTemplatePool instance, RandomSource pRandom, Operation<StructurePoolElement> operation, | ||
@Local(argsOnly = true) Holder<StructureTemplatePool> structure, @Local(ordinal = 0, argsOnly = true) Optional<ResourceLocation> startPool, @Local(argsOnly = true) BlockPos pos, @Local(argsOnly = true) Structure.GenerationContext context) { | ||
var original = operation.call(instance, pRandom); | ||
if (GameNerfsModule.villageSpawnNerf) { | ||
Optional<String> left = quark$getPoolId(original); | ||
if (left.isPresent()) { | ||
String id = left.get(); | ||
if (id.contains("village") && id.contains("town_centers")) { | ||
if (context.heightAccessor() instanceof ProtoChunk pc && | ||
((AccessorChunkAccess) pc).getLevelHeightAccessor() instanceof ServerLevel sl) { | ||
BlockPos spawn = sl.getSharedSpawnPos(); | ||
double spawnDistanceSq = spawn.distSqr(pos); | ||
RandomSource r = RandomSource.create(pos.asLong()); | ||
float maxDist = GameNerfsModule.villageSpawnNerfDistance; | ||
double probability = 1 - (spawnDistanceSq / (maxDist * maxDist)); | ||
if (r.nextDouble() < probability) { | ||
int tries = 0; | ||
while (!id.contains("zombie")) { | ||
if (tries++ > 4) { | ||
return EmptyPoolElement.INSTANCE; | ||
} | ||
original = operation.call(instance, pRandom); | ||
Optional<String> s = quark$getPoolId(original); | ||
if (s.isPresent()) { | ||
id = s.get(); | ||
} | ||
tries++; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return original; | ||
} | ||
|
||
@Unique | ||
private static Optional<String> quark$getPoolId(StructurePoolElement le) { | ||
if (le instanceof AccessorSinglePoolElement se) { | ||
Optional<ResourceLocation> left = se.getTemplate().left(); | ||
return left.map(ResourceLocation::getPath); | ||
} | ||
return Optional.empty(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/org/violetmoon/quark/mixin/mixins/accessor/AccessorChunkAccess.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,18 @@ | ||
package org.violetmoon.quark.mixin.mixins.accessor; | ||
|
||
import com.mojang.datafixers.util.Either; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.level.LevelHeightAccessor; | ||
import net.minecraft.world.level.chunk.ChunkAccess; | ||
import net.minecraft.world.level.levelgen.structure.pools.SinglePoolElement; | ||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
@Mixin(ChunkAccess.class) | ||
public interface AccessorChunkAccess { | ||
|
||
@Accessor("levelHeightAccessor") | ||
LevelHeightAccessor getLevelHeightAccessor(); | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/org/violetmoon/quark/mixin/mixins/accessor/AccessorSinglePoolElement.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,17 @@ | ||
package org.violetmoon.quark.mixin.mixins.accessor; | ||
|
||
import com.mojang.datafixers.util.Either; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.level.levelgen.structure.pools.SinglePoolElement; | ||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; | ||
import org.checkerframework.checker.units.qual.A; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
@Mixin(SinglePoolElement.class) | ||
public interface AccessorSinglePoolElement { | ||
|
||
@Accessor("template") | ||
Either<ResourceLocation, StructureTemplate> getTemplate(); | ||
|
||
} |
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