From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Taiyou06 Date: Sun, 9 Mar 2025 00:36:26 +0100 Subject: [PATCH] Spawner Configurations diff --git a/net/minecraft/world/level/BaseSpawner.java b/net/minecraft/world/level/BaseSpawner.java index 9fa9d84033c28071120e8a1c796ace4f9a45d4c5..9914e347838f55b4658a0ab8998bc0eeade0f4f8 100644 --- a/net/minecraft/world/level/BaseSpawner.java +++ b/net/minecraft/world/level/BaseSpawner.java @@ -55,6 +55,12 @@ public abstract class BaseSpawner { public boolean isNearPlayer(Level level, BlockPos pos) { if (level.purpurConfig.spawnerDeactivateByRedstone && level.hasNeighborSignal(pos)) return false; // Purpur - Redstone deactivates spawners + // Leaf start - Spawner Configurations + // Skip player proximity check if disabled in config + if (org.dreeam.leaf.config.modules.gameplay.SpawnerSettings.enabled && !org.dreeam.leaf.config.modules.gameplay.SpawnerSettings.checkForNearbyPlayers) { + return true; // Always act as if players are nearby + } + // Leaf end - Spawner Configurations return level.hasNearbyAlivePlayerThatAffectsSpawningForSpawner(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, this.requiredPlayerRange); // Paper - Affects Spawning API // Leaf - Optimize nearby alive players for spawning } @@ -77,6 +83,20 @@ public abstract class BaseSpawner { } } + // Leaf start - Spawner Configurations + private int maxAllowedLight(EntityType entityType) { + if (entityType.getCategory().isFriendly()) { + return 15; // No light restriction for passive mobs + } else if (entityType == EntityType.SPIDER || entityType == EntityType.CAVE_SPIDER) { + return 7; // Spiders can spawn in light level 7 or lower + } else if (entityType == EntityType.ENDERMAN) { + return 7; // Endermen can spawn in light level 7 or lower + } + + return 0; // Complete darkness for other hostile mobs + } + // Leaf end - Spawner Configurations + public void serverTick(ServerLevel serverLevel, BlockPos pos) { if (spawnCount <= 0 || maxNearbyEntities <= 0) return; // Paper - Ignore impossible spawn tick // Paper start - Configurable mob spawner tick rate @@ -84,6 +104,15 @@ public abstract class BaseSpawner { tickDelay = serverLevel.paperConfig().tickRates.mobSpawner; if (tickDelay == -1) { return; } // If disabled // Paper end - Configurable mob spawner tick rate + + // Leaf start - Spawner Configurations + // Apply custom min/max spawn delays if enabled + if (org.dreeam.leaf.config.modules.gameplay.SpawnerSettings.enabled) { + this.minSpawnDelay = org.dreeam.leaf.config.modules.gameplay.SpawnerSettings.minSpawnDelay; + this.maxSpawnDelay = org.dreeam.leaf.config.modules.gameplay.SpawnerSettings.maxSpawnDelay; + } + // Leaf end - Spawner Configurations + if (this.isNearPlayer(serverLevel, pos)) { if (this.spawnDelay < -tickDelay) { // Paper - Configurable mob spawner tick rate this.delay(serverLevel, pos); @@ -112,18 +141,41 @@ public abstract class BaseSpawner { pos.getZ() + (random.nextDouble() - random.nextDouble()) * this.spawnRange + 0.5 ) ); - if (serverLevel.noCollision(optional.get().getSpawnAABB(vec3.x, vec3.y, vec3.z))) { + // Leaf start - Spawner Configurations + // Skip collision check if block checks are disabled + boolean skipBlockChecks = org.dreeam.leaf.config.modules.gameplay.SpawnerSettings.enabled && + !org.dreeam.leaf.config.modules.gameplay.SpawnerSettings.spawnerBlockChecks; + if (skipBlockChecks || serverLevel.noCollision(optional.get().getSpawnAABB(vec3.x, vec3.y, vec3.z))) { BlockPos blockPos = BlockPos.containing(vec3); + // Add light level check if enabled + if (org.dreeam.leaf.config.modules.gameplay.SpawnerSettings.enabled && + org.dreeam.leaf.config.modules.gameplay.SpawnerSettings.lightLevelCheck) { + int lightLevel = serverLevel.getMaxLocalRawBrightness(blockPos); + if (lightLevel > maxAllowedLight(optional.get())) { + continue; + } + } + + // Add water check if enabled + if (org.dreeam.leaf.config.modules.gameplay.SpawnerSettings.enabled && + org.dreeam.leaf.config.modules.gameplay.SpawnerSettings.waterPreventSpawnCheck && + serverLevel.getBlockState(blockPos).getFluidState().is(net.minecraft.tags.FluidTags.WATER)) { + continue; + } + + // Handle spawn rules checks + boolean skipSpawnRules = false; + // Leaf end - Spawner Configurations if (nextSpawnData.getCustomSpawnRules().isPresent()) { if (!optional.get().getCategory().isFriendly() && serverLevel.getDifficulty() == Difficulty.PEACEFUL) { continue; } SpawnData.CustomSpawnRules customSpawnRules = nextSpawnData.getCustomSpawnRules().get(); - if (!customSpawnRules.isValidPosition(blockPos, serverLevel)) { + if (!skipBlockChecks && !customSpawnRules.isValidPosition(blockPos, serverLevel)) { // Leaf - Spawner Configurations continue; } - } else if (!SpawnPlacements.checkSpawnRules(optional.get(), serverLevel, EntitySpawnReason.SPAWNER, blockPos, serverLevel.getRandom())) { + } else if (!skipBlockChecks && !SpawnPlacements.checkSpawnRules(optional.get(), serverLevel, EntitySpawnReason.SPAWNER, blockPos, serverLevel.getRandom())) { // Leaf - Spawner Configurations continue; } @@ -151,6 +203,7 @@ public abstract class BaseSpawner { return; } + if (!org.dreeam.leaf.config.modules.gameplay.SpawnerSettings.enabled || org.dreeam.leaf.config.modules.gameplay.SpawnerSettings.spawnerMaxNearbyCheck) { // Leaf - Spawner Configurations - Skip max nearby entity check if disabled int size = serverLevel.getEntities( EntityTypeTest.forExactClass(entity.getClass()), new AABB(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1, pos.getY() + 1, pos.getZ() + 1).inflate(this.spawnRange), @@ -161,12 +214,16 @@ public abstract class BaseSpawner { this.delay(serverLevel, pos); return; } + } // Leaf - Spawner Configurations entity.preserveMotion = true; // Paper - Fix Entity Teleportation and cancel velocity if teleported; preserve entity motion from tag entity.snapTo(entity.getX(), entity.getY(), entity.getZ(), random.nextFloat() * 360.0F, 0.0F); if (entity instanceof Mob mob) { - if (nextSpawnData.getCustomSpawnRules().isEmpty() && !mob.checkSpawnRules(serverLevel, EntitySpawnReason.SPAWNER) - || !mob.checkSpawnObstruction(serverLevel)) { + // Leaf start - Spawner Configurations + // Skip spawn rule and obstruction checks if block checks are disabled + if (!skipBlockChecks && (nextSpawnData.getCustomSpawnRules().isEmpty() && !mob.checkSpawnRules(serverLevel, EntitySpawnReason.SPAWNER) + || !mob.checkSpawnObstruction(serverLevel))) { + // Leaf end - Spawner Configurations continue; } @@ -231,10 +288,16 @@ public abstract class BaseSpawner { tag.read("SpawnData", SpawnData.CODEC).ifPresent(spawnData -> this.setNextSpawnData(level, pos, spawnData)); this.spawnPotentials = tag.read("SpawnPotentials", SpawnData.LIST_CODEC) .orElseGet(() -> WeightedList.of(this.nextSpawnData != null ? this.nextSpawnData : new SpawnData())); + // Leaf start - Spawner Configurations + if (org.dreeam.leaf.config.modules.gameplay.SpawnerSettings.enabled) { + this.minSpawnDelay = org.dreeam.leaf.config.modules.gameplay.SpawnerSettings.minSpawnDelay; + this.maxSpawnDelay = org.dreeam.leaf.config.modules.gameplay.SpawnerSettings.maxSpawnDelay; + } else { // Paper start - use int if set this.minSpawnDelay = tag.getIntOr("Paper.MinSpawnDelay", tag.getIntOr("MinSpawnDelay", 200)); this.maxSpawnDelay = tag.getIntOr("Paper.MaxSpawnDelay", tag.getIntOr("MaxSpawnDelay", 800)); // Paper end - use int if set + } // Leaf end - Spawner Configurations this.spawnCount = tag.getIntOr("SpawnCount", 4); this.maxNearbyEntities = tag.getIntOr("MaxNearbyEntities", 6); this.requiredPlayerRange = tag.getIntOr("RequiredPlayerRange", 16);