net.minecraft.item.Item Java Examples

The following examples show how to use net.minecraft.item.Item. 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: ClientProxy.java    From enderutilities with GNU Lesser General Public License v3.0 7 votes vote down vote up
@SubscribeEvent
public void registerItemColorHandlers(ColorHandlerEvent.Item event)
{
    ItemColors colors = event.getItemColors();

    if (EnderUtilitiesBlocks.ELEVATOR.isEnabled())
    {
        colors.registerItemColorHandler(new ItemColorHandlerDyes(1, 0xFFFFFF), Item.getItemFromBlock(EnderUtilitiesBlocks.ELEVATOR));
    }

    if (EnderUtilitiesBlocks.ELEVATOR_SLAB.isEnabled())
    {
        colors.registerItemColorHandler(new ItemColorHandlerDyes(1, 0xFFFFFF), Item.getItemFromBlock(EnderUtilitiesBlocks.ELEVATOR_SLAB));
    }

    if (EnderUtilitiesBlocks.ELEVATOR_LAYER.isEnabled())
    {
        colors.registerItemColorHandler(new ItemColorHandlerDyes(1, 0xFFFFFF), Item.getItemFromBlock(EnderUtilitiesBlocks.ELEVATOR_LAYER));
    }
}
 
Example #2
Source File: EntityMage.java    From ToroQuest with GNU General Public License v3.0 6 votes vote down vote up
private void dropLootItem(Item item, int amount) {
	if (amount == 0) {
		return;
	}

	for (int i = 0; i < amount; i++) {
		ItemStack stack = new ItemStack(item);
		EntityItem dropItem = new EntityItem(world, posX, posY, posZ, stack.copy());
		dropItem.setNoPickupDelay();
		dropItem.motionY = rand.nextDouble();
		dropItem.motionZ = rand.nextDouble() - 0.5d;
		dropItem.motionX = rand.nextDouble() - 0.5d;
		world.spawnEntity(dropItem);
	}

}
 
Example #3
Source File: AuthorCmd.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(args.length == 0)
		throw new CmdSyntaxError();
	
	if(!MC.player.abilities.creativeMode)
		throw new CmdError("Creative mode only.");
	
	ItemStack heldItem = MC.player.inventory.getMainHandStack();
	int heldItemID = Item.getRawId(heldItem.getItem());
	int writtenBookID = Item.getRawId(Items.WRITTEN_BOOK);
	
	if(heldItemID != writtenBookID)
		throw new CmdError(
			"You must hold a written book in your main hand.");
	
	String author = String.join(" ", args);
	heldItem.putSubTag("author", StringTag.of(author));
}
 
Example #4
Source File: EnderStorageClientProxy.java    From EnderStorage with MIT License 6 votes vote down vote up
@Override
public void init()
{
    if(config.getTag("checkUpdates").getBooleanValue(true))
        CCUpdateChecker.updateCheck("EnderStorage");
    ClientUtils.enhanceSupportersList("EnderStorage");

    super.init();

    PacketCustom.assignHandler(EnderStorageCPH.channel, new EnderStorageCPH());

    MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(blockEnderChest), new ItemEnderStorageRenderer());

    ClientRegistry.bindTileEntitySpecialRenderer(TileEnderChest.class, new EnderChestRenderer());
    ClientRegistry.bindTileEntitySpecialRenderer(TileEnderTank.class, new EnderTankRenderer());
}
 
Example #5
Source File: Utils.java    From OpenModsLib with MIT License 6 votes vote down vote up
static Matcher<ItemStack> containsItem(final Item item, final int size) {
	return new BaseMatcher<ItemStack>() {
		@Override
		public boolean matches(Object o) {
			if (o instanceof ItemStack) {
				ItemStack stack = (ItemStack)o;
				return stack.getItem() == item && stack.getCount() == size;
			}

			return false;
		}

		@Override
		public void describeTo(Description arg0) {
			arg0.appendText(String.format("%dx%s", size, item.getUnlocalizedName()));
		}
	};
}
 
