Java Code Examples for net.minecraft.item.ItemStack.getItemDamage()

The following are Jave code examples for showing how to use getItemDamage() of the net.minecraft.item.ItemStack 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: HeroUtils   File: RecipeInputOreDict.java   View Source Code Vote up 6 votes
@Override
public boolean matches(ItemStack subject) {
	List<ItemStack> inputs = getOres();
	boolean useOreStackMeta = (meta == null);
	Item subjectItem = subject.getItem();
	int subjectMeta = subject.getItemDamage();

	for (ItemStack oreStack : inputs) {
		Item oreItem = oreStack.getItem();
		if (oreItem == null) continue; // ignore invalid

		int metaRequired = useOreStackMeta ? oreStack.getItemDamage() : meta;

		if (subjectItem == oreItem &&
				(subjectMeta == metaRequired || metaRequired == OreDictionary.WILDCARD_VALUE)) {
			return true;
		}
	}

	return false;
}
 
Example 2
Project: pnc-repressurized   File: NetworkConnectionPlayerHandler.java   View Source Code Vote up 6 votes
@Override
protected void onSlotHack(int slot, boolean nuked) {
    if (!nuked && gui instanceof GuiSecurityStationHacking) {
        ((GuiSecurityStationHacking) gui).onSlotHack(slot);
    }
    ItemStack stack = station.getPrimaryInventory().getStackInSlot(slot);
    if (stack.getItemDamage() == ItemNetworkComponents.NETWORK_REGISTRY || stack.getItemDamage() == ItemNetworkComponents.DIAGNOSTIC_SUBROUTINE) {
        hackedSuccessfully = true;
        EntityPlayer player = FMLClientHandler.instance().getClient().player;
        NetworkHandler.sendToServer(new PacketSecurityStationAddHacker(station, player.getName()));
        FMLClientHandler.instance().getClient().player.closeScreen();
        player.sendStatusMessage(new TextComponentString(TextFormatting.GREEN + "Hacking successful! This Security Station now doesn't protect the area any longer!"), false);
        if (gui instanceof GuiSecurityStationHacking)
            ((GuiSecurityStationHacking) gui).removeUpdatesOnConnectionHandlers();
    }
}
 
Example 3
Project: minecraft-quiverbow   File: CoinTosser.java   View Source Code Vote up 5 votes
@Override
public String getModelTexPath(ItemStack stack)	// The model texture path
{
	if (stack.getItemDamage() >= stack.getMaxDamage()) { return "CoinTosser_empty"; }	// Empty
	if (this.getCooldown(stack) > 0) { return "CoinTosser_hot"; }

	return "CoinTosser";
}
 
Example 4
Project: Bewitchment   File: TileApiary.java   View Source Code Vote up 5 votes
@Override
public void update() {
	if (!world.isRemote) {
		++tick;
		final ItemStack bee = getStackInSlot(0);
		if (!bee.isEmpty() && bee.getItemDamage() < 35) {
			lookForFlowers();
			if (tick % 60 == 0 && world.rand.nextBoolean()) {
				world.playSound(null, pos, WitchSoundEvents.BUZZ, SoundCategory.BLOCKS, 0.1F, 1F);
			}
			if (flowerCount > 0) {
				if (world.rand.nextInt(3) == 0 && tick % (GEN - flowerCount * 3) == 0) {
					for (int i = 1; i < 16; i++) {
						if (!getStackInSlot(i).isEmpty()) {
							bee.attemptDamageItem(1, world.rand, player);
							bonemealArea();

							itemStacks.set(i, randomItem());
							break;
						}
					}
				}
				flowerCount = 0;
			}
		}
	}
}
 
Example 5
Project: minecraft-quiverbow   File: Crossbow_Blaze.java   View Source Code Vote up 5 votes
@Override
public String getModelTexPath(ItemStack stack)	// The model texture path
{
	if (stack.getItemDamage() >= stack.getMaxDamage()) { return "CrossbowBlaze_empty"; }		// empty

	return "CrossbowBlaze";	// Regular
}
 
Example 6
Project: pnc-repressurized   File: PacketUpdateSearchStack.java   View Source Code Vote up 5 votes
public PacketUpdateSearchStack(ItemStack stack) {
    if (stack != null) {
        itemId = Item.getIdFromItem(stack.getItem());
        itemDamage = stack.getItemDamage();
    } else {
        itemId = itemDamage = -1;
    }
}
 
Example 7
Project: Mods   File: TileEntityAmmoFurnace.java   View Source Code Vote up 5 votes
/**
 * Returns true if the furnace can smelt an item, i.e. has a source item,
 * destination stack isn't full, etc.
 */
