aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/bartworks/common/items/ItemStonageRotors.java
blob: 913c7c4fd4aa4bd8572558d7c88852ec6e2ab707 (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
/*
 * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in the Software without restriction,
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following
 * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial
 * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

package bartworks.common.items;

import static ic2.api.item.IKineticRotor.GearboxType.WATER;
import static ic2.api.item.IKineticRotor.GearboxType.WIND;

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.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;

import bartworks.MainMod;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ic2.api.item.IKineticRotor;
import ic2.core.block.kineticgenerator.gui.GuiWaterKineticGenerator;
import ic2.core.block.kineticgenerator.gui.GuiWindKineticGenerator;
import ic2.core.util.StackUtil;

public class ItemStonageRotors extends Item implements IKineticRotor {

    private final int[] DiaMinMax = new int[3];
    private final float eff;
    private final IKineticRotor.GearboxType type;
    private final ResourceLocation tex;
    private final String itemTex;
    private final int speed;
    private final float mRotor;
    private final int maxDamageEx;
    private int dura;

    public ItemStonageRotors(int diameter, float eff, int speed, float mRotor, int min, int max, int durability,
        IKineticRotor.GearboxType type, ResourceLocation tex, String Name, String itemTex) {
        this.DiaMinMax[0] = diameter;
        this.DiaMinMax[1] = min;
        this.DiaMinMax[2] = max;
        this.eff = eff;
        this.mRotor = mRotor;
        this.speed = speed;
        this.type = type;
        this.tex = tex;
        this.setMaxDamage(30000);
        this.maxDamageEx = durability;
        this.setUnlocalizedName(Name);
        this.setCreativeTab(MainMod.BWT);
        this.itemTex = itemTex;
    }

    @Override
    @SideOnly(Side.CLIENT)
    public void registerIcons(IIconRegister iconRegister) {
        this.itemIcon = iconRegister.registerIcon(MainMod.MOD_ID + ":" + this.itemTex);
    }

    @Override
    public void addInformation(ItemStack itemStack, EntityPlayer player, List<String> info, boolean b) {
        info.add(
            StatCollector.translateToLocalFormatted("ic2.itemrotor.wind.info", this.DiaMinMax[1], this.DiaMinMax[2]));
        IKineticRotor.GearboxType type = null;
        if (Minecraft.getMinecraft().currentScreen instanceof GuiWaterKineticGenerator) {
            type = WATER;
        } else if (Minecraft.getMinecraft().currentScreen instanceof GuiWindKineticGenerator) {
            type = WIND;
        }
        info.add(StatCollector.translateToLocal("tooltip.rotor.0.name") + " " + this.DiaMinMax[0]);
        info.add(
            StatCollector.translateToLocal("tooltip.rotor.1.name") + " "
                + (this.getMaxDamageEx() - this.getDamageOfStack(itemStack)) / 100
                + "/"
                + this.getMaxDamageEx() / 100);
        info.add(StatCollector.translateToLocal("tooltip.rotor.2.name") + " " + this.eff);
        info.add(StatCollector.translateToLocal("tooltip.rotor.3.name") + " " + this.speed);
        info.add(StatCollector.translateToLocal("tooltip.rotor.4.name") + " " + this.mRotor);
        if (type != null) {
            info.add(StatCollector.translateToLocal("ic2.itemrotor.fitsin." + this.isAcceptedType(itemStack, type)));
        }
    }

    @Override
    public int getDiameter(ItemStack itemStack) {
        return this.DiaMinMax[0];
    }

    @Override
    public ResourceLocation getRotorRenderTexture(ItemStack itemStack) {
        return this.tex;
    }

    @Override
    public float getEfficiency(ItemStack itemStack) {
        return this.eff;
    }

    @Override
    public int getMinWindStrength(ItemStack itemStack) {
        return this.DiaMinMax[1];
    }

    @Override
    public int getMaxWindStrength(ItemStack itemStack) {
        return this.DiaMinMax[2];
    }

    @Override
    public boolean isAcceptedType(ItemStack itemStack, IKineticRotor.GearboxType gearboxType) {
        return gearboxType.equals(this.type);
    }

    public int getSpeed() {
        return this.speed;
    }

    public float getmRotor() {
        return this.mRotor;
    }

    public void setDamageForStack(ItemStack stack, int advDmg) {
        NBTTagCompound nbtData = StackUtil.getOrCreateNbtData(stack);
        nbtData.setInteger("DmgEx", advDmg);
        if (this.maxDamageEx > 0) {
            double p = (double) advDmg / (double) this.maxDamageEx;
            int newDmg = (int) (stack.getMaxDamage() * p);
            if (newDmg >= stack.getMaxDamage()) {
                newDmg = stack.getMaxDamage() - 1;
            }
            stack.setItemDamage(newDmg);
            this.dura = newDmg;
        }
    }

    public int getDamageOfStack(ItemStack stack) {
        NBTTagCompound nbtData = StackUtil.getOrCreateNbtData(stack);
        this.dura = nbtData.getInteger("DmgEx");
        return this.dura;
    }

    public int getMaxDamageEx() {
        return this.maxDamageEx;
    }

    public void damageItemStack(ItemStack stack, int Dmg) {
        this.setDamageForStack(stack, this.getDamageOfStack(stack) + Dmg);
    }
}