當前位置: 首頁>>代碼示例>>Java>>正文


Java EntityPlayerMP.getHeldItemMainhand方法代碼示例

本文整理匯總了Java中net.minecraft.entity.player.EntityPlayerMP.getHeldItemMainhand方法的典型用法代碼示例。如果您正苦於以下問題:Java EntityPlayerMP.getHeldItemMainhand方法的具體用法?Java EntityPlayerMP.getHeldItemMainhand怎麽用?Java EntityPlayerMP.getHeldItemMainhand使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.minecraft.entity.player.EntityPlayerMP的用法示例。


在下文中一共展示了EntityPlayerMP.getHeldItemMainhand方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: payPrice

import net.minecraft.entity.player.EntityPlayerMP; //導入方法依賴的package包/類
public boolean payPrice(EntityPlayerMP p) {
	ItemStack i = p.getHeldItemMainhand();
	if (material == CraftMat.STONE) {
		if (i.getItem() == FirmaMod.pebble) {
			if (i.getCount() > 1) {
				i.setCount(i.getCount() - 1);
				return true;
			}
		}
		return false;
	} else if (material == CraftMat.CLAY) {
		if (i.getItem() == FirmaMod.clay) {
			if (i.getCount() > 5) {
				i.setCount(i.getCount() - 5);
				return true;
			}
		}
		return false;
	}
	return false;
}
 
開發者ID:trigg,項目名稱:Firma,代碼行數:22,代碼來源:Recipe.java

示例2: handle

import net.minecraft.entity.player.EntityPlayerMP; //導入方法依賴的package包/類
public static void handle(NBTTagCompound tag)
{
	try
	{
		UUID requesterID = UUID.fromString(tag.getString("uuid"));
		SpecialAttack attack = SpecialAttack.registry.get(tag.getString("attackID"));
		boolean rightClick = tag.getBoolean("rightClick");
		EntityPlayerMP player = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUUID(requesterID);
		ItemStack is = !player.getHeldItemMainhand().isEmpty() ? player.getHeldItemMainhand() : player.getHeldItemOffhand();
		if (attack.canExecute(player, WeaponType.getType(is), EnumWeaponWeight.getWeaponWeight(is), rightClick))
		{
			IExPPlayer.of(player).setCurrentSpecialAttack(attack.wrap(), true);
			VoidNetwork.sendDataToClient(ExPPackets.SPECIAL_ATTACK, tag, player);
		}
	}
	catch (Exception ex)
	{
		ExPMisc.modLogger.log(LogLevel.Error, "Malformed client combat packet! %s", ex, tag);
	}
}
 
開發者ID:V0idWa1k3r,項目名稱:ExPetrum,代碼行數:21,代碼來源:ServerCombatHandler.java

示例3: handle

import net.minecraft.entity.player.EntityPlayerMP; //導入方法依賴的package包/類
private void handle(PacketSetSelectedItem message, MessageContext ctx) {
	EntityPlayerMP player = ctx.getServerHandler().player;
	if (player != null && !player.getHeldItemMainhand().isEmpty() && DankNullUtils.isDankNull(player.getHeldItemMainhand())) {
		InventoryDankNull inventory = new InventoryDankNull(player.getHeldItemMainhand());
		DankNullUtils.setSelectedStackIndex(inventory, index, false);
	}
}
 
開發者ID:p455w0rd,項目名稱:DankNull,代碼行數:8,代碼來源:PacketSetSelectedItem.java

示例4: execute

import net.minecraft.entity.player.EntityPlayerMP; //導入方法依賴的package包/類
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    EntityPlayerMP player = getCommandSenderAsPlayer(sender);
    ItemStack held = player.getHeldItemMainhand();
    if(held.isEmpty()) {
        held = player.getHeldItemOffhand();
    }
    if(held.isEmpty()) {
        player.sendMessage(new TextComponentTranslation("command.modularmachinery.hand.empty"));
        return;
    }
    Item i = held.getItem();
    StringBuilder sb = new StringBuilder();
    sb.append(i.getRegistryName().toString());
    if(i.getHasSubtypes()) {
        sb.append("@").append(held.getItemDamage());
    }
    NBTTagCompound cmp = held.serializeNBT();
    if(cmp.hasKey("tag")) {
        String json = NBTJsonSerializer.serializeNBT(cmp.getTag("tag"));
        if(!json.isEmpty()) {
            sb.append(" (with nbt: ").append(json).append(" )");
        }
    }

    String str = sb.toString();
    player.sendMessage(new TextComponentString(str));
    ModularMachinery.NET_CHANNEL.sendTo(new PktCopyToClipboard(str), player);

    int burn = TileEntityFurnace.getItemBurnTime(held);
    if(burn > 0) {
        player.sendMessage(new TextComponentString("Fuel BurnTime: " + burn));
    }
}
 
開發者ID:HellFirePvP,項目名稱:ModularMachinery,代碼行數:35,代碼來源:CommandHand.java

示例5: auxHarvestBlock

