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


Java ForgeEventFactory.onPlayerInteract方法代碼示例

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


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

示例1: attack

import net.minecraftforge.event.ForgeEventFactory; //導入方法依賴的package包/類
@SubscribeEvent
public void attack(final PlayerInteractEvent event) {
    if (event.action != PlayerInteractEvent.Action.LEFT_CLICK_BLOCK) {
        return;
    }
    final EntityPlayer player = event.entityPlayer;
    if (event.world == null || event.world.isRemote) {
        return;
    }
    if (player == null || !(player instanceof EntityPlayerMP)) {
        return;
    }
    final ItemStack heldItem = player.getHeldItem();
    if (heldItem == null || heldItem.getItem() != this) {
        return;
    }
    if (heldItem.getItemDamage() == 32767) {
        heldItem.stackSize = 0;
        return;
    }
    final int i = player.inventory.currentItem;
    if (i >= 9 || i < 0) {
        return;
    }
    event.setCanceled(true);
    final ItemStack item = heldItem.copy();
    heldItem.setItemDamage(32767);
    player.inventory.setInventorySlotContents(i, (ItemStack)null);
    final int x = event.x;
    final int y = event.y;
    final int z = event.z;
    final int side = event.face;
    try {
        final PlayerInteractEvent e = ForgeEventFactory.onPlayerInteract(player, PlayerInteractEvent.Action.LEFT_CLICK_BLOCK, x, y, z, side, player.worldObj);
        final boolean result = !e.isCanceled() && event.useBlock != Event.Result.DENY;
        if (result) {
            final Block block = event.world.getBlock(x, y, z);
            block.onBlockClicked(event.world, x, y, z, player);
        }
    }
    catch (Exception err) {
        for (int j = 0; j < player.inventory.getSizeInventory(); ++j) {
            final ItemStack stackInSlot = player.inventory.getStackInSlot(i);
            if (stackInSlot != null) {
                if (stackInSlot.getItem() == this) {
                    if (stackInSlot.getItemDamage() == 32767) {
                        player.inventory.setInventorySlotContents(j, (ItemStack)null);
                    }
                }
            }
        }
        if (player.inventory.getStackInSlot(i) == null) {
            player.inventory.setInventorySlotContents(i, item);
        }
        else if (!player.inventory.addItemStackToInventory(item)) {
            player.dropPlayerItemWithRandomChoice(item, false);
        }
        throw Throwables.propagate((Throwable)err);
    }
    ((EntityPlayerMP)player).playerNetServerHandler.sendPacket((Packet)new S23PacketBlockChange(x, y, z, event.world));
    final ItemStack newItem = player.inventory.getStackInSlot(i);
    player.inventory.setInventorySlotContents(i, item);
    if (newItem != null && !player.inventory.addItemStackToInventory(newItem.copy())) {
        player.dropPlayerItemWithRandomChoice(newItem.copy(), false);
    }
    ((EntityPlayerMP)player).mcServer.getConfigurationManager().syncPlayerInventory((EntityPlayerMP)player);
}
 
開發者ID:sameer,項目名稱:ExtraUtilities,代碼行數:68,代碼來源:ItemGlove.java

示例2: onItemUseFirst

