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


Java ForgeEventFactory類代碼示例

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


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

示例1: insertItem

import net.minecraftforge.event.ForgeEventFactory; //導入依賴的package包/類
@Nonnull
@Override
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
    EntityPlayer player = getPlayer();
    if (player == null || getFoodValue(stack) <= 0) return stack;
    if (!okToFeed(stack, player)) return stack;

    if (simulate) return ItemStack.EMPTY;

    int startValue = stack.getCount();
    ItemStack remainingItem = stack;
    while (stack.getCount() > 0) {
        remainingItem = stack.onItemUseFinish(player.world, player);
        remainingItem = ForgeEventFactory.onItemUseFinish(player, stack, 0, remainingItem);
        if (remainingItem.getCount() > 0 && (remainingItem != stack || remainingItem.getCount() != startValue)) {
            if (!player.inventory.addItemStackToInventory(remainingItem) && remainingItem.getCount() > 0) {
                player.dropItem(remainingItem, false);
            }
        }
        if (stack.getCount() == startValue) break;
    }
    return remainingItem.getCount() > 0 ? remainingItem : ItemStack.EMPTY;
}
 
開發者ID:TeamPneumatic,項目名稱:pnc-repressurized,代碼行數:24,代碼來源:TileEntityAerialInterface.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 (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

示例3: 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

示例4: 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

示例5: 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

示例6: onItemUseFinish

import net.minecraftforge.event.ForgeEventFactory; //導入依賴的package包/類
protected void onItemUseFinish()
{
	if (this.itemInUse != null)
	{
		updateItemUse(this.itemInUse, 16);
		int i = this.itemInUse.stackSize;
		ItemStack itemstack = this.itemInUse.onFoodEaten(this.worldObj, this);

		itemstack = ForgeEventFactory.onItemUseFinish(this, this.itemInUse, this.itemInUseCount, itemstack);
		if ((itemstack != this.itemInUse) || ((itemstack != null) && (itemstack.stackSize != i)))
		{
			this.inventory.mainInventory[this.inventory.currentItem] = itemstack;
			if ((itemstack != null) && (itemstack.stackSize == 0)) {
				this.inventory.mainInventory[this.inventory.currentItem] = null;
			}
		}
		clearItemInUse();
	}
}
 
開發者ID:4Space,項目名稱:4Space-5,代碼行數:20,代碼來源:EntityPlayer.java

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: update

import net.minecraftforge.event.ForgeEventFactory; //導入依賴的package包/類
@Override
public void update() {
	if(!worldObj.isRemote && !worldObj.isBlockPowered(pos) && worldObj.getTotalWorldTime() % breakModTime == 0 && 
			this.hasLPCell() && this.canDrawCellPower(breakLE)) {
		BlockPos check = this.pos.offset(EnumFacing.getFront(this.getBlockMetadata()));
		
		// make sure the block is valid and isn't unbreakable
		IBlockState checkState = worldObj.getBlockState(check);
		Block checkBlock = checkState.getBlock();
		if(checkBlock != null && !checkBlock.isAir(checkState, worldObj, check) && checkState.getBlockHardness(worldObj, check) >= 0) {
			List<ItemStack> drops = checkBlock.getDrops(this.worldObj, check, checkState, 0);
            float chance = ForgeEventFactory.fireBlockHarvesting(drops, this.worldObj, check, 
            		this.worldObj.getBlockState(check), 0, 1, false, null);
            if(random.nextFloat() <= chance) {
            	this.drawCellPower(breakLE);
            	worldObj.destroyBlock(check, true);
            }
		}
	}
}
 
開發者ID:sblectric,項目名稱:LightningCraft,代碼行數:21,代碼來源:TileEntityLightningBreaker.java

示例12: 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

示例13: 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

示例14: dropBlockAsItemWithChance

import net.minecraftforge.event.ForgeEventFactory; //導入依賴的package包/類
@Override
public void dropBlockAsItemWithChance(World p_149690_1_, int p_149690_2_, int p_149690_3_, int p_149690_4_, int p_149690_5_, float p_149690_6_, int p_149690_7_)
{
    if (!p_149690_1_.isRemote)
    {
        ArrayList<ItemStack> items = getDrops(p_149690_1_, p_149690_2_, p_149690_3_, p_149690_4_, p_149690_5_, p_149690_7_);
        p_149690_6_ = ForgeEventFactory.fireBlockHarvesting(items, p_149690_1_, this, p_149690_2_, p_149690_3_, p_149690_4_, p_149690_5_, p_149690_7_, p_149690_6_, false, harvesters.get());

        for (ItemStack item : items)
        {
            if (p_149690_1_.rand.nextFloat() <= p_149690_6_)
            {
                this.dropBlockAsItem(p_149690_1_, p_149690_2_, p_149690_3_, p_149690_4_, item);
            }
        }
    }
}
 
開發者ID:NovaViper,項目名稱:ZeroQuest,代碼行數:18,代碼來源:BlockNileGrainOre.java

示例15: 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


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