From 6f9c0bf3cb456ab08a6aba477175f89cd7f4cfc5 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Wed, 24 Jan 2018 17:18:25 +1100 Subject: [PATCH] Expand CreatureSpawner API By: Senmori --- .../nms-patches/MobSpawnerAbstract.patch | 20 ++++++ .../block/CraftCreatureSpawner.java | 64 +++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/paper-server/nms-patches/MobSpawnerAbstract.patch b/paper-server/nms-patches/MobSpawnerAbstract.patch index 0d3b89df11..9f63bb2a99 100644 --- a/paper-server/nms-patches/MobSpawnerAbstract.patch +++ b/paper-server/nms-patches/MobSpawnerAbstract.patch @@ -1,5 +1,25 @@ --- a/net/minecraft/server/MobSpawnerAbstract.java +++ b/net/minecraft/server/MobSpawnerAbstract.java +@@ -12,13 +12,13 @@ + private MobSpawnerData spawnData = new MobSpawnerData(); + private double d; + private double e; +- private int minSpawnDelay = 200; +- private int maxSpawnDelay = 800; +- private int spawnCount = 4; ++ public int minSpawnDelay = 200; // CraftBukkit private -> public ++ public int maxSpawnDelay = 800; // CraftBukkit private -> public ++ public int spawnCount = 4; // CraftBukkit private -> public + private Entity i; +- private int maxNearbyEntities = 6; +- private int requiredPlayerRange = 16; +- private int spawnRange = 4; ++ public int maxNearbyEntities = 6; // CraftBukkit private -> public ++ public int requiredPlayerRange = 16; // CraftBukkit private -> public ++ public int spawnRange = 4; // CraftBukkit private -> public + + public MobSpawnerAbstract() {} + @@ -32,6 +32,7 @@ public void setMobName(@Nullable MinecraftKey minecraftkey) { if (minecraftkey != null) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java index 67f4c73036..2ec7084346 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java @@ -1,5 +1,6 @@ package org.bukkit.craftbukkit.block; +import com.google.common.base.Preconditions; import net.minecraft.server.MinecraftKey; import net.minecraft.server.TileEntityMobSpawner; import org.bukkit.Material; @@ -57,4 +58,67 @@ public class CraftCreatureSpawner extends CraftBlockEntityState 0, "Maximum Spawn Delay must be greater than 0."); + Preconditions.checkArgument(spawnDelay >= getMinSpawnDelay(), "Maximum Spawn Delay must be greater than or equal to Minimum Spawn Delay"); + this.getSnapshot().getSpawner().maxSpawnDelay = spawnDelay; + } + + @Override + public int getMaxNearbyEntities() { + return this.getSnapshot().getSpawner().maxNearbyEntities; + } + + @Override + public void setMaxNearbyEntities(int maxNearbyEntities) { + this.getSnapshot().getSpawner().maxNearbyEntities = maxNearbyEntities; + } + + @Override + public int getSpawnCount() { + return this.getSnapshot().getSpawner().spawnCount; + } + + @Override + public void setSpawnCount(int count) { + this.getSnapshot().getSpawner().spawnCount = count; + } + + @Override + public int getRequiredPlayerRange() { + return this.getSnapshot().getSpawner().requiredPlayerRange; + } + + @Override + public void setRequiredPlayerRange(int requiredPlayerRange) { + this.getSnapshot().getSpawner().requiredPlayerRange = requiredPlayerRange; + } + + @Override + public int getSpawnRange() { + return this.getSnapshot().getSpawner().spawnRange; + } + + @Override + public void setSpawnRange(int spawnRange) { + this.getSnapshot().getSpawner().spawnRange = spawnRange; + } }