Search in sources :

Example 1 with MetaOreDictItem

use of gregtech.api.items.metaitem.MetaOreDictItem in project GregTech by GregTechCEu.

the class MetaItems method init.

public static void init() {
    MetaItem1 first = new MetaItem1();
    first.setRegistryName("meta_item_1");
    MetaTool tool = new MetaTool();
    tool.setRegistryName("meta_tool");
    CT_OREDICT_ITEM = new MetaOreDictItem((short) 0);
    CT_OREDICT_ITEM.setRegistryName("meta_oredict_item_ct");
    MetaArmor armor = new MetaArmor();
    armor.setRegistryName("gt_armor");
    for (OrePrefix prefix : orePrefixes) {
        String regName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, prefix.name());
        MetaPrefixItem metaOrePrefix = new MetaPrefixItem(prefix);
        metaOrePrefix.setRegistryName(String.format("meta_%s", regName));
    }
}
Also used : MetaArmor(gregtech.common.items.armor.MetaArmor) OrePrefix(gregtech.api.unification.ore.OrePrefix) MetaPrefixItem(gregtech.api.items.materialitem.MetaPrefixItem) MetaOreDictItem(gregtech.api.items.metaitem.MetaOreDictItem)

Example 2 with MetaOreDictItem

use of gregtech.api.items.metaitem.MetaOreDictItem in project GregTech by GregTechCEu.

the class ClientProxy method addMaterialFormulaHandler.

@SubscribeEvent
public static void addMaterialFormulaHandler(@Nonnull ItemTooltipEvent event) {
    ItemStack itemStack = event.getItemStack();
    // Handles Item tooltips
    List<String> tooltips = new ArrayList<>();
    // Test for Items
    UnificationEntry unificationEntry = OreDictUnifier.getUnificationEntry(itemStack);
    if (itemStack.getItem() instanceof MetaOreDictItem) {
        // Test for OreDictItems
        MetaOreDictItem oreDictItem = (MetaOreDictItem) itemStack.getItem();
        Optional<String> oreDictName = OreDictUnifier.getOreDictionaryNames(itemStack).stream().findFirst();
        if (oreDictName.isPresent() && oreDictItem.OREDICT_TO_FORMULA.containsKey(oreDictName.get()) && !oreDictItem.OREDICT_TO_FORMULA.get(oreDictName.get()).isEmpty()) {
            tooltips.add(TextFormatting.YELLOW + oreDictItem.OREDICT_TO_FORMULA.get(oreDictName.get()));
        }
    } else if (unificationEntry != null && unificationEntry.material != null) {
        if (unificationEntry.material.getChemicalFormula() != null && !unificationEntry.material.getChemicalFormula().isEmpty())
            tooltips.add(TextFormatting.YELLOW + unificationEntry.material.getChemicalFormula());
    } else if (ItemNBTUtils.hasTag(itemStack)) {
        // Test for Fluids
        // Vanilla bucket
        tooltips = FluidTooltipUtil.getFluidTooltip(ItemNBTUtils.getString(itemStack, "FluidName"));
        // GTCE Cells, Forestry cans, some other containers
        if (tooltips == null || tooltips.size() == 0) {
            NBTTagCompound compound = itemStack.getTagCompound();
            if (compound != null && compound.hasKey(FluidHandlerItemStack.FLUID_NBT_KEY, Constants.NBT.TAG_COMPOUND)) {
                FluidStack fstack = FluidStack.loadFluidStackFromNBT(compound.getCompoundTag(FluidHandlerItemStack.FLUID_NBT_KEY));
                tooltips = FluidTooltipUtil.getFluidTooltip(fstack);
            }
        }
    } else if (itemStack.getItem().equals(Items.WATER_BUCKET)) {
        // Water and Lava buckets have a separate registry name from other buckets
        tooltips = FluidTooltipUtil.getWaterTooltip();
    } else if (itemStack.getItem().equals(Items.LAVA_BUCKET)) {
        tooltips = FluidTooltipUtil.getLavaTooltip();
    }
    if (tooltips != null) {
        for (String s : tooltips) {
            if (s == null || s.isEmpty())
                continue;
            event.getToolTip().add(s);
        }
    }
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) UnificationEntry(gregtech.api.unification.stack.UnificationEntry) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) FluidHandlerItemStack(net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack) ItemStack(net.minecraft.item.ItemStack) MetaOreDictItem(gregtech.api.items.metaitem.MetaOreDictItem) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

MetaOreDictItem (gregtech.api.items.metaitem.MetaOreDictItem)2 MetaPrefixItem (gregtech.api.items.materialitem.MetaPrefixItem)1 OrePrefix (gregtech.api.unification.ore.OrePrefix)1 UnificationEntry (gregtech.api.unification.stack.UnificationEntry)1 MetaArmor (gregtech.common.items.armor.MetaArmor)1 ArrayList (java.util.ArrayList)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 FluidHandlerItemStack (net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1