I am trying to make a sword that will spawn diamonds upon breaking any block. This is my first ever mod and I don't think I am understanding how to spawn objects. I overriding the onBlockDestroyed method and adding the spawnAdditionalDrops method to drop diamonds upon the block breaking. Would someone be able to help me figure out how to set diamonds to be dropped?
@Override
public boolean onBlockDestroyed(ItemStack stack, World worldIn, BlockState state, BlockPos pos,
LivingEntity entityLiving) {
IItemProvider provider = new IItemProvider() {
@Override
public Item asItem() {
// I'm not sure whats going on here.
return null;
}
};
ItemStack itemDrop = new ItemStack(provider);
if (state.getBlockHardness(worldIn, pos) != 0.0F) {
stack.damageItem(100, entityLiving, (entity) -> {
entity.sendBreakAnimation(EquipmentSlotType.MAINHAND);
state.spawnAdditionalDrops((ServerWorld) worldIn, pos, itemDrop);
});
}
return super.onBlockDestroyed(stack, worldIn, state, pos, entityLiving);
}