net.minecraft.item.ItemStack Java Examples

The following examples show how to use net.minecraft.item.ItemStack. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: PneumaticCraft   Author: MineMaarten   File: BlockTrackEntryInventory.java    License: GNU General Public License v3.0 7 votes vote down vote up
@Override
public void addInformation(World world, int x, int y, int z, TileEntity te, List<String> infoList){
    try {
        IInventory inventory = IOHelper.getInventoryForTE(te);
        if(inventory != null) {
            boolean empty = true;
            ItemStack[] inventoryStacks = new ItemStack[inventory.getSizeInventory()];
            for(int i = 0; i < inventory.getSizeInventory(); i++) {
                ItemStack iStack = inventory.getStackInSlot(i);
                if(iStack != null) empty = false;
                inventoryStacks[i] = iStack;
            }
            if(empty) {
                infoList.add("Contents: Empty");
            } else {
                infoList.add("Contents:");
                PneumaticCraftUtils.sortCombineItemStacksAndToString(infoList, inventoryStacks);
            }
        }
    } catch(Throwable e) {
        addTileEntityToBlackList(te, e);
    }
}
 
Example #2
Source Project: Wizardry   Author: TeamWizardry   File: PacketSwapPearl.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void handle(@NotNull MessageContext ctx) {
	EntityPlayerMP player = ctx.getServerHandler().player;

	ItemStack swappable = player.getHeldItemMainhand();

	ItemStack storageStack = BaublesSupport.getItem(player, IPearlStorageHolder.class);
	IPearlStorageHolder holder = (IPearlStorageHolder) storageStack.getItem();
	int originalPearlCount = holder.getPearlCount(storageStack);

	if (!storageStack.isEmpty() && swappable.getItem() instanceof IPearlSwappable) {
		ItemStack pearl = ((IPearlSwappable) swappable.getItem()).swapPearl(swappable, holder.removePearl(storageStack, index, false));
		holder.addPearl(storageStack, pearl, false);
	}

	PacketHandler.NETWORK.sendTo(new PacketUpdatePearlGUI(originalPearlCount, holder.getPearlCount(storageStack), index, swappable.getTagCompound(), storageStack.getTagCompound()), player);
}
 
Example #3
Source Project: Ex-Aliquo   Author: Zerokyuuni   File: HayCrook.java    License: MIT License 6 votes vote down vote up
@Override
public boolean onBlockStartBreak(ItemStack item, int X, int Y, int Z, EntityPlayer player)
{
	World world = player.worldObj;
	int blockID = world.getBlockId(X,Y,Z);
	int meta = world.getBlockMetadata(X, Y, Z);
	boolean validTarget = false;
	
	Block block = Block.blocksList[blockID];
	
	if (block.isBlockReplaceable(null, 0, 0, 0))
	{
		block.dropBlockAsItem(world, X, Y, Z, meta, 2);
	}
	
	return true;
}
 
Example #4
Source Project: Wurst7   Author: Wurst-Imperium   File: RenameCmd.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void call(String[] args) throws CmdException
{
	if(!MC.player.abilities.creativeMode)
		throw new CmdError("Creative mode only.");
	
	if(args.length == 0)
		throw new CmdSyntaxError();
	
	String message = args[0];
	for(int i = 1; i < args.length; i++)
		message += " " + args[i];
	
	message = message.replace("$", "�").replace("��", "$");
	ItemStack item = MC.player.inventory.getMainHandStack();
	
	if(item == null)
		throw new CmdError("There is no item in your hand.");
	
	item.setCustomName(new LiteralText(message));
	ChatUtils.message("Renamed item to \"" + message + "�r\".");
}
 
Example #5
Source Project: enderutilities   Author: maruohon   File: ItemChairWand.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean doKeyBindingAction(EntityPlayer player, ItemStack stack, int key)
{
    // Shift + Scroll: Change entity width
    if (EnumKey.SCROLL.matches(key, HotKeys.MOD_SHIFT))
    {
        NBTUtils.cycleByteValue(stack, "Chair", "Width", 1, 64, EnumKey.keypressActionIsReversed(key) == false);
        return true;
    }
    // Alt + Scroll: Change entity height
    else if (EnumKey.SCROLL.matches(key, HotKeys.MOD_ALT))
    {
        NBTUtils.cycleByteValue(stack, "Chair", "Height", 1, 64, EnumKey.keypressActionIsReversed(key) == false);
        return true;
    }

    return false;
}
 
