Java Code Examples for net.minecraft.init.Items.NAME_TAG

The following are Jave code examples for showing how to use NAME_TAG of the net.minecraft.init.Items class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Bewitchment   File: BlockApiary.java   View Source Code Vote up 5 votes
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
	if (!worldIn.isRemote) {
		final TileEntity tile = worldIn.getTileEntity(pos);
		if (tile == null || !(tile instanceof TileApiary)) return false;

		ItemStack heldItem = playerIn.getHeldItem(hand);
		if (!heldItem.isEmpty() && heldItem.getItem() == Items.NAME_TAG) {
			((TileApiary) tile).setCustomInventoryName(heldItem.getDisplayName());
		} else {
			playerIn.openGui(Bewitchment.instance, LibGui.APIARY.ordinal(), worldIn, pos.getX(), pos.getY(), pos.getZ());
		}
	}
	return true;
}
 
Example 2
Project: Bewitchment   File: BlockOven.java   View Source Code Vote up 5 votes
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
	if (!worldIn.isRemote) {
		final TileEntity tile1 = worldIn.getTileEntity(pos);
		if (tile1 == null || !(tile1 instanceof TileOven)) return false;

		ItemStack heldItem = playerIn.getHeldItem(hand);
		if (!heldItem.isEmpty() && heldItem.getItem() == Items.NAME_TAG) {
			((TileOven) tile1).setCustomName(heldItem.getDisplayName());
		} else {
			playerIn.openGui(Bewitchment.instance, LibGui.OVEN.ordinal(), worldIn, pos.getX(), pos.getY(), pos.getZ());
		}
	}
	return true;
}
 
Example 3
Project: Backmemed   File: EntityVillager.java   View Source Code Vote up 5 votes
public boolean processInteract(EntityPlayer player, EnumHand hand)
{
    ItemStack itemstack = player.getHeldItem(hand);
    boolean flag = itemstack.getItem() == Items.NAME_TAG;

    if (flag)
    {
        itemstack.interactWithEntity(player, this, hand);
        return true;
    }
    else if (!this.func_190669_a(itemstack, this.getClass()) && this.isEntityAlive() && !this.isTrading() && !this.isChild())
    {
        if (this.buyingList == null)
        {
            this.populateBuyingList();
        }

        if (hand == EnumHand.MAIN_HAND)
        {
            player.addStat(StatList.TALKED_TO_VILLAGER);
        }

        if (!this.world.isRemote && !this.buyingList.isEmpty())
        {
            this.setCustomer(player);
            player.displayVillagerTradeGui(this);
        }
        else if (this.buyingList.isEmpty())
        {
            return super.processInteract(player, hand);
        }

        return true;
    }
    else
    {
        return super.processInteract(player, hand);
    }
}
 
Example 4
Project: Backmemed   File: EntityPig.java   View Source Code Vote up 5 votes
public boolean processInteract(EntityPlayer player, EnumHand hand)
{
    if (!super.processInteract(player, hand))
    {
        ItemStack itemstack = player.getHeldItem(hand);

        if (itemstack.getItem() == Items.NAME_TAG)
        {
            itemstack.interactWithEntity(player, this, hand);
            return true;
        }
        else if (this.getSaddled() && !this.isBeingRidden())
        {
            if (!this.world.isRemote)
            {
                player.startRiding(this);
            }

            return true;
        }
        else if (itemstack.getItem() == Items.SADDLE)
        {
            itemstack.interactWithEntity(player, this, hand);
            return true;
        }
        else
        {
            return false;
        }
    }
    else
    {
        return true;
    }
}
 