private boolean canSmelt() {
	int[] ammoTypesCount = new int[ItemAmmo.AMMO_TYPES.length];
	for (int i = 0; i < 9; i++) {
		ItemStack base = this.furnaceItemStacks.get(i);
		// System.out.println("Base: "+i+" "+base+"
		// "+ItemAmmo.AMMO_RECIPES[base.getItemDamage()]);
		if (base != null && base.getMetadata() < TF2CraftingManager.AMMO_RECIPES.length 
				&& base.getItem() instanceof ItemAmmo && !(base.getItem() instanceof ItemFireAmmo)
				&& TF2CraftingManager.AMMO_RECIPES[base.getItemDamage()] != null) {
			/*
			 * &&
			 * base.getCount()>=ItemAmmo.AMMO_RECIPES[base.getItemDamage()].
			 * getRecipeOutput().getCount()){
			 */
			ammoTypesCount[base.getItemDamage()] += base.getCount();
			if (ammoTypesCount[base.getItemDamage()] >= MathHelper.ceil(
					TF2CraftingManager.AMMO_RECIPES[base.getItemDamage()].getRecipeOutput().getCount() * 1.2f)) {
				this.ammoSmeltType = base.getItemDamage();
				return true;
			}
		}
		/*
		 * ItemStack itemstack =
		 * FurnaceRecipes.instance().getSmeltingResult(this.
		 * furnaceItemStacks[0]); if (itemstack == null) return false; if
		 * (this.furnaceItemStacks[2] == null) return true; if
		 * (!this.furnaceItemStacks[2].isItemEqual(itemstack)) return false;
		 * int result = furnaceItemStacks[2].getCount() +
		 * itemstack.getCount(); return result <= getInventoryStackLimit() &&
		 * result <= this.furnaceItemStacks[2].getMaxStackSize();
		 */// Forge BugFix: Make it respect stack sizes properly.
	}
	return false;
}
 
Example 8
Project: WirelessRedstone   File: Remote.java   View Source Code Vote up 5 votes
public boolean isBeingHeld() {
    ItemStack held = owner.inventory.getCurrentItem();
    return owner.inventory.currentItem == slot && //same slot
            held != null && //not holding nothing
            held.getItem() == ModItems.itemRemote && //same item type
            held.getItemDamage() == freq;//same freq
}
 
Example 9
Project: uniquecrops   File: ItemEdibleMetal.java   View Source Code Vote up 5 votes
private ItemStack convertEdibles(ItemStack stack) {
	
	int[] oreIDs = OreDictionary.getOreIDs(stack);
	if (oreIDs.length == 0) return stack;

	String oreName = OreDictionary.getOreName(oreIDs[0]);
	ItemStack converted = OreDictionary.getOres(oreName).get(0);
	if (converted != null)
		return new ItemStack(converted.getItem(), stack.stackSize, converted.getItemDamage());
	
	return stack;
}
 
Example 10
Project: CustomWorldGen   File: EntityZombie.java   View Source Code Vote up 5 votes
/**
 * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
 * use this to react to sunlight and start to burn.
 */
public void onLivingUpdate()
{
    if (this.worldObj.isDaytime() && !this.worldObj.isRemote && !this.isChild() && (this.getZombieType() == null || this.getZombieType().isSunSensitive()))
    {
        float f = this.getBrightness(1.0F);
        BlockPos blockpos = this.getRidingEntity() instanceof EntityBoat ? (new BlockPos(this.posX, (double)Math.round(this.posY), this.posZ)).up() : new BlockPos(this.posX, (double)Math.round(this.posY), this.posZ);

        if (f > 0.5F && this.rand.nextFloat() * 30.0F < (f - 0.4F) * 2.0F && this.worldObj.canSeeSky(blockpos))
        {
            boolean flag = true;
            ItemStack itemstack = this.getItemStackFromSlot(EntityEquipmentSlot.HEAD);

            if (itemstack != null)
            {
                if (itemstack.isItemStackDamageable())
                {
                    itemstack.setItemDamage(itemstack.getItemDamage() + this.rand.nextInt(2));

                    if (itemstack.getItemDamage() >= itemstack.getMaxDamage())
                    {
                        this.renderBrokenItemStack(itemstack);
                        this.setItemStackToSlot(EntityEquipmentSlot.HEAD, (ItemStack)null);
                    }
                }

                flag = false;
            }

            if (flag)
            {
                this.setFire(8);
            }
        }
    }

    super.onLivingUpdate();
}
 
Example 11
Project: minecraft-quiverbow   File: GatlingAmmo.java   View Source Code Vote up 5 votes
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) 
   {  
	if (world.isRemote) { return stack; }	// Not doing this on client side
	
	if (stack.getItemDamage() == 0) { return stack; }	// Already fully loaded
	
	boolean doSFX = false;
	
	int counter = 4;
	
	while (counter > 0)	// Doing it 4 times, to speed that process up a bit
	{
		if (player.inventory.hasItem(Items.reeds) && player.inventory.hasItem(Items.stick))
		{
			// ...why does this not work? Is it because I'm in creative? Yes, it is. :|
			int dmg = stack.getItemDamage() - 1;
			stack.setItemDamage(dmg);
			
			//System.out.println("Set ITEM DMG to " + dmg + ".");
			
			player.inventory.consumeInventoryItem(Items.reeds);	// We're just grabbing what we need from the inventory
			player.inventory.consumeInventoryItem(Items.stick);
			
			// SFX
			doSFX = true;
		}
		// else, doesn't have what it takes
		else
		{
			//player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "[" + this.getItemStackDisplayName(stack) + "] Can't find sticks or sugar canes."));
		}
		
		counter -= 1;
	}
	
	if (doSFX) { world.playSoundAtEntity(player, "random.wood_click", 0.5F, 1.50F); }
	
	return stack;
   }
 
