当前位置: 首页>>代码示例>>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;未经允许,请勿转载。