aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java
blob: 4933039264190abdf9af9bac9b7c23b34e6b3294 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package gtPlusPlus.xmod.tinkers.material;

import static gregtech.api.enums.Mods.TinkerConstruct;
import static gtPlusPlus.core.util.math.MathUtils.safeCast_LongToInt;

import java.util.HashMap;

import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.fluids.Fluid;

import cpw.mods.fml.common.event.FMLInterModComms;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.core.material.Material;
import gtPlusPlus.core.util.Utils;
import gtPlusPlus.xmod.tinkers.HandlerTinkers;
import gtPlusPlus.xmod.tinkers.util.TinkersUtils;

public class BaseTinkersMaterial {

    private static final HashMap<String, Integer> aInternalMaterialIdMap = new HashMap<>();
    private static int aNextFreeID;

    public final String mLocalName;

    private final String mUnlocalName;
    private final int mID;
    private final Material mMaterial;

    static {
        aNextFreeID = (Short.MAX_VALUE / 2) + 420;
    }

    public BaseTinkersMaterial(Material aMaterial) {
        mLocalName = aMaterial.getLocalizedName();
        mUnlocalName = "material.gtpp." + Utils.sanitizeString(mLocalName);
        mMaterial = aMaterial;
        mID = aNextFreeID++;
        Logger.INFO("[TiCon] Assigning ID " + mID + " to " + mLocalName + ".");
        aInternalMaterialIdMap.put(mUnlocalName, mID);
        HandlerTinkers.mTinkerMaterials.add(this);
    }

    public String getUnlocalName() {
        return mUnlocalName;
    }

    private static int calcDurability(Material aMaterial) {
        return safeCast_LongToInt(aMaterial.vDurability);
    }

    private static int calcMiningSpeed(Material aMaterial) {
        return (aMaterial.vHarvestLevel * 2) + aMaterial.vTier;
    }

    private static int calcHarvestLevel(Material aMaterial) {
        return aMaterial.vHarvestLevel;
    }

    private static int calcAttack(Material aMaterial) {
        return aMaterial.vHarvestLevel + aMaterial.vTier + aMaterial.vRadiationLevel;
    }

    private static float calcHandleModifier(Material aMaterial) {
        return 1f;
    }

    private static int calcReinforced(Material aMaterial) {
        return aMaterial.getMeltingPointC() / 3600;
    }

    private static int calcBowProjectileSpeed(Material aMaterial) {
        return aMaterial.vHarvestLevel + 2;
    }

    private static int calcBowDrawSpeed(Material aMaterial) {
        return aMaterial.vHarvestLevel + 8;
    }

    private static float calcProjectileMass(Material aMaterial) {
        return (aMaterial.getMeltingPointC() / 1800) * 0.1f;
    }

    private static float calcProjectileFragility(Material aMaterial) {
        return 0f;
    }

    private static String calcStyle(Material aMaterial) {
        String aReturn;
        int aTemp = aMaterial.getMeltingPointC();
        if (aTemp < 3600) {
            aReturn = "" + EnumChatFormatting.WHITE;
        } else if (aTemp >= 3600) {
            aReturn = "" + EnumChatFormatting.YELLOW;
        } else if (aTemp >= (3600 * 2)) {
            aReturn = "" + EnumChatFormatting.GREEN;
        } else if (aTemp >= (3600 * 3)) {
            aReturn = "" + EnumChatFormatting.RED;
        } else if (aTemp >= (3600 * 4)) {
            aReturn = "" + EnumChatFormatting.DARK_RED;
        } else {
            aReturn = "" + EnumChatFormatting.GOLD;
        }
        return aReturn;
    }

    private static int calcColour(Material aMaterial) {
        return aMaterial.getRgbAsHex();
    }