import net.minecraftforge.event.ForgeEventFactory; //導入方法依賴的package包/類
public boolean onItemUseFirst(final ItemStack stack, final EntityPlayer player, final World world, final int x, final int y, final int z, final int side, final float hitX, final float hitY, final float hitZ) {
    if (player == null) {
        return false;
    }
    final ItemStack heldItem = player.getHeldItem();
    if (heldItem == null || heldItem.getItem() != this) {
        return false;
    }
    if (ExtraUtilsMod.proxy.isAltSneaking()) {
        if (world.isRemote) {
            ExtraUtilsMod.proxy.sendAltUsePacket(x, y, z, side, stack, hitX, hitY, hitZ);
            return true;
        }
        return false;
    }
    else {
        if (heldItem.getItemDamage() == 32767) {
            heldItem.stackSize = 0;
            return true;
        }
        final int i = player.inventory.currentItem;
        if (i >= 9 || i < 0) {
            return false;
        }
        final ItemStack item = heldItem.copy();
        heldItem.setItemDamage(32767);
        player.inventory.setInventorySlotContents(i, (ItemStack)null);
        try {
            final PlayerInteractEvent event = ForgeEventFactory.onPlayerInteract(player, PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK, x, y, z, side, player.worldObj);
            final boolean result = !event.isCanceled() && event.useBlock != Event.Result.DENY;
            if (result) {
                final Block block = world.getBlock(x, y, z);
                block.onBlockActivated(world, x, y, z, player, side, hitX, hitY, hitZ);
            }
        }
        catch (Exception err) {
            for (int j = 0; j < player.inventory.getSizeInventory(); ++j) {
                final ItemStack stackInSlot = player.inventory.getStackInSlot(i);
                if (stackInSlot != null) {
                    if (stackInSlot.getItem() == this) {
                        if (stackInSlot.getItemDamage() == 32767) {
                            player.inventory.setInventorySlotContents(j, (ItemStack)null);
                        }
                    }
                }
            }
            if (player.inventory.getStackInSlot(i) == null) {
                player.inventory.setInventorySlotContents(i, item);
            }
            else if (!player.inventory.addItemStackToInventory(item)) {
                player.dropPlayerItemWithRandomChoice(item, false);
            }
            throw Throwables.propagate((Throwable)err);
        }
        final ItemStack newItem = player.inventory.getStackInSlot(i);
        player.inventory.setInventorySlotContents(i, item);
        if (newItem != null && !player.inventory.addItemStackToInventory(newItem.copy())) {
            player.dropPlayerItemWithRandomChoice(newItem.copy(), false);
        }
        if (player.worldObj.isRemote) {
            ExtraUtilsMod.proxy.sendUsePacket(x, y, z, side, item, hitX, hitY, hitZ);
        }
        else {
            if (player instanceof EntityPlayerMP) {
                ((EntityPlayerMP)player).mcServer.getConfigurationManager().syncPlayerInventory((EntityPlayerMP)player);
            }
            player.openContainer.detectAndSendChanges();
        }
        return true;
    }
}
 
開發者ID:sameer,項目名稱:ExtraUtilities,代碼行數:72,代碼來源:ItemGlove.java

示例3: onBlockClicked

import net.minecraftforge.event.ForgeEventFactory; //導入方法依賴的package包/類
public void onBlockClicked(int p_73074_1_, int p_73074_2_, int p_73074_3_, int p_73074_4_)
{
    if (!this.gameType.isAdventure() || this.thisPlayerMP.isCurrentToolAdventureModeExempt(p_73074_1_, p_73074_2_, p_73074_3_))
    {
        PlayerInteractEvent event = ForgeEventFactory.onPlayerInteract(thisPlayerMP, Action.LEFT_CLICK_BLOCK, p_73074_1_, p_73074_2_, p_73074_3_, p_73074_4_, theWorld);
        if (event.isCanceled())
        {
            thisPlayerMP.playerNetServerHandler.sendPacket(new S23PacketBlockChange(p_73074_1_, p_73074_2_, p_73074_3_, theWorld));
            return;
        }

        if (this.isCreative())
        {
            if (!this.theWorld.extinguishFire((EntityPlayer)null, p_73074_1_, p_73074_2_, p_73074_3_, p_73074_4_))
            {
                this.tryHarvestBlock(p_73074_1_, p_73074_2_, p_73074_3_);
            }
        }
        else
        {
            this.initialDamage = this.curblockDamage;
            float f = 1.0F;
            Block block = this.theWorld.getBlock(p_73074_1_, p_73074_2_, p_73074_3_);


            if (!block.isAir(theWorld, p_73074_1_, p_73074_2_, p_73074_3_))
            {
                if (event.useBlock != Event.Result.DENY)
                {
                    block.onBlockClicked(theWorld, p_73074_1_, p_73074_2_, p_73074_3_, thisPlayerMP);
                    theWorld.extinguishFire(null, p_73074_1_, p_73074_2_, p_73074_3_, p_73074_4_);
                }
                else
                {
                    thisPlayerMP.playerNetServerHandler.sendPacket(new S23PacketBlockChange(p_73074_1_, p_73074_2_, p_73074_3_, theWorld));
                }
                f = block.getPlayerRelativeBlockHardness(thisPlayerMP, thisPlayerMP.worldObj, p_73074_1_, p_73074_2_, p_73074_3_);
            }

            if (event.useItem == Event.Result.DENY)
            {
                if (f >= 1.0f)
                {
                    thisPlayerMP.playerNetServerHandler.sendPacket(new S23PacketBlockChange(p_73074_1_, p_73074_2_, p_73074_3_, theWorld));
                }
                return;
            }

            if (!block.isAir(theWorld, p_73074_1_, p_73074_2_, p_73074_3_) && f >= 1.0F)
            {
                this.tryHarvestBlock(p_73074_1_, p_73074_2_, p_73074_3_);
            }
            else
            {
                this.isDestroyingBlock = true;
                this.partiallyDestroyedBlockX = p_73074_1_;
                this.partiallyDestroyedBlockY = p_73074_2_;
                this.partiallyDestroyedBlockZ = p_73074_3_;
                int i1 = (int)(f * 10.0F);
                this.theWorld.destroyBlockInWorldPartially(this.thisPlayerMP.getEntityId(), p_73074_1_, p_73074_2_, p_73074_3_, i1);
                this.durabilityRemainingOnBlock = i1;
            }
        }
    }
}
 