Example #6
Source File: OreDictHandler.java    From bartworks with MIT License 6 votes vote down vote up
public static void adaptCacheForWorld(){
    Set<String> used = new HashSet<>(OreDictHandler.cache.keySet());
    OreDictHandler.cache.clear();
    OreDictHandler.cacheNonBW.clear();
    for (String s : used) {
        if (!OreDictionary.getOres(s).isEmpty()) {
            ItemStack tmpstack = OreDictionary.getOres(s).get(0).copy();
            Pair<Integer, Short> p = new Pair<>(Item.getIdFromItem(tmpstack.getItem()), (short) tmpstack.getItemDamage());
            OreDictHandler.cache.put(s, p);
            for (ItemStack tmp : OreDictionary.getOres(s)) {
                Pair<Integer, Short> p2 = new Pair<>(Item.getIdFromItem(tmp.getItem()), (short) tmp.getItemDamage());
                GameRegistry.UniqueIdentifier UI = GameRegistry.findUniqueIdentifierFor(tmp.getItem());
                if (UI == null)
                    UI = GameRegistry.findUniqueIdentifierFor(Block.getBlockFromItem(tmp.getItem()));
                if (!UI.modId.equals(MainMod.MOD_ID) && !UI.modId.equals(BartWorksCrossmod.MOD_ID) && !UI.modId.equals("BWCore")) {
                    OreDictHandler.cacheNonBW.add(p2);
                }
            }
        }
    }
}
 
Example #7
Source File: ThaumcraftApi.java    From GardenCollection with MIT License 6 votes vote down vote up
/**
 * Checks to see if the passed item/block already has aspects associated with it.
 * @param id
 * @param meta
 * @return 
 */
public static boolean exists(Item item, int meta) {
	AspectList tmp = ThaumcraftApi.objectTags.get(Arrays.asList(item,meta));
	if (tmp==null) {
		tmp = ThaumcraftApi.objectTags.get(Arrays.asList(item,OreDictionary.WILDCARD_VALUE));
		if (meta==OreDictionary.WILDCARD_VALUE && tmp==null) {
			int index=0;
			do {
				tmp = ThaumcraftApi.objectTags.get(Arrays.asList(item,index));
				index++;
			} while (index<16 && tmp==null);
		}
		if (tmp==null) return false;
	}
	
	return true;
}
 
Example #8
Source File: ProcessorRecipes.java    From EmergingTechnology with MIT License 6 votes vote down vote up
private static void registerThirdPartyRecipes() {

        List<ItemStack> plasticInputs = new ArrayList<ItemStack>();
        List<ItemStack> clearPlasticInputs = new ArrayList<ItemStack>();
        List<ItemStack> paperInputs = new ArrayList<ItemStack>();
        List<ItemStack> fertilizerInputs = new ArrayList<ItemStack>();

        if (ModLoader.isDumpsterDivingLoaded()) {
            fertilizerInputs.add(new ItemStack(Item.getByNameOrId("dumpsterdiving:mold_apple")));
            fertilizerInputs.add(new ItemStack(Item.getByNameOrId("dumpsterdiving:mold_pumpkin")));
            fertilizerInputs.add(new ItemStack(Item.getByNameOrId("dumpsterdiving:slop_rand")));
            fertilizerInputs.add(new ItemStack(Item.getByNameOrId("dumpsterdiving:mold_bread")));
            fertilizerInputs.add(new ItemStack(Item.getByNameOrId("dumpsterdiving:mold_stew")));
            paperInputs.add(new ItemStack(Item.getByNameOrId("dumpsterdiving:scrap_wooddust")));
        }

        registerProcessorRecipes(new ItemStack(ModItems.plasticblock), plasticInputs);
        registerProcessorRecipes(new ItemStack(ModItems.clearplasticblock), clearPlasticInputs);
        registerProcessorRecipes(new ItemStack(ModItems.paperpulp), paperInputs);
        registerProcessorRecipes(new ItemStack(ModItems.fertilizer), fertilizerInputs);
    }
 
