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


Java ItemStack.equals方法代碼示例

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


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

示例1: getEntity

import net.minecraft.item.ItemStack; //導入方法依賴的package包/類
public EntityLivingBase getEntity(ItemStack stack)
{
	if(stack.getItem() == Item.getItemFromBlock(Blocks.AIR)
			|| stack.equals(ItemStack.EMPTY))
	{
		this.entity = null;
		return null;
	}
	try
	{
		this.entity = (EntityLivingBase) ForgeRegistries.ENTITIES.getValue((ItemMonsterPlacer.getNamedIdFrom(stack))).newInstance(world);

	}
	catch (NullPointerException e) {
	}
	return this.entity;
}
 
開發者ID:kenijey,項目名稱:harshencastle,代碼行數:18,代碼來源:TileEntityHarshenSpawner.java

示例2: onUpdate

import net.minecraft.item.ItemStack; //導入方法依賴的package包/類
@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected)
{
	if(isOn(stack))
	{
		Shield sh = getShield(stack);
		if(entityIn instanceof EntityPlayer)
		{
			sh.update(stack, (EntityPlayer) entityIn);
			ItemStack active = EntityUtil.getActivePlayerShield((EntityPlayer) entityIn);
			ItemAnimaShield sI = (ItemAnimaShield) active.getItem();
			if(!active.equals(stack) && sI.isOn(active))
			{
				setOff(stack, (EntityPlayer) entityIn);
			}
		}
		if(!stack.isEmpty())
		{
			stack.getTagCompound().setTag("shield", sh.serialize());
			super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected);
		}

		if(worldIn.getTotalWorldTime() % 40 == 0)
			this.removeCharge(stack, 1);

		if(getCurrentCharge(stack) == 0 && entityIn instanceof EntityPlayer)
		{
			setOff(stack, (EntityPlayer) entityIn);
		}
	}
}
 
開發者ID:Lemonszz,項目名稱:Anima-Mundi,代碼行數:32,代碼來源:ItemAnimaShield.java

示例3: run

import net.minecraft.item.ItemStack; //導入方法依賴的package包/類
@Override
public void run() {
    try {
        while (!stopped) {
            // check to see if we've finished the book
            if(!parser.hasNext()) {
                this.status = Status.FINISHED;
                break;
            }

            sleep();

            // wait for screen
            if (MC.currentScreen != null) {
                this.status = Status.AWAITING_GUI_CLOSE;
                continue;
            }

            // search for empty book
            int slot = -1;
            ItemStack selected = null;
            for (int i = 0; i < InventoryPlayer.getHotbarSize(); i++) {
                ItemStack stack = getLocalPlayer().inventory.getStackInSlot(i);
                if (stack != null
                        && !stack.equals(ItemStack.EMPTY)
                        && stack.getItem() instanceof ItemWritableBook) {
                    slot = i;
                    selected = stack;
                    break;
                }
            }

            // make sure we found a book
            if (slot == -1) {
                this.status = Status.NEED_EMPTY_BOOKS_IN_HOTBAR;
                continue;
            }

            // set selected item to that slot
            while(getLocalPlayer().inventory.currentItem != slot) {
                getLocalPlayer().inventory.currentItem = slot;
                this.status = Status.CHANGING_HELD_ITEM;
                sleep();
            }

            final ItemStack item = selected;

            // open the book gui screen
            this.status = Status.OPENING_BOOK;
            MC.addScheduledTask(() -> getLocalPlayer().openBook(item, EnumHand.MAIN_HAND));

            // wait for gui to open
            while(!(MC.currentScreen instanceof GuiScreenBook)) sleep();

            // send book to server
            this.status = Status.WRITING_BOOK;
            MC.addScheduledTask(() -> {
                sendBook(item);
                MC.displayGuiScreen(null);
            });

            // wait for screen to close
            while (MC.currentScreen != null) sleep();
        }
    } catch (Throwable t) {
        this.status = Status.ERROR;
    } finally {
        if(finalListener != null) {
            finalListener.accept(this);
            finalListener = null;
        }

        // set stopped to true
        this.stopped = true;

        if(!this.status.equals(Status.FINISHED) && !this.status.equals(Status.ERROR))
            this.status = Status.STOPPED;
    }
}
 
開發者ID:fr1kin,項目名稱:ForgeHax,代碼行數:80,代碼來源:BookBot.java

示例4: interact

import net.minecraft.item.ItemStack; //導入方法依賴的package包/類
@SubscribeEvent
public static void interact(EntityInteract event) {
	
	ItemStack itemstack = event.getItemStack();
	EntityPlayer player = event.getEntityPlayer();
	Entity entity = event.getTarget();
	World world = event.getWorld();
	
	if (world.isRemote || itemstack.equals(ItemStack.EMPTY)) {
		
		return;
		
	}

	if ( entity instanceof EntityOcelot && ((EntityOcelot) entity).isSitting() && !entity.isDead && itemstack.getItem() instanceof ItemShears) {
		
		if (itemstack.getItemDamage() > 1) {
			
			itemstack.damageItem(2, player);
			world.spawnEntity(new EntityItem(world, entity.posX, entity.posY, entity.lastTickPosZ, new ItemStack(ModItems.itemcathair)));
			
		} else {
			
			itemstack.damageItem(1, player);
			if (Math.random() > .5) {
				
				world.spawnEntity(new EntityItem(world, entity.posX, entity.posY, entity.lastTickPosZ, new ItemStack(ModItems.itemcathair)));
				
			}
			
		}
		
		if (itemstack.getMaxDamage() <= -1) {
			
			entity.onKillCommand();
			
		} else {
		
			if (100 / (((itemstack.getMaxDamage() + 1) / (itemstack.getItemDamage() + 1))) * Math.random() * 2 >= Math.random() * 50) {
				
				DamageSource killedByShears = new ModDeath("killedByShears", player);
				
				entity.attackEntityFrom(killedByShears, 1);
			
			}
			
		}
		
		event.setCanceled(true);
		
	}
	
}
 
開發者ID:Bedrockbreaker,項目名稱:rtap,代碼行數:54,代碼來源:ModEvents.java


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