mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-25 14:24:35 +00:00
commit 0d4dc5991e572793134c0c1af8bb35db528071ad Author: pupnewfster <[email protected]> Date: Thu Mar 7 19:25:28 2019 -0500 IntelliJ inspections, Unused Import commit c757d3236b6304b1d3295ad392b88677bccf3003 Author: pupnewfster <[email protected]> Date: Thu Mar 7 19:09:24 2019 -0500 IntelliJ inspections, Constant conditions & exceptions commit c63a821ef9fc705941052a876cc1ef950471912e Author: pupnewfster <[email protected]> Date: Thu Mar 7 17:41:31 2019 -0500 IntelliJ inspections, @NotNull/@Nullable problems commit 506bbfd3241336082b17e5d47f8cec496666dcff Author: pupnewfster <[email protected]> Date: Thu Mar 7 16:50:46 2019 -0500 IntelliJ inspections, Unused label commit bad10c2428346b5feb1816e4a78d7cc2bc1259f0 Author: pupnewfster <[email protected]> Date: Thu Mar 7 15:33:54 2019 -0500 IntelliJ inspections, Unused assignment commit bfe633afbfb6380d0f5ee2e8ab14f8981a455681 Author: pupnewfster <[email protected]> Date: Thu Mar 7 15:32:02 2019 -0500 IntelliJ inspections, 'equals()' between objects of inconvertible types commit 6d179f8639fad1a7c3fa01467c003a8fd309da09 Author: pupnewfster <[email protected]> Date: Thu Mar 7 15:29:28 2019 -0500 IntelliJ inspections, Unused import commit c21f1cfa5566308237dc8bddb8b79908e272a637 Author: pupnewfster <[email protected]> Date: Thu Mar 7 15:25:41 2019 -0500 IntelliJ inspections, Unused import commit e5d9e03af582c7315b057861b8f0019e46157dee Author: pupnewfster <[email protected]> Date: Thu Mar 7 15:23:10 2019 -0500 IntelliJ inspections, Redundant 'throws' clause commit 1c589ba5740411a5595e9fda177696670bc7b7df Author: pupnewfster <[email protected]> Date: Thu Mar 7 15:21:07 2019 -0500 IntelliJ inspections, Static member referenced by instance variable commit 6c17e9ca7fb22a0e285337133659e826f3bfdfee Author: pupnewfster <[email protected]> Date: Thu Mar 7 15:20:02 2019 -0500 IntelliJ inspections, Catch block may ignore exception commit 42b3cd788ceb7d6ce657d582bbbd8345a2ec5676 Author: pupnewfster <[email protected]> Date: Thu Mar 7 15:16:29 2019 -0500 IntelliJ inspections, Unnecessary label on 'break' statement commit f6abc3c66f3aca147edb274720cdb94bff568b0b Author: pupnewfster <[email protected]> Date: Thu Mar 7 15:15:29 2019 -0500 IntelliJ inspections, Too weak variable type leads to unnecessary cast commit 6356d1fea8d55907ae1c7b011223fbbc07236c1f Author: pupnewfster <[email protected]> Date: Thu Mar 7 15:11:17 2019 -0500 IntelliJ inspections, Redundant type cast commit 559c1a2ff523fd7e23f3750d5c801af73876f1d0 Author: pupnewfster <[email protected]> Date: Thu Mar 7 15:04:45 2019 -0500 IntelliJ inspections, Redundant type arguments commit ae816ec2a79cf4c8fee776db651a54f68c1dacaa Author: pupnewfster <[email protected]> Date: Thu Mar 7 15:01:27 2019 -0500 IntelliJ inspections, Redundant Collection operation commit 1da69b8baff922b98a32163c7d5f90aa77a6a8bc Author: pupnewfster <[email protected]> Date: Thu Mar 7 15:00:55 2019 -0500 IntelliJ inspections, Redundant array creation commit 7e3ef81a3597c596d2206c93442e950ac9183de0 Author: pupnewfster <[email protected]> Date: Thu Mar 7 15:00:11 2019 -0500 IntelliJ inspections, Condition is covered by further condition commit f298bbb9f31ecbe935ef6cbf98b56951434a05f8 Author: pupnewfster <[email protected]> Date: Thu Mar 7 14:58:10 2019 -0500 IntelliJ inspections, Redundant 'Collection.addAll()' call commit ce715c5cd724c4dc71ff2cb53e5bc12f16289f12 Author: pupnewfster <[email protected]> Date: Thu Mar 7 14:56:56 2019 -0500 IntelliJ inspections, 'Collection.toArray()' call style commit 0bde4b0eb23ac5d8f40a410ed55315e4a422a30c Author: pupnewfster <[email protected]> Date: Thu Mar 7 14:55:40 2019 -0500 IntelliJ inspections, Calls to 'Arrays.asList()' with too few arguments commit 6d06d11dcf9c077ed6b216a0bbd61434b10fc610 Author: pupnewfster <[email protected]> Date: Thu Mar 7 14:52:26 2019 -0500 IntelliJ inspections, Pointless arithmetic expression commit 6501d725af1eda5127489f77fd723396002b29b2 Author: pupnewfster <[email protected]> Date: Thu Mar 7 14:42:32 2019 -0500 IntelliJ inspections, Anonymous type can be replaced with lambda commit 85341ae5df9d63fb0ad7281c260c77d064adf0c2 Author: pupnewfster <[email protected]> Date: Thu Mar 7 14:41:40 2019 -0500 IntelliJ inspections, Explicit type can be replaced with <> commit 7e2feae7189b92cb513499aed113d4a2634622c6 Author: pupnewfster <[email protected]> Date: Thu Mar 7 14:38:47 2019 -0500 IntelliJ inspections, Unnecessary 'null' check before method call commit 2c75a38fe9a969f832cd5777f4fad81ef47d037b Author: pupnewfster <[email protected]> Date: Thu Mar 7 14:37:33 2019 -0500 IntelliJ inspections, 'switch' statement with too few branches commit 2e2aff57f7910aef5a68f41a1918e2c8a98509ec Author: pupnewfster <[email protected]> Date: Thu Mar 7 14:34:50 2019 -0500 IntelliJ inspections, Simplifiable conditional statement commit 243f6a975f8b3da5e70a5c1a116db2aedd10900e Author: pupnewfster <[email protected]> Date: Thu Mar 7 14:33:09 2019 -0500 IntelliJ inspections, Duplicate condition in 'if' statement commit a80c67fc30b737990e7805a8741dce120232badc Author: pupnewfster <[email protected]> Date: Thu Mar 7 14:32:17 2019 -0500 IntelliJ inspections, Unnecessary semicolon commit 5a7220ee574c9d38d71db07e4fa995a56fee1eed Author: pupnewfster <[email protected]> Date: Thu Mar 7 14:31:58 2019 -0500 IntelliJ inspections, Unnecessary enum/interface modifier commit f3a66f4462033d2f446c2961a1ad8e9cfde3ed36 Author: pupnewfster <[email protected]> Date: Thu Mar 7 14:30:36 2019 -0500 IntelliJ inspections, Unnecessary conversion to String commit 1662540be864db4669cd80c8c46a9b35be202b62 Author: pupnewfster <[email protected]> Date: Thu Mar 7 14:29:33 2019 -0500 IntelliJ inspections, C styled array declaration
290 lines
8.4 KiB
Java
290 lines
8.4 KiB
Java
package mekanism.common.item;
|
|
|
|
import cofh.redstoneflux.api.IEnergyContainerItem;
|
|
import ic2.api.item.IElectricItemManager;
|
|
import ic2.api.item.ISpecialElectricItem;
|
|
|
|
import java.util.List;
|
|
|
|
import mekanism.api.EnumColor;
|
|
import mekanism.api.energy.IEnergizedItem;
|
|
import mekanism.client.render.ModelCustomArmor;
|
|
import mekanism.client.render.ModelCustomArmor.ArmorModel;
|
|
import mekanism.common.Mekanism;
|
|
import mekanism.common.capabilities.ItemCapabilityWrapper;
|
|
import mekanism.common.config.MekanismConfig.general;
|
|
import mekanism.common.integration.MekanismHooks;
|
|
import mekanism.common.integration.forgeenergy.ForgeEnergyItemWrapper;
|
|
import mekanism.common.integration.ic2.IC2ItemManager;
|
|
import mekanism.common.integration.tesla.TeslaItemWrapper;
|
|
import mekanism.common.util.ItemDataUtils;
|
|
import mekanism.common.util.LangUtils;
|
|
import mekanism.common.util.MekanismUtils;
|
|
import net.minecraft.client.model.ModelBiped;
|
|
import net.minecraft.client.util.ITooltipFlag;
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
import net.minecraft.init.SoundEvents;
|
|
import net.minecraft.inventory.EntityEquipmentSlot;
|
|
import net.minecraft.item.ItemArmor;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
import net.minecraft.util.DamageSource;
|
|
import net.minecraft.util.NonNullList;
|
|
import net.minecraft.util.math.MathHelper;
|
|
import net.minecraft.world.World;
|
|
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
|
import net.minecraftforge.common.util.EnumHelper;
|
|
import net.minecraftforge.event.entity.living.LivingAttackEvent;
|
|
import net.minecraftforge.fml.common.Optional.Interface;
|
|
import net.minecraftforge.fml.common.Optional.InterfaceList;
|
|
import net.minecraftforge.fml.common.Optional.Method;
|
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
@InterfaceList({
|
|
@Interface(iface = "ic2.api.item.ISpecialElectricItem", modid = MekanismHooks.IC2_MOD_ID),
|
|
@Interface(iface = "cofh.redstoneflux.api.IEnergyContainerItem", modid = MekanismHooks.REDSTONEFLUX_MOD_ID),
|
|
@Interface(iface = "ic2.api.item.ISpecialElectricItem", modid = MekanismHooks.IC2_MOD_ID)
|
|
})
|
|
public class ItemFreeRunners extends ItemArmor implements IEnergizedItem, ISpecialElectricItem, IEnergyContainerItem
|
|
{
|
|
/** The maximum amount of energy this item can hold. */
|
|
public double MAX_ELECTRICITY = 64000;
|
|
|
|
public ItemFreeRunners()
|
|
{
|
|
super(EnumHelper.addArmorMaterial("FRICTIONBOOTS", "frictionboots", 0, new int[] {0, 0, 0, 0}, 0, SoundEvents.ITEM_ARMOR_EQUIP_GENERIC, 0), 0, EntityEquipmentSlot.FEET);
|
|
setMaxStackSize(1);
|
|
setCreativeTab(Mekanism.tabMekanism);
|
|
}
|
|
|
|
@Override
|
|
public boolean isValidArmor(ItemStack stack, EntityEquipmentSlot armorType, Entity entity)
|
|
{
|
|
return armorType == EntityEquipmentSlot.FEET;
|
|
}
|
|
|
|
@Override
|
|
public String getArmorTexture(ItemStack stack, Entity entity, EntityEquipmentSlot slot, String type)
|
|
{
|
|
return "mekanism:render/NullArmor.png";
|
|
}
|
|
|
|
@Override
|
|
@SideOnly(Side.CLIENT)
|
|
public ModelBiped getArmorModel(EntityLivingBase entityLiving, ItemStack itemStack, EntityEquipmentSlot armorSlot, ModelBiped _default)
|
|
{
|
|
ModelCustomArmor model = ModelCustomArmor.INSTANCE;
|
|
model.modelType = ArmorModel.FREERUNNERS;
|
|
return model;
|
|
}
|
|
|
|
@Override
|
|
@SideOnly(Side.CLIENT)
|
|
public void addInformation(ItemStack itemstack, World world, List<String> list, ITooltipFlag flag)
|
|
{
|
|
list.add(EnumColor.AQUA + LangUtils.localize("tooltip.storedEnergy") + ": " + EnumColor.GREY + MekanismUtils.getEnergyDisplay(getEnergy(itemstack), getMaxEnergy(itemstack)));
|
|
list.add(EnumColor.GREY + LangUtils.localize("tooltip.mode") + ": " + EnumColor.GREY + getMode(itemstack).getName());
|
|
}
|
|
|
|
public ItemStack getUnchargedItem()
|
|
{
|
|
return new ItemStack(this);
|
|
}
|
|
|
|
@Override
|
|
public void getSubItems(@Nonnull CreativeTabs tabs, @Nonnull NonNullList<ItemStack> list)
|
|
{
|
|
if(!isInCreativeTab(tabs)) return;
|
|
ItemStack discharged = new ItemStack(this);
|
|
list.add(discharged);
|
|
ItemStack charged = new ItemStack(this);
|
|
setEnergy(charged, ((IEnergizedItem)charged.getItem()).getMaxEnergy(charged));
|
|
list.add(charged);
|
|
}
|
|
|
|
@Override
|
|
public double getEnergy(ItemStack itemStack)
|
|
{
|
|
return ItemDataUtils.getDouble(itemStack, "energyStored");
|
|
}
|
|
|
|
@Override
|
|
public void setEnergy(ItemStack itemStack, double amount)
|
|
{
|
|
ItemDataUtils.setDouble(itemStack, "energyStored", Math.max(Math.min(amount, getMaxEnergy(itemStack)), 0));
|
|
}
|
|
|
|
@Override
|
|
public double getMaxEnergy(ItemStack itemStack)
|
|
{
|
|
return MAX_ELECTRICITY;
|
|
}
|
|
|
|
@Override
|
|
public double getMaxTransfer(ItemStack itemStack)
|
|
{
|
|
return getMaxEnergy(itemStack)*0.005;
|
|
}
|
|
|
|
@Override
|
|
public boolean canReceive(ItemStack itemStack)
|
|
{
|
|
return getMaxEnergy(itemStack)-getEnergy(itemStack) > 0;
|
|
}
|
|
|
|
@Override
|
|
public boolean canSend(ItemStack itemStack)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
@Method(modid = MekanismHooks.REDSTONEFLUX_MOD_ID)
|
|
public int receiveEnergy(ItemStack theItem, int energy, boolean simulate)
|
|
{
|
|
if(canReceive(theItem))
|
|
{
|
|
double energyNeeded = getMaxEnergy(theItem)-getEnergy(theItem);
|
|
double toReceive = Math.min(energy*general.FROM_RF, energyNeeded);
|
|
|
|
if(!simulate)
|
|
{
|
|
setEnergy(theItem, getEnergy(theItem) + toReceive);
|
|
}
|
|
|
|
return (int)Math.round(toReceive*general.TO_RF);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
@Override
|
|
@Method(modid = MekanismHooks.REDSTONEFLUX_MOD_ID)
|
|
public int extractEnergy(ItemStack theItem, int energy, boolean simulate)
|
|
{
|
|
if(canSend(theItem))
|
|
{
|
|
double energyRemaining = getEnergy(theItem);
|
|
double toSend = Math.min((energy*general.FROM_RF), energyRemaining);
|
|
|
|
if(!simulate)
|
|
{
|
|
setEnergy(theItem, getEnergy(theItem) - toSend);
|
|
}
|
|
|
|
return (int)Math.round(toSend*general.TO_RF);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
@Override
|
|
@Method(modid = MekanismHooks.REDSTONEFLUX_MOD_ID)
|
|
public int getEnergyStored(ItemStack theItem)
|
|
{
|
|
return (int)Math.round(getEnergy(theItem)*general.TO_RF);
|
|
}
|
|
|
|
@Override
|
|
@Method(modid = MekanismHooks.REDSTONEFLUX_MOD_ID)
|
|
public int getMaxEnergyStored(ItemStack theItem)
|
|
{
|
|
return (int)Math.round(getMaxEnergy(theItem)*general.TO_RF);
|
|
}
|
|
|
|
@Override
|
|
public boolean showDurabilityBar(ItemStack stack)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public double getDurabilityForDisplay(ItemStack stack)
|
|
{
|
|
return 1D-(getEnergy(stack)/getMaxEnergy(stack));
|
|
}
|
|
|
|
@Override
|
|
public int getRGBDurabilityForDisplay(@Nonnull ItemStack stack)
|
|
{
|
|
return MathHelper.hsvToRGB(Math.max(0.0F, (float)(1-getDurabilityForDisplay(stack))) / 3.0F, 1.0F, 1.0F);
|
|
}
|
|
|
|
@Override
|
|
@Method(modid = MekanismHooks.IC2_MOD_ID)
|
|
public IElectricItemManager getManager(ItemStack itemStack)
|
|
{
|
|
return IC2ItemManager.getManager(this);
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public void onEntityAttacked(LivingAttackEvent event)
|
|
{
|
|
EntityLivingBase base = event.getEntityLiving();
|
|
ItemStack stack = base.getItemStackFromSlot(EntityEquipmentSlot.FEET);
|
|
|
|
if(!stack.isEmpty() && stack.getItem() instanceof ItemFreeRunners)
|
|
{
|
|
ItemFreeRunners boots = (ItemFreeRunners)stack.getItem();
|
|
|
|
if(boots.getMode(stack) == FreeRunnerMode.NORMAL && boots.getEnergy(stack) > 0 && event.getSource() == DamageSource.FALL)
|
|
{
|
|
boots.setEnergy(stack, boots.getEnergy(stack)-event.getAmount()*50);
|
|
event.setCanceled(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public ICapabilityProvider initCapabilities(ItemStack stack, NBTTagCompound nbt)
|
|
{
|
|
return new ItemCapabilityWrapper(stack, new TeslaItemWrapper(), new ForgeEnergyItemWrapper());
|
|
}
|
|
|
|
public enum FreeRunnerMode
|
|
{
|
|
NORMAL("tooltip.freerunner.regular", EnumColor.DARK_GREEN),
|
|
DISABLED("tooltip.freerunner.disabled", EnumColor.DARK_RED);
|
|
|
|
private String unlocalized;
|
|
private EnumColor color;
|
|
|
|
FreeRunnerMode(String unlocalized, EnumColor color)
|
|
{
|
|
this.unlocalized = unlocalized;
|
|
this.color = color;
|
|
}
|
|
|
|
public FreeRunnerMode increment()
|
|
{
|
|
return ordinal() < values().length-1 ? values()[ordinal()+1] : values()[0];
|
|
}
|
|
|
|
public String getName()
|
|
{
|
|
return color + LangUtils.localize(unlocalized);
|
|
}
|
|
}
|
|
|
|
public FreeRunnerMode getMode(ItemStack itemStack)
|
|
{
|
|
return FreeRunnerMode.values()[ItemDataUtils.getInt(itemStack, "mode")];
|
|
}
|
|
|
|
public void setMode(ItemStack itemStack, FreeRunnerMode mode)
|
|
{
|
|
ItemDataUtils.setInt(itemStack, "mode", mode.ordinal());
|
|
}
|
|
|
|
public void incrementMode(ItemStack itemStack)
|
|
{
|
|
setMode(itemStack, getMode(itemStack).increment());
|
|
}
|
|
}
|