mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 11:59:25 +00:00
Fix Mob Spawner logic with CustomSpawnRules. Closes #8398
This commit is contained in:
1 parent
bc24487d0e
commit
a9237cff75
3 files changed
+20
-6
No files matched your search
@@ -1,16 +1,18 @@
|
||||
--- a/net/minecraft/world/level/BaseSpawner.java
|
||||
+++ b/net/minecraft/world/level/BaseSpawner.java
|
||||
@@ -125,11 +_,12 @@
|
||||
@@ -125,11 +_,15 @@
|
||||
entity.m_7678_(entity.m_20185_(), entity.m_20186_(), entity.m_20189_(), p_151312_.f_46441_.nextFloat() * 360.0F, 0.0F);
|
||||
if (entity instanceof Mob) {
|
||||
Mob mob = (Mob)entity;
|
||||
- if (this.f_45444_.m_186574_().isEmpty() && !mob.m_5545_(p_151312_, MobSpawnType.SPAWNER) || !mob.m_6914_(p_151312_)) {
|
||||
+ if (!net.minecraftforge.event.ForgeEventFactory.canEntitySpawnSpawner(mob, p_151312_, (float)entity.m_20185_(), (float)entity.m_20186_(), (float)entity.m_20189_(), this)) {
|
||||
+ net.minecraftforge.eventbus.api.Event.Result res = net.minecraftforge.event.ForgeEventFactory.canEntitySpawn(mob, p_151312_, (float)entity.m_20185_(), (float)entity.m_20186_(), (float)entity.m_20189_(), this, MobSpawnType.SPAWNER);
|
||||
+ if (res == net.minecraftforge.eventbus.api.Event.Result.DENY) continue;
|
||||
+ if (res == net.minecraftforge.eventbus.api.Event.Result.DEFAULT)
|
||||
if (this.f_45444_.m_186574_().isEmpty() && !mob.m_5545_(p_151312_, MobSpawnType.SPAWNER) || !mob.m_6914_(p_151312_)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (this.f_45444_.m_186567_().m_128440_() == 1 && this.f_45444_.m_186567_().m_128425_("id", 8)) {
|
||||
+ if (!net.minecraftforge.event.ForgeEventFactory.doSpecialSpawn(mob, p_151312_, (float)entity.m_20185_(), (float)entity.m_20186_(), (float)entity.m_20189_(), this, MobSpawnType.SPAWNER))
|
||||
+ if (!net.minecraftforge.event.ForgeEventFactory.doSpecialSpawn(mob, (LevelAccessor)p_151312_, (float)entity.m_20185_(), (float)entity.m_20186_(), (float)entity.m_20189_(), this, MobSpawnType.SPAWNER))
|
||||
((Mob)entity).m_6518_(p_151312_, p_151312_.m_6436_(entity.m_142538_()), MobSpawnType.SPAWNER, (SpawnGroupData)null, (CompoundTag)null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,6 +204,7 @@ public class ForgeEventFactory
|
||||
return event.getResult();
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true, since = "1.18.1")
|
||||
public static boolean canEntitySpawnSpawner(Mob entity, Level world, float x, float y, float z, BaseSpawner spawner)
|
||||
{
|
||||
Result result = canEntitySpawn(entity, world, x, y, z, spawner, MobSpawnType.SPAWNER);
|
||||
@@ -213,7 +214,12 @@ public class ForgeEventFactory
|
||||
return result == Result.ALLOW;
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true, since = "1.18.1")
|
||||
public static boolean doSpecialSpawn(Mob entity, Level world, float x, float y, float z, BaseSpawner spawner, MobSpawnType spawnReason)
|
||||
{
|
||||
return doSpecialSpawn(entity, (LevelAccessor)world, x, y, z, spawner, spawnReason);
|
||||
}
|
||||
public static boolean doSpecialSpawn(Mob entity, LevelAccessor world, float x, float y, float z, BaseSpawner spawner, MobSpawnType spawnReason)
|
||||
{
|
||||
return MinecraftForge.EVENT_BUS.post(new LivingSpawnEvent.SpecialSpawn(entity, world, x, y, z, spawner, spawnReason));
|
||||
}
|
||||
@@ -255,7 +261,7 @@ public class ForgeEventFactory
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event.getDisplayname();
|
||||
}
|
||||
|
||||
|
||||
public static Component getPlayerTabListDisplayName(Player player)
|
||||
{
|
||||
PlayerEvent.TabListNameFormat event = new PlayerEvent.TabListNameFormat(player);
|
||||
|
||||
@@ -118,7 +118,7 @@ public class LivingSpawnEvent extends LivingEvent
|
||||
* SpecialSpawn is fired when an Entity is to be spawned.<br>
|
||||
* This allows you to do special inializers in the new entity.<br>
|
||||
* <br>
|
||||
* This event is fired via the {@link ForgeEventFactory#doSpecialSpawn(Mob, Level, float, float, float, BaseSpawner, MobSpawnType)}.<br>
|
||||
* This event is fired via the {@link ForgeEventFactory#doSpecialSpawn(Mob, LevelAccessor, float, float, float, BaseSpawner, MobSpawnType)}.<br>
|
||||
* <br>
|
||||
* This event is {@link net.minecraftforge.eventbus.api.Cancelable}.<br>
|
||||
* If this event is canceled, the Entity is not spawned.<br>
|
||||
@@ -137,7 +137,13 @@ public class LivingSpawnEvent extends LivingEvent
|
||||
/**
|
||||
* @param spawner the position of a tileentity or approximate position of an entity that initiated the spawn if any
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.18.1")
|
||||
public SpecialSpawn(Mob entity, Level world, double x, double y, double z, @Nullable BaseSpawner spawner, MobSpawnType spawnReason)
|
||||
{
|
||||
this(entity, (LevelAccessor)world, x, y, z, spawner, spawnReason);
|
||||
}
|
||||
|
||||
public SpecialSpawn(Mob entity, LevelAccessor world, double x, double y, double z, @Nullable BaseSpawner spawner, MobSpawnType spawnReason)
|
||||
{
|
||||
super(entity, world, x, y, z);
|
||||
this.spawner = spawner;
|
||||
|
||||
Reference in new issue
Block a user