add a bit of null safety and make sure the list is not empty before firing events
@@ -11,6 +11,7 @@ import mekanism.common.Mekanism;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
+import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
@@ -47,10 +48,10 @@ public final class MinerUtils
{
try
{
- ItemStack it = (ItemStack)getSilkTouchDrop.invoke(block, state);
- if (!it.isEmpty())
+ Object it = getSilkTouchDrop.invoke(block, state);
+ if (it != null && it instanceof ItemStack && !((ItemStack)it).isEmpty())
{
- ret.add(it);
+ ret.add((ItemStack)it);
}
} catch (InvocationTargetException|IllegalAccessException e){
Mekanism.logger.error("Block.getSilkTouchDrop errored", e);
@@ -59,10 +60,15 @@ public final class MinerUtils
else//fallback to old method
{
Item item = Item.getItemFromBlock(block);
+ if (item != null && item != Items.AIR)
+ {
int meta = item.getHasSubtypes() ? block.getMetaFromState(state) : 0;
ret.add(new ItemStack(item, 1, meta));
}
+ }
+ if (ret.size() > 0)
+ {
List<ItemStack> blockDrops = block.getDrops(world, obj.getPos(), state, 0);
if(specialSilkIDs.contains(block) || (blockDrops != null && blockDrops.size() > 0))
@@ -70,9 +76,13 @@ public final class MinerUtils
net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(ret, world, obj.getPos(), state, 0, 1.0f, true, null);
return ret;
}
+ }
} else {
List<ItemStack> blockDrops = block.getDrops(world, obj.getPos(), state, 0);
+ if (blockDrops.size() > 0)
+ {
net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(blockDrops, world, obj.getPos(), state, 0, 1.0f, true, null);
+ }
return blockDrops;
}
