「BioFertilizer サンプルソース」是使用Minecraft 1.8.9 Forge API 进行的Mod开发的示例源代码
環境
-
- Mac OS X Yosemite
-
- Java 1.8.0_25
- Eclipse Mars.1 Release (4.5.1)
请用中文重新表达以下内容,只需要一种选择:
酱汁
package in.webya.Chrowa3Sample;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraft.item.ItemDye;
public class Chrowa3Fertilizer extends Item {
public Chrowa3Fertilizer(){
super();
setCreativeTab(CreativeTabs.tabMaterials);
setUnlocalizedName("BioFertilizer");
setMaxStackSize(64);
}
@Override
public String getItemStackDisplayName(ItemStack itemstack){
return "BioFertilizer";
}
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
{
int blockId = Block.getIdFromBlock(worldIn.getBlockState(pos).getBlock());
if(blockId == 2 || blockId == 6)
{
ItemDye.applyBonemeal(stack, worldIn, pos, playerIn);
ItemDye.spawnBonemealParticles(worldIn, pos.add(0,1,0), 15);
return true;
}
return false;
}
}
在onItemUse()方法中,调用ItemDye.applyBonemeal()函数可以将其作为”肥料”使用。然而,这个函数仅仅限定了目标为”草方块”和”橡树苗”。
此外,使用ItemDye.spawnBonemealParticles()函数可以显示施肥后的粒子效果。