本文整理匯總了Java中net.minecraft.client.entity.EntityPlayerSP.getHeldItem方法的典型用法代碼示例。如果您正苦於以下問題:Java EntityPlayerSP.getHeldItem方法的具體用法?Java EntityPlayerSP.getHeldItem怎麽用?Java EntityPlayerSP.getHeldItem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.minecraft.client.entity.EntityPlayerSP
的用法示例。
在下文中一共展示了EntityPlayerSP.getHeldItem方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onPlayerRightClick
import net.minecraft.client.entity.EntityPlayerSP; //導入方法依賴的package包/類
public boolean onPlayerRightClick(EntityPlayerSP player, WorldClient worldIn, ItemStack heldStack, BlockPos hitPos, EnumFacing side, Vec3 hitVec)
{
this.syncCurrentPlayItem();
float f = (float)(hitVec.xCoord - (double)hitPos.getX());
float f1 = (float)(hitVec.yCoord - (double)hitPos.getY());
float f2 = (float)(hitVec.zCoord - (double)hitPos.getZ());
boolean flag = false;
if (!this.mc.theWorld.getWorldBorder().contains(hitPos))
{
return false;
}
else
{
if (this.currentGameType != WorldSettings.GameType.SPECTATOR)
{
IBlockState iblockstate = worldIn.getBlockState(hitPos);
if ((!player.isSneaking() || player.getHeldItem() == null) && iblockstate.getBlock().onBlockActivated(worldIn, hitPos, iblockstate, player, side, f, f1, f2))
{
flag = true;
}
if (!flag && heldStack != null && heldStack.getItem() instanceof ItemBlock)
{
ItemBlock itemblock = (ItemBlock)heldStack.getItem();
if (!itemblock.canPlaceBlockOnSide(worldIn, hitPos, side, player, heldStack))
{
return false;
}
}
}
this.netClientHandler.addToSendQueue(new C08PacketPlayerBlockPlacement(hitPos, side.getIndex(), player.inventory.getCurrentItem(), f, f1, f2));
if (!flag && this.currentGameType != WorldSettings.GameType.SPECTATOR)
{
if (heldStack == null)
{
return false;
}
else if (this.currentGameType.isCreative())
{
int i = heldStack.getMetadata();
int j = heldStack.stackSize;
boolean flag1 = heldStack.onItemUse(player, worldIn, hitPos, side, f, f1, f2);
heldStack.setItemDamage(i);
heldStack.stackSize = j;
return flag1;
}
else
{
return heldStack.onItemUse(player, worldIn, hitPos, side, f, f1, f2);
}
}
else
{
return true;
}
}
}
示例2: processRightClickBlock
import net.minecraft.client.entity.EntityPlayerSP; //導入方法依賴的package包/類
public EnumActionResult processRightClickBlock(EntityPlayerSP player, WorldClient worldIn, BlockPos stack, EnumFacing pos, Vec3d facing, EnumHand vec)
{
this.syncCurrentPlayItem();
ItemStack itemstack = player.getHeldItem(vec);
float f = (float)(facing.xCoord - (double)stack.getX());
float f1 = (float)(facing.yCoord - (double)stack.getY());
float f2 = (float)(facing.zCoord - (double)stack.getZ());
boolean flag = false;
if (!this.mc.world.getWorldBorder().contains(stack))
{
return EnumActionResult.FAIL;
}
else
{
if (this.currentGameType != GameType.SPECTATOR)
{
IBlockState iblockstate = worldIn.getBlockState(stack);
if ((!player.isSneaking() || player.getHeldItemMainhand().func_190926_b() && player.getHeldItemOffhand().func_190926_b()) && iblockstate.getBlock().onBlockActivated(worldIn, stack, iblockstate, player, vec, pos, f, f1, f2))
{
flag = true;
}
if (!flag && itemstack.getItem() instanceof ItemBlock)
{
ItemBlock itemblock = (ItemBlock)itemstack.getItem();
if (!itemblock.canPlaceBlockOnSide(worldIn, stack, pos, player, itemstack))
{
return EnumActionResult.FAIL;
}
}
}
this.connection.sendPacket(new CPacketPlayerTryUseItemOnBlock(stack, pos, vec, f, f1, f2));
if (!flag && this.currentGameType != GameType.SPECTATOR)
{
if (itemstack.func_190926_b())
{
return EnumActionResult.PASS;
}
else if (player.getCooldownTracker().hasCooldown(itemstack.getItem()))
{
return EnumActionResult.PASS;
}
else
{
if (itemstack.getItem() instanceof ItemBlock && !player.canUseCommandBlock())
{
Block block = ((ItemBlock)itemstack.getItem()).getBlock();
if (block instanceof BlockCommandBlock || block instanceof BlockStructure)
{
return EnumActionResult.FAIL;
}
}
if (this.currentGameType.isCreative())
{
int i = itemstack.getMetadata();
int j = itemstack.func_190916_E();
EnumActionResult enumactionresult = itemstack.onItemUse(player, worldIn, stack, vec, pos, f, f1, f2);
itemstack.setItemDamage(i);
itemstack.func_190920_e(j);
return enumactionresult;
}
else
{
return itemstack.onItemUse(player, worldIn, stack, vec, pos, f, f1, f2);
}
}
}
else
{
return EnumActionResult.SUCCESS;
}
}
}