Search in sources :

Example 1 with TC_AspectStack

use of gregapi.data.TC.TC_AspectStack in project gregtech6 by GregTech6.

the class MultiItemRandom method addItem.

/**
 * This adds a Custom Item.
 * @param aID The Id of the assigned Item [0 - 32766]
 * @param aEnglish The Default Localised Name of the created Item
 * @param aToolTip The Default ToolTip of the created Item, you can also insert null for having no ToolTip
 * @param aFoodBehavior The Food Value of this Item. Can be null aswell. Just a convenience thing.
 * @param aRandomData The OreDict Names you want to give the Item. Also used for TC Aspects and some other things.
 * @return An ItemStack containing the newly created Item.
 */
@SuppressWarnings("unchecked")
public final ItemStack addItem(int aID, String aEnglish, String aToolTip, Object... aRandomData) {
    if (aToolTip == null)
        aToolTip = "";
    if (mAllowedToAddItems && aID >= 0 && aID < 32767 && aID != W) {
        mLastID = (short) aID;
        ItemStack aStack = ST.make(this, 1, aID);
        if (UT.Code.stringValid(aEnglish)) {
            mEnabledItems.set(aID);
            mVisibleItems.set(aID);
            LH.add(getUnlocalizedName(aStack) + ".name", aEnglish);
            LH.add(getUnlocalizedName(aStack) + ".tooltip", aToolTip);
        }
        List<TC_AspectStack> tAspects = new ArrayListNoNulls<>();
        // Important Stuff to do first
        for (Object tRandomData : aRandomData) if (tRandomData instanceof TagData) {
            if (tRandomData == TD.Creative.HIDDEN) {
                mVisibleItems.set(aID, F);
                continue;
            }
            if (tRandomData == TD.Properties.AUTO_BLACKLIST) {
                OM.blacklist_(aStack);
                continue;
            }
        }
        // now check for the rest
        for (Object tRandomData : aRandomData) if (tRandomData != null) {
            boolean tUseOreDict = T;
            if (tRandomData instanceof ItemStackSet) {
                ((ItemStackSet<?>) tRandomData).add(aStack);
                continue;
            }
            if (tRandomData instanceof TagData) {
                continue;
            }
            if (tRandomData instanceof Number) {
                setBurnValue(aID, ((Number) tRandomData).intValue());
                continue;
            }
            if (tRandomData instanceof IFoodStat) {
                setFoodBehavior(aID, (IFoodStat) tRandomData);
                if (IL.IC2_Food_Can_Empty.exists() && IL.IC2_Food_Can_Filled.exists() && getContainerItem(aStack) == null) {
                    int tFoodValue = ((IFoodStat) tRandomData).getFoodLevel(this, aStack, null);
                    if (tFoodValue > 0)
                        RM.Canner.addRecipe2(T, 16, tFoodValue * 16, aStack, IL.IC2_Food_Can_Empty.get(tFoodValue), ((IFoodStat) tRandomData).isRotten(this, aStack, null) ? IL.IC2_Food_Can_Spoiled.get(tFoodValue, IL.IC2_Food_Can_Filled.get(tFoodValue)) : IL.IC2_Food_Can_Filled.get(tFoodValue));
                }
                tUseOreDict = F;
            }
            if (tRandomData instanceof ICover) {
                CoverRegistry.put(aStack, (ICover) tRandomData);
                tUseOreDict = F;
            }
            if (tRandomData instanceof IBehavior) {
                addItemBehavior(aID, (IBehavior<MultiItem>) tRandomData);
                tUseOreDict = F;
            }
            if (tRandomData instanceof IItemEnergy) {
                setElectricStats(aID, (IItemEnergy) tRandomData);
                tUseOreDict = F;
            }
            if (tRandomData instanceof IItemContainer) {
                ((IItemContainer) tRandomData).set(aStack);
                tUseOreDict = F;
            }
            if (tRandomData instanceof TC_AspectStack) {
                ((TC_AspectStack) tRandomData).addToAspectList(tAspects);
                continue;
            }
            if (tRandomData instanceof OreDictItemData) {
                if (((OreDictItemData) tRandomData).hasValidPrefixMaterialData()) {
                    OM.reg(aStack, tRandomData);
                    ItemStack tStack = ((OreDictItemData) tRandomData).getStack(1);
                    // Priority over autogenerated PrefixItems, but not over the hardcoded Compatibility Targets.
                    if (ST.invalid(tStack) || tStack.getItem() instanceof PrefixItem) {
                        OreDictManager.INSTANCE.setTarget_(((OreDictItemData) tRandomData).mPrefix, ((OreDictItemData) tRandomData).mMaterial.mMaterial, aStack);
                        continue;
                    }
                }
                OreDictManager.INSTANCE.addItemData_(aStack, (OreDictItemData) tRandomData);
                continue;
            }
            if (tRandomData instanceof FluidStack) {
                tRandomData = new FluidContainerData((FluidStack) tRandomData, ST.copy_(aStack), getContainerItem(aStack), T);
                // if (((FluidContainerData)tRandomData).emptyContainer != null)
                // RM.Canner.addRecipe1(T, 16, Math.max(((FluidContainerData)tRandomData).fluid.amount / 64, 16), ((FluidContainerData)tRandomData).emptyContainer, ((FluidContainerData)tRandomData).fluid, NF, ((FluidContainerData)tRandomData).filledContainer);
                // RM.Canner.addRecipe1(T, 16, Math.max(((FluidContainerData)tRandomData).fluid.amount / 64, 16), ((FluidContainerData)tRandomData).filledContainer, NF, ((FluidContainerData)tRandomData).fluid, ST.container(((FluidContainerData)tRandomData).filledContainer, F));
                FL.reg((FluidContainerData) tRandomData, T, F);
                continue;
            }
            if (tRandomData instanceof FluidContainerData) {
                // if (((FluidContainerData)tRandomData).emptyContainer != null)
                // RM.Canner.addRecipe1(T, 16, Math.max(((FluidContainerData)tRandomData).fluid.amount / 64, 16), ((FluidContainerData)tRandomData).emptyContainer, ((FluidContainerData)tRandomData).fluid, NF, ((FluidContainerData)tRandomData).filledContainer);
                // RM.Canner.addRecipe1(T, 16, Math.max(((FluidContainerData)tRandomData).fluid.amount / 64, 16), ((FluidContainerData)tRandomData).filledContainer, NF, ((FluidContainerData)tRandomData).fluid, ST.container(((FluidContainerData)tRandomData).filledContainer, F));
                FL.reg((FluidContainerData) tRandomData, T, F);
                continue;
            }
            if (tRandomData instanceof Runnable) {
                GAPI.mAfterPostInit.add((Runnable) tRandomData);
                tUseOreDict = F;
            }
            if (tUseOreDict) {
                OM.reg(tRandomData, aStack);
                continue;
            }
        }
        if (COMPAT_TC != null)
            COMPAT_TC.registerThaumcraftAspectsToItem(aStack, tAspects, F);
        return ST.update(ST.make(this, 1, aID));
    }
    return null;
}
Also used : IItemEnergy(gregapi.item.IItemEnergy) OreDictItemData(gregapi.oredict.OreDictItemData) FluidStack(net.minecraftforge.fluids.FluidStack) IFoodStat(gregapi.item.multiitem.food.IFoodStat) ItemStackSet(gregapi.code.ItemStackSet) IItemContainer(gregapi.code.IItemContainer) PrefixItem(gregapi.item.prefixitem.PrefixItem) FluidContainerData(net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData) ArrayListNoNulls(gregapi.code.ArrayListNoNulls) TC_AspectStack(gregapi.data.TC.TC_AspectStack) IBehavior(gregapi.item.multiitem.behaviors.IBehavior) ICover(gregapi.cover.ICover) TagData(gregapi.code.TagData) ItemStack(net.minecraft.item.ItemStack)

