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


Java ForgeEventFactory.onPlayerDestroyItem方法代碼示例

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


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

示例1: onItemRightClick

import net.minecraftforge.event.ForgeEventFactory; //導入方法依賴的package包/類
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
{
    ItemStack stack = player.getHeldItem(hand);
    
    if (isCooked)
    {
        player.inventory.addItemStackToInventory(new ItemStack(RegisterItems.marshmallowCooked));
        player.inventory.addItemStackToInventory(new ItemStack(RegisterItems.roastingStick));
        stack.setCount(stack.getCount() - 1);
    }
    else
    {
        player.inventory.addItemStackToInventory(new ItemStack(RegisterItems.marshmallow));
        player.inventory.addItemStackToInventory(new ItemStack(RegisterItems.roastingStick));
        stack.setCount(stack.getCount() - 1);
    }

    if (stack.getCount() <= 0)
    {
        player.inventory.setItemStack(ItemStack.EMPTY);
        ForgeEventFactory.onPlayerDestroyItem(player, stack, hand);
    }
    player.inventoryContainer.detectAndSendChanges();
    return ActionResult.newResult(EnumActionResult.PASS, stack);
}
 
開發者ID:einsteinsci,項目名稱:BetterBeginningsReborn,代碼行數:27,代碼來源:ItemRoastingStickMallow.java

示例2: onItemRightClick

import net.minecraftforge.event.ForgeEventFactory; //導入方法依賴的package包/類
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
{
    ItemStack stack = player.getHeldItem(hand);
    
    if (player.inventory.hasItemStack(new ItemStack(RegisterItems.marshmallow)))
    {
        stack.setCount(stack.getCount() - 1);
        ItemStack mallowStick = new ItemStack(RegisterItems.roastingStickRawMallow);
        if (!player.inventory.addItemStackToInventory(mallowStick))
        {
            EntityItem drop = new EntityItem(world, player.posX, player.posY, player.posZ, mallowStick);

            world.spawnEntity(drop);
        }

        stack.setCount(stack.getCount() - 1); // Why is this done twice?
        if (stack.getCount() <= 0)
        {
            player.inventory.setItemStack(ItemStack.EMPTY);
            ForgeEventFactory.onPlayerDestroyItem(player, stack, hand);
        }
    }
    player.inventoryContainer.detectAndSendChanges();
    return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
}
 
開發者ID:einsteinsci,項目名稱:BetterBeginningsReborn,代碼行數:27,代碼來源:ItemRoastingStick.java

示例3: getContainerItem

import net.minecraftforge.event.ForgeEventFactory; //導入方法依賴的package包/類
public static ItemStack getContainerItem(ItemStack stack)
{
    if (stack == null) return null;

    if (stack.getItem().hasContainerItem(stack))
    {
        stack = stack.getItem().getContainerItem(stack);
        if (stack != null && stack.isItemStackDamageable() && stack.getMetadata() > stack.getMaxDamage())
        {
            ForgeEventFactory.onPlayerDestroyItem(craftingPlayer.get(), stack, null);
            return null;
        }
        return stack;
    }
    return null;
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:17,代碼來源:ForgeHooks.java

示例4: damageShield

import net.minecraftforge.event.ForgeEventFactory; //導入方法依賴的package包/類
/** Fixed vanilla code */
private void damageShield(EntityPlayer owner, float damage) {
	int i = 1 + MathHelper.floor(damage);
	owner.getActiveItemStack().damageItem(i, owner);

	if (owner.getActiveItemStack().getCount() <= 0) {
		EnumHand enumhand = owner.getActiveHand();
		ForgeEventFactory.onPlayerDestroyItem(owner, owner.getActiveItemStack(), enumhand);

		if(enumhand == EnumHand.MAIN_HAND) {
			owner.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, ItemStack.EMPTY);
		} else {
			owner.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, ItemStack.EMPTY);
		}

		owner.resetActiveHand();
		owner.playSound(SoundEvents.ITEM_SHIELD_BREAK, 0.8F, 0.8F + owner.world.rand.nextFloat() * 0.4F);
	}
}
 
開發者ID:sblectric,項目名稱:AdvancedCombat,代碼行數:20,代碼來源:CustomShieldHandler.java

示例5: breakBlock