開發者ID:xtrafrancyz,項目名稱:Cauldron,代碼行數:66,代碼來源:ItemInWorldManager.java

示例4: activateBlockOrUseItem

import net.minecraftforge.event.ForgeEventFactory; //導入方法依賴的package包/類
public boolean activateBlockOrUseItem(EntityPlayer p_73078_1_, World p_73078_2_, ItemStack p_73078_3_, int p_73078_4_, int p_73078_5_, int p_73078_6_, int p_73078_7_, float p_73078_8_, float p_73078_9_, float p_73078_10_)
{
    PlayerInteractEvent event = ForgeEventFactory.onPlayerInteract(p_73078_1_, Action.RIGHT_CLICK_BLOCK, p_73078_4_, p_73078_5_, p_73078_6_, p_73078_7_, p_73078_2_);
    if (event.isCanceled())
    {
        thisPlayerMP.playerNetServerHandler.sendPacket(new S23PacketBlockChange(p_73078_4_, p_73078_5_, p_73078_6_, theWorld));
        return false;
    }

    if (p_73078_3_ != null && p_73078_3_.getItem().onItemUseFirst(p_73078_3_, p_73078_1_, p_73078_2_, p_73078_4_, p_73078_5_, p_73078_6_, p_73078_7_, p_73078_8_, p_73078_9_, p_73078_10_))
    {
        if (p_73078_3_.stackSize <= 0) ForgeEventFactory.onPlayerDestroyItem(thisPlayerMP, p_73078_3_);
        return true;
    }

    Block block = p_73078_2_.getBlock(p_73078_4_, p_73078_5_, p_73078_6_);
    boolean isAir = block.isAir(p_73078_2_, p_73078_4_, p_73078_5_, p_73078_6_);
    boolean useBlock = !p_73078_1_.isSneaking() || p_73078_1_.getHeldItem() == null;
    if (!useBlock) useBlock = p_73078_1_.getHeldItem().getItem().doesSneakBypassUse(p_73078_2_, p_73078_4_, p_73078_5_, p_73078_6_, p_73078_1_);
    boolean result = false;

    if (useBlock)
    {
        if (event.useBlock != Event.Result.DENY)
        {
            result = block.onBlockActivated(p_73078_2_, p_73078_4_, p_73078_5_, p_73078_6_, p_73078_1_, p_73078_7_, p_73078_8_, p_73078_9_, p_73078_10_);
        }
        else
        {
            thisPlayerMP.playerNetServerHandler.sendPacket(new S23PacketBlockChange(p_73078_4_, p_73078_5_, p_73078_6_, theWorld));
            result = event.useItem != Event.Result.ALLOW;
        }
    }

    if (p_73078_3_ != null && !result && event.useItem != Event.Result.DENY)
    {
        int meta = p_73078_3_.getItemDamage();
        int size = p_73078_3_.stackSize;
        result = p_73078_3_.tryPlaceItemIntoWorld(p_73078_1_, p_73078_2_, p_73078_4_, p_73078_5_, p_73078_6_, p_73078_7_, p_73078_8_, p_73078_9_, p_73078_10_);
        if (isCreative())
        {
            p_73078_3_.setItemDamage(meta);
            p_73078_3_.stackSize = size;
        }
        if (p_73078_3_.stackSize <= 0) ForgeEventFactory.onPlayerDestroyItem(thisPlayerMP, p_73078_3_);
    }

    /* Re-enable if this causes bukkit incompatibility, or re-write client side to only send a single packet per right click.
    if (par3ItemStack != null && ((!result && event.useItem != Event.Result.DENY) || event.useItem == Event.Result.ALLOW))
    {
        this.tryUseItem(thisPlayerMP, par2World, par3ItemStack);
    }*/
    return result;
}
 
開發者ID:xtrafrancyz,項目名稱:Cauldron,代碼行數:55,代碼來源:ItemInWorldManager.java

示例5: onBlockClicked

