LoginSignup
2
2

More than 5 years have passed since last update.

Minecraft 1.8.9 Forge API を使った Mod開発「BioFertilizer サンプルソース」

Last updated at Posted at 2016-03-01

環境

  • 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() を呼ぶことで「肥料」として機能します。しかし、blockId で対象を「草ブロック」と「オークの苗木」に絞っています。

また、ItemDye.spawnBonemealParticles() で肥料を撒いた後のパーティクルを表示します。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2