Example #6
Source Project: enderutilities   Author: maruohon   File: RenderEventHandler.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
private void renderPlacementPropertiesHud(EntityPlayer player)
{
    ItemStack stack = player.getHeldItemMainhand();

    if (stack.isEmpty() || (stack.getItem() instanceof ItemBlockEnderUtilities) == false)
    {
        stack = player.getHeldItemOffhand();
    }

    if (stack.isEmpty() == false && stack.getItem() instanceof ItemBlockPlacementProperty)
    {
        ItemBlockPlacementProperty item = (ItemBlockPlacementProperty) stack.getItem();

        if (item.hasPlacementProperty(stack))
        {
            renderText(this.getPlacementPropertiesText(item, stack, player), 4, 0, HudAlignment.BOTTOM_LEFT, true, true, this.mc);
        }
    }
}
 
Example #7
Source Project: enderutilities   Author: maruohon   File: ItemHandyBag.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Returns an ItemStack containing an enabled Handy Bag in the player's inventory, or null if none is found.
 */
public static ItemStack getOpenableBag(EntityPlayer player)
{
    IItemHandler playerInv = player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
    List<Integer> slots = InventoryUtils.getSlotNumbersOfMatchingItems(playerInv, EnderUtilitiesItems.HANDY_BAG);

    for (int slot : slots)
    {
        ItemStack stack = playerInv.getStackInSlot(slot);

        if (bagIsOpenable(stack))
        {
            return stack;
        }
    }

    return ItemStack.EMPTY;
}
 
Example #8
Source Project: customstuff4   Author: cubex2   File: MachineManager.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static boolean isPartOfFuel(ResourceLocation list, ItemStack stack)
{
    if (stack.isEmpty())
        return false;

    if (list.toString().equals("minecraft:vanilla"))
    {
        return TileEntityFurnace.getItemBurnTime(stack) > 0;
    }

    for (MachineFuel fuel : getInstance(list).fuels)
    {
        if (fuel.getFuelInput().stream()
                .anyMatch(input -> ItemHelper.stackMatchesRecipeInput(stack, input, false)))
            return true;
    }

    return false;
}
 
Example #9
Source Project: ToroQuest   Author: ToroCraft   File: PlayerCivilizationCapabilityImpl.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public List<ItemStack> acceptQuest(List<ItemStack> in) {
	Province province = getInCivilization();
	if (province == null) {
		return null;
	}

	if (getCurrentQuestFor(province) != null) {
		return null;
	}

	QuestData data = getNextQuestFor(province);
	quests.add(data);
	nextQuests.remove(data);

	return new QuestDelegator(data).accept(in);
}
 
Example #10
Source Project: PneumaticCraft   Author: MineMaarten   File: ItemPlasticPlants.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player){
    BlockPneumaticPlantBase plant = (BlockPneumaticPlantBase)getPlantBlockIDFromSeed(stack.getItemDamage());
    if(plant == Blockss.squidPlant) {
        MovingObjectPosition mop = getMovingObjectPositionFromPlayer(world, player, true);
        if(mop != null) {
            int x = mop.blockX;
            int y = mop.blockY;
            int z = mop.blockZ;
            if(player.canPlayerEdit(x, y, z, 1, stack) && player.canPlayerEdit(x, y + 1, z, 1, stack)) {
                if(plant.canBlockStay(world, x, y + 1, z) && world.isAirBlock(x, y + 1, z)) {
                    stack.stackSize--;
                    world.setBlock(x, y + 1, z, Blockss.squidPlant, 7, 3);
                }
            }
        }
    }
    return stack;
}
 
Example #11
Source Project: enderutilities   Author: maruohon   File: BlockStorage.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
{
    if (state.getValue(TYPE).retainsContents())
    {
        drops.add(this.getDroppedItemWithNBT(world, pos, state, false));
    }
    else
    {
        super.getDrops(drops, world, pos, state, fortune);
    }
}
 