    public void generate() {

        Logger.INFO("[TiCon] Trying to generate Material: " + mLocalName);
        int id = mID;
        if (id > 0) {

            NBTTagCompound tag = new NBTTagCompound();
            tag.setInteger("Id", id);
            tag.setString("Name", mUnlocalName);
            tag.setString("localizationString", mLocalName);
            tag.setInteger("Durability", calcDurability(mMaterial)); // 97
            tag.setInteger("MiningSpeed", calcMiningSpeed(mMaterial)); // 150
            tag.setInteger("HarvestLevel", calcHarvestLevel(mMaterial)); // 1
            tag.setInteger("Attack", calcAttack(mMaterial)); // 0
            tag.setFloat("HandleModifier", calcHandleModifier(mMaterial)); // 1.0f
            tag.setInteger("Reinforced", calcReinforced(mMaterial)); // 0
            tag.setFloat("Bow_ProjectileSpeed", calcBowProjectileSpeed(mMaterial)); // 3.0f
            tag.setInteger("Bow_DrawSpeed", calcBowDrawSpeed(mMaterial)); // 18
            tag.setFloat("Projectile_Mass", calcProjectileMass(mMaterial)); // 0.69f
            tag.setFloat("Projectile_Fragility", calcProjectileFragility(mMaterial)); // 0.2f
            tag.setString("Style", calcStyle(mMaterial));
            tag.setInteger("Color", calcColour(mMaterial));

            boolean generate = generateRecipes(mMaterial, id);

            if (generate) {
                Logger.INFO("[TiCon] Sending IMC: addMaterial - " + mLocalName + ".");
                FMLInterModComms.sendMessage(TinkerConstruct.ID, "addMaterial", tag);

                ItemStack itemstack = mMaterial.getIngot(1);
                tag = new NBTTagCompound();
                tag.setInteger("MaterialId", id);
                NBTTagCompound item = new NBTTagCompound();
                itemstack.writeToNBT(item);
                tag.setTag("Item", item);
                tag.setInteger("Value", 2); // What is value for?

                Logger.INFO("[TiCon] Sending IMC: addPartBuilderMaterial - " + mLocalName + ".");
                FMLInterModComms.sendMessage(TinkerConstruct.ID, "addPartBuilderMaterial", tag);

                tag = new NBTTagCompound();
                tag.setInteger("MaterialId", id);
                tag.setInteger("Value", 2); // What is value for?
                item = new NBTTagCompound();
                itemstack.writeToNBT(item);
                tag.setTag("Item", item);

                Logger.INFO("[TiCon] Sending IMC: addMaterialItem - " + mLocalName + ".");
                FMLInterModComms.sendMessage(TinkerConstruct.ID, "addMaterialItem", tag);
            }
        }
    }

    private boolean generateRecipes(Material aMaterial, int aID) {

        Block aMatBlock = aMaterial.getBlock();
        int aMelt = aMaterial.getMeltingPointC();
        Fluid aFluid = aMaterial.getFluidStack(0)
            .getFluid();

        if (aMatBlock == null || aFluid == null) {
            return false;
        }

        TinkersUtils.registerFluidType(mLocalName, aMatBlock, 0, aMelt, aFluid, true);
        TinkersUtils.addMelting(aMaterial.getBlock(1), aMatBlock, 0, aMelt, aMaterial.getFluidStack(144 * 9));
        TinkersUtils.addMelting(aMaterial.getIngot(1), aMatBlock, 0, aMelt, aMaterial.getFluidStack(144));
        if (aMelt <= 3600) {
            ItemStack ingotcast = TinkersUtils.getPattern(1);
            TinkersUtils.addBasinRecipe(aMaterial.getBlock(1), aMaterial.getFluidStack(144 * 9), null, true, 100);
            TinkersUtils
                .addCastingTableRecipe(aMaterial.getIngot(1), aMaterial.getFluidStack(144), ingotcast, false, 50);
        }
        TinkersUtils.generateCastingRecipes(aMaterial, aID);

        return true;
    }
}