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 File: BlockTrackEntryInventory.java    From PneumaticCraft with 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 File: PlayerCivilizationCapabilityImpl.java    From ToroQuest with 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 #3
Source File: ItemHandyBag.java    From enderutilities with 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 #4
Source File: HayCrook.java    From Ex-Aliquo with 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 #5
Source File: MachineManager.java    From customstuff4 with 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 #6
Source File: RenderEventHandler.java    From enderutilities with 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 File: ItemChairWand.java    From enderutilities with 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 #8
Source File: PacketSwapPearl.java    From Wizardry with 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 #9
Source File: RenameCmd.java    From Wurst7 with 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 #10
Source File: ItemPlasticPlants.java    From PneumaticCraft with 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 File: MoCEntityThrowableRock.java    From mocreaturesdev with 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 #12
Source File: TileEntityInventory.java    From BigReactors with 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 #13
Source File: ItemRuler.java    From enderutilities with 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 #14
Source File: ContainerGasLift.java    From PneumaticCraft with 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 #15
Source File: PneumaticRecipeRegistry.java    From PneumaticCraft with 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 #16
Source File: SlotSaltFurnace.java    From TofuCraftReload with 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 File: BlockCompostBin.java    From GardenCollection with 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 #18
Source File: TileEntityEngineeringTable.java    From Cyberware with 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 #19
Source File: ItemIC2Baubles.java    From Electro-Magic-Tools with 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 #20
Source File: RenderCodex.java    From Wizardry with 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 #21
Source File: FurnaceRecipeHandler.java    From NotEnoughItems with 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 #22
Source File: ArrowCount.java    From Hyperium with 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 #23
Source File: RecipeHandlerCyaniteReprocessor.java    From NEI-Integration with 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)));
                }
            }
        }
    }
}
 
Example #24
Source File: AutoToolModule.java    From seppuku with GNU General Public License v3.0 5 votes vote down vote up
private float blockStrength(BlockPos pos, ItemStack stack) {
    final Minecraft mc = Minecraft.getMinecraft();

    float hardness = mc.world.getBlockState(pos).getBlockHardness(mc.world, pos);

    if (hardness < 0.0F) {
        return 0.0F;
    }

    if (!canHarvestBlock(mc.world.getBlockState(pos).getBlock(), pos, stack)) {
        return getDigSpeed(mc.world.getBlockState(pos), pos, stack) / hardness / 100F;
    } else {
        return getDigSpeed(mc.world.getBlockState(pos), pos, stack) / hardness / 30F;
    }
}
 
Example #25
Source File: GTColorItemBlock.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Color getColor(ItemStack stack, int index) {
	NBTTagCompound nbt = StackUtil.getNbtData(stack);
	if (nbt.hasKey("color")) {
		return new Color(nbt.getInteger("color"));
	}
	if (this.block instanceof IGTColorBlock) {
		return ((IGTColorBlock) block).getColor(null, null, null, this.block, index);
	} else {
		return null;
	}
}
 
Example #26
Source File: BrewingFuelRegistryHelper.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
public static void registerFuel(ItemStack fuel, int brews) {
	try {
		Class<?> cls = Class.forName("ganymedes01.etfuturum.recipes.BrewingFuelRegistry");
		Method m = cls.getMethod("registerFuel", ItemStack.class, int.class);
		m.invoke(null, fuel, brews);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example #27
Source File: CmdEnchant.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
public void enchant(ItemStack item, Enchantment e, int level) {
	if (item.getTag() == null) item.setTag(new CompoundTag());
	if (!item.getTag().contains("Enchantments", 9)) {
		item.getTag().put("Enchantments", new ListTag());
    }

    ListTag listnbt = item.getTag().getList("Enchantments", 10);
    CompoundTag compoundnbt = new CompoundTag();
    compoundnbt.putString("id", String.valueOf(Registry.ENCHANTMENT.getId(e)));
    compoundnbt.putInt("lvl", level);
    listnbt.add(compoundnbt);
}
 
Example #28
Source File: BlockPedestal.java    From Artifacts with MIT License 5 votes vote down vote up
private void dropItems(World world, int x, int y, int z){
	Random rand = new Random();

	TileEntity tileEntity = world.getTileEntity(x, y, z);
	if (!(tileEntity instanceof IInventory)) {
		return;
	}
	IInventory inventory = (IInventory) tileEntity;

	for (int i = 0; i < inventory.getSizeInventory(); i++) {
		ItemStack item = inventory.getStackInSlot(i);

		if (item != null && item.stackSize > 0) {
			float rx = rand.nextFloat() * 0.8F + 0.1F;
			float ry = rand.nextFloat() * 0.8F + 0.1F;
			float rz = rand.nextFloat() * 0.8F + 0.1F;

			EntityItem entityItem = new EntityItem(world,
					x + rx, y + ry, z + rz,
					new ItemStack(item.getItem(), item.stackSize, item.getItemDamage()));

			if (item.hasTagCompound()) {
				entityItem.getEntityItem().setTagCompound((NBTTagCompound) item.getTagCompound().copy());
			}

			float factor = 0.05F;
			entityItem.motionX = rand.nextGaussian() * factor;
			entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
			entityItem.motionZ = rand.nextGaussian() * factor;
			world.spawnEntityInWorld(entityItem);
			item.stackSize = 0;
		}
	}
}
 
Example #29
Source File: SimpleItemFilter.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void onMaxStackSizeChange() {
    for (int i = 0; i < itemFilterSlots.getSlots(); i++) {
        ItemStack itemStack = itemFilterSlots.getStackInSlot(i);
        if (!itemStack.isEmpty()) {
            itemStack.setCount(Math.min(itemStack.getCount(), getMaxStackSize()));
        }
    }
}
 
Example #30
Source File: CraftingManagerCS4Test.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void test_addRecipe_vanilla()
{
    assertThrows(IllegalArgumentException.class, () ->
            CraftingManagerCS4.addRecipe(new ResourceLocation("minecraft:vanilla"),
                                         new DamageableShapelessOreRecipe(new ResourceLocation("group"),
                                                                          new int[] {1},
                                                                          new ItemStack(Items.APPLE),
                                                                          Ingredient.fromItem(Items.APPLE))));
}