import net.minecraftforge.event.ForgeEventFactory; //導入方法依賴的package包/類
public void breakBlock(BlockPos pos) {
    IBlockState state = this.blockSystem.getBlockState(pos);
    Block block = state.getBlock();
    if (this.blockSystem.getMainWorld().isRemote) {
        this.blockSystem.playEvent(2001, pos, Block.getStateId(state));
        if (BlockSystems.PROXY.isClientPlayer(this.player)) {
            BlockSystems.NETWORK_WRAPPER.sendToServer(new BreakBlockMessage(this.player, this.blockSystem, pos, BreakBlockMessage.BreakState.BREAK));
        }
    }
    if (!this.player.capabilities.isCreativeMode) {
        ItemStack heldItem = this.player.getHeldItemMainhand();
        if (heldItem != null) {
            heldItem.onBlockDestroyed(this.blockSystem, state, pos, this.player);
            if (heldItem.stackSize <= 0) {
                ForgeEventFactory.onPlayerDestroyItem(this.player, heldItem, EnumHand.MAIN_HAND);
                this.player.setHeldItem(EnumHand.MAIN_HAND, null);
            }
        }
        block.harvestBlock(this.blockSystem, this.player, pos, state, this.blockSystem.getTileEntity(pos), heldItem);
    }
    boolean removed = block.removedByPlayer(state, this.blockSystem, pos, this.player, false);
    if (removed) {
        block.onBlockDestroyedByPlayer(this.blockSystem, pos, state);
    }
}
 
開發者ID:gegy1000,項目名稱:BlockSystems,代碼行數:26,代碼來源:BlockSystemPlayerHandler.java

示例6: onReceiveServer

import net.minecraftforge.event.ForgeEventFactory; //導入方法依賴的package包/類
@Override
public void onReceiveServer(MinecraftServer server, WorldServer world, EntityPlayerMP player, MessageContext context) {
    BlockSystem blockSystem = BlockSystems.PROXY.getBlockSystemHandler(world).getBlockSystem(this.blockSystem);
    if (blockSystem != null) {
        IBlockState state = blockSystem.getBlockState(this.position);
        ItemStack heldItem = player.getHeldItem(this.hand);
        if (!state.getBlock().onBlockActivated(blockSystem, this.position, state, player, this.hand, heldItem, this.side, this.hitX, this.hitY, this.hitZ)) {
            if (heldItem != null) {
                int size = heldItem.stackSize;
                heldItem.onItemUse(player, blockSystem, this.position, this.hand, this.side, this.hitX, this.hitY, this.hitZ);
                if (player.capabilities.isCreativeMode && heldItem.stackSize < size) {
                    heldItem.stackSize = size;
                }
                if (heldItem.stackSize <= 0) {
                    player.setHeldItem(this.hand, null);
                    ForgeEventFactory.onPlayerDestroyItem(player, heldItem, this.hand);
                }
            }
        }
    }
}
 
開發者ID:gegy1000,項目名稱:BlockSystems,代碼行數:22,代碼來源:InteractBlockMessage.java

示例7: transform

import net.minecraftforge.event.ForgeEventFactory; //導入方法依賴的package包/類
@Override
public ItemStack transform(ItemStack input, EntityPlayer craftingPlayer) {
    if(!input.isItemStackDamageable()) return input;

    // Shockingly, there's already code to prevent us from going below 0 (undamaged)
    int newDamage = input.getItemDamage()+by;
    input.setItemDamage(newDamage);

    // Check if we've destroyed it.
    if (input.getMetadata() > input.getMaxDamage())
    {
        ForgeEventFactory.onPlayerDestroyItem(craftingPlayer, input, null);
        return null;
    }
    return input;
}
 
開發者ID:legendblade,項目名稱:CraftingHarmonics,代碼行數:17,代碼來源:DamageOnCraft.java

示例8: attackEvent

