From f6a9c7e7a821d23aa64359c83f1f2ecac9fa3496 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 10 Jan 2019 17:02:56 +0100 Subject: [PATCH] fix a serverside crash for the animal effect Closes #22 --- .../naturesaura/chunk/effect/AnimalEffect.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/effect/AnimalEffect.java b/src/main/java/de/ellpeck/naturesaura/chunk/effect/AnimalEffect.java index da10265f..0f4aa524 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/effect/AnimalEffect.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/effect/AnimalEffect.java @@ -18,6 +18,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; +import net.minecraftforge.fml.relauncher.ReflectionHelper; import java.util.Comparator; import java.util.List; @@ -53,12 +54,19 @@ public class AnimalEffect implements IDrainSpotEffect { continue; ItemStack stack = item.getItem(); - if (!(stack.getItem() instanceof ItemEgg) || item.getAge() < item.lifespan / 2) + if (!(stack.getItem() instanceof ItemEgg)) + continue; + // The getAge() method is private for absolutely no reason but I want it so I don't care + int age = ReflectionHelper.getPrivateValue(EntityItem.class, item, "field_70292_b", "age"); + if (age < item.lifespan / 2) continue; - stack.shrink(1); - if (stack.isEmpty()) + if (stack.getCount() <= 1) item.setDead(); + else { + stack.shrink(1); + item.setItem(stack); + } EntityChicken chicken = new EntityChicken(world); chicken.setGrowingAge(-24000);