Search in sources :

Example 46 with Material

use of gregtech.api.unification.material.Material in project GregTech by GregTechCEu.

the class OreRecipeHandler method processCrushedPurified.

public static void processCrushedPurified(OrePrefix purifiedPrefix, Material material, OreProperty property) {
    ItemStack crushedCentrifugedStack = OreDictUnifier.get(OrePrefix.crushedCentrifuged, material);
    ItemStack dustStack = OreDictUnifier.get(OrePrefix.dustPure, material);
    Material byproductMaterial = GTUtility.selectItemInList(1, material, property.getOreByProducts(), Material.class);
    ItemStack byproductStack = OreDictUnifier.get(OrePrefix.dust, byproductMaterial);
    RecipeMaps.FORGE_HAMMER_RECIPES.recipeBuilder().input(purifiedPrefix, material).outputs(dustStack).duration(10).EUt(16).buildAndRegister();
    RecipeMaps.MACERATOR_RECIPES.recipeBuilder().input(purifiedPrefix, material).outputs(dustStack).chancedOutput(byproductStack, 1400, 850).duration(400).buildAndRegister();
    ModHandler.addShapelessRecipe(String.format("purified_ore_to_dust_%s", material), dustStack, 'h', new UnificationEntry(purifiedPrefix, material));
    if (!crushedCentrifugedStack.isEmpty()) {
        RecipeMaps.THERMAL_CENTRIFUGE_RECIPES.recipeBuilder().input(purifiedPrefix, material).outputs(crushedCentrifugedStack, OreDictUnifier.get(OrePrefix.dustTiny, byproductMaterial, 3)).buildAndRegister();
    }
    if (material.hasProperty(PropertyKey.GEM)) {
        ItemStack exquisiteStack = OreDictUnifier.get(OrePrefix.gemExquisite, material);
        ItemStack flawlessStack = OreDictUnifier.get(OrePrefix.gemFlawless, material);
        ItemStack gemStack = OreDictUnifier.get(OrePrefix.gem, material);
        ItemStack flawedStack = OreDictUnifier.get(OrePrefix.gemFlawed, material);
        ItemStack chippedStack = OreDictUnifier.get(OrePrefix.gemChipped, material);
        if (material.hasFlag(HIGH_SIFTER_OUTPUT)) {
            RecipeBuilder<SimpleRecipeBuilder> builder = RecipeMaps.SIFTER_RECIPES.recipeBuilder().input(purifiedPrefix, material).chancedOutput(exquisiteStack, 500, 150).chancedOutput(flawlessStack, 1500, 200).chancedOutput(gemStack, 5000, 1000).chancedOutput(dustStack, 2500, 500).duration(400).EUt(16);
            if (!flawedStack.isEmpty())
                builder.chancedOutput(flawedStack, 2000, 500);
            if (!chippedStack.isEmpty())
                builder.chancedOutput(chippedStack, 3000, 350);
            builder.buildAndRegister();
        } else {
            RecipeBuilder<SimpleRecipeBuilder> builder = RecipeMaps.SIFTER_RECIPES.recipeBuilder().input(purifiedPrefix, material).chancedOutput(exquisiteStack, 300, 100).chancedOutput(flawlessStack, 1000, 150).chancedOutput(gemStack, 3500, 500).chancedOutput(dustStack, 5000, 750).duration(400).EUt(16);
            if (!flawedStack.isEmpty())
                builder.chancedOutput(flawedStack, 2500, 300);
            if (!exquisiteStack.isEmpty())
                builder.chancedOutput(chippedStack, 3500, 400);
            builder.buildAndRegister();
        }
    }
    processMetalSmelting(purifiedPrefix, material, property);
}
Also used : UnificationEntry(gregtech.api.unification.stack.UnificationEntry) SimpleRecipeBuilder(gregtech.api.recipes.builders.SimpleRecipeBuilder) Material(gregtech.api.unification.material.Material) ItemStack(net.minecraft.item.ItemStack)

Example 47 with Material

use of gregtech.api.unification.material.Material in project GregTech by GregTechCEu.

the class ToolMetaItem method getHarvestLevel.