Example 5
Project: Clef   File: BlockInstrumentPlayer.java   View Source Code Vote up 4 votes
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
    TileEntity te = worldIn.getTileEntity(pos);
    if(te instanceof TileEntityInstrumentPlayer)
    {
        TileEntityInstrumentPlayer player = (TileEntityInstrumentPlayer)te;
        boolean hasSlot = false;
        ItemStack is = playerIn.getHeldItemMainhand();
        if(is.getItem() == Clef.itemInstrument && !playerIn.isSneaking())
        {
            if(is.getTagCompound() == null && !worldIn.isRemote)
            {
                InstrumentLibrary.assignRandomInstrument(is);
            }
            //Find a free slot
            for(int i = 0; i < player.getSizeInventory(); i++)
            {
                ItemStack is1 = player.getStackInSlot(i);
                if(is1.isEmpty())
                {
                    hasSlot = true;
                    worldIn.playSound(null, pos.getX() + 0.5D, pos.getY() + 1D, pos.getZ() + 0.5D, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((worldIn.rand.nextFloat() - worldIn.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
                    if(!worldIn.isRemote)
                    {
                        player.setInventorySlotContents(i, is);
                        player.markDirty();
                        playerIn.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
                        playerIn.inventory.markDirty();
                        worldIn.notifyBlockUpdate(pos, state, state, 3);
                    }
                    break;
                }
            }
        }
        else if(is.getItem() == Items.NAME_TAG && is.hasDisplayName())
        {
            boolean full = true;
            for(int i = 0; i < 9 ; i++)
            {
                if(player.getStackInSlot(i).isEmpty())
                {
                    full = false;
                    break;
                }
            }
            if(!full)
            {
                return false;
            }
            if(worldIn.isRemote)
            {
                for(Instrument instrument : InstrumentLibrary.instruments)
                {
                    if(instrument.info.itemName.equalsIgnoreCase(is.getDisplayName()))
                    {
                        Clef.channel.sendToServer(new PacketCreateInstrument(instrument.info.itemName, pos));
                        break;
                    }
                }
            }
            return true;
        }
        if(!hasSlot && !player.justCreatedInstrument)
        {
            FMLNetworkHandler.openGui(playerIn, Clef.instance, 0, worldIn, pos.getX(), pos.getY(), pos.getZ());
        }
        return true;
    }
    return false;
}
 
Example 6
Project: Clef   File: PacketCreateInstrument.java   View Source Code Vote up 4 votes
@Override
public void execute(Side side, EntityPlayer player)
{
    if(Clef.config.creatableInstruments == 0)
    {
        return;
    }

    TileEntity te = player.world.getTileEntity(pos);
    if(te instanceof TileEntityInstrumentPlayer)
    {
        TileEntityInstrumentPlayer player1 = (TileEntityInstrumentPlayer)te;
        boolean full = true;
        for(int i = 0; i < 9 ; i++)
        {
            if(player1.getStackInSlot(i) == null)
            {
                full = false;
                break;
            }
        }
        if(full)
        {
            ItemStack is1 = player.getHeldItemMainhand();
            if(is1.getItem() == Items.NAME_TAG && is1.hasDisplayName())
            {
                Instrument ins = null;
                for(Instrument instrument : InstrumentLibrary.instruments)
                {
                    if(instrument.info.itemName.equals(instrumentName))
                    {
                        ins = instrument;
                        break;
                    }
                }
                if(ins == null)
                {
                    if(Clef.config.creatableInstruments == 1 || Clef.config.creatableInstruments == 3)
                    {
                        InstrumentLibrary.requestInstrument(instrumentName, player);
                    }
                }
                else if(Clef.config.creatableInstruments < 2)
                {
                    return;
                }

                for(int i = 0; i < 9; i++)
                {
                    player1.setInventorySlotContents(i, null);
                }
                ItemStack is = new ItemStack(Clef.itemInstrument, 1, 0);
                NBTTagCompound tag = new NBTTagCompound();
                tag.setString("itemName", instrumentName);
                is.setTagCompound(tag);
                InventoryHelper.spawnItemStack(player.world, pos.getX() + 0.5D, pos.getY() + 1D, pos.getZ() + 0.5D, is);
                player.world.playSound(null, pos.getX() + 0.5D, pos.getY() + 1D, pos.getZ() + 0.5D, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((player.world.rand.nextFloat() - player.world.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
                player1.markDirty();
                player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
                player.inventory.markDirty();
                player1.justCreatedInstrument = true;
            }
        }
    }
    return;
}
 
Example 7
Project: Backmemed   File: EntityArmorStand.java   View Source Code Vote up 4 votes
/**
 * Applies the given player interaction to this Entity.
 */
public EnumActionResult applyPlayerInteraction(EntityPlayer player, Vec3d vec, EnumHand stack)
{
    ItemStack itemstack = player.getHeldItem(stack);

    if (!this.hasMarker() && itemstack.getItem() != Items.NAME_TAG)
    {
        if (!this.world.isRemote && !player.isSpectator())
        {
            EntityEquipmentSlot entityequipmentslot = EntityLiving.getSlotForItemStack(itemstack);

            if (itemstack.func_190926_b())
            {
                EntityEquipmentSlot entityequipmentslot1 = this.func_190772_a(vec);
                EntityEquipmentSlot entityequipmentslot2 = this.isDisabled(entityequipmentslot1) ? entityequipmentslot : entityequipmentslot1;

                if (this.func_190630_a(entityequipmentslot2))
                {
                    this.swapItem(player, entityequipmentslot2, itemstack, stack);
                }
            }
            else
            {
                if (this.isDisabled(entityequipmentslot))
                {
                    return EnumActionResult.FAIL;
                }

                if (entityequipmentslot.getSlotType() == EntityEquipmentSlot.Type.HAND && !this.getShowArms())
                {
                    return EnumActionResult.FAIL;
                }

                this.swapItem(player, entityequipmentslot, itemstack, stack);
            }

            return EnumActionResult.SUCCESS;
        }
        else
        {
            return EnumActionResult.SUCCESS;
        }
    }
    else
    {
        return EnumActionResult.PASS;
    }
}