Example #9
Source File: EntityBlock.java    From OpenModsLib with MIT License 6 votes vote down vote up
private void dropBlock() {
	final Block block = blockState.getBlock();

	Random rand = world.rand;

	final int count = block.quantityDropped(blockState, 0, rand);
	for (int i = 0; i < count; i++) {
		final Item item = block.getItemDropped(blockState, rand, 0);
		if (item != null) {
			ItemStack toDrop = new ItemStack(item, 1, block.damageDropped(blockState));
			entityDropItem(toDrop, 0.1f);
		}
	}

	if (tileEntity instanceof IInventory) {
		IInventory inv = (IInventory)tileEntity;
		for (int i = 0; i < inv.getSizeInventory(); i++) {
			ItemStack is = inv.getStackInSlot(i);
			if (is != null) entityDropItem(is, 0.1f);
		}
	}
}
 
Example #10
Source File: ModHandler.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static Object finalizeIngredient(Object ingredient) {
    if (ingredient instanceof MetaItem.MetaValueItem) {
        ingredient = ((MetaItem<?>.MetaValueItem) ingredient).getStackForm();
    } else if (ingredient instanceof Enum) {
        ingredient = ((Enum<?>) ingredient).name();
    } else if (ingredient instanceof UnificationEntry) {
        ingredient = ingredient.toString();
    } else if (!(ingredient instanceof ItemStack
        || ingredient instanceof Item
        || ingredient instanceof Block
        || ingredient instanceof String
        || ingredient instanceof Character
        || ingredient instanceof Boolean)) {
        throw new IllegalArgumentException(ingredient.getClass().getSimpleName() + " type is not suitable for crafting input.");
    }
    return ingredient;
}
 
Example #11
Source File: ThaumcraftApi.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
public static Object[] getCraftingRecipeKey(EntityPlayer player, ItemStack stack) {
	int[] key = new int[] {Item.getIdFromItem(stack.getItem()),stack.getItemDamage()};
	if (keyCache.containsKey(key)) {
		if (keyCache.get(key)==null) return null;
		if (ThaumcraftApiHelper.isResearchComplete(player.getCommandSenderName(), (String)(keyCache.get(key))[0]))
			return keyCache.get(key);
		else 
			return null;
	}
	for (ResearchCategoryList rcl:ResearchCategories.researchCategories.values()) {
		for (ResearchItem ri:rcl.research.values()) {
			if (ri.getPages()==null) continue;
			for (int a=0;a<ri.getPages().length;a++) {
				ResearchPage page = ri.getPages()[a];
				if (page.recipe!=null && page.recipe instanceof CrucibleRecipe[]) {
					CrucibleRecipe[] crs = (CrucibleRecipe[]) page.recipe;
					for (CrucibleRecipe cr:crs) {
						if (cr.getRecipeOutput().isItemEqual(stack)) {
							keyCache.put(key,new Object[] {ri.key,a});
							if (ThaumcraftApiHelper.isResearchComplete(player.getCommandSenderName(), ri.key))
								return new Object[] {ri.key,a};
						}
					}
				} else
				if (page.recipeOutput!=null && stack !=null && page.recipeOutput.isItemEqual(stack)) {
					keyCache.put(key,new Object[] {ri.key,a});
					if (ThaumcraftApiHelper.isResearchComplete(player.getCommandSenderName(), ri.key))
						return new Object[] {ri.key,a};
					else 
						return null;
				}
			}
		}
	}
	keyCache.put(key,null);
	return null;
}
 
Example #12
Source File: MixinLayerArmorBase.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Inject(method = "renderLayer", at = @At("HEAD"), cancellable = true)
private void preRenderLayer(EntityLivingBase entitylivingbaseIn, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks,
                            float netHeadYaw, float headPitch, float scale, int armorSlot, CallbackInfo ci) {
    ItemStack itemstack = this.getCurrentArmor(entitylivingbaseIn, armorSlot);

    if (itemstack != null && itemstack.getItem() instanceof ItemArmor) {
        Item item = itemstack.getItem();
        if (Settings.HIDE_LEATHER_ARMOR &&
            (item == Items.leather_boots || item == Items.leather_leggings || item == Items.leather_chestplate || item == Items.leather_helmet)) {
            ci.cancel();
        }
    }
}
 