import net.minecraftforge.event.ForgeEventFactory; //導入方法依賴的package包/類
@SubscribeEvent
public void attackEvent (LivingAttackEvent e) {
    if (e.getEntityLiving().getActiveItemStack() == null)
        return;
    final ItemStack stack = e.getEntityLiving().getActiveItemStack();
    if (stack.getItem() instanceof ItemCustomShield && e.getAmount() > 0.0f) {
        final int i = 1 + MathHelper.floor(e.getAmount());
        stack.damageItem(i, e.getEntityLiving());
        if (stack.stackSize <= 0) {
            final EnumHand enumhand = e.getEntityLiving().getActiveHand();
            if (e.getEntityLiving() instanceof EntityPlayer)
                ForgeEventFactory.onPlayerDestroyItem((EntityPlayer) e.getEntityLiving(), stack, enumhand);
            e.getEntityLiving().setItemStackToSlot(enumhand == EnumHand.MAIN_HAND ? EntityEquipmentSlot.MAINHAND : EntityEquipmentSlot.OFFHAND, null);
            if (e.getEntityLiving().getEntityWorld().isRemote)
                e.getEntityLiving().playSound(SoundEvents.BLOCK_ANVIL_BREAK, 0.8F, 0.8F + e.getEntityLiving().getEntityWorld().rand.nextFloat() * 0.4F);
        }
    }
}
 
開發者ID:MinecraftModDevelopmentMods,項目名稱:MMDLib-old,代碼行數:19,代碼來源:ForgeEventHandler.java

示例9: processRightClick

import net.minecraftforge.event.ForgeEventFactory; //導入方法依賴的package包/類
/**
 * Handles right clicking of an item
 */
public EnumActionResult processRightClick(ItemStack stack, EnumHand hand) {
    if (getSettler().getCooldownTracker().hasCooldown(stack.getItem())) {
        return EnumActionResult.PASS;
    } else {
        EnumActionResult eventResult = ForgeHooks.onItemRightClick(getSettler().getFakePlayerImplementation(), hand);
        if (eventResult != null) {
            return eventResult;
        }
        int stackSize = stack.getCount();
        int meta = stack.getMetadata();
        ActionResult<ItemStack> result = stack.useItemRightClick(getWorld(), getSettler().getFakePlayerImplementation(), hand);
        ItemStack newStack = result.getResult();
        if (newStack == stack && newStack.getCount() == stackSize && newStack.getMaxItemUseDuration() <= 0 && newStack.getMetadata() == meta) {
            return result.getType();
        } else {
            getSettler().setHeldItem(hand, newStack);
            if (newStack.isEmpty()) {
                getSettler().setHeldItem(hand, ItemStack.EMPTY);
                ForgeEventFactory.onPlayerDestroyItem(getSettler().getFakePlayerImplementation(), newStack, hand);
            }
        }
        return result.getType();
    }
}
 
開發者ID:InfinityRaider,項目名稱:SettlerCraft,代碼行數:28,代碼來源:SettlerInteractionController.java

示例10: onMessage

import net.minecraftforge.event.ForgeEventFactory; //導入方法依賴的package包/類
@Override
public IMessage onMessage(SculptureOperationMessage message,
        MessageContext ctx) {

  World w = ctx.getServerHandler().playerEntity.worldObj;
  if (Operations.validOperation(w, message.x, message.y, message.z, message.pos, message.flags)) {
    Operations.applyOperation(w, message.x, message.y, message.z, message.pos, message.flags, message.block, message.meta);
  }

  EntityPlayer ep = ctx.getServerHandler().playerEntity;
  ItemStack is = ep.getCurrentEquippedItem();

  if ((message.flags & Operations.DAMAGE) != 0) {
    is.damageItem(1, ep);
  } else if ((Operations.CONSUME & message.flags) != 0) {
    if (!ep.capabilities.isCreativeMode) {
      is.stackSize--;
      if (is.stackSize <= 0) {
        ForgeEventFactory.onPlayerDestroyItem(ep, is);
        ep.inventory.mainInventory[ep.inventory.currentItem] = null;
      }
    }
  }

  return null;
}
 
開發者ID:twothe,項目名稱:DaVincing,代碼行數:27,代碼來源:SculptureOperationMessage.java

示例11: onMessage

import net.minecraftforge.event.ForgeEventFactory; //導入方法依賴的package包/類
@Override
public IMessage onMessage(SculptureOperationMessage message,
		MessageContext ctx) {
	
	World w = ctx.getServerHandler().playerEntity.worldObj;
	if(Operations.validOperation(w, message.x, message.y, message.z, message.pos, message.flags))
		Operations.applyOperation(w, message.x, message.y, message.z, message.pos, message.flags, message.block, message.meta);
	
	EntityPlayer ep = ctx.getServerHandler().playerEntity;
	ItemStack is = ep.getCurrentEquippedItem();
	
	if((message.flags & Operations.DAMAGE) > 0)
		is.damageItem(1, ep);
	else if((Operations.CONSUME & message.flags) > 0){
		if(!ep.capabilities.isCreativeMode){
			is.stackSize--;
			if(is.stackSize <= 0){
				ForgeEventFactory.onPlayerDestroyItem(ep,is);
				ep.inventory.mainInventory[ep.inventory.currentItem] = null;
			}
		}
	}				
	
	return null;
}
 
