如果特定项目是自定义项目,则要简单得多。
在您的自定义项目中,设置onItemUse
(用于右键单击)或onItemClick
(用于左键单击)功能:
public boolean onItemUse(ItemStack item, EntityPlayer player, World world,
// which block was in the target when clicked
int posx, int posy, int posz,
// where on the target block was clicked (0.0-1.0)
int side, float blockx, float blocky, float blockz)
{
if(world.isRemote) {
// can't do anything here as we don't own the world (client side)
return false;
}
// server side - here we can change the block
这个函数被传递给被点击的方块的坐标,以及世界对象。然后,您可以测试被点击的方块,并对它做任何事情(本例将其设置为泥土):
rv = world.setBlock(posx,posy,posz,Blocks.dirt);
当然,如果你把它放在自定义物品自己的onItemUse函数中,那么你就不需要测试来确定物品是否配备了,因为它必须是为了调用该函数。