[1.19.4] Revamp and fix spawn events (#9133)

This commit is contained in:
Brennan Ward authored and GitHub committed 2023-03-23 18:29:06 +00:00
1 parent b33efc0727
commit 2815e69407
18 files changed
+558 -320

No files matched your search

@@ -1093,11 +1093,6 @@ public class ForgeHooks
return event.getVanillaNoteId();
}
public static int canEntitySpawn(Mob entity, LevelAccessor world, double x, double y, double z, BaseSpawner spawner, MobSpawnType spawnReason) {
Result res = ForgeEventFactory.canEntitySpawn(entity, world, x, y, z, null, spawnReason);
return res == Result.DEFAULT ? 0 : res == Result.DENY ? -1 : 1;
}
public static boolean hasNoElements(Ingredient ingredient)
{
ItemStack[] items = ingredient.getItems();
@@ -6,6 +6,7 @@
package net.minecraftforge.common;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
@@ -135,5 +136,14 @@ public class ForgeInternalHandler
event.addListener(TierSortingRegistry.getReloadListener());
event.addListener(CreativeModeTabRegistry.getReloadListener());
}
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void builtinMobSpawnBlocker(EntityJoinLevelEvent event)
{
if(event.getEntity() instanceof Mob mob && mob.isSpawnCancelled())
{
event.setCanceled(true);
}
}
}