mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 08:27:43 +01:00
Allow toggling special MobSpawners per world
In vanilla, these are all hardcoded on for world type 0 (overworld) and hardcoded off for every other world type. Default config behaviour matches this.
This commit is contained in:
@@ -1,5 +1,31 @@
|
||||
--- a/net/minecraft/server/level/ServerLevel.java
|
||||
+++ b/net/minecraft/server/level/ServerLevel.java
|
||||
@@ -595,7 +_,24 @@
|
||||
// CraftBukkit end
|
||||
this.tickTime = tickTime;
|
||||
this.server = server;
|
||||
- this.customSpawners = customSpawners;
|
||||
+ // Purpur start - Allow toggling special MobSpawners per world
|
||||
+ this.customSpawners = Lists.newArrayList();
|
||||
+ if (purpurConfig.phantomSpawning) {
|
||||
+ customSpawners.add(new net.minecraft.world.level.levelgen.PhantomSpawner());
|
||||
+ }
|
||||
+ if (purpurConfig.patrolSpawning) {
|
||||
+ customSpawners.add(new net.minecraft.world.level.levelgen.PatrolSpawner());
|
||||
+ }
|
||||
+ if (purpurConfig.catSpawning) {
|
||||
+ customSpawners.add(new net.minecraft.world.entity.npc.CatSpawner());
|
||||
+ }
|
||||
+ if (purpurConfig.villageSiegeSpawning) {
|
||||
+ customSpawners.add(new net.minecraft.world.entity.ai.village.VillageSiege());
|
||||
+ }
|
||||
+ if (purpurConfig.villagerTraderSpawning) {
|
||||
+ customSpawners.add(new net.minecraft.world.entity.npc.WanderingTraderSpawner(serverLevelData));
|
||||
+ }
|
||||
+ // Purpur end - Allow toggling special MobSpawners per world
|
||||
this.serverLevelData = serverLevelData;
|
||||
ChunkGenerator chunkGenerator = levelStem.generator();
|
||||
// CraftBukkit start
|
||||
@@ -934,9 +_,18 @@
|
||||
&& this.random.nextDouble() < currentDifficultyAt.getEffectiveDifficulty() * this.paperConfig().entities.spawning.skeletonHorseThunderSpawnChance.or(0.01) // Paper - Configurable spawn chances for skeleton horses
|
||||
&& !this.getBlockState(blockPos.below()).is(Blocks.LIGHTNING_ROD);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
- if (this.tickCount % 20 == 0) {
|
||||
- this.heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.REGEN); // CraftBukkit
|
||||
+ // Purpur start - Customizable wither health and healing
|
||||
+ // Purpur start - Customizable wither health and healing - customizable heal rate and amount
|
||||
+ if (this.tickCount % level().purpurConfig.witherHealthRegenDelay == 0) {
|
||||
+ this.heal(level().purpurConfig.witherHealthRegenAmount, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.REGEN); // CraftBukkit
|
||||
+ // Purpur end - Customizable wither health and healing
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
--- a/net/minecraft/world/entity/npc/WanderingTraderSpawner.java
|
||||
+++ b/net/minecraft/world/entity/npc/WanderingTraderSpawner.java
|
||||
@@ -147,7 +_,17 @@
|
||||
int i1 = pos.getX() + this.random.nextInt(maxDistance * 2) - maxDistance;
|
||||
int i2 = pos.getZ() + this.random.nextInt(maxDistance * 2) - maxDistance;
|
||||
int height = level.getHeight(Heightmap.Types.WORLD_SURFACE, i1, i2);
|
||||
- BlockPos blockPos1 = new BlockPos(i1, height, i2);
|
||||
+ // Purpur start - Allow toggling special MobSpawners per world - allow traders to spawn below nether roof
|
||||
+ BlockPos.MutableBlockPos blockPos1 = new BlockPos.MutableBlockPos(i1, height, i2);
|
||||
+ if (level.dimensionType().hasCeiling()) {
|
||||
+ do {
|
||||
+ blockPos1.relative(net.minecraft.core.Direction.DOWN);
|
||||
+ } while (!level.getBlockState(blockPos1).isAir());
|
||||
+ do {
|
||||
+ blockPos1.relative(net.minecraft.core.Direction.DOWN);
|
||||
+ } while (level.getBlockState(blockPos1).isAir() && blockPos1.getY() > 0);
|
||||
+ }
|
||||
+ // Purpur end - Allow toggling special MobSpawners per world
|
||||
if (placementType.isSpawnPositionOk(level, blockPos1, EntityType.WANDERING_TRADER)) {
|
||||
blockPos = blockPos1;
|
||||
break;
|
||||
@@ -2,6 +2,7 @@ package org.purpurmc.purpur;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.logging.Level;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
@@ -11,6 +12,7 @@ import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import org.apache.commons.lang.BooleanUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@@ -59,6 +61,12 @@ public class PurpurWorldConfig {
|
||||
return PurpurConfig.config.getBoolean("world-settings." + worldName + "." + path, PurpurConfig.config.getBoolean("world-settings.default." + path));
|
||||
}
|
||||
|
||||
private boolean getBoolean(String path, Predicate<Boolean> predicate) {
|
||||
String val = getString(path, "default").toLowerCase();
|
||||
Boolean bool = BooleanUtils.toBooleanObject(val, "true", "false", "default");
|
||||
return predicate.test(bool);
|
||||
}
|
||||
|
||||
private double getDouble(String path, double def) {
|
||||
PurpurConfig.config.addDefault("world-settings.default." + path, def);
|
||||
return PurpurConfig.config.getDouble("world-settings." + worldName + "." + path, PurpurConfig.config.getDouble("world-settings.default." + path));
|
||||
@@ -221,6 +229,21 @@ public class PurpurWorldConfig {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean catSpawning;
|
||||
public boolean patrolSpawning;
|
||||
public boolean phantomSpawning;
|
||||
public boolean villagerTraderSpawning;
|
||||
public boolean villageSiegeSpawning;
|
||||
private void mobSpawnerSettings() {
|
||||
// values of "default" or null will default to true only if the world environment is normal (aka overworld)
|
||||
Predicate<Boolean> predicate = (bool) -> (bool != null && bool) || (bool == null && environment == World.Environment.NORMAL);
|
||||
catSpawning = getBoolean("gameplay-mechanics.mob-spawning.village-cats", predicate);
|
||||
patrolSpawning = getBoolean("gameplay-mechanics.mob-spawning.raid-patrols", predicate);
|
||||
phantomSpawning = getBoolean("gameplay-mechanics.mob-spawning.phantoms", predicate);
|
||||
villagerTraderSpawning = getBoolean("gameplay-mechanics.mob-spawning.wandering-traders", predicate);
|
||||
villageSiegeSpawning = getBoolean("gameplay-mechanics.mob-spawning.village-sieges", predicate);
|
||||
}
|
||||
|
||||
public boolean idleTimeoutKick = true;
|
||||
public boolean idleTimeoutTickNearbyEntities = true;
|
||||
public boolean idleTimeoutCountAsSleeping = false;
|
||||
|
||||
Reference in New Issue
Block a user