From 1b89af4bbaa4f75dedd0ff8a408808e5167f7700 Mon Sep 17 00:00:00 2001 From: Weedoof <73194383+Weedoof@users.noreply.github.com> Date: Fri, 15 Jul 2022 01:27:55 -0400 Subject: [PATCH] Fixes #43 Catches errors if a mob is riding another with custom ai and its chunk unloads. Mostly noticeable in the case of Alex's mobs. It even targets the right branch this time! --- .../pamhc2crops/events/TemptationTask.java | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/main/java/pam/pamhc2crops/events/TemptationTask.java b/src/main/java/pam/pamhc2crops/events/TemptationTask.java index 78f1351..6b88e1f 100644 --- a/src/main/java/pam/pamhc2crops/events/TemptationTask.java +++ b/src/main/java/pam/pamhc2crops/events/TemptationTask.java @@ -180,27 +180,47 @@ public void onEntitySpawn(EntityJoinWorldEvent event) { if (entity instanceof ChickenEntity) { ChickenEntity chicken = (ChickenEntity) entity; - chicken.goalSelector.addGoal(3, new MoreTemptation(chicken, 1.0D, false, Chicken)); + try { + chicken.goalSelector.addGoal(3, new MoreTemptation(chicken, 1.0D, false, Chicken)); + } catch(IllegalArgumentException e) { + // whoops + } } if (entity instanceof CowEntity) { CowEntity cow = (CowEntity) entity; - cow.goalSelector.addGoal(3, new MoreTemptation(cow, 1.25D, false, Grain)); + try { + cow.goalSelector.addGoal(3, new MoreTemptation(cow, 1.25D, false, Grain)); + } catch(IllegalArgumentException e) { + // whoops + } } if (entity instanceof SheepEntity) { SheepEntity sheep = (SheepEntity) entity; - sheep.goalSelector.addGoal(3, new MoreTemptation(sheep, 1.0D, false, Grain)); + try { + sheep.goalSelector.addGoal(3, new MoreTemptation(sheep, 1.0D, false, Grain)); + } catch(IllegalArgumentException e) { + // whoops + } } if (entity instanceof PigEntity) { PigEntity pig = (PigEntity) entity; - pig.goalSelector.addGoal(4, new MoreTemptation(pig, 1.2D, false, Pig)); + try { + pig.goalSelector.addGoal(4, new MoreTemptation(pig, 1.2D, false, Pig)); + } catch(IllegalArgumentException e) { + // whoops + } } if (entity instanceof RabbitEntity) { RabbitEntity rabbit = (RabbitEntity) entity; - rabbit.goalSelector.addGoal(4, new MoreTemptation(rabbit, 1.2D, false, Rabbit)); + try { + rabbit.goalSelector.addGoal(4, new MoreTemptation(rabbit, 1.2D, false, Rabbit)); + } catch(IllegalArgumentException e) { + // whoops + } } } -} \ No newline at end of file +}