import net.minecraftforge.event.ForgeEventFactory; //導入方法依賴的package包/類
/**
 * if not creative, it calls destroyBlockInWorldPartially untill the block is broken first. par4 is the specific
 * side. tryHarvestBlock can also be the result of this call
 */
public void onBlockClicked(int par1, int par2, int par3, int par4)
{
    if (!this.gameType.isAdventure() || this.thisPlayerMP.isCurrentToolAdventureModeExempt(par1, par2, par3))
    {
        PlayerInteractEvent event = ForgeEventFactory.onPlayerInteract(thisPlayerMP, Action.LEFT_CLICK_BLOCK, par1, par2, par3, par4);
        if (event.isCanceled())
        {
            thisPlayerMP.playerNetServerHandler.sendPacketToPlayer(new Packet53BlockChange(par1, par2, par3, theWorld));
            return;
        }

        if (this.isCreative())
        {
            if (!this.theWorld.extinguishFire((EntityPlayer)null, par1, par2, par3, par4))
            {
                this.tryHarvestBlock(par1, par2, par3);
            }
        }
        else
        {
            this.initialDamage = this.curblockDamage;
            float f = 1.0F;
            int i1 = this.theWorld.getBlockId(par1, par2, par3);

            Block block = Block.blocksList[i1];

            if (block != null)
            {
                if (event.useBlock != Event.Result.DENY)
                {
                    block.onBlockClicked(theWorld, par1, par2, par3, thisPlayerMP);
                    theWorld.extinguishFire(thisPlayerMP, par1, par2, par3, par4);
                }
                else
                {
                    thisPlayerMP.playerNetServerHandler.sendPacketToPlayer(new Packet53BlockChange(par1, par2, par3, theWorld));
                }
                f = block.getPlayerRelativeBlockHardness(thisPlayerMP, thisPlayerMP.worldObj, par1, par2, par3);
            }

            if (event.useItem == Event.Result.DENY)
            {
                if (f >= 1.0f)
                {
                    thisPlayerMP.playerNetServerHandler.sendPacketToPlayer(new Packet53BlockChange(par1, par2, par3, theWorld));
                }
                return;
            }

            if (i1 > 0 && f >= 1.0F)
            {
                this.tryHarvestBlock(par1, par2, par3);
            }
            else
            {
                this.isDestroyingBlock = true;
                this.partiallyDestroyedBlockX = par1;
                this.partiallyDestroyedBlockY = par2;
                this.partiallyDestroyedBlockZ = par3;
                int j1 = (int)(f * 10.0F);
                this.theWorld.destroyBlockInWorldPartially(this.thisPlayerMP.entityId, par1, par2, par3, j1);
                this.durabilityRemainingOnBlock = j1;
            }
        }
    }
}
 
開發者ID:HATB0T,項目名稱:RuneCraftery,代碼行數:71,代碼來源:ItemInWorldManager.java

示例6: activateBlockOrUseItem

import net.minecraftforge.event.ForgeEventFactory; //導入方法依賴的package包/類
/**
 * Activate the clicked on block, otherwise use the held item. Args: player, world, itemStack, x, y, z, side,
 * xOffset, yOffset, zOffset
 */
