package oneeyemaker.progressivegenerators.item; import java.util.List; import oneeyemaker.progressivegenerators.ProgressiveGenerators; import ic2.api.item.ICustomDamageItem; import ic2.api.item.IKineticRotor; import ic2.core.init.BlocksItems; import ic2.core.init.Localization; import ic2.core.ref.IItemModelProvider; import ic2.core.ref.ItemName; import ic2.core.util.StackUtil; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.NonNullList; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class ItemKineticRotor extends Item implements IItemModelProvider, ICustomDamageItem, IKineticRotor { private final String name; private final int diameter; private final float efficiency; private final int minimumWindStrength; private final int maximumWindStrength; private int maximumDamage; public ItemKineticRotor(String name, int maximumDamage, int diameter, float efficiency, int minimumWindStrength, int maximumWindStrength) { this.name = name + "_kinetic_rotor"; this.setMaxDamage(maximumDamage); this.diameter = diameter; this.efficiency = efficiency; this.minimumWindStrength = minimumWindStrength; this.maximumWindStrength = maximumWindStrength; this.setMaxStackSize(1); this.setNoRepair(); this.setCreativeTab(ProgressiveGenerators.CreativeTab); BlocksItems.registerItem(this, new ResourceLocation(ProgressiveGenerators.MOD_ID, this.name)); } @Override @SuppressWarnings({"deprecation"}) public int getMaxDamage() { return this.maximumDamage; } @Override public Item setMaxDamage(int maximumDamage) { this.maximumDamage = maximumDamage; if (maximumDamage > 0) { this.addPropertyOverride(new ResourceLocation("damaged"), (stack, world, entity) -> stack.isItemDamaged() ? 1.0F : 0.0F); this.addPropertyOverride(new ResourceLocation("damage"), (stack, world, entity) -> MathHelper.clamp( (float) stack.getItemDamage() / stack.getMaxDamage(), 0.0F, 1.0F)); } return this; } @Override public boolean isDamageable() { return this.maximumDamage > 0; } @Override public String getUnlocalizedName() { return ProgressiveGenerators.MOD_ID + ".kinetic_rotor." + this.name; } @Override public String getUnlocalizedName(ItemStack stack) { return this.getUnlocalizedName(); } @Override @SideOnly(Side.CLIENT) public void addInformation(ItemStack stack, World worldIn, List tooltip, ITooltipFlag flag) { tooltip.add( Localization.translate("ic2.itemrotor.wind.info", this.minimumWindStrength, this.maximumWindStrength)); } @Override public String getItemStackDisplayName(ItemStack stack) { return Localization.translate(this.getUnlocalizedName(stack)); } @Override public void getSubItems(CreativeTabs tab, NonNullList items) { if (this.isInCreativeTab(tab)) { ItemStack stack = new ItemStack(this); this.setCustomDamage(stack, 0); items.add(stack); } } @Override public int getDamage(ItemStack stack) { return this.getCustomDamage(stack); } @Override public int getMetadata(ItemStack stack) { return this.getCustomDamage(stack); } @Override public int getMaxDamage(ItemStack stack) { return this.maximumDamage; } @Override public boolean isDamaged(ItemStack stack) { return this.getCustomDamage(stack) > 0; } @Override public void setDamage(ItemStack stack, int damage) { this.setCustomDamage(stack, damage); } @Override @SideOnly(Side.CLIENT) public void registerModels(ItemName itemName) { ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation( ProgressiveGenerators.MOD_ID + ":kinetic_rotor/" + this.name)); } @Override public int getCustomDamage(ItemStack stack) { return stack.hasTagCompound() ? stack.getTagCompound().getInteger("rotor_damage") : 0; } @Override public int getMaxCustomDamage(ItemStack stack) { return this.maximumDamage; } @Override public void setCustomDamage(ItemStack stack, int damage) { damage = MathHelper.clamp(damage, 0, this.maximumDamage); NBTTagCompound tagCompound = StackUtil.getOrCreateNbtData(stack); tagCompound.setInteger("rotor_damage", damage); } @Override public boolean applyCustomDamage(ItemStack stack, int damage, EntityLivingBase entity) { this.setCustomDamage(stack, this.getCustomDamage(stack) + damage); return true; } @Override public int getDiameter(ItemStack stack) { return this.diameter; } @Override public ResourceLocation getRotorRenderTexture(ItemStack stack) { return new ResourceLocation(ProgressiveGenerators.MOD_ID, "textures/items/kinetic_rotor/" + this.name + "_model.png"); } @Override public float getEfficiency(ItemStack stack) { return this.efficiency; } @Override public int getMinWindStrength(ItemStack stack) { return this.minimumWindStrength; } @Override public int getMaxWindStrength(ItemStack stack) { return this.maximumWindStrength; } @Override public boolean isAcceptedType(ItemStack stack, GearboxType gearboxType) { return !StackUtil.isEmpty(stack); } }