From 4b9bf30fed973443fe97633b6dff55d83cbb740d Mon Sep 17 00:00:00 2001 From: diesieben07 Date: Mon, 27 Jun 2016 01:35:59 +0200 Subject: [PATCH] Fix mob-spawners crashing for non-living entities and simply the patch in the process (#3042) --- .../tileentity/MobSpawnerBaseLogic.java.patch | 7 ++----- .../net/minecraftforge/event/ForgeEventFactory.java | 13 +++++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/patches/minecraft/net/minecraft/tileentity/MobSpawnerBaseLogic.java.patch b/patches/minecraft/net/minecraft/tileentity/MobSpawnerBaseLogic.java.patch index f20307a0cb..cfdbcfabc4 100644 --- a/patches/minecraft/net/minecraft/tileentity/MobSpawnerBaseLogic.java.patch +++ b/patches/minecraft/net/minecraft/tileentity/MobSpawnerBaseLogic.java.patch @@ -1,14 +1,11 @@ --- ../src-base/minecraft/net/minecraft/tileentity/MobSpawnerBaseLogic.java +++ ../src-work/minecraft/net/minecraft/tileentity/MobSpawnerBaseLogic.java -@@ -117,10 +117,14 @@ +@@ -117,10 +117,11 @@ EntityLiving entityliving = entity instanceof EntityLiving ? (EntityLiving)entity : null; entity.func_70012_b(entity.field_70165_t, entity.field_70163_u, entity.field_70161_v, world.field_73012_v.nextFloat() * 360.0F, 0.0F); - if (entityliving == null || entityliving.func_70601_bi() && entityliving.func_70058_J()) -+ net.minecraftforge.fml.common.eventhandler.Event.Result canSpawn = net.minecraftforge.event.ForgeEventFactory.canEntitySpawn(entityliving, this.func_98271_a(), (float)entity.field_70165_t, (float)entity.field_70163_u, (float)entity.field_70161_v); -+ boolean force = canSpawn == net.minecraftforge.fml.common.eventhandler.Event.Result.ALLOW || -+ (canSpawn == net.minecraftforge.fml.common.eventhandler.Event.Result.DEFAULT && (entityliving.func_70601_bi() && entityliving.func_70058_J())); -+ if (entityliving == null || force) ++ if (entityliving == null || net.minecraftforge.event.ForgeEventFactory.canEntitySpawnSpawner(entityliving, func_98271_a(), (float)entity.field_70165_t, (float)entity.field_70163_u, (float)entity.field_70161_v)) { if (this.field_98282_f.func_185277_b().func_186856_d() == 1 && this.field_98282_f.func_185277_b().func_150297_b("id", 8) && entity instanceof EntityLiving) { diff --git a/src/main/java/net/minecraftforge/event/ForgeEventFactory.java b/src/main/java/net/minecraftforge/event/ForgeEventFactory.java index b4b25abe61..eead4dfdc2 100644 --- a/src/main/java/net/minecraftforge/event/ForgeEventFactory.java +++ b/src/main/java/net/minecraftforge/event/ForgeEventFactory.java @@ -161,6 +161,19 @@ public class ForgeEventFactory return event.getResult(); } + public static boolean canEntitySpawnSpawner(EntityLiving entity, World world, float x, float y, float z) + { + Result result = canEntitySpawn(entity, world, x, y, z); + if (result == Result.DEFAULT) + { + return entity.getCanSpawnHere() && entity.isNotColliding(); // vanilla logic + } + else + { + return result == Result.ALLOW; + } + } + public static boolean doSpecialSpawn(EntityLiving entity, World world, float x, float y, float z) { return MinecraftForge.EVENT_BUS.post(new LivingSpawnEvent.SpecialSpawn(entity, world, x, y, z));