9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2025-12-19 14:59:32 +00:00
Files
LeavesMC/patches/server/0062-Spawn-ignore-lc.patch
2024-08-14 17:07:19 +08:00

48 lines
2.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <58360096+s-yh-china@users.noreply.github.com>
Date: Thu, 29 Jun 2023 22:40:24 +0800
Subject: [PATCH] Spawn ignore lc
diff --git a/src/main/java/net/minecraft/world/level/NaturalSpawner.java b/src/main/java/net/minecraft/world/level/NaturalSpawner.java
index c5b26fdb173a59280e790a5d5a687e0c0114bb74..7cb97b7623b603aa5469c92f5a6816673c994540 100644
--- a/src/main/java/net/minecraft/world/level/NaturalSpawner.java
+++ b/src/main/java/net/minecraft/world/level/NaturalSpawner.java
@@ -199,6 +199,19 @@ public final class NaturalSpawner {
}
public static int spawnCategoryForChunk(MobCategory group, ServerLevel world, LevelChunk chunk, NaturalSpawner.SpawnPredicate checker, NaturalSpawner.AfterSpawnCallback runner, int maxSpawns, Consumer<Entity> trackEntity) {
// Paper end - Optional per player mob spawns
+ // Leaves start - ignore lc
+ if (org.leavesmc.leaves.LeavesConfig.ignoreLC) {
+ int spawnN = 0;
+ for (int i = chunk.getMinBuildHeight(); i < chunk.getMaxBuildHeight(); i += 16) {
+ net.minecraft.world.level.chunk.LevelChunkSection section = chunk.getSections()[chunk.getSectionIndex(i)];
+ if (section != null && !section.hasOnlyAir()) {
+ BlockPos pos = getRandomPosInChunk(world, chunk).offset(0, i, 0);
+ spawnN += spawnCategoryForPosition(group, world, chunk, pos, checker, runner, maxSpawns, trackEntity);
+ }
+ }
+ return spawnN;
+ }
+ // Leaves stop - ignore lc
BlockPos blockposition = NaturalSpawner.getRandomPosWithin(world, chunk);
if (blockposition.getY() >= world.getMinBuildHeight() + 1) {
@@ -207,6 +220,16 @@ public final class NaturalSpawner {
return 0; // Paper - Optional per player mob spawns
}
+ // Leaves start - ignore lc
+ private static BlockPos getRandomPosInChunk(Level world, LevelChunk chunk) {
+ ChunkPos chunkPos = chunk.getPos();
+ int x = chunkPos.getMinBlockX() + world.random.nextInt(16);
+ int z = chunkPos.getMinBlockZ() + world.random.nextInt(16);
+ int y = world.random.nextInt(16) + 1;
+ return new BlockPos(x, y, z);
+ }
+ // Leaves stop - ignore lc
+
@VisibleForDebug
public static void spawnCategoryForPosition(MobCategory group, ServerLevel world, BlockPos pos) {
NaturalSpawner.spawnCategoryForPosition(group, world, world.getChunk(pos), pos, (entitytypes, blockposition1, ichunkaccess) -> {