開發者ID:hypercross,項目名稱:minepainter,代碼行數:26,代碼來源:SculptureOperationMessage.java

示例12: placeTorch

import net.minecraftforge.event.ForgeEventFactory; //導入方法依賴的package包/類
public static boolean placeTorch(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float xOffset, float yOffset, float zOffset) {
    for (int i = 0; i < player.inventory.mainInventory.length; i++) {
        ItemStack torchStack = player.inventory.mainInventory[i];
        if (torchStack == null || !torchStack.getUnlocalizedName().toLowerCase().contains("torch")) continue;
        Item item = torchStack.getItem();
        if (!(item instanceof ItemBlock)) continue;
        int oldMeta = torchStack.getItemDamage();
        int oldSize = torchStack.stackSize;
        boolean result = torchStack.tryPlaceItemIntoWorld(player, world, x, y, z, side, xOffset, yOffset, zOffset);
        if (player.capabilities.isCreativeMode) {
            torchStack.setItemDamage(oldMeta);
            torchStack.stackSize = oldSize;
        } else if (torchStack.stackSize <= 0) {
            ForgeEventFactory.onPlayerDestroyItem(player, torchStack);
            player.inventory.mainInventory[i] = null;
        }
        if (result) return true;
    }
    return false;
}
 
開發者ID:TeamAmeriFrance,項目名稱:Electro-Magic-Tools,代碼行數:21,代碼來源:RandomHelper.java

示例13: damageAxe

import net.minecraftforge.event.ForgeEventFactory; //導入方法依賴的package包/類
private ItemStack damageAxe(ItemStack stack) {
    if (stack.attemptDamageItem(1, random)) {
        ForgeEventFactory.onPlayerDestroyItem(ForgeHooks.getCraftingPlayer(), stack, null);
        return null;
    }

    return stack;
}
 
開發者ID:droidicus,項目名稱:AquaRegia,代碼行數:9,代碼來源:ShapelessCuttingRecipe.java

示例14: damageItem

import net.minecraftforge.event.ForgeEventFactory; //導入方法依賴的package包/類
private ItemStack damageItem(ItemStack stack) {
	if (stack.attemptDamageItem(1, random)) {
		ForgeEventFactory.onPlayerDestroyItem(ForgeHooks.getCraftingPlayer(), stack, null);
		return null;
	}

	return stack;
}
 
開發者ID:WolfieWaffle,項目名稱:Survivalist-Lighting,代碼行數:9,代碼來源:ShapelessDamageRecipe.java

示例15: onItemRightClick

import net.minecraftforge.event.ForgeEventFactory; //導入方法依賴的package包/類
public boolean onItemRightClick(EntityPlayer player, EnumHand hand) {
    boolean success = false;
    success |= this.interact(this.get(this.getMousedOver(player), player), player, hand);
    ItemStack heldItem = player.getHeldItem(hand);
    if (heldItem != null) {
        int prevSize = heldItem.stackSize;
        ActionResult<ItemStack> result = heldItem.useItemRightClick(player.world, player, hand);
        if (result.getType() != EnumActionResult.SUCCESS) {
            for (Map.Entry<Integer, BlockSystem> blockSystem : this.blockSystems.entrySet()) {
                result = heldItem.useItemRightClick(blockSystem.getValue(), player, hand);
                if (result.getType() == EnumActionResult.SUCCESS) {
                    break;
                }
            }
        }
        success |= result.getType() == EnumActionResult.SUCCESS;
        ItemStack output = result.getResult();
        if (output != heldItem || output.stackSize != prevSize) {
            if (player.capabilities.isCreativeMode && output.stackSize < prevSize) {
                output.stackSize = prevSize;
            }
            player.setHeldItem(hand, output);
            if (output.stackSize <= 0) {
                player.setHeldItem(hand, null);
                ForgeEventFactory.onPlayerDestroyItem(player, output, hand);
            }
        }
    }
    return success;
}
 
開發者ID:gegy1000,項目名稱:BlockSystems,代碼行數:31,代碼來源:ServerBlockSystemHandler.java


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