Example 2 with TC_AspectStack

use of gregapi.data.TC.TC_AspectStack in project gregtech6 by GregTech6.

the class MultiItemTool method addTool.

/**
 * This adds a Custom Item to the ending Range.
 * @param aID The Id of the assigned Tool Class [0 - 32765] (only even Numbers allowed! Uneven ID's are empty electric Items)
 * @param aEnglish The Default Localized Name of the created Item
 * @param aToolTip The Default ToolTip of the created Item, you can also insert null for having no ToolTip
 * @param aToolStats The Food Value of this Item. Can be null as well.
 * @param aRandomParameters The OreDict Names you want to give the Item. Also used to assign Thaumcraft Aspects.
 * @return An ItemStack containing the newly created Item, but without specific Stats.
 */
public final ItemStack addTool(int aID, String aEnglish, String aToolTip, IToolStats aToolStats, Object... aRandomParameters) {
    if (aToolTip == null)
        aToolTip = "";
    if (aID >= 0 && aID < 32766 && isUsableMeta((short) aID)) {
        LH.add(getUnlocalizedName() + "." + aID + ".name", aEnglish);
        LH.add(getUnlocalizedName() + "." + aID + ".tooltip", aToolTip);
        LH.add(getUnlocalizedName() + "." + (aID + 1) + ".name", aEnglish + " (Empty)");
        LH.add(getUnlocalizedName() + "." + (aID + 1) + ".tooltip", "You need to recharge it");
        mToolStats.put((short) aID, aToolStats);
        mToolStats.put((short) (aID + 1), aToolStats);
        aToolStats.onStatsAddedToTool(this, aID);
        ItemStack rStack = ST.make(this, 1, aID);
        List<TC_AspectStack> tAspects = new ArrayListNoNulls<>();
        for (Object tRandomParameter : aRandomParameters) {
            if (tRandomParameter instanceof TC_AspectStack)
                ((TC_AspectStack) tRandomParameter).addToAspectList(tAspects);
            else if (tRandomParameter instanceof ItemStackSet)
                ((ItemStackSet<?>) tRandomParameter).add(rStack.copy());
            else
                OM.reg(tRandomParameter, rStack);
        }
        if (COMPAT_TC != null)
            COMPAT_TC.registerThaumcraftAspectsToItem(rStack, tAspects, F);
        return rStack;
    }
    return null;
}
Also used : TC_AspectStack(gregapi.data.TC.TC_AspectStack) ItemStackSet(gregapi.code.ItemStackSet) ItemStack(net.minecraft.item.ItemStack) ArrayListNoNulls(gregapi.code.ArrayListNoNulls)

