Skip to content

Commit

Permalink
Fix crash when reanimating mobs without spawn egg, Closes #1005
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Sep 25, 2023
1 parent bcac8a4 commit 4900005
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SpawnEggItem;
import net.minecraftforge.common.ForgeSpawnEggItem;
import net.minecraftforge.fluids.capability.IFluidHandler;
import org.apache.commons.lang3.mutable.MutableDouble;
Expand All @@ -26,10 +27,6 @@ public boolean canTick(BlockEntitySpiritReanimator tile, ItemStack itemStack, in
return tile.getTank().getFluidAmount() >= getRequiredMb(tile, tick) && tile.canWork();
}

protected ItemStack getSpawnEgg(EntityType<?> entityType) {
return new ItemStack(ForgeSpawnEggItem.fromEntityType(entityType));
}

@Override
public void onTick(BlockEntitySpiritReanimator tile, ItemStack itemStack, int slot, int tick) {
// Drain the tank a bit.
Expand All @@ -38,7 +35,10 @@ public void onTick(BlockEntitySpiritReanimator tile, ItemStack itemStack, int sl
ItemStack spawnEgg = ItemStack.EMPTY;
EntityType<?> entityType = tile.getEntityType();
if(entityType != null) {
spawnEgg = getSpawnEgg(entityType);
SpawnEggItem spawnEggItem = ForgeSpawnEggItem.fromEntityType(entityType);
if (spawnEggItem != null) {
spawnEgg = new ItemStack(spawnEggItem);
}
}
if(!spawnEgg.isEmpty() && addToProduceSlot(tile, spawnEgg)) {
tile.getInventory().removeItem(BlockEntitySpiritReanimator.SLOT_EGG, 1);
Expand Down

0 comments on commit 4900005

Please sign in to comment.