Example 12
Project: BetterBeginningsReborn   File: ItemRotisserie.java   View Source Code Vote up 5 votes
@Override
public boolean doCookingDamage(ItemStack stack)
{
    int damage = stack.getItemDamage();
    stack.setItemDamage(damage + 1);

    return stack.getItemDamage() >= stack.getMaxDamage();
}
 
Example 13
Project: uniquecrops   File: ItemGeneric.java   View Source Code Vote up 5 votes
@Override
public int getBurnTime(ItemStack fuel) {
	
	if (fuel.getItem() == this && fuel.getItemDamage() == 3)
		return 16000;
	
	return 0;
}
 
Example 14
Project: minecraft-quiverbow   File: OWR.java   View Source Code Vote up 5 votes
@Override
public String getModelTexPath(ItemStack stack)	// The model texture path
{
	if (stack.getItemDamage() >= stack.getMaxDamage()) { return "OWR_empty"; }	// empty
	if (this.getCooldown(stack) > 0) { return "OWR_hot"; }						// Cooling down

	return "OWR";	// Regular
}
 
Example 15
Project: Bewitchment   File: ItemHorseshoe.java   View Source Code Vote up 4 votes
@Override
public void onWornTick(ItemStack itemstack, EntityLivingBase player) {
	if (itemstack.getItemDamage() == 0 && player.ticksExisted % 40 == 0) {
		player.addPotionEffect(new PotionEffect(MobEffects.LUCK, 120, 0, true, true));
	}
}
 
Example 16
Project: minecraft-territorialdealings   File: Recipe_LeaderRequired.java   View Source Code Vote up 4 votes
@Override
public boolean matches(InventoryCrafting matrix, World world)
   {
       ArrayList arraylist = new ArrayList(this.recipeItems);

       for (int column = 0; column < 3; ++column)
       {
           for (int row = 0; row < 3; ++row)
           {
               ItemStack itemstack = matrix.getStackInRowAndColumn(row, column);

               if (itemstack != null)
               {
                   boolean flag = false;
                   Iterator<ItemStack> iterator = arraylist.iterator();

                   while (iterator.hasNext())
                   {
                       ItemStack requiredItemStack = iterator.next();

                       if (itemstack.getItem() == requiredItemStack.getItem() && (requiredItemStack.getItemDamage() == OreDictionary.WILDCARD_VALUE || itemstack.getItemDamage() == requiredItemStack.getItemDamage()))
                       {
                           flag = true;
                           arraylist.remove(requiredItemStack);
                           break;
                       }
                   }

                   if (!flag)
                   {
                       return false;
                   }
               }
               // else, there's nothing in that slot
           }
       }

       if (arraylist.isEmpty() && world.isRemote)
       {
       	if (this.getRecipeOutput().getItem() instanceof PaymentOrder && this.hasPaymentOrderInMatrix(matrix))
		{
           	return true;	// Only leaders can craft this item, but refilling is free
		}
       	else
       	{
       		// All items were found and we're on client side. Asking the server now if you're a leader (Can't craft this if you aren't)
       		return ClientHelper.isPlayerLeader(Minecraft.getMinecraft().thePlayer.dimension, Minecraft.getMinecraft().thePlayer.getEntityId());
       		//return false;
       	}
       }
       else if (!world.isRemote)
       {
       	// Server side. How do I get the player instance?
       	// Answer: I don't. :|
       	// I could get the player list and see which one has a container open and THEN seeing which one has the items in the matrix listed here?
       	Main.console("[Territorial Dealings - Server] Can't check if this player is allowed to craft this item, since I don't know who asked for this recipe on this side. :/");
       }

       return arraylist.isEmpty();
   }
 
Example 17
Project: DankNull   File: DankNullUtils.java   View Source Code Vote up 4 votes
public static int getSlotCount(ItemStack stack) {
	return (stack.getItemDamage() + 1) * 9;
}
 
Example 18
Project: BetterBeginningsReborn   File: CampfirePanRecipeHandler.java   View Source Code Vote up 4 votes
private boolean canBeSmelted(ItemStack stack, ItemStack stack2)
{
	return stack2.getItem() == stack.getItem()
			&& (stack2.getItemDamage() == OreDictionary.WILDCARD_VALUE || stack2.getItemDamage() == stack
			.getItemDamage());
}
 
Example 19
Project: genera   File: ItemGlassJar.java   View Source Code Vote up 4 votes
@Override
public String getUnlocalizedName(ItemStack stack) {
    return super.getUnlocalizedName() + "_" + (stack.getItemDamage() == 0 ? "empty" : "full");
}
 
Example 20
Project: EndermanEvolution   File: IronChests.java   View Source Code Vote up 4 votes
public static IronChestType getChestType(ItemStack stack) {
	if (isIronChest(stack)) {
		return IronChestType.VALUES[stack.getItemDamage()];
	}
	return null;
}