aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus/xmod/ic2/item/CustomKineticRotor.java
blob: 82daf41c908f8cd1f979496c1822987becf66ca2 (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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
package gtPlusPlus.xmod.ic2.item;

import static gregtech.api.enums.Mods.EnderIO;

import java.util.List;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;

import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ic2.api.item.IKineticRotor;
import ic2.core.IC2;
import ic2.core.block.kineticgenerator.gui.GuiWaterKineticGenerator;
import ic2.core.block.kineticgenerator.gui.GuiWindKineticGenerator;

public class CustomKineticRotor extends Item implements IKineticRotor {

    private final int mTier;

    @SideOnly(Side.CLIENT)
    private IIcon[] mTextures;

    private static final String[] mRegistrationNames = new String[] { "itemwoodrotor", "itemironrotor",
        "itemsteelrotor", "itemwcarbonrotor" };

    private static final String[] mUnlocalNames = new String[] { "itemEnergeticRotor", "itemTungstenSteelRotor",
        "itemVibrantRotor", "itemIridiumRotor", "itemMagnaliumRotor", "itemUltimetRotor", };
    private static final int[] mMaxDurability = new int[] { 512000, 809600, 1600000, 3200000 };
    private static final int[] mRadius = new int[] { 9, 11, 13, 15 };
    private static final float[] mEfficiency = new float[] { 0.9f, 1.0f, 1.2f, 1.5f };
    private static final int[] mMinWindStrength = new int[] { 12, 14, 16, 18 };
    private static final int[] mMaxWindStrength = new int[] { 80, 120, 160, 320 };

    private static final ResourceLocation[] mResourceLocations = new ResourceLocation[] {
        new ResourceLocation(IC2.textureDomain, "textures/items/rotors/rotorEnergeticModel.png"),
        new ResourceLocation(IC2.textureDomain, "textures/items/rotors/rotorTungstenSteelModel.png"),
        new ResourceLocation(IC2.textureDomain, "textures/items/rotors/rotorVibrantModel.png"),
        new ResourceLocation(IC2.textureDomain, "textures/items/rotors/rotorIridiumModel.png"),
        new ResourceLocation(IC2.textureDomain, "textures/items/rotors/rotorMagnaliumModel.png"),
        new ResourceLocation(IC2.textureDomain, "textures/items/rotors/rotorUltimetModel.png"), };

    private final int maxWindStrength;
    private final int minWindStrength;
    private final int radius;
    private final float efficiency;
    private final ResourceLocation renderTexture;

    public CustomKineticRotor(int aTier) {
        mTier = aTier;
        this.setMaxStackSize(1);
        // Handle Differences if EIO is not loaded
        if (!EnderIO.isModLoaded() && (aTier == 0 || aTier == 2)) {
            this.renderTexture = mResourceLocations[(aTier == 0 ? 4 : 5)];
            this.setUnlocalizedName(mUnlocalNames[(aTier == 0 ? 4 : 5)]);
        } else {
            this.renderTexture = mResourceLocations[aTier];
            this.setUnlocalizedName(mUnlocalNames[aTier]);
        }
        this.setMaxDamage(mMaxDurability[aTier]);
        this.radius = mRadius[aTier];
        this.efficiency = mEfficiency[aTier];
        this.minWindStrength = mMinWindStrength[aTier];
        this.maxWindStrength = mMaxWindStrength[aTier];
        this.setNoRepair();
        this.setCreativeTab(IC2.tabIC2);
        GameRegistry.registerItem(this, mRegistrationNames[aTier]);
    }

    @Override
    public void setDamage(final ItemStack stack, final int damage) {
        if (mTier < 3) {
            super.setDamage(stack, damage);
        }
    }

    @Override
    public void addInformation(final ItemStack itemStack, final EntityPlayer player, final List info, final boolean b) {

        info.add(
            StatCollector.translateToLocalFormatted(
                "ic2.itemrotor.wind.info",
                new Object[] { this.minWindStrength, this.maxWindStrength }));

        GearboxType type = null;
        if (Minecraft.getMinecraft().currentScreen != null
            && Minecraft.getMinecraft().currentScreen instanceof GuiWaterKineticGenerator) {
            type = GearboxType.WATER;
        } else if (Minecraft.getMinecraft().currentScreen != null
            && Minecraft.getMinecraft().currentScreen instanceof GuiWindKineticGenerator) {
                type = GearboxType.WIND;
            }

        if (type != null) {
            info.add(StatCollector.translateToLocal("ic2.itemrotor.fitsin." + this.isAcceptedType(itemStack, type)));
        }
    }

    @Override
    public int getDiameter(final ItemStack stack) {
        return this.radius;
    }

    @Override
    public ResourceLocation getRotorRenderTexture(final ItemStack stack) {
        return this.renderTexture;
    }

    @Override
    public float getEfficiency(final ItemStack stack) {
        return this.efficiency;
    }

    @Override
    public int getMinWindStrength(final ItemStack stack) {
        return this.minWindStrength;
    }

    @Override
    public int getMaxWindStrength(final ItemStack stack) {
        return this.maxWindStrength;
    }

    @Override
    public boolean isAcceptedType(final ItemStack stack, final IKineticRotor.GearboxType type) {
        return (type == IKineticRotor.GearboxType.WIND) || (type == IKineticRotor.GearboxType.WATER);
    }

    @Override
    public String getUnlocalizedName() {
        return "ic2." + super.getUnlocalizedName().substring(5);
    }

    @Override
    public String getUnlocalizedName(ItemStack itemStack) {
        return this.getUnlocalizedName();
    }

    @Override
    public String getItemStackDisplayName(ItemStack itemStack) {
        return StatCollector.translateToLocal(this.getUnlocalizedName(itemStack));
    }

    @Override
    public boolean showDurabilityBar(ItemStack stack) {
        return mTier < 3;
    }

    @Override
    @SideOnly(Side.CLIENT)
    public IIcon getIconFromDamage(int meta) {
        if (!EnderIO.isModLoaded() && (mTier == 0 || mTier == 2)) {
            if (mTier == 0) {
                return mTextures[4];
            } else {
                return mTextures[5];
            }
        } else {
            return mTextures[mTier];
        }
    }

    @Override
    @SideOnly(Side.CLIENT)
    public IIcon getIconIndex(ItemStack aIndex) {
        if (!EnderIO.isModLoaded() && (mTier == 0 || mTier == 2)) {
            if (mTier == 0) {
                return mTextures[4];
            } else {
                return mTextures[5];
            }
        } else {
            return mTextures[mTier];
        }
    }

    @Override
    @SideOnly(Side.CLIENT)
    public IIcon getIconFromDamageForRenderPass(int aDmg, int aPass) {
        if (!EnderIO.isModLoaded() && (mTier == 0 || mTier == 2)) {
            if (mTier == 0) {
                return mTextures[4];
            } else {
                return mTextures[5];
            }
        } else {
            return mTextures[mTier];
        }
    }

    @Override
    protected String getIconString() {
        return super.getIconString();
    }

    @Override
    public double getDurabilityForDisplay(ItemStack stack) {
        return super.getDurabilityForDisplay(stack);
    }

    @Override
    @SideOnly(Side.CLIENT)
    public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) {
        if (!EnderIO.isModLoaded() && (mTier == 0 || mTier == 2)) {
            if (mTier == 0) {
                return mTextures[4];
            } else {
                return mTextures[5];
            }
        } else {
            return mTextures[mTier];
        }
    }

    @Override
    @SideOnly(Side.CLIENT)
    public IIcon getIcon(ItemStack stack, int pass) {
        if (!EnderIO.isModLoaded() && (mTier == 0 || mTier == 2)) {
            if (mTier == 0) {
                return mTextures[4];
            } else {
                return mTextures[5];
            }
        } else {
            return mTextures[mTier];
        }
    }

    @Override
    public void registerIcons(IIconRegister iconRegister) {
        int aIndex = 0;
        mTextures = new IIcon[6];
        for (String y : mUnlocalNames) {
            mTextures[aIndex++] = iconRegister.registerIcon(IC2.textureDomain + ":" + "rotors/" + y);
        }
    }
}