Example #13
Source File: TerminalIdAccess.java    From OpenPeripheral-Addons with MIT License 5 votes vote down vote up
@Override
public Optional<Long> getFor(ItemStack stack) {
	final Item item = stack.getItem();
	if (item instanceof ITerminalItem) {
		final ITerminalItem terminalItem = (ITerminalItem)item;
		return Optional.fromNullable(terminalItem.getTerminalGuid(stack));
	}

	return Optional.absent();
}
 
Example #14
Source File: ItemUtils.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static String getStackString(ItemStack stack)
{
    if (stack.isEmpty() == false)
    {
        ResourceLocation rl = Item.REGISTRY.getNameForObject(stack.getItem());

        return String.format("[%s @ %d - display: %s - NBT: %s] (%s)",
                rl != null ? rl.toString() : "null", stack.getMetadata(), stack.getDisplayName(),
                stack.getTagCompound() != null ? stack.getTagCompound().toString() : "<no NBT>",
                stack.toString());
    }

    return "<empty>";
}
 
Example #15
Source File: EnderStorage.java    From EnderStorage with MIT License 5 votes vote down vote up
private void loadPersonalItem() {
    ConfigTag tag = config.getTag("personalItemID")
            .setComment("The name of the item used to set the chest to personal. Diamond by default");
    String name = tag.getValue("diamond");
    personalItem = (Item) Item.itemRegistry.getObject(name);
    if (personalItem == null) {
        personalItem = Items.diamond;
        tag.setValue("diamond");
    }
}
 
Example #16
Source File: RecipeHandlerApiary.java    From NEI-Integration with MIT License 5 votes vote down vote up
public CachedApiaryRecipe() {
    this.input = new PositionedStack(new ItemStack(ItemRegistry.queenbeeItem), 21, 24);
    
    int i = 0;
    for (Entry<Item, Float> e : BEE_PRODUCTS.entrySet()) {
        this.outputs.add(new PositionedStackAdv(new ItemStack(e.getKey()), 57 + 18 * i, 6).setChance(e.getValue()));
        i++;
    }
}
 
Example #17
Source File: PositionedStack.java    From NotEnoughItems with MIT License 5 votes vote down vote up
public boolean contains(Item ingred) {
    for (ItemStack item : items) {
        if (item.getItem() == ingred) {
            return true;
        }
    }

    return false;
}
 
Example #18
Source File: BlockTurbinePart.java    From BigReactors with MIT License 5 votes vote down vote up
@Override
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List)
{
	for(int i = 0; i < _subBlocks.length; i++) {
		par3List.add(new ItemStack(this, 1, i));
	}
}
 
