Java Code Examples for net.minecraft.item.ItemStack

The following are top voted examples for showing how to use net.minecraft.item.ItemStack. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Proyecto-DASI   File: MinecraftTypeHelper.java   View source code 7 votes vote down vote up
/** Attempt to parse string as a Variation, allowing for block properties having different names to the enum values<br>
 * (eg blue_orchid vs orchidBlue etc.)
 * @param part the string (potentially in the 'wrong' format, eg 'orchidBlue')
 * @param is the ItemStack from which this string came (eg from is.getUnlocalisedName)
 * @return a Variation, if one exists, that matches the part string passed in, or one of the ItemStacks current property values.
 */
public static Variation attemptToGetAsVariant(String part, ItemStack is)
{
    if (is.getItem() instanceof ItemBlock)
    {
        // Unlocalised name doesn't always match the names we use in types.xsd
        // (which are the names displayed by Minecraft when using the F3 debug etc.)
        ItemBlock ib = (ItemBlock)(is.getItem());
        IBlockState bs = ib.block.getStateFromMeta(is.getMetadata());
        for (IProperty prop : (java.util.Set<IProperty>)bs.getProperties().keySet())
        { 
            Comparable<?> comp = bs.getValue(prop);
            Variation var = attemptToGetAsVariant(comp.toString());
            if (var != null)
                return var;
        }
        return null;
    }
    else
        return attemptToGetAsVariant(part);
}
 
Example 2
Project: Mods   File: ItemStatue.java   View source code 6 votes vote down vote up
@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos,
		EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
	ItemStack stack = playerIn.getHeldItem(hand);
	if (!worldIn.isRemote && stack.hasTagCompound() && stack.getTagCompound().hasKey("Statue")) {
		EntityStatue statue =new EntityStatue(worldIn);
		statue.readEntityFromNBT(stack.getTagCompound().getCompoundTag("Statue"));
		BlockPos off = pos.offset(facing);
		statue.setPosition(off.getX()+0.5, off.getY(), off.getZ()+0.5);
		statue.rotationYaw = playerIn.rotationYawHead;
		statue.renderYawOffset = playerIn.rotationYawHead;

		statue.ticksLeft = -1;
		worldIn.spawnEntity(statue);
		if (!playerIn.capabilities.isCreativeMode)
			stack.shrink(1);
		return EnumActionResult.SUCCESS;
	}
	return EnumActionResult.SUCCESS;
}
 
Example 3
Project: Backmemed   File: CustomItems.java   View source code 6 votes vote down vote up
public static IBakedModel getCustomItemModel(ItemStack p_getCustomItemModel_0_, IBakedModel p_getCustomItemModel_1_, ResourceLocation p_getCustomItemModel_2_)
{
    if (p_getCustomItemModel_1_.isGui3d())
    {
        return p_getCustomItemModel_1_;
    }
    else if (itemProperties == null)
    {
        return p_getCustomItemModel_1_;
    }
    else
    {
        CustomItemProperties customitemproperties = getCustomItemProperties(p_getCustomItemModel_0_, 1);
        return customitemproperties == null ? p_getCustomItemModel_1_ : customitemproperties.getModel(p_getCustomItemModel_2_);
    }
}
 
Example 4
Project: CustomWorldGen   File: CraftingManager.java   View source code 6 votes vote down vote up
public ItemStack[] getRemainingItems(InventoryCrafting craftMatrix, World worldIn)
{
    for (IRecipe irecipe : this.recipes)
    {
        if (irecipe.matches(craftMatrix, worldIn))
        {
            return irecipe.getRemainingItems(craftMatrix);
        }
    }

    ItemStack[] aitemstack = new ItemStack[craftMatrix.getSizeInventory()];

    for (int i = 0; i < aitemstack.length; ++i)
    {
        aitemstack[i] = craftMatrix.getStackInSlot(i);
    }

    return aitemstack;
}
 
