This commit is contained in:
Brianna O'Keefe 2018-11-29 20:30:03 -05:00
parent da3b435ddf
commit 62a78b3330
2 changed files with 6 additions and 3 deletions

View File

@ -32,7 +32,7 @@ public class SpawnerStack {
this.amount = amount;
CreatureSpawner creatureSpawner = (CreatureSpawner)location.getBlock().getState();
Reflection.setRange(creatureSpawner, 4 * amount);
Reflection.setRange(creatureSpawner, 4 * amount, amount > 6 ? amount + 3 : 6);
creatureSpawner.update();
}

View File

@ -9,9 +9,9 @@ import java.lang.reflect.Method;
public class Reflection {
private static Class<?> clazzCraftCreatureSpawner, clazzTileEntityMobSpawner = null;
private static Method methodGetTileEntity, methodGetSpawner;
private static Field fieldSpawnRange;
private static Field fieldSpawnRange, fieldMaxNearbyEntities;
public static CreatureSpawner setRange(CreatureSpawner creatureSpawner, int amount) {
public static CreatureSpawner setRange(CreatureSpawner creatureSpawner, int amount, int max) {
try {
if (clazzCraftCreatureSpawner == null) {
String ver = Bukkit.getServer().getClass().getPackage().getName().substring(23);
@ -22,12 +22,15 @@ public class Reflection {
methodGetSpawner = clazzTileEntityMobSpawner.getDeclaredMethod("getSpawner");
fieldSpawnRange = clazzMobSpawnerAbstract.getDeclaredField("spawnRange");
fieldSpawnRange.setAccessible(true);
fieldMaxNearbyEntities = clazzMobSpawnerAbstract.getDeclaredField("maxNearbyEntities");
fieldSpawnRange.setAccessible(true);
}
Object objCraftCreatureSpawner = clazzCraftCreatureSpawner.cast(creatureSpawner);
Object objTileEntityMobSpawner = clazzTileEntityMobSpawner.cast(methodGetTileEntity.invoke(objCraftCreatureSpawner));
Object objMobSpawnerAbstract = methodGetSpawner.invoke(objTileEntityMobSpawner);
fieldSpawnRange.set(objMobSpawnerAbstract, amount);
fieldMaxNearbyEntities.set(objMobSpawnerAbstract, max);
} catch (ReflectiveOperationException e) {
e.printStackTrace();