public int getHarvestLevel(ItemStack itemStack) {
    T metaToolValueItem = getItem(itemStack);
    if (metaToolValueItem != null) {
        NBTTagCompound toolTag = getToolStatsTag(itemStack);
        Material toolMaterial = getToolMaterial(itemStack);
        IToolStats toolStats = metaToolValueItem.getToolStats();
        int harvestLevel = 0;
        if (toolTag != null && toolTag.hasKey("HarvestLevel")) {
            harvestLevel = toolTag.getInteger("HarvestLevel");
        } else if (toolMaterial != null) {
            DustProperty prop = toolMaterial.getProperty(PropertyKey.DUST);
            if (prop != null)
                harvestLevel = prop.getHarvestLevel();
            else
                return 0;
        }
        int baseHarvestLevel = toolStats.getBaseQuality(itemStack);
        return baseHarvestLevel + harvestLevel;
    }
    return 0;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Material(gregtech.api.unification.material.Material) DustProperty(gregtech.api.unification.material.properties.DustProperty)

Example 48 with Material

use of gregtech.api.unification.material.Material in project GregTech by GregTechCEu.

the class ToolMetaItem method getItemStackDisplayName.

@Nonnull
@Override
public String getItemStackDisplayName(ItemStack stack) {
    if (stack.getItemDamage() >= metaItemOffset) {
        T item = getItem(stack);
        if (item == null) {
            return "invalid item";
        }
        Material primaryMaterial = getToolMaterial(stack);
        String materialName = primaryMaterial == null ? "" : String.valueOf(primaryMaterial.getLocalizedName());
        return LocalizationUtils.format("metaitem." + item.unlocalizedName + ".name", materialName);
    }
    return super.getItemStackDisplayName(stack);
}
Also used : Material(gregtech.api.unification.material.Material) Nonnull(javax.annotation.Nonnull)

Example 49 with Material

use of gregtech.api.unification.material.Material in project GregTech by GregTechCEu.

the class ToolMetaItem method getMaxItemDamage.

@Override
public int getMaxItemDamage(ItemStack itemStack) {
    T metaToolValueItem = getItem(itemStack);
    if (metaToolValueItem != null) {
        NBTTagCompound toolTag = getToolStatsTag(itemStack);
        Material toolMaterial = getToolMaterial(itemStack);
        IToolStats toolStats = metaToolValueItem.getToolStats();
        int materialDurability = 0;
        if (toolTag != null && toolTag.hasKey("MaxDurability")) {
            materialDurability = toolTag.getInteger("MaxDurability");
        } else if (toolMaterial != null) {
            ToolProperty prop = toolMaterial.getProperty(PropertyKey.TOOL);
            if (prop != null)
                materialDurability = prop.getToolDurability();
            else
                return 0;
        }
        float multiplier = toolStats.getMaxDurabilityMultiplier(itemStack);
        return (int) (materialDurability * multiplier);
    }
    return 0;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Material(gregtech.api.unification.material.Material) ToolProperty(gregtech.api.unification.material.properties.ToolProperty)

Example 50 with Material

use of gregtech.api.unification.material.Material in project GregTech by GregTechCEu.

the class ToolMetaItemListener method onAnvilChange.

@SubscribeEvent
public static void onAnvilChange(AnvilUpdateEvent event) {
    ItemStack firstStack = event.getLeft();
    ItemStack secondStack = event.getRight();
    if (!firstStack.isEmpty() && !secondStack.isEmpty() && firstStack.getItem() instanceof ToolMetaItem) {
        ToolMetaItem<?> toolMetaItem = (ToolMetaItem<?>) firstStack.getItem();
        MetaToolValueItem toolValueItem = toolMetaItem.getItem(firstStack);
        if (toolValueItem == null) {
            return;
        }
        Material toolMaterial = ToolMetaItem.getToolMaterial(firstStack);
        OrePrefix solidPrefix = getSolidPrefix(toolMaterial);
        UnificationEntry unificationEntry = OreDictUnifier.getUnificationEntry(secondStack);
        double toolDamage = toolMetaItem.getItemDamage(firstStack) / (toolMetaItem.getMaxItemDamage(firstStack) * 1.0);
        double materialForFullRepair = toolValueItem.getAmountOfMaterialToRepair(firstStack);
        int durabilityPerUnit = (int) Math.ceil(toolMetaItem.getMaxItemDamage(firstStack) / materialForFullRepair);
        int materialUnitsRequired = Math.min(secondStack.getCount(), (int) Math.ceil(toolDamage * materialForFullRepair));
        int repairCost = (MathHelper.clamp(toolMaterial.getHarvestLevel(), 2, 3) - 1) * materialUnitsRequired;
        if (toolDamage > 0.0 && materialUnitsRequired > 0 && unificationEntry != null && unificationEntry.material == toolMaterial && unificationEntry.orePrefix == solidPrefix) {
            int durabilityToRegain = durabilityPerUnit * materialUnitsRequired;
            ItemStack resultStack = firstStack.copy();
            toolMetaItem.regainItemDurability(resultStack, durabilityToRegain);
            event.setMaterialCost(materialUnitsRequired);
            event.setCost(repairCost);
            event.setOutput(resultStack);
        }
    }
}
Also used : OrePrefix(gregtech.api.unification.ore.OrePrefix) UnificationEntry(gregtech.api.unification.stack.UnificationEntry) MetaToolValueItem(gregtech.api.items.toolitem.ToolMetaItem.MetaToolValueItem) Material(gregtech.api.unification.material.Material) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

Material (gregtech.api.unification.material.Material)76 ItemStack (net.minecraft.item.ItemStack)31 UnificationEntry (gregtech.api.unification.stack.UnificationEntry)19 OrePrefix (gregtech.api.unification.ore.OrePrefix)13 MaterialStack (gregtech.api.unification.stack.MaterialStack)12 Nonnull (javax.annotation.Nonnull)10 PropertyKey (gregtech.api.unification.material.properties.PropertyKey)9 Block (net.minecraft.block.Block)8 IBlockState (net.minecraft.block.state.IBlockState)8 GTValues (gregtech.api.GTValues)7 Collectors (java.util.stream.Collectors)7 Nullable (javax.annotation.Nullable)7 Materials (gregtech.api.unification.material.Materials)6 DustProperty (gregtech.api.unification.material.properties.DustProperty)6 ToolProperty (gregtech.api.unification.material.properties.ToolProperty)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 GregTechAPI (gregtech.api.GregTechAPI)5 OreDictUnifier (gregtech.api.unification.OreDictUnifier)5 MarkerMaterial (gregtech.api.unification.material.MarkerMaterial)5 ItemMaterialInfo (gregtech.api.unification.stack.ItemMaterialInfo)5