Example 3 with TC_AspectStack

use of gregapi.data.TC.TC_AspectStack in project gregtech6 by GregTech6.

the class OreDictPrefix method onOreRegistration.

@Override
public void onOreRegistration(OreDictRegistrationContainer aEvent) {
    if (aEvent.mMaterial == MT.NULL) {
        if (!contains(TD.Prefix.MATERIAL_BASED)) {
            if (COMPAT_TC != null && !(aEvent.mStack.getItem() instanceof IEssentiaContainerItem) && !(aEvent.mStack.getItem() instanceof MultiItemRandom) && !MD.MC.owns(aEvent.mRegName) && !MD.TC.owns(aEvent.mRegName)) {
                List<TC_AspectStack> tAspects = new ArrayListNoNulls<>();
                for (TC_AspectStack tAspect : mAspects) tAspect.addToAspectList(tAspects);
                COMPAT_TC.registerThaumcraftAspectsToItem(ST.amount(1, aEvent.mStack), tAspects, F);
            }
            for (IOreDictListenerEvent tListener : mListenersOre) {
                if (D2)
                    ORD.println("Processing '" + aEvent.mOreDictName + "' with the Prefix '" + mNameInternal + "' and without Material at " + UT.Reflection.getClassName(tListener));
                tListener.onOreRegistration(aEvent);
            }
            mRegistrations.add(aEvent);
            if (!mRegisteredItems.contains(new ItemStackContainer(aEvent.mStack, W)))
                mRegisteredItems.add(aEvent.mStack);
        }
    } else {
        if (!mIgnoredRegistrations.contains(aEvent.mMaterial)) {
            if (!aEvent.mMaterial.contains(TD.Properties.INVALID_MATERIAL)) {
                if (COMPAT_TC != null && !(aEvent.mStack.getItem() instanceof IEssentiaContainerItem) && !(aEvent.mStack.getItem() instanceof MultiItemRandom) && !MD.MC.owns(aEvent.mRegName) && !MD.TC.owns(aEvent.mRegName)) {
                    List<TC_AspectStack> tAspects = new ArrayListNoNulls<>();
                    for (TC_AspectStack tAspect : mAspects) {
                        if (tAspect.mAspect == TC.METALLUM && !aEvent.mMaterial.mHasMetallum) {
                            // replacing Metallum with Ordo for non-metallic Stuff.
                            TC.stack(TC.ORDO, tAspect.mAmount).addToAspectList(tAspects);
                        } else {
                            tAspect.addToAspectList(tAspects);
                        }
                    }
                    if (mAmount >= U || mAmount < 0)
                        for (TC_AspectStack tAspect : aEvent.mMaterial.mAspects) tAspect.addToAspectList(tAspects);
                    COMPAT_TC.registerThaumcraftAspectsToItem(ST.amount(1, aEvent.mStack), tAspects, F);
                }
                for (IOreDictListenerEvent tListener : mListenersOre) {
                    if (D2)
                        ORD.println("Processing '" + aEvent.mOreDictName + "' with the Prefix '" + mNameInternal + "' and the Material '" + aEvent.mMaterial.mNameInternal + "' at " + UT.Reflection.getClassName(tListener));
                    tListener.onOreRegistration(aEvent);
                }
                mRegistrations.add(aEvent);
            }
            aEvent.mMaterial.mRegisteredItems.add(new ItemStackContainer(aEvent.mStack));
            mRegisteredMaterials.add(aEvent.mMaterial);
            if (!mRegisteredItems.contains(new ItemStackContainer(aEvent.mStack, W)))
                mRegisteredItems.add(aEvent.mStack);
        }
    }
}
Also used : IEssentiaContainerItem(thaumcraft.api.aspects.IEssentiaContainerItem) ItemStackContainer(gregapi.code.ItemStackContainer) IOreDictListenerEvent(gregapi.oredict.event.IOreDictListenerEvent) TC_AspectStack(gregapi.data.TC.TC_AspectStack) MultiItemRandom(gregapi.item.multiitem.MultiItemRandom) ArrayListNoNulls(gregapi.code.ArrayListNoNulls)

Aggregations

ArrayListNoNulls (gregapi.code.ArrayListNoNulls)3 TC_AspectStack (gregapi.data.TC.TC_AspectStack)3 ItemStackSet (gregapi.code.ItemStackSet)2 ItemStack (net.minecraft.item.ItemStack)2 IItemContainer (gregapi.code.IItemContainer)1 ItemStackContainer (gregapi.code.ItemStackContainer)1 TagData (gregapi.code.TagData)1 ICover (gregapi.cover.ICover)1 IItemEnergy (gregapi.item.IItemEnergy)1 MultiItemRandom (gregapi.item.multiitem.MultiItemRandom)1 IBehavior (gregapi.item.multiitem.behaviors.IBehavior)1 IFoodStat (gregapi.item.multiitem.food.IFoodStat)1 PrefixItem (gregapi.item.prefixitem.PrefixItem)1 OreDictItemData (gregapi.oredict.OreDictItemData)1 IOreDictListenerEvent (gregapi.oredict.event.IOreDictListenerEvent)1 FluidContainerData (net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 IEssentiaContainerItem (thaumcraft.api.aspects.IEssentiaContainerItem)1