public boolean activateBlockOrUseItem(EntityPlayer par1EntityPlayer, World par2World, ItemStack par3ItemStack, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
{
    PlayerInteractEvent event = ForgeEventFactory.onPlayerInteract(par1EntityPlayer, Action.RIGHT_CLICK_BLOCK, par4, par5, par6, par7);
    if (event.isCanceled())
    {
        thisPlayerMP.playerNetServerHandler.sendPacketToPlayer(new Packet53BlockChange(par4, par5, par6, theWorld));
        return false;
    }

    Item item = (par3ItemStack != null ? par3ItemStack.getItem() : null);
    if (item != null && item.onItemUseFirst(par3ItemStack, par1EntityPlayer, par2World, par4, par5, par6, par7, par8, par9, par10))
    {
        if (par3ItemStack.stackSize <= 0) ForgeEventFactory.onPlayerDestroyItem(thisPlayerMP, par3ItemStack);
        return true;
    }

    int i1 = par2World.getBlockId(par4, par5, par6);
    Block block = Block.blocksList[i1];
    boolean result = false;

    if (block != null && (!par1EntityPlayer.isSneaking() || ( par1EntityPlayer.getHeldItem() == null || par1EntityPlayer.getHeldItem().getItem().shouldPassSneakingClickToBlock(par2World, par4, par5, par6))))
    {
        if (event.useBlock != Event.Result.DENY)
        {
            result = block.onBlockActivated(par2World, par4, par5, par6, par1EntityPlayer, par7, par8, par9, par10);
        }
        else
        {
            thisPlayerMP.playerNetServerHandler.sendPacketToPlayer(new Packet53BlockChange(par4, par5, par6, theWorld));
            result = event.useItem != Event.Result.ALLOW;
        }
    }

    if (par3ItemStack != null && !result && event.useItem != Event.Result.DENY)
    {
        int meta = par3ItemStack.getItemDamage();
        int size = par3ItemStack.stackSize;
        result = par3ItemStack.tryPlaceItemIntoWorld(par1EntityPlayer, par2World, par4, par5, par6, par7, par8, par9, par10);
        if (isCreative())
        {
            par3ItemStack.setItemDamage(meta);
            par3ItemStack.stackSize = size;
        }
        if (par3ItemStack.stackSize <= 0) ForgeEventFactory.onPlayerDestroyItem(thisPlayerMP, par3ItemStack);
    }

    /* Re-enable if this causes bukkit incompatibility, or re-write client side to only send a single packet per right click.
    if (par3ItemStack != null && ((!result && event.useItem != Event.Result.DENY) || event.useItem == Event.Result.ALLOW))
    {
        this.tryUseItem(thisPlayerMP, par2World, par3ItemStack);
    }*/
    return result;
}
 
開發者ID:HATB0T,項目名稱:RuneCraftery,代碼行數:58,代碼來源:ItemInWorldManager.java

示例7: rightClick

import net.minecraftforge.event.ForgeEventFactory; //導入方法依賴的package包/類
private boolean rightClick(ChunkPosition pos){
    int xCoord = pos.chunkPosX;
    int yCoord = pos.chunkPosY;
    int zCoord = pos.chunkPosZ;

    ForgeDirection faceDir = ProgWidgetPlace.getDirForSides(((ISidedWidget)widget).getSides());
    EntityPlayer player = drone.getFakePlayer();
    World worldObj = drone.getWorld();
    int dx = faceDir.offsetX;
    int dy = faceDir.offsetY;
    int dz = faceDir.offsetZ;
    int x = xCoord /*+ dx*/;
    int y = yCoord /*+ dy*/;
    int z = zCoord /*+ dz*/;

    player.setPosition(x + 0.5, y + 0.5 - player.eyeHeight, z + 0.5);
    player.rotationPitch = faceDir.offsetY * -90;
    switch(faceDir){
        case NORTH:
            player.rotationYaw = 180;
            break;
        case SOUTH:
            player.rotationYaw = 0;
            break;
        case WEST:
            player.rotationYaw = 90;
            break;
        case EAST:
            player.rotationYaw = -90;
    }

    try {
        PlayerInteractEvent event = ForgeEventFactory.onPlayerInteract(player, Action.RIGHT_CLICK_AIR, x, y, z, faceDir.ordinal(), worldObj);
        if(event.isCanceled()) return false;

        Block block = worldObj.getBlock(x, y, z);

        ItemStack stack = player.getCurrentEquippedItem();
        if(stack != null && stack.getItem().onItemUseFirst(stack, player, worldObj, x, y, z, faceDir.ordinal(), dx, dy, dz)) return false;

        if(!worldObj.isAirBlock(x, y, z) && block.onBlockActivated(worldObj, x, y, z, player, faceDir.ordinal(), dx, dy, dz)) return false;

        if(stack != null) {
            boolean isGoingToShift = false;
            if(stack.getItem() instanceof ItemReed || stack.getItem() instanceof ItemRedstone) {
                isGoingToShift = true;
            }
            int useX = isGoingToShift ? xCoord : x;
            int useY = isGoingToShift ? yCoord : y;
            int useZ = isGoingToShift ? zCoord : z;
            if(stack.getItem().onItemUse(stack, player, worldObj, useX, useY, useZ, faceDir.ordinal(), dx, dy, dz)) return false;

            ItemStack copy = stack.copy();
            player.setCurrentItemOrArmor(0, stack.getItem().onItemRightClick(stack, worldObj, player));
            if(!copy.isItemEqual(stack)) return true;
        }
        return false;
    } catch(Throwable e) {
        Log.error("DroneAIBlockInteract crashed! Stacktrace: ");
        e.printStackTrace();
        return false;
    }
}
 
開發者ID:MineMaarten,項目名稱:PneumaticCraft,代碼行數:64,代碼來源:DroneAIBlockInteract.java


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