From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: jmp Date: Thu, 20 Aug 2020 11:20:12 -0700 Subject: [PATCH] PaperPR Add Wandering Trader spawn rate config Adds config options for modifying the spawn rates of Wandering Traders. These values are all easy to understand and configure after a quick read of this page on the Minecraft wiki: https://minecraft.gamepedia.com/Wandering_Trader#Spawning Usages of the vanilla WanderingTraderSpawnDelay and WanderingTraderSpawnChance values in IWorldServerData are removed as they were only used in certain places, with hardcoded values used in other places. diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java index b0fcf76047..3bc0731243 100644 --- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java +++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java @@ -670,4 +670,17 @@ public class PaperWorldConfig { log("Using vanilla redstone algorithm."); } } + + public int villagerTraderSpawnMinuteTicks = 1200; + public int villagerTraderSpawnDayTicks = 24000; + public int villagerTraderSpawnChanceFailureIncrement = 25; + public int villagerTraderSpawnChanceMin = 25; + public int villagerTraderSpawnChanceMax = 75; + private void villagerTraderSettings() { + villagerTraderSpawnMinuteTicks = getInt("wandering-trader.spawn-minute-length", villagerTraderSpawnMinuteTicks); + villagerTraderSpawnDayTicks = getInt("wandering-trader.spawn-day-length", villagerTraderSpawnDayTicks); + villagerTraderSpawnChanceFailureIncrement = getInt("wandering-trader.spawn-chance-failure-increment", villagerTraderSpawnChanceFailureIncrement); + villagerTraderSpawnChanceMin = getInt("wandering-trader.spawn-chance-min", villagerTraderSpawnChanceMin); + villagerTraderSpawnChanceMax = getInt("wandering-trader.spawn-chance-max", villagerTraderSpawnChanceMax); + } } diff --git a/src/main/java/net/minecraft/server/MobSpawnerTrader.java b/src/main/java/net/minecraft/server/MobSpawnerTrader.java index f88c7b5480..e47315cd47 100644 --- a/src/main/java/net/minecraft/server/MobSpawnerTrader.java +++ b/src/main/java/net/minecraft/server/MobSpawnerTrader.java @@ -9,49 +9,58 @@ public class MobSpawnerTrader implements MobSpawner { private final Random a = new Random(); private final IWorldDataServer b; - private int c; - private int d; - private int e; + private int c; public final int getMinuteTimer() { return this.c; } public final void setMinuteTimer(int x) { this.c = x; } // Paper - OBFHELPER + private int d; public final int getDayTimer() { return this.d; } public final void setDayTimer(int x) { this.d = x; } // Paper - OBFHELPER + private int e; public final int getSpawnChance() { return this.e; } public final void setSpawnChance(int x) { this.e = x; } // Paper - OBFHELPER public MobSpawnerTrader(IWorldDataServer iworlddataserver) { this.b = iworlddataserver; - this.c = 1200; - this.d = iworlddataserver.v(); - this.e = iworlddataserver.w(); - if (this.d == 0 && this.e == 0) { - this.d = 24000; - iworlddataserver.g(this.d); - this.e = 25; - iworlddataserver.h(this.e); - } - + // Paper start + this.setMinuteTimer(Integer.MIN_VALUE); + //this.d = iworlddataserver.v(); // Paper - This value is read from the world file only for the first spawn, after which vanilla uses a hardcoded value + //this.e = iworlddataserver.w(); // Paper - This value is read from the world file only for the first spawn, after which vanilla uses a hardcoded value + //if (this.d == 0 && this.e == 0) { + // this.d = 24000; + // iworlddataserver.g(this.d); + // this.e = 25; + // iworlddataserver.h(this.e); + //} + // Paper end } @Override public int a(WorldServer worldserver, boolean flag, boolean flag1) { + // Paper start + if (this.getMinuteTimer() == Integer.MIN_VALUE) { + this.setMinuteTimer(worldserver.paperConfig.villagerTraderSpawnMinuteTicks); + this.setDayTimer(worldserver.paperConfig.villagerTraderSpawnDayTicks); + this.setSpawnChance(worldserver.paperConfig.villagerTraderSpawnChanceMin); + } if (!worldserver.getGameRules().getBoolean(GameRules.DO_TRADER_SPAWNING)) { return 0; - } else if (--this.c > 0) { + } else if (this.getMinuteTimer() - 1 > 0) { + this.setMinuteTimer(this.getMinuteTimer() - 1); return 0; } else { - this.c = 1200; - this.d -= 1200; - this.b.g(this.d); - if (this.d > 0) { + this.setMinuteTimer(worldserver.paperConfig.villagerTraderSpawnMinuteTicks); + this.setDayTimer(getDayTimer() - worldserver.paperConfig.villagerTraderSpawnMinuteTicks); + //this.b.g(this.d); // Paper - We don't need to save this value to disk if it gets set back to a hardcoded value anyways + if (this.getDayTimer() > 0) { return 0; } else { - this.d = 24000; + this.setDayTimer(worldserver.paperConfig.villagerTraderSpawnDayTicks); if (!worldserver.getGameRules().getBoolean(GameRules.DO_MOB_SPAWNING)) { return 0; } else { - int i = this.e; + int i = this.getSpawnChance(); - this.e = MathHelper.clamp(this.e + 25, 25, 75); - this.b.h(this.e); + this.setSpawnChance(MathHelper.clamp(i + worldserver.paperConfig.villagerTraderSpawnChanceFailureIncrement, worldserver.paperConfig.villagerTraderSpawnChanceMin, worldserver.paperConfig.villagerTraderSpawnChanceMax)); + //this.b.h(this.e); // Paper - We don't need to save this value to disk if it gets set back to a hardcoded value anyways if (this.a.nextInt(100) > i) { return 0; } else if (this.a(worldserver)) { - this.e = 25; + this.setSpawnChance(worldserver.paperConfig.villagerTraderSpawnChanceMin); + // Paper end return 1; } else { return 0;