Example 5
Project: Loot-Slash-Conquer   File: ItemLEBauble.java   View source code 6 votes vote down vote up
@Override
public void onEquipped(ItemStack stack, EntityLivingBase entity) 
{
	if (entity.getEntityWorld().isRemote) entity.playSound(SoundEvents.ITEM_ARMOR_EQUIP_DIAMOND, 0.1F, 1.3f);
	else
	{
		if (entity instanceof EntityPlayer)
		{
			EntityPlayer player = (EntityPlayer) entity;
			PlayerInformation info = (PlayerInformation) player.getCapability(CapabilityPlayerInformation.PLAYER_INFORMATION, null);
			
			if (info != null && info.getPlayerLevel() >= NBTHelper.loadStackNBT(stack).getInteger("Level"))
			{
				EventPlayerTick.updateStats(player, info);
			}
			else player.sendMessage(new TextComponentString(TextFormatting.RED + "WARNING: You are using a high-leveled item. It will be useless and will not provide any bonuses."));
		}
	}
}
 
Example 6
Project: minecraft-quiverbow   File: Recipe_AA_Plating.java   View source code 6 votes vote down vote up
private ItemStack getAAFromMatrix(InventoryCrafting matrix)
{
	int counter = 0;
	
	while (counter < matrix.getSizeInventory())
	{
		if (matrix.getStackInSlot(counter) != null && matrix.getStackInSlot(counter).getItem() instanceof PackedUpAA)
		{
			return matrix.getStackInSlot(counter);	// Found it
		}
		
		counter += 1;
	}
	
	return null;
}
 
Example 7
Project: minecraft-quiverbow   File: Recipe_AA_Weapon.java   View source code 6 votes vote down vote up
@Override
public ItemStack getCraftingResult(InventoryCrafting matrix)
   {
	ItemStack stack = this.result.copy();
	ItemStack previousAA = this.getAAFromMatrix(matrix);
	
	if (previousAA != null && previousAA.hasTagCompound())	// Copying existing properties
	{
		stack.setTagCompound((NBTTagCompound) previousAA.getTagCompound().copy());
	}
	else	// ...or just applying new ones
	{
		stack.setTagCompound(new NBTTagCompound());
	}
	
	// Apply the new upgrade now
	stack.getTagCompound().setBoolean("hasWeaponUpgrade", true);
	
	if (stack.getTagCompound().getInteger("currentHealth") == 0)	// Just making sure it's not shown with 0 health
	{
		if (stack.getTagCompound().getBoolean("hasArmorUpgrade")) { stack.getTagCompound().setInteger("currentHealth", 40); }
		else { stack.getTagCompound().setInteger("currentHealth", 20); } // Fresh turret, so setting some health
	}
	
       return stack;
   }
 
Example 8
Project: minecraft-quiverbow   File: FlintDuster.java   View source code 6 votes vote down vote up
@Override
public void doSingleFire(ItemStack stack, World world, Entity entity)		// Server side
{
	// Ignoring cooldown for firing purposes

	// SFX
	world.playSoundAtEntity(entity, "mob.bat.takeoff", 0.5F, 0.6F);

	// Ready
	FlintDust shot = new FlintDust(world, entity, (float) this.Speed);

	// Properties
	shot.damage = this.Dmg;
	shot.ticksInAirMax = this.MaxBlocks;

	// Go
	world.spawnEntityInWorld(shot);

	this.consumeAmmo(stack, entity, 1);
	this.setCooldown(stack, 4);
}
 
Example 9
Project: minecraft-quiverbow   File: RPG.java   View source code 6 votes vote down vote up
@Override
public void addRecipes()
{
	if (this.Enabled)
	{
		// One Firework Rocket Launcher (empty)
		GameRegistry.addRecipe(new ItemStack(this, 1 , this.getMaxDamage()), "x  ", "yx ", "zyx",
				'x', Blocks.planks,
				'y', Items.iron_ingot,
				'z', Items.flint_and_steel
				);
	}
	else if (Main.noCreative) { this.setCreativeTab(null); }	// Not enabled and not allowed to be in the creative menu

	// Fill the RPG with 1 rocket
	GameRegistry.addRecipe(new ItemStack(this), " ab", "zya", " x ",
			'x', new ItemStack(this, 1 , this.getMaxDamage()),
			'y', Blocks.tnt,
			'z', Blocks.planks,
			'a', Items.paper,
			'b', Items.string
			);
}
 