Example #19
Source File: BlockGardenProxy.java    From GardenCollection with MIT License 5 votes vote down vote up
private Block getPlantBlock (TileEntityGarden tileEntity, Item item) {
    if (item == null)
        return null;
    if (item instanceof IPlantable)
        return ((IPlantable)item).getPlant(tileEntity.getWorldObj(), tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
    if (item instanceof ItemBlock)
        return Block.getBlockFromItem(item);

    return null;
}
 
Example #20
Source File: BlockTofuGemOre.java    From TofuCraftReload with MIT License 5 votes vote down vote up
/**
 * Get the quantity dropped based on the given fortune level
 */
public int quantityDroppedWithBonus(int fortune, Random random) {
    if (fortune > 0 && Item.getItemFromBlock(this) != this.getItemDropped((IBlockState) this.getBlockState().getValidStates().iterator().next(), random, fortune)) {
        int i = random.nextInt(fortune + 2) - 1;

        if (i < 0) {
            i = 0;
        }

        return this.quantityDropped(random) * (i + 1);
    } else {
        return this.quantityDropped(random);
    }
}
 
Example #21
Source File: ClientProxy.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
private static void registerBlockItem(Block toRegister) {
    Item item = Item.getItemFromBlock(toRegister);
    Minecraft.getMinecraft()
        .getRenderItem()
        .getItemModelMesher()
        .register(item, 0,
            new ModelResourceLocation(ValkyrienSkiesMod.MOD_ID + ":" + item.getTranslationKey()
                .substring(5), "inventory"));
}
 
Example #22
Source File: ItemResource.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 5 votes vote down vote up
@SideOnly(Side.CLIENT)
@Override
public void getSubItems(Item par1, CreativeTabs xCreativeTabs, List list) {
    for (int j = 0; j < 5; ++j) {
        list.add(new ItemStack(par1, 1, j));
    }
}
 
Example #23
Source File: LPHelper.java    From ExtraCells1 with MIT License 5 votes vote down vote up
public LPHelper()
{
	try
	{
		Class LPMain = Class.forName("logisticspipes.LogisticsPipes");
		Field field = LPMain.getDeclaredField("LogisticsFluidContainer");
		LPFluidItem = (Item) field.get(Item.appleGold);
	} catch (Throwable e)
	{
		LPInstalled = false;
	}
	LPInstalled = LPFluidItem != null;
}
 
Example #24
Source File: FacadeHelper.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static ImmutableList<ItemStack> retrieveValidItemsList() {
    return StreamSupport.stream(Item.REGISTRY.spliterator(), false)
        .filter(item -> item instanceof ItemBlock)
        .flatMap(item -> getSubItems(item).stream())
        .filter(FacadeHelper::isValidFacade)
        .collect(GTUtility.toImmutableList());
}
 
Example #25
Source File: BlockLantern.java    From GardenCollection with MIT License 5 votes vote down vote up
@Override
public ArrayList<ItemStack> getDrops (World world, int x, int y, int z, int metadata, int fortune) {
    TileEntityLantern tile = getTileEntity(world, x, y, z);
    ArrayList<ItemStack> ret = new ArrayList<ItemStack>();

    int count = quantityDropped(metadata, fortune, world.rand);
    for(int i = 0; i < count; i++)
    {
        Item item = getItemDropped(metadata, world.rand, fortune);
        if (item != null)
        {
            boolean glass = false;
            String source = null;
            int sourceMeta = 0;

            if (tile != null) {
                glass = tile.hasGlass();
                source = tile.getLightSource();
                sourceMeta = tile.getLightSourceMeta();
            }

            ItemStack stack = ((ItemLantern)Item.getItemFromBlock(this)).makeItemStack(1, metadata, glass, source, sourceMeta);
            ret.add(stack);
        }
    }
    return ret;
}
 
Example #26
Source File: ItemElectricThorHammer.java    From Electro-Magic-Tools with 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 #27
Source File: FurnaceRecipeHandler.java    From NotEnoughItems with MIT License 5 votes vote down vote up
private static Set<Item> excludedFuels() {
    Set<Item> efuels = new HashSet<Item>();
    efuels.add(Item.getItemFromBlock(Blocks.brown_mushroom));
    efuels.add(Item.getItemFromBlock(Blocks.red_mushroom));
    efuels.add(Item.getItemFromBlock(Blocks.standing_sign));
    efuels.add(Item.getItemFromBlock(Blocks.wall_sign));
    efuels.add(Item.getItemFromBlock(Blocks.trapped_chest));
    return efuels;
}
 
Example #28
Source File: ItemStackMetadataBuilder.java    From OpenPeripheral with MIT License 5 votes vote down vote up
@Override
public IMetaProviderProxy createProxy(final ItemStack stack) {
	final Item item = stack.getItem();
	if (item == null) return null;

	final Map<String, IItemStackMetaProvider<?>> providers = getProviders(item, stack);
	return new Proxy(providers, stack, item);
}
 
Example #29
Source File: BlockDoorBase.java    From Sakura_mod with MIT License 5 votes vote down vote up
private Item getItem()
  {
      if(this == BlockLoader.BAMBOODOOR){
          return ItemLoader.BAMBOO_DOOR;
      }
return ItemLoader.BAMBOO_DOOR;
  }
 
Example #30
Source File: AdapterWritingDesk.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
private NotebookWrapper createInventoryWrapper(TileEntity tile, Index slot) {
	ItemStack notebook = GET_NOTEBOOK.call(tile, slot.byteValue());
	Preconditions.checkState(notebook != null, "Empty slot");
	Item item = notebook.getItem();
	Preconditions.checkState(item instanceof IItemPageCollection, "Invalid item in slot");
	return new NotebookWrapper((WorldServer)tile.getWorldObj(), (IItemPageCollection)item, notebook);
}