Example #12
Source Project: NotEnoughItems   Author: TheCBProject   File: ContainerPotionCreator.java    License: MIT License 5 votes vote down vote up
@Override
public void onSlotChanged() {
    super.onSlotChanged();
    if (getHasStack()) {
        ItemStack stack = getStack();
        if (!stack.hasTagCompound()) {
            stack.setTagCompound(new NBTTagCompound());
        }
        if (!stack.getTagCompound().hasKey("CustomPotionEffects")) {
            stack.getTagCompound().setTag("CustomPotionEffects", new NBTTagList());
        }
    }
}
 
Example #13
Source Project: Electro-Magic-Tools   Author: TeamAmeriFrance   File: ItemThaumiumDrill.java    License: GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings({"rawtypes", "unchecked"})
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) {
    ItemStack itemStack = new ItemStack(this, 1);
    if (getChargedItem(itemStack) == this) {
        ItemStack charged = new ItemStack(this, 1);
        ElectricItem.manager.charge(charged, 2147483647, 2147483647, true, false);
        itemList.add(charged);
    }
    if (getEmptyItem(itemStack) == this) {
        itemList.add(new ItemStack(this, 1, getMaxDamage()));
    }
}
 
Example #14
Source Project: BigReactors   Author: erogenousbeef-zz   File: TileEntityInventory.java    License: MIT License 5 votes vote down vote up
@Override
public void setInventorySlotContents(int slot, ItemStack itemstack) {
	_inventories[slot] = itemstack;
	if(itemstack != null && itemstack.stackSize > getInventoryStackLimit())
	{
		itemstack.stackSize = getInventoryStackLimit();
	}
}
 
Example #15
Source Project: GardenCollection   Author: jaquadro   File: BlockCompostBin.java    License: MIT License 5 votes vote down vote up
@Override
public void breakBlock (World world, int x, int y, int z, Block block, int data) {
    TileEntityCompostBin te = getTileEntity(world, x, y, z);

    if (te != null) {
        for (int i = 0; i < te.getSizeInventory(); i++) {
            ItemStack item = te.getStackInSlot(i);
            if (item != null)
                dropBlockAsItem(world, x, y, z, item);
        }
    }

    super.breakBlock(world, x, y, z, block, data);
}
 
Example #16
Source Project: TofuCraftReload   Author: 0999312   File: SlotSaltFurnace.java    License: MIT License 5 votes vote down vote up
@Override
public ItemStack onTake(EntityPlayer par1EntityPlayer, ItemStack par2ItemStack)
{
    this.onCrafting(par2ItemStack);
    super.onTake(par1EntityPlayer, par2ItemStack);
    return par2ItemStack;
}
 
Example #17
Source Project: TofuCraftReload   Author: 0999312   File: TileEntityTFCompressor.java    License: MIT License 5 votes vote down vote up
@Override
public boolean canWork() {
    if (energy >= POWER) { //If energy is suitable
        if (((ItemStack) this.inventory.get(0)).isEmpty()) {
            return false;
        } else {
            ItemStack itemstack = CompressorRecipes.getResult(this.inventory.get(0));

            if (itemstack.isEmpty()) {
                return false;
            } else {
                ItemStack itemstack1 = this.inventory.get(1);

                if (itemstack1.isEmpty()) {
                    return true;
                } else if (!itemstack1.isItemEqual(itemstack)) {
                    return false;
                } else if (itemstack1.getCount() + itemstack.getCount() <= this.getInventoryStackLimit() && itemstack1.getCount() + itemstack.getCount() <= itemstack1.getMaxStackSize())  // Forge fix: make furnace respect stack sizes in furnace recipes
                {
                    return true;
                } else {
                    return itemstack1.getCount() + itemstack.getCount() <= itemstack.getMaxStackSize(); // Forge fix: make furnace respect stack sizes in furnace recipes
                }
            }
        }
    }
    return false;
}
 
Example #18
Source Project: NotEnoughItems   Author: Chicken-Bones   File: ContainerPotionCreator.java    License: MIT License 5 votes vote down vote up
@Override
public void onSlotChanged() {
    super.onSlotChanged();
    if (getHasStack()) {
        ItemStack stack = getStack();
        if (!stack.hasTagCompound())
            stack.setTagCompound(new NBTTagCompound());
        if (!stack.getTagCompound().hasKey("CustomPotionEffects"))
            stack.getTagCompound().setTag("CustomPotionEffects", new NBTTagList());
    }
}
 