import net.minecraft.entity.player.EntityPlayerMP; //導入方法依賴的package包/類
/**
 * Destroys and tries to harvest a block with the currently active tool, except that instead of calling
 * onBlockDestroyed, it calls onBlockAuxDestroyed on the tool, preventing infinite loops.
 */
public static boolean auxHarvestBlock(World world, BlockPos pos, EntityPlayerMP player) {
	if (world.isRemote) return false; //Shouldn't even be possible if we have an EntityPlayerMP!
	
	GameType gameType = player.interactionManager.getGameType();
	
	int exp = net.minecraftforge.common.ForgeHooks.onBlockBreakEvent(world, gameType, player, pos);
       if (exp == -1) {
           return false;
       } else {
           IBlockState iblockstate = world.getBlockState(pos);
           if (iblockstate.getBlockHardness(world, pos)<0) return false;
           TileEntity tileentity = world.getTileEntity(pos);
           Block block = iblockstate.getBlock();

           if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !player.canUseCommandBlock()) {
               world.notifyBlockUpdate(pos, iblockstate, iblockstate, 3);
               return false;
           } else {
               ItemStack stack = player.getHeldItemMainhand();
               if (!stack.isEmpty() && stack.getItem().onBlockStartBreak(stack, pos, player)) return false;

               world.playEvent(player, 2001, pos, Block.getStateId(iblockstate));
               boolean removed = false;

               if (gameType==GameType.CREATIVE) {
                   removed = removeBlock(world, pos, player, false);
                   player.connection.sendPacket(new SPacketBlockChange(world, pos));
               } else {
                   ItemStack itemstack1 = player.getHeldItemMainhand();
                   ItemStack itemstack2 = itemstack1.isEmpty() ? ItemStack.EMPTY : itemstack1.copy();
                   boolean canHarvest = iblockstate.getBlock().canHarvestBlock(world, pos, player);

                   if (!itemstack1.isEmpty()) {
                   //    itemstack1.onBlockDestroyed(world, iblockstate, pos, player);
                    if (itemstack1.getItem() instanceof IAuxDestroyBlock) {
                    	((IAuxDestroyBlock)itemstack1.getItem()).onBlockAuxDestroyed(world, iblockstate, pos, player);
                    }
                   }
                   
                   removed = removeBlock(world, pos, player, canHarvest);
                   if (removed && canHarvest) {
                       iblockstate.getBlock().harvestBlock(world, player, pos, iblockstate, tileentity, itemstack2);
                   }
               }

               // Drop experience
               if (gameType!=GameType.CREATIVE && removed && exp > 0) {
                   iblockstate.getBlock().dropXpOnBlockBreak(world, pos, exp);
               }
               return removed;
           }
       }
}
 
開發者ID:elytra,項目名稱:Thermionics,代碼行數:58,代碼來源:ToolHelper.java

示例6: onBlockBreakEvent

import net.minecraft.entity.player.EntityPlayerMP; //導入方法依賴的package包/類
public static int onBlockBreakEvent(World world, GameType gameType, EntityPlayerMP entityPlayer, BlockPos pos)
{
    // Logic from tryHarvestBlock for pre-canceling the event
    boolean preCancelEvent = false;
    if (gameType.isCreative() && entityPlayer.getHeldItemMainhand() != null && entityPlayer.getHeldItemMainhand().getItem() instanceof ItemSword)
        preCancelEvent = true;

    if (gameType.isAdventure())
    {
        if (gameType == GameType.SPECTATOR)
            preCancelEvent = true;

        if (!entityPlayer.isAllowEdit())
        {
            ItemStack itemstack = entityPlayer.getHeldItemMainhand();
            if (itemstack == null || !itemstack.canDestroy(world.getBlockState(pos).getBlock()))
                preCancelEvent = true;
        }
    }

    // Tell client the block is gone immediately then process events
    if (world.getTileEntity(pos) == null)
    {
        SPacketBlockChange packet = new SPacketBlockChange(world, pos);
        packet.blockState = Blocks.AIR.getDefaultState();
        entityPlayer.connection.sendPacket(packet);
    }

    // Post the block break event
    IBlockState state = world.getBlockState(pos);
    BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, state, entityPlayer);
    event.setCanceled(preCancelEvent);
    MinecraftForge.EVENT_BUS.post(event);

    // Handle if the event is canceled
    if (event.isCanceled())
    {
        // Let the client know the block still exists
        entityPlayer.connection.sendPacket(new SPacketBlockChange(world, pos));

        // Update any tile entity data for this block
        TileEntity tileentity = world.getTileEntity(pos);
        if (tileentity != null)
        {
            Packet<?> pkt = tileentity.getUpdatePacket();
            if (pkt != null)
            {
                entityPlayer.connection.sendPacket(pkt);
            }
        }
    }
    return event.isCanceled() ? -1 : event.getExpToDrop();
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:54,代碼來源:ForgeHooks.java


注:本文中的net.minecraft.entity.player.EntityPlayerMP.getHeldItemMainhand方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。