2024-12-11 22:26:55 +01:00
|
|
|
--- a/net/minecraft/world/level/BaseSpawner.java
|
|
|
|
+++ b/net/minecraft/world/level/BaseSpawner.java
|
2016-03-02 22:03:53 +01:00
|
|
|
@@ -49,15 +49,17 @@
|
|
|
|
public int maxNearbyEntities = 6;
|
|
|
|
public int requiredPlayerRange = 16;
|
|
|
|
public int spawnRange = 4;
|
|
|
|
+ private int tickDelay = 0; // Paper - Configurable mob spawner tick rate
|
|
|
|
|
|
|
|
public BaseSpawner() {}
|
2024-12-11 22:26:55 +01:00
|
|
|
|
|
|
|
public void setEntityId(EntityType<?> type, @Nullable Level world, RandomSource random, BlockPos pos) {
|
|
|
|
this.getOrCreateNextSpawnData(world, random, pos).getEntityToSpawn().putString("id", BuiltInRegistries.ENTITY_TYPE.getKey(type).toString());
|
|
|
|
+ this.spawnPotentials = SimpleWeightedRandomList.empty(); // CraftBukkit - SPIGOT-3496, MC-92282
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isNearPlayer(Level world, BlockPos pos) {
|
2016-03-01 21:47:52 +01:00
|
|
|
- return world.hasNearbyAlivePlayer((double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, (double) this.requiredPlayerRange);
|
|
|
|
+ return world.hasNearbyAlivePlayerThatAffectsSpawning((double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, (double) this.requiredPlayerRange); // Paper - Affects Spawning API
|
|
|
|
}
|
|
|
|
|
|
|
|
public void clientTick(Level world, BlockPos pos) {
|
2016-03-02 22:03:53 +01:00
|
|
|
@@ -82,13 +84,18 @@
|
|
|
|
}
|
|
|
|
|
|
|
|
public void serverTick(ServerLevel world, BlockPos pos) {
|
|
|
|
+ // Paper start - Configurable mob spawner tick rate
|
|
|
|
+ if (spawnDelay > 0 && --tickDelay > 0) return;
|
|
|
|
+ tickDelay = world.paperConfig().tickRates.mobSpawner;
|
|
|
|
+ if (tickDelay == -1) { return; } // If disabled
|
|
|
|
+ // Paper end - Configurable mob spawner tick rate
|
|
|
|
if (this.isNearPlayer(world, pos)) {
|
|
|
|
- if (this.spawnDelay == -1) {
|
|
|
|
+ if (this.spawnDelay < -tickDelay) { // Paper - Configurable mob spawner tick rate
|
|
|
|
this.delay(world, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.spawnDelay > 0) {
|
|
|
|
- --this.spawnDelay;
|
|
|
|
+ this.spawnDelay -= tickDelay; // Paper - Configurable mob spawner tick rate
|
|
|
|
} else {
|
|
|
|
boolean flag = false;
|
|
|
|
RandomSource randomsource = world.getRandom();
|
2018-01-14 23:01:31 +01:00
|
|
|
@@ -123,8 +130,22 @@
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else if (!SpawnPlacements.checkSpawnRules((EntityType) optional.get(), world, EntitySpawnReason.SPAWNER, blockposition1, world.getRandom())) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ // Paper start - PreCreatureSpawnEvent
|
|
|
|
+ com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent event = new com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent(
|
|
|
|
+ io.papermc.paper.util.MCUtil.toLocation(world, d0, d1, d2),
|
|
|
|
+ org.bukkit.craftbukkit.entity.CraftEntityType.minecraftToBukkit(optional.get()),
|
|
|
|
+ org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER
|
|
|
|
+ );
|
|
|
|
+ if (!event.callEvent()) {
|
|
|
|
+ flag = true;
|
|
|
|
+ if (event.shouldAbortSpawn()) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
+ // Paper end - PreCreatureSpawnEvent
|
|
|
|
|
|
|
|
Entity entity = EntityType.loadEntityRecursive(nbttagcompound, world, EntitySpawnReason.SPAWNER, (entity1) -> {
|
|
|
|
entity1.moveTo(d0, d1, d2, entity1.getYRot(), entity1.getXRot());
|
|
|
|
@@ -157,13 +178,26 @@
|
2024-12-11 22:26:55 +01:00
|
|
|
((Mob) entity).finalizeSpawn(world, world.getCurrentDifficultyAt(entity.blockPosition()), EntitySpawnReason.SPAWNER, (SpawnGroupData) null);
|
|
|
|
}
|
|
|
|
|
|
|
|
- Optional optional1 = mobspawnerdata.getEquipment();
|
|
|
|
+ Optional<net.minecraft.world.entity.EquipmentTable> optional1 = mobspawnerdata.getEquipment(); // CraftBukkit - decompile error
|
|
|
|
|
|
|
|
Objects.requireNonNull(entityinsentient);
|
|
|
|
optional1.ifPresent(entityinsentient::equip);
|
2014-02-02 17:55:46 +01:00
|
|
|
+ // Spigot Start
|
|
|
|
+ if ( entityinsentient.level().spigotConfig.nerfSpawnerMobs )
|
|
|
|
+ {
|
|
|
|
+ entityinsentient.aware = false;
|
|
|
|
+ }
|
|
|
|
+ // Spigot End
|
2024-12-11 22:26:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- if (!world.tryAddFreshEntityWithPassengers(entity)) {
|
2017-06-19 01:17:05 +02:00
|
|
|
+ entity.spawnedViaMobSpawner = true; // Paper
|
2017-07-31 08:45:19 +02:00
|
|
|
+ flag = true; // Paper
|
2024-12-11 22:26:55 +01:00
|
|
|
+ // CraftBukkit start
|
|
|
|
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callSpawnerSpawnEvent(entity, pos).isCancelled()) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ if (!world.tryAddFreshEntityWithPassengers(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER)) {
|
|
|
|
+ // CraftBukkit end
|
|
|
|
this.delay(world, pos);
|
|
|
|
return;
|
|
|
|
}
|
2018-01-14 23:01:31 +01:00
|
|
|
@@ -174,7 +208,7 @@
|
2017-07-31 08:45:19 +02:00
|
|
|
((Mob) entity).spawnAnim();
|
|
|
|
}
|
|
|
|
|
|
|
|
- flag = true;
|
|
|
|
+ //flag = true; // Paper - moved up above cancellable event
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|