Example #19
private String getTemplateNameFromItem()
{
    ItemStack stack = this.mc.player.getHeldItemMainhand();

    if (stack.isEmpty() == false && stack.getItem() == EnderUtilitiesItems.BUILDERS_WAND &&
        ItemBuildersWand.Mode.getMode(stack) == Mode.COPY)
    {
        return ((ItemBuildersWand) stack.getItem()).getTemplateName(stack, Mode.COPY);
    }

    return "";
}
 
Example #20
Source Project: MineLittlePony   Author: MineLittlePony   File: SkullFeature.java    License: MIT License 5 votes vote down vote up
private void renderSkull(MatrixStack stack, VertexConsumerProvider renderContext, ItemStack itemstack, boolean isVillager, float limbDistance, int lightUv) {
    stack.translate(0, 0, -0.14F);
    float f = 1.1875f;
    stack.scale(f, -f, -f);
    if (isVillager) {
        stack.translate(0, 0.0625F, 0);
    }

    GameProfile profile = null;

    if (itemstack.hasTag()) {
        CompoundTag nbt = itemstack.getTag();

        assert nbt != null;

        if (nbt.contains("SkullOwner", 10)) {
            profile = NbtHelper.toGameProfile(nbt.getCompound("SkullOwner"));
        } else if (nbt.contains("SkullOwner", 8)) {
            profile = SkullBlockEntity.loadProperties(new GameProfile(null, nbt.getString("SkullOwner")));
            nbt.put("SkullOwner", NbtHelper.fromGameProfile(new CompoundTag(), profile));
        }
    }

    SkullType type = ((AbstractSkullBlock) ((BlockItem) itemstack.getItem()).getBlock()).getSkullType();

    stack.translate(-0.5, 0, -0.5);
    SkullBlockEntityRenderer.render(null, 180, type, profile, limbDistance, stack, renderContext, lightUv);
}
 
Example #21
Source Project: PneumaticCraft   Author: MineMaarten   File: ContainerGasLift.java    License: GNU General Public License v3.0 5 votes vote down vote up
public ContainerGasLift(InventoryPlayer inventoryPlayer, TileEntityGasLift te){
    super(te);

    // add the upgrade slots
    for(int i = 0; i < 2; i++) {
        for(int j = 0; j < 2; j++) {
            addSlotToContainer(new SlotUpgrade(te, i * 2 + j, 11 + j * 18, 29 + i * 18));
        }
    }

    addSlotToContainer(new Slot(te, 4, 55, 48){
        @Override
        public boolean isItemValid(ItemStack stack){
            return stack != null && stack.isItemEqual(new ItemStack(Blockss.pressureTube));
        }
    });

    // Add the player's inventory slots to the container
    for(int inventoryRowIndex = 0; inventoryRowIndex < 3; ++inventoryRowIndex) {
        for(int inventoryColumnIndex = 0; inventoryColumnIndex < 9; ++inventoryColumnIndex) {
            addSlotToContainer(new Slot(inventoryPlayer, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 8 + inventoryColumnIndex * 18, 84 + inventoryRowIndex * 18));
        }
    }

    // Add the player's action bar slots to the container
    for(int actionBarSlotIndex = 0; actionBarSlotIndex < 9; ++actionBarSlotIndex) {
        addSlotToContainer(new Slot(inventoryPlayer, actionBarSlotIndex, 8 + actionBarSlotIndex * 18, 142));
    }

    if(te.getTankInfo(ForgeDirection.UP)[0].fluid != null && te.getTankInfo(ForgeDirection.UP)[0].fluid.getFluid() == Fluids.oil) {
        AchievementHandler.giveAchievement(inventoryPlayer.player, new ItemStack(Fluids.getBucket(Fluids.oil)));
    }
}
 
Example #22
Source Project: enderutilities   Author: maruohon   File: ItemRuler.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public void cycleLocationSelection(ItemStack rulerStack, boolean reverse)
{
    ItemStack moduleStack = this.getSelectedModuleStack(rulerStack, ModuleType.TYPE_MEMORY_CARD_MISC);

    if (moduleStack.isEmpty() == false)
    {
        int max = Math.min(this.getLocationCount(rulerStack), 7);
        NBTUtils.cycleByteValue(moduleStack, TAG_WRAPPER, TAG_SELECTED_LOCATION, max, reverse);
    }
}
 
Example #23
Source Project: mocreaturesdev   Author: DrZhark   File: MoCEntityThrowableRock.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void transformToItem()
{
    EntityItem entityitem = new EntityItem(worldObj, posX, posY, posZ, new ItemStack(getType(), 1, getMetadata()));
    entityitem.delayBeforeCanPickup = 10;
    entityitem.age = 5500;
    worldObj.spawnEntityInWorld(entityitem);
    this.setDead();
}
 
Example #24
Source Project: PneumaticCraft   Author: MineMaarten   File: PneumaticRecipeRegistry.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static boolean isItemEqual(Object o, ItemStack stack){

        if(o instanceof ItemStack) {
            return OreDictionary.itemMatches((ItemStack)o, stack, false);
        } else {
            String oreDict = (String)((Pair)o).getKey();
            return OreDictionaryHelper.isItemEqual(oreDict, stack);
        }
    }
 
Example #25
Source Project: Electro-Magic-Tools   Author: TeamAmeriFrance   File: ItemIC2Baubles.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public BaubleType getBaubleType(ItemStack stack) {
	if (stack.getItemDamage() <= 1) {
		return BaubleType.RING;
	} else {
		return null;
	}
}
 
Example #26
Source Project: Cyberware   Author: Flaxbeard   File: TileEntityEngineeringTable.java    License: MIT License 5 votes vote down vote up
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate)
{
	slots.overrideExtract = true;
	ItemStack ret = slots.extractItem(slot, amount, simulate);
	slots.overrideExtract = false;
	return ret;
}
 
Example #27
Source Project: Wizardry   Author: TeamWizardry   File: RenderCodex.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public List<ItemStack> getSpellInventory(ItemStack stack) {
	if (!NBTHelper.getBoolean(stack, "has_spell", false)) return new ArrayList<>();

	NBTTagList spellList = NBTHelper.getList(stack, NBTConstants.NBT.SPELL, net.minecraftforge.common.util.Constants.NBT.TAG_STRING);
	if (spellList == null) return new ArrayList<>();

	return SpellUtils.getSpellItems(SpellUtils.deserializeModuleList(spellList));
}
 
Example #28
Source Project: NotEnoughItems   Author: Chicken-Bones   File: FurnaceRecipeHandler.java    License: MIT License 5 votes vote down vote up
@Override
public void loadCraftingRecipes(ItemStack result) {
    Map<ItemStack, ItemStack> recipes = (Map<ItemStack, ItemStack>) FurnaceRecipes.instance().getSmeltingList();
    for (Entry<ItemStack, ItemStack> recipe : recipes.entrySet())
        if (NEIServerUtils.areStacksSameType(recipe.getValue(), result))
            arecipes.add(new SmeltingPair(recipe.getKey(), recipe.getValue()));
}
 
Example #29
Source Project: Hyperium   Author: HyperiumClient   File: ArrowCount.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void draw(int starX, double startY, boolean isConfig) {
    List<ItemStack> list = new ArrayList<>();
    list.add(new ItemStack(Item.getItemById(262), 64));
    EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer;
    if (thePlayer != null) {
        int c = Arrays.stream(thePlayer.inventory.mainInventory).filter(Objects::nonNull).filter(is ->
            is.getUnlocalizedName().equalsIgnoreCase("item.arrow")).mapToInt(is -> is.stackSize).sum();
        ElementRenderer.render(list, starX, startY, false);
        ElementRenderer.draw(starX + 16, startY + 8, "x" + (isConfig ? 64 : c));
    }
}
 
Example #30
Source Project: NEI-Integration   Author: Tonius   File: RecipeHandlerCyaniteReprocessor.java    License: MIT License 5 votes vote down vote up
@Override
public void loadUsageRecipes(ItemStack ingred) {
    super.loadUsageRecipes(ingred);
    for (OreDictToReactantMapping o : solidToReactant.values()) {
        ReactantData data = Reactants.getReactant(o.getProduct());
        if (data.isWaste()) {
            for (ItemStack ore : OreDictionary.getOres(o.getSource())) {
                if (Utils.areStacksSameTypeCraftingSafe(ore, ingred)) {
                    this.arecipes.add(new CachedCyaniteReprocessorRecipe(ore, OreDictionary.getOres("ingotBlutonium").get(0)));
                }
            }
        }
    }
}