Example 10
Project: Backmemed   File: WorldClient.java   View source code 6 votes vote down vote up
public void doVoidFogParticles(int posX, int posY, int posZ)
{
    int i = 32;
    Random random = new Random();
    ItemStack itemstack = this.mc.player.getHeldItemMainhand();

    if (itemstack == null || Block.getBlockFromItem(itemstack.getItem()) != Blocks.BARRIER)
    {
        itemstack = this.mc.player.getHeldItemOffhand();
    }

    boolean flag = this.mc.playerController.getCurrentGameType() == GameType.CREATIVE && !itemstack.func_190926_b() && itemstack.getItem() == Item.getItemFromBlock(Blocks.BARRIER);
    BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();

    for (int j = 0; j < 667; ++j)
    {
        this.showBarrierParticles(posX, posY, posZ, 16, random, flag, blockpos$mutableblockpos);
        this.showBarrierParticles(posX, posY, posZ, 32, random, flag, blockpos$mutableblockpos);
    }
}
 
Example 11
Project: pnc-repressurized   File: TileEntityPressureChamberInterface.java   View source code 6 votes vote down vote up
private void importFromChamber(TileEntityPressureChamberValve core) {
    ItemStackHandler chamberStacks = core.getStacksInChamber();
    for (ItemStack chamberStack : new ItemStackHandlerIterable(chamberStacks)) {
        ItemStack inputStack = inventory.getStackInSlot(0);
        if ((inputStack.isEmpty() || inputStack.isItemEqual(chamberStack)) && filterHandler.doesItemMatchFilter(chamberStack)) {
            int maxAllowedItems = Math.abs(core.getAirHandler(null).getAir()) / PneumaticValues.USAGE_CHAMBER_INTERFACE;
            if (maxAllowedItems > 0) {
                if (!inputStack.isEmpty()) {
                    maxAllowedItems = Math.min(maxAllowedItems, chamberStack.getMaxStackSize() - inputStack.getCount());
                }
                int transferredItems = Math.min(chamberStack.getCount(), maxAllowedItems);
                ItemStack toTransferStack = chamberStack.copy().splitStack(transferredItems);
                ItemStack excess = inventory.insertItem(0, toTransferStack, true);
                if (excess.getCount() < toTransferStack.getCount()) {
                    // we can transfer at least some of the items
                    transferredItems = toTransferStack.getCount() - excess.getCount();
                    core.addAir((core.getAirHandler(null).getAir() > 0 ? -1 : 1) * transferredItems * PneumaticValues.USAGE_CHAMBER_INTERFACE);
                    toTransferStack.setCount(transferredItems);
                    inventory.insertItem(0, toTransferStack, false);
                    chamberStack.shrink(transferredItems);
                }
            }
        }
    }
}
 
Example 12
Project: FoodCraft-Reloaded   File: TileEntitySmeltingDrinkMachine.java   View source code 5 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound tag) {
    super.readFromNBT(tag);
    CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.getStorage().readNBT(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, itemStackHandler, null, tag.getTag("Items"));
    progress = tag.getInteger("progress");
    fuel = tag.getInteger("fuel");
    output = new ItemStack(tag.getCompoundTag("output"));
    fluidStack = FluidStack.loadFluidStackFromNBT(tag.getCompoundTag("fluidOutput"));
}
 
Example 13
Project: pnc-repressurized   File: SemiBlockLogistics.java   View source code 5 votes vote down vote up
@Override
public void addDrops(NonNullList<ItemStack> drops) {
    super.addDrops(drops);

    boolean shouldAddTag = false;
    for (int i = 0; i < filters.getSlots(); i++) {
        if (!filters.getStackInSlot(i).isEmpty()) { //Only set a tag when there are requests.
            shouldAddTag = true;
            break;
        }
    }

    for (FluidTank fluidFilter : fluidFilters) {
        if (fluidFilter.getFluidAmount() > 0) {
            shouldAddTag = true;
            break;
        }
    }

    if (invisible) shouldAddTag = true;

    if (shouldAddTag) {
        ItemStack drop = drops.get(0);
        NBTTagCompound tag = new NBTTagCompound();
        writeToNBT(tag);
        drop.setTagCompound(tag);
    }
}
 
Example 14
Project: Loot-Slash-Conquer   File: ItemGenerator.java   View source code 5 votes vote down vote up
/** Creates a melee weapon/armor with randomized stats. */
public static void create(ItemStack stack, NBTTagCompound nbt, World world, ChunkPos pos)
{
	/*
	 * Set rarity
	 * Set level
	 * Generate attributes based on Rarity
	 * 		- Common: 0-1 attributes
	 * 		- Uncommon: 1-2 attributes
	 * 		- Rare: 2-3 attributes
	 * 		- Legendary: 3-4 attributes
	 * 		- Mythic: 4-5 attributes
	 * Generate base damage and base attack speed
	 * Generate name based on attributes + material/type
	 */
	
	if (Rarity.getRarity(nbt) != Rarity.DEFAULT)
	{
		IChunkLevelHolder chunkLevelHolder = world.getCapability(CapabilityChunkLevel.CHUNK_LEVEL, null);
		IChunkLevel chunkLevel = chunkLevelHolder.getChunkLevel(pos);
		int level = chunkLevel.getChunkLevel();
		
		//Rarity.setRarity(nbt, Rarity.getRandomRarity(nbt, ItemGeneratorHelper.rand)); // sets a random rarity
		ItemGeneratorHelper.setTypes(stack, nbt);
		nbt.setInteger("Level", level); // set level to current player level
		ItemGeneratorHelper.setRandomAttributes(stack, nbt, Rarity.getRarity(nbt));
		ItemGeneratorHelper.setAttributeModifiers(nbt, stack);
		nbt.setInteger("HideFlags", 6); // hides Attribute Modifier and Unbreakable tags
	}
}
 
Example 15
Project: DecompiledMinecraft   File: InventoryMerchant.java   View source code 5 votes vote down vote up
/**
 * Removes a stack from the given slot and returns it.
 */
public ItemStack removeStackFromSlot(int index)
{
    if (this.theInventory[index] != null)
    {
        ItemStack itemstack = this.theInventory[index];
        this.theInventory[index] = null;
        return itemstack;
    }
    else
    {
        return null;
    }
}
 
Example 16
Project: chesttransporter   File: ItemChestTransporter.java   View source code 5 votes vote down vote up
private void damageItem(ItemStack stack, EntityPlayer player)
{
    if (!player.capabilities.isCreativeMode)
    {
        stack.damageItem(1, player);
        if (type.maxDamage == 1)
            stack.damageItem(1, player);
    }
}
 
Example 17
Project: Backmemed   File: Bootstrap.java   View source code 5 votes vote down vote up
protected ItemStack dispenseStack(IBlockSource source, ItemStack stack)
{
    Block block = Block.getBlockFromItem(stack.getItem());
    World world = source.getWorld();
    EnumFacing enumfacing = (EnumFacing)source.getBlockState().getValue(BlockDispenser.FACING);
    BlockPos blockpos = source.getBlockPos().offset(enumfacing);
    this.field_190911_b = world.func_190527_a(block, blockpos, false, EnumFacing.DOWN, (Entity)null);

    if (this.field_190911_b)
    {
        EnumFacing enumfacing1 = world.isAirBlock(blockpos.down()) ? enumfacing : EnumFacing.UP;
        IBlockState iblockstate = block.getDefaultState().withProperty(BlockShulkerBox.field_190957_a, enumfacing1);
        world.setBlockState(blockpos, iblockstate);
        TileEntity tileentity = world.getTileEntity(blockpos);
        ItemStack itemstack = stack.splitStack(1);

        if (itemstack.hasTagCompound())
        {
            ((TileEntityShulkerBox)tileentity).func_190586_e(itemstack.getTagCompound().getCompoundTag("BlockEntityTag"));
        }

        if (itemstack.hasDisplayName())
        {
            ((TileEntityShulkerBox)tileentity).func_190575_a(itemstack.getDisplayName());
        }

        world.updateComparatorOutputLevel(blockpos, iblockstate.getBlock());
    }

    return stack;
}
 
Example 18
Project: harshencastle   File: HarshenRegistry.java   View source code 5 votes vote down vote up
@Override
public CauldronLiquid registerCauldronLiquid(ItemStack fullItem, ItemStack emptyItem, CauldronLiquid liquid, int fillBy) {
	fillBy = MathHelper.clamp(fillBy, 1, 3);
	liquid.setModID(modID);
	if(emptyItem == null || emptyItem.isEmpty())
		return registerItemLiquid(fullItem, liquid);
	INPUT_FILLBY.put(fullItem, fillBy);
	OUTPUT_FILLBY.put(emptyItem, fillBy);
	INPUT_MAP.put(fullItem, liquid);
	OUTPUT_MAP.put(liquid, emptyItem);
	return liquid;
}
 
Example 19
Project: CustomWorldGen   File: EntitySheep.java   View source code 5 votes vote down vote up
@Override
public java.util.List<ItemStack> onSheared(ItemStack item, net.minecraft.world.IBlockAccess world, BlockPos pos, int fortune)
{
    this.setSheared(true);
    int i = 1 + this.rand.nextInt(3);

    java.util.List<ItemStack> ret = new java.util.ArrayList<ItemStack>();
    for (int j = 0; j < i; ++j)
        ret.add(new ItemStack(Item.getItemFromBlock(Blocks.WOOL), 1, this.getFleeceColor().getMetadata()));

    this.playSound(SoundEvents.ENTITY_SHEEP_SHEAR, 1.0F, 1.0F);
    return ret;
}
 
Example 20
Project: BetterBeginningsReborn   File: KilnRecipeHandler.java   View source code 5 votes vote down vote up
public static void removeRecipe(RecipeElement input, ItemStack output)
{
    ItemStack result = instance().smeltingList.get(input);
    if(instance().smeltingList.containsKey(input) && ItemStack.areItemStacksEqual(result, output)) return;
    {
	instance().experienceList.remove(result);
	instance().smeltingList.remove(input);
    }
}
 
Example 21
Project: ExPetrum   File: ItemRock.java   View source code 5 votes vote down vote up
@Override
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> subItems)
{
	if (tab != this.getCreativeTab())
	{
		return;
	}

	Stream.of(EnumRockClass.values()).forEach(c -> subItems.add(new ItemStack(this, 1, c.ordinal())));
}
 
Example 22
Project: BaseClient   File: EntityPlayer.java   View source code 5 votes vote down vote up
/**
 * (abstract) Protected helper method to write subclass entity data to NBT.
 */
public void writeEntityToNBT(NBTTagCompound tagCompound)
{
    super.writeEntityToNBT(tagCompound);
    tagCompound.setTag("Inventory", this.inventory.writeToNBT(new NBTTagList()));
    tagCompound.setInteger("SelectedItemSlot", this.inventory.currentItem);
    tagCompound.setBoolean("Sleeping", this.sleeping);
    tagCompound.setShort("SleepTimer", (short)this.sleepTimer);
    tagCompound.setFloat("XpP", this.experience);
    tagCompound.setInteger("XpLevel", this.experienceLevel);
    tagCompound.setInteger("XpTotal", this.experienceTotal);
    tagCompound.setInteger("XpSeed", this.xpSeed);
    tagCompound.setInteger("Score", this.getScore());

    if (this.spawnChunk != null)
    {
        tagCompound.setInteger("SpawnX", this.spawnChunk.getX());
        tagCompound.setInteger("SpawnY", this.spawnChunk.getY());
        tagCompound.setInteger("SpawnZ", this.spawnChunk.getZ());
        tagCompound.setBoolean("SpawnForced", this.spawnForced);
    }

    this.foodStats.writeNBT(tagCompound);
    this.capabilities.writeCapabilitiesToNBT(tagCompound);
    tagCompound.setTag("EnderItems", this.theInventoryEnderChest.saveInventoryToNBT());
    ItemStack itemstack = this.inventory.getCurrentItem();

    if (itemstack != null && itemstack.getItem() != null)
    {
        tagCompound.setTag("SelectedItem", itemstack.writeToNBT(new NBTTagCompound()));
    }
}
 
Example 23
Project: SimpleTubes   File: SimpleTubes.java   View source code 5 votes vote down vote up
public void displayAllRelevantItems(NonNullList<ItemStack> list) {
	//Blocks
	list.add(new ItemStack(proxy.blockTube, 1, 0));
	list.add(new ItemStack(proxy.blockDisplacer, 1, 0));
	
	//Items
	for (int i = 0; i < 17; i++)
		list.add(new ItemStack(proxy.itemPaintbrush, 1, i));

	list.add(new ItemStack(proxy.itemUpgrade, 1, 0));
}
 
Example 24
Project: BaseClient   File: InventoryPlayer.java   View source code 5 votes vote down vote up
public boolean canHeldItemHarvest(Block blockIn)
{
    if (blockIn.getMaterial().isToolNotRequired())
    {
        return true;
    }
    else
    {
        ItemStack itemstack = this.getStackInSlot(this.currentItem);
        return itemstack != null ? itemstack.canHarvestBlock(blockIn) : false;
    }
}
 
Example 25
Project: CustomWorldGen   File: EntityMinecartContainer.java   View source code 5 votes vote down vote up
/**
 * (abstract) Protected helper method to read subclass entity data from NBT.
 */
protected void readEntityFromNBT(NBTTagCompound compound)
{
    super.readEntityFromNBT(compound);
    this.minecartContainerItems = new ItemStack[this.getSizeInventory()];

    if (compound.hasKey("LootTable", 8))
    {
        this.lootTable = new ResourceLocation(compound.getString("LootTable"));
        this.lootTableSeed = compound.getLong("LootTableSeed");
    }
    else
    {
        NBTTagList nbttaglist = compound.getTagList("Items", 10);

        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
            NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
            int j = nbttagcompound.getByte("Slot") & 255;

            if (j >= 0 && j < this.minecartContainerItems.length)
            {
                this.minecartContainerItems[j] = ItemStack.loadItemStackFromNBT(nbttagcompound);
            }
        }
    }
}
 
Example 26
Project: Thermionics   File: ItemChunkUnloader.java   View source code 5 votes vote down vote up
@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack stack, World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
	tooltip.add(I18n.translateToLocal("item.thermionics.chunkunloader.tip"));
	int loadedState = stack.getItemDamage();
	switch(loadedState) {
	default: //Default to unattuned
		
	case 0: tooltip.add(I18n.translateToLocalFormatted("thermionics.data.chunkunloader.unattuned")); break;
	case 1: tooltip.add(I18n.translateToLocalFormatted("thermionics.data.chunkunloader.unloaded")); break;
	case 2: tooltip.add(I18n.translateToLocalFormatted("thermionics.data.chunkunloader.loaded")); break;
	}
}
 
Example 27
Project: connor41-etfuturum2   File: TippedArrow.java   View source code 5 votes vote down vote up
public static ItemStack setEffect(ItemStack stack, Potion potion, int duration) {
	stack.setTagCompound(new NBTTagCompound());
	NBTTagCompound nbt = new NBTTagCompound();
	stack.getTagCompound().setTag("Potion", nbt);

	PotionEffect effect = new PotionEffect(potion.getId(), potion.isInstant() ? 1 : duration);
	effect.writeCustomPotionEffectToNBT(nbt);

	return stack;
}
 
Example 28
Project: Backmemed   File: TileEntityDispenser.java   View source code 5 votes vote down vote up
public boolean func_191420_l()
{
    for (ItemStack itemstack : this.stacks)
    {
        if (!itemstack.func_190926_b())
        {
            return false;
        }
    }

    return true;
}
 
Example 29
Project: Whoosh   File: ItemTransporter.java   View source code 5 votes vote down vote up
@Override
public boolean decrMode(ItemStack stack) {

    if (!stack.hasTagCompound()) {
        stack.setTagCompound(new NBTTagCompound());
    }
    int curMode = getMode(stack);
    curMode--;
    if (curMode <= 0) {
        curMode = getNumModes(stack) - 1;
    }
    stack.getTagCompound().setInteger("Mode", curMode);
    return true;
}
 
Example 30
Project: Industrial-Foregoing   File: EnchantmentInvokerBlock.java   View source code 5 votes vote down vote up
public void createRecipe() {
    RecipeUtils.addShapedRecipe(new ItemStack(this), "pbp", "dmd", "ooo",
            'p', ItemRegistry.plastic,
            'b', Items.BOOK,
            'd', "gemDiamond",
            'm', MachineCaseItem.INSTANCE,
            'o', Blocks.OBSIDIAN);
}
 
Example 31
Project: Industrial-Foregoing   File: PageItemList.java   View source code 5 votes vote down vote up
public static List<PageItemList> generatePagesFromItemStacks(List<ItemStack> stacks, String display) {
    List<PageItemList> pages = new ArrayList<>();
    while (stacks.size() > 49) {
        pages.add(new PageItemList(stacks.subList(0, 49), display));
        stacks = stacks.subList(49, stacks.size());
    }
    pages.add(new PageItemList(stacks, display));
    return pages;
}
 
Example 32
Project: ModularMachinery   File: ItemBlockMachineComponent.java   View source code 5 votes vote down vote up
@Override
public int getColorFromItemstack(ItemStack stack, int tintIndex) {
    if(stack.isEmpty()) {
        return 0;
    }
    return Config.machineColor;
}
 
Example 33
Project: pnc-repressurized   File: TileEntityOmnidirectionalHopper.java   View source code 5 votes vote down vote up
protected boolean doImport(int maxItems) {
    boolean success = false;

    // Suck from input inventory
    IItemHandler handler = IOHelper.getInventoryForTE(IOHelper.getNeighbor(this, inputDir));
    if (handler != null) {
        for (int i = 0; i < maxItems; i++) {
            LocatedItemStack extracted = IOHelper.extractOneItem(handler, true);
            if (!extracted.stack.isEmpty()) {
                ItemStack excess = ItemHandlerHelper.insertItem(inventory, extracted.stack, false);
                if (excess.isEmpty()) {
                    handler.extractItem(extracted.slot, 1, false);
                    success = true;
                } else {
                    break;
                }
            } else {
                break;
            }
        }
    }

    // Suck in item entities
    for (EntityItem entity : getNeighborItems(this, inputDir)) {
        if (!entity.isDead) {
            ItemStack remainder = IOHelper.insert(this, entity.getItem(), null, false);
            if (remainder.isEmpty()) {
                entity.setDead();
                success = true;
            }
        }
    }

    return success;
}
 
Example 34
Project: Firma   File: ClayBlock2.java   View source code 5 votes vote down vote up
@Override
public String getSpecialName(ItemStack stack) {
	if (stack == null) {
		throw new NullPointerException();
	}
	return RockEnum2.getName(stack.getMetadata());
}
 
Example 35
Project: harshencastle   File: JEIRitualWrapper.java   View source code 5 votes vote down vote up
@SuppressWarnings("unchecked")
public JEIRitualWrapper(RitualRecipes recipe) {
	ImmutableList.Builder<List<ItemStack>> builder = ImmutableList.builder();
	for(HarshenStack hStack : recipe.getInputs())
		builder.add(hStack.getStackList());
	input = builder.build();
	output = recipe.getOutput();
}
 
Example 36
Project: pnc-repressurized   File: NetworkConnectionAIHandler.java   View source code 5 votes vote down vote up
public NetworkConnectionAIHandler(GuiSecurityStationBase gui, TileEntitySecurityStation station, int baseX,
                                  int baseY, int nodeSpacing, int color) {
    super(gui, station, baseX, baseY, nodeSpacing, color, TileEntityConstants.NETWORK_AI_BRIDGE_SPEED);
    for (int i = 0; i < station.getPrimaryInventory().getSlots(); i++) {
        ItemStack stack = station.getPrimaryInventory().getStackInSlot(i);
        if (stack.getItemDamage() == ItemNetworkComponents.DIAGNOSTIC_SUBROUTINE) {
            slotHacked[i] = true;
        }
    }
}
 
Example 37
Project: ThermionicsWorld   File: ThermionicsWorld.java   View source code 5 votes vote down vote up
public static void addMeatCompressionRecipe(IForgeRegistry<IRecipe> registry, EnumEdibleMeat meat, boolean cooked, ItemStack ingredient) {
	ResourceLocation group = new ResourceLocation("thermionics_world", "compress.meat");
	Ingredient input = Ingredient.fromStacks(ingredient);
	ShapedRecipes recipe = 
			new ShapedRecipes(group.toString(), 3, 3,
			NonNullList.withSize(3*3, input),
			new ItemStack(TWBlocks.MEAT_EDIBLE, 1, BlockMeatEdible.getMetaFromValue(meat, cooked)) );
	recipe.setRegistryName(new ResourceLocation("thermionics_world", meat.getName()+((cooked)?".cooked":".raw")+"_CompressToBlock"));
	registry.register(recipe);
}
 
Example 38
Project: Backmemed   File: RecipesMapCloning.java   View source code 5 votes vote down vote up
/**
 * Used to check if a recipe matches current crafting inventory
 */
public boolean matches(InventoryCrafting inv, World worldIn)
{
    int i = 0;
    ItemStack itemstack = ItemStack.field_190927_a;

    for (int j = 0; j < inv.getSizeInventory(); ++j)
    {
        ItemStack itemstack1 = inv.getStackInSlot(j);

        if (!itemstack1.func_190926_b())
        {
            if (itemstack1.getItem() == Items.FILLED_MAP)
            {
                if (!itemstack.func_190926_b())
                {
                    return false;
                }

                itemstack = itemstack1;
            }
            else
            {
                if (itemstack1.getItem() != Items.MAP)
                {
                    return false;
                }

                ++i;
            }
        }
    }

    return !itemstack.func_190926_b() && i > 0;
}
 
Example 39
Project: DecompiledMinecraft   File: SlotCrafting.java   View source code 5 votes vote down vote up
/**
 * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
 * stack.
 */
public ItemStack decrStackSize(int amount)
{
    if (this.getHasStack())
    {
        this.amountCrafted += Math.min(amount, this.getStack().stackSize);
    }

    return super.decrStackSize(amount);
}
 
Example 40
Project: BaseClient   File: TileEntityHopper.java   View source code 5 votes vote down vote up
private boolean transferItemsOut()
{
    IInventory iinventory = this.getInventoryForHopperTransfer();

    if (iinventory == null)
    {
        return false;
    }
    else
    {
        EnumFacing enumfacing = BlockHopper.getFacing(this.getBlockMetadata()).getOpposite();

        if (this.isInventoryFull(iinventory, enumfacing))
        {
            return false;
        }
        else
        {
            for (int i = 0; i < this.getSizeInventory(); ++i)
            {
                if (this.getStackInSlot(i) != null)
                {
                    ItemStack itemstack = this.getStackInSlot(i).copy();
                    ItemStack itemstack1 = putStackInInventoryAllSlots(iinventory, this.decrStackSize(i, 1), enumfacing);

                    if (itemstack1 == null || itemstack1.stackSize == 0)
                    {
                        iinventory.markDirty();
                        return true;
                    }

                    this.setInventorySlotContents(i, itemstack);
                }
            }

            return false;
        }
    }
}