converted electric item interface handling to more maintainable scala traits
This commit is contained in:
parent
3ff5b59eef
commit
8cdd184be2
10 changed files with 514 additions and 716 deletions
|
@ -0,0 +1,16 @@
|
|||
package net.machinemuse.api.electricity
|
||||
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.entity.Entity
|
||||
import icbm.api.explosion.{IEMPItem, IExplosive}
|
||||
|
||||
/**
|
||||
* Author: MachineMuse (Claire Semple)
|
||||
* Created: 10:21 PM, 4/20/13
|
||||
*/
|
||||
trait EMPElectricItem extends IEMPItem with MuseElectricItem {
|
||||
|
||||
def onEMP(itemStack: ItemStack, entity: Entity, empExplosive: IExplosive) {
|
||||
setCurrentEnergy(itemStack, 0)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package net.machinemuse.api.electricity
|
||||
|
||||
import net.minecraft.item.ItemStack
|
||||
import universalelectricity.core.item.IItemElectric
|
||||
|
||||
/**
|
||||
* Author: MachineMuse (Claire Semple)
|
||||
* Created: 10:00 PM, 4/20/13
|
||||
*/
|
||||
trait IC2ElectricItem extends IItemElectric with MuseElectricItem {
|
||||
def canProvideEnergy(itemStack: ItemStack): Boolean = true
|
||||
|
||||
def getChargedItemId(itemStack: ItemStack): Int = itemStack.itemID
|
||||
|
||||
def getEmptyItemId(itemStack: ItemStack): Int = itemStack.itemID
|
||||
|
||||
def getMaxCharge(itemStack: ItemStack): Int = IC2ElectricAdapter.museEnergyToEU(getCurrentEnergy(itemStack)).asInstanceOf[Int]
|
||||
|
||||
def getTier(itemStack: ItemStack): Int = IC2ElectricAdapter.getTier(itemStack)
|
||||
|
||||
def getTransferLimit(itemStack: ItemStack): Int = IC2ElectricAdapter.museEnergyToEU(Math.sqrt(getMaxEnergy(itemStack))).asInstanceOf[Int]
|
||||
|
||||
def charge(itemStack: ItemStack, amount: Int, tier: Int, ignoreTransferLimit: Boolean, simulate: Boolean): Int = {
|
||||
val current: Double = getCurrentEnergy(itemStack)
|
||||
val given: Double = giveEnergyTo(itemStack, IC2ElectricAdapter.museEnergyFromEU(amount))
|
||||
if (simulate) {
|
||||
setCurrentEnergy(itemStack, current)
|
||||
}
|
||||
IC2ElectricAdapter.museEnergyToEU(given).asInstanceOf[Int]
|
||||
}
|
||||
|
||||
def discharge(itemStack: ItemStack, amount: Int, tier: Int, ignoreTransferLimit: Boolean, simulate: Boolean): Int = {
|
||||
val current: Double = getCurrentEnergy(itemStack)
|
||||
val taken: Double = drainEnergyFrom(itemStack, IC2ElectricAdapter.museEnergyFromEU(amount))
|
||||
if (simulate) {
|
||||
setCurrentEnergy(itemStack, current)
|
||||
}
|
||||
IC2ElectricAdapter.museEnergyToEU(taken).asInstanceOf[Int]
|
||||
}
|
||||
|
||||
def canUse(itemStack: ItemStack, amount: Int): Boolean = {
|
||||
val requested: Double = IC2ElectricAdapter.museEnergyFromEU(amount)
|
||||
requested < getCurrentEnergy(itemStack)
|
||||
}
|
||||
|
||||
def canShowChargeToolTip(itemStack: ItemStack): Boolean = false
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
package net.machinemuse.api.electricity
|
||||
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.machinemuse.api.{ModuleManager, MuseItemUtils}
|
||||
|
||||
/**
|
||||
* Author: MachineMuse (Claire Semple)
|
||||
* Created: 10:12 PM, 4/20/13
|
||||
*/
|
||||
trait MuseElectricItem {
|
||||
/**
|
||||
* Call to get the energy of an item
|
||||
*
|
||||
* @param stack
|
||||
* ItemStack to set
|
||||
* @return Current energy level
|
||||
*/
|
||||
def getCurrentEnergy(stack: ItemStack): Double = {
|
||||
MuseItemUtils.getDoubleOrZero(stack, ElectricItemUtils.CURRENT_ENERGY)
|
||||
}
|
||||
|
||||
/**
|
||||
* Call to set the energy of an item
|
||||
*
|
||||
* @param stack
|
||||
* ItemStack to set
|
||||
* @return Maximum energy level
|
||||
*/
|
||||
def getMaxEnergy(stack: ItemStack): Double = {
|
||||
ModuleManager.computeModularProperty(stack, ElectricItemUtils.MAXIMUM_ENERGY)
|
||||
}
|
||||
|
||||
/**
|
||||
* Call to set the energy of an item
|
||||
*
|
||||
* @param stack
|
||||
* ItemStack to set
|
||||
* @param energy
|
||||
* Level to set it to
|
||||
*/
|
||||
def setCurrentEnergy(stack: ItemStack, energy: Double) {
|
||||
MuseItemUtils.setDoubleOrRemove(stack, ElectricItemUtils.CURRENT_ENERGY, energy)
|
||||
}
|
||||
|
||||
/**
|
||||
* Call to drain energy from an item
|
||||
*
|
||||
* @param stack
|
||||
* ItemStack being requested for energy
|
||||
* @param requested
|
||||
* Amount of energy to drain
|
||||
* @return Amount of energy successfully drained
|
||||
*/
|
||||
def drainEnergyFrom(stack: ItemStack, requested: Double): Double = {
|
||||
val available: Double = getCurrentEnergy(stack)
|
||||
if (available > requested) {
|
||||
setCurrentEnergy(stack, available - requested)
|
||||
requested
|
||||
}
|
||||
else {
|
||||
setCurrentEnergy(stack, 0)
|
||||
available
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call to give energy to an item
|
||||
*
|
||||
* @param stack
|
||||
* ItemStack being provided with energy
|
||||
* @param provided
|
||||
* Amount of energy to add
|
||||
* @return Amount of energy added
|
||||
*/
|
||||
def giveEnergyTo(stack: ItemStack, provided: Double): Double = {
|
||||
val available: Double = getCurrentEnergy(stack)
|
||||
val max: Double = getMaxEnergy(stack)
|
||||
if (available + provided < max) {
|
||||
setCurrentEnergy(stack, available + provided)
|
||||
provided
|
||||
}
|
||||
else {
|
||||
setCurrentEnergy(stack, max)
|
||||
max - available
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package net.machinemuse.api.electricity
|
||||
|
||||
import net.minecraft.item.ItemStack
|
||||
import thermalexpansion.api.item.IChargeableItem
|
||||
|
||||
/**
|
||||
* Author: MachineMuse (Claire Semple)
|
||||
* Created: 10:05 PM, 4/20/13
|
||||
*/
|
||||
trait TEElectricItem extends IChargeableItem with MuseElectricItem {
|
||||
def receiveEnergy(theItem: ItemStack, energy: Float, doReceive: Boolean): Float = {
|
||||
val receivedME: Double = TEElectricAdapter.museEnergyFromMJ(energy)
|
||||
val eatenME: Double = giveEnergyTo(theItem, receivedME)
|
||||
TEElectricAdapter.museEnergyToMJ(eatenME).asInstanceOf[Float]
|
||||
}
|
||||
|
||||
def transferEnergy(theItem: ItemStack, energy: Float, doTransfer: Boolean): Float = {
|
||||
val requesteddME: Double = TEElectricAdapter.museEnergyFromMJ(energy)
|
||||
val takenME: Double = drainEnergyFrom(theItem, requesteddME)
|
||||
TEElectricAdapter.museEnergyToMJ(takenME).asInstanceOf[Float]
|
||||
}
|
||||
|
||||
def getEnergyStored(theItem: ItemStack): Float = {
|
||||
TEElectricAdapter.museEnergyToMJ(getCurrentEnergy(theItem)).asInstanceOf[Float]
|
||||
}
|
||||
|
||||
def getMaxEnergyStored(theItem: ItemStack): Float = {
|
||||
TEElectricAdapter.museEnergyToMJ(getMaxEnergy(theItem)).asInstanceOf[Float]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package net.machinemuse.api.electricity
|
||||
|
||||
import universalelectricity.core.item.IItemElectric
|
||||
import universalelectricity.core.electricity.ElectricityPack
|
||||
import net.minecraft.item.ItemStack
|
||||
|
||||
/**
|
||||
* Created with IntelliJ IDEA.
|
||||
* User: MachineMuse
|
||||
*/
|
||||
trait UEElectricItem extends IItemElectric with MuseElectricItem {
|
||||
def getJoules(itemStack: ItemStack): Double = {
|
||||
UEElectricAdapter.museEnergyToJoules(getCurrentEnergy(itemStack))
|
||||
}
|
||||
|
||||
def setJoules(joules: Double, itemStack: ItemStack) {
|
||||
setCurrentEnergy(itemStack, UEElectricAdapter.museEnergyFromJoules(joules))
|
||||
}
|
||||
|
||||
def getMaxJoules(itemStack: ItemStack): Double = {
|
||||
UEElectricAdapter.museEnergyToJoules(getMaxEnergy(itemStack))
|
||||
}
|
||||
|
||||
def getVoltage(itemStack: ItemStack): Double = {
|
||||
120
|
||||
}
|
||||
|
||||
def onReceive(electricityPack: ElectricityPack, itemStack: ItemStack): ElectricityPack = {
|
||||
val energyReceiving: Double = UEElectricAdapter.museEnergyFromElectricityPack(electricityPack)
|
||||
val energyConsumed: Double = giveEnergyTo(itemStack, energyReceiving)
|
||||
val packConsumed: ElectricityPack = UEElectricAdapter.museEnergyToElectricityPack(energyConsumed, getVoltage(itemStack))
|
||||
packConsumed
|
||||
}
|
||||
|
||||
def onProvide(electricityPack: ElectricityPack, itemStack: ItemStack): ElectricityPack = {
|
||||
val energyRequested: Double = UEElectricAdapter.museEnergyFromElectricityPack(electricityPack)
|
||||
val energyGiven: Double = drainEnergyFrom(itemStack, energyRequested)
|
||||
val packGiven: ElectricityPack = UEElectricAdapter.museEnergyToElectricityPack(energyGiven, getVoltage(itemStack))
|
||||
packGiven
|
||||
}
|
||||
|
||||
def getReceiveRequest(itemStack: ItemStack): ElectricityPack = {
|
||||
UEElectricAdapter.museEnergyToElectricityPack(getMaxEnergy(itemStack) - getCurrentEnergy(itemStack), getVoltage(itemStack))
|
||||
}
|
||||
|
||||
def getProvideRequest(itemStack: ItemStack): ElectricityPack = {
|
||||
UEElectricAdapter.museEnergyToElectricityPack(getMaxEnergy(itemStack) - getCurrentEnergy(itemStack), getVoltage(itemStack))
|
||||
}
|
||||
}
|
|
@ -1,242 +0,0 @@
|
|||
package net.machinemuse.powersuits.item;
|
||||
|
||||
import ic2.api.ICustomElectricItem;
|
||||
import icbm.api.explosion.IEMPItem;
|
||||
import icbm.api.explosion.IExplosive;
|
||||
import net.machinemuse.api.ModuleManager;
|
||||
import net.machinemuse.api.MuseItemUtils;
|
||||
import net.machinemuse.api.electricity.ElectricItemUtils;
|
||||
import net.machinemuse.api.electricity.IC2ElectricAdapter;
|
||||
import net.machinemuse.api.electricity.TEElectricAdapter;
|
||||
import net.machinemuse.api.electricity.UEElectricAdapter;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.item.EnumArmorMaterial;
|
||||
import net.minecraft.item.ItemArmor;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import thermalexpansion.api.item.IChargeableItem;
|
||||
import universalelectricity.core.electricity.ElectricityPack;
|
||||
import universalelectricity.core.item.IItemElectric;
|
||||
|
||||
public abstract class ItemElectricArmor extends ItemArmor
|
||||
implements
|
||||
IItemElectric,
|
||||
ICustomElectricItem,
|
||||
IEMPItem,
|
||||
IChargeableItem
|
||||
|
||||
{
|
||||
public ItemElectricArmor(int par1, EnumArmorMaterial par2EnumArmorMaterial, int par3, int par4) {
|
||||
super(par1, par2EnumArmorMaterial, par3, par4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call to get the energy of an item
|
||||
*
|
||||
* @param stack
|
||||
* ItemStack to set
|
||||
* @return Current energy level
|
||||
*/
|
||||
public double getCurrentEnergy(ItemStack stack) {
|
||||
return MuseItemUtils.getDoubleOrZero(stack, ElectricItemUtils.CURRENT_ENERGY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call to set the energy of an item
|
||||
*
|
||||
* @param stack
|
||||
* ItemStack to set
|
||||
* @return Maximum energy level
|
||||
*/
|
||||
public double getMaxEnergy(ItemStack stack) {
|
||||
return ModuleManager.computeModularProperty(stack, ElectricItemUtils.MAXIMUM_ENERGY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call to set the energy of an item
|
||||
*
|
||||
* @param stack
|
||||
* ItemStack to set
|
||||
* @param energy
|
||||
* Level to set it to
|
||||
*/
|
||||
public void setCurrentEnergy(ItemStack stack, double energy) {
|
||||
MuseItemUtils.setDoubleOrRemove(stack, ElectricItemUtils.CURRENT_ENERGY, energy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call to drain energy from an item
|
||||
*
|
||||
* @param stack
|
||||
* ItemStack being requested for energy
|
||||
* @param requested
|
||||
* Amount of energy to drain
|
||||
* @return Amount of energy successfully drained
|
||||
*/
|
||||
public double drainEnergyFrom(ItemStack stack, double requested) {
|
||||
double available = getCurrentEnergy(stack);
|
||||
if (available > requested) {
|
||||
setCurrentEnergy(stack, available - requested);
|
||||
return requested;
|
||||
} else {
|
||||
setCurrentEnergy(stack, 0);
|
||||
return available;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call to give energy to an item
|
||||
*
|
||||
* @param stack
|
||||
* ItemStack being provided with energy
|
||||
* @param provided
|
||||
* Amount of energy to add
|
||||
* @return Amount of energy added
|
||||
*/
|
||||
public double giveEnergyTo(ItemStack stack, double provided) {
|
||||
double available = getCurrentEnergy(stack);
|
||||
double max = getMaxEnergy(stack);
|
||||
if (available + provided < max) {
|
||||
setCurrentEnergy(stack, available + provided);
|
||||
return provided;
|
||||
} else {
|
||||
setCurrentEnergy(stack, max);
|
||||
return max - available;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getJoules(ItemStack itemStack) {
|
||||
return UEElectricAdapter.museEnergyToJoules(getCurrentEnergy(itemStack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setJoules(double joules, ItemStack itemStack) {
|
||||
setCurrentEnergy(itemStack, UEElectricAdapter.museEnergyFromJoules(joules));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxJoules(ItemStack itemStack) {
|
||||
return UEElectricAdapter.museEnergyToJoules(getMaxEnergy(itemStack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getVoltage(ItemStack itemStack) {
|
||||
return 120;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectricityPack onReceive(ElectricityPack electricityPack, ItemStack itemStack) {
|
||||
double energyReceiving = UEElectricAdapter.museEnergyFromElectricityPack(electricityPack);
|
||||
double energyConsumed = giveEnergyTo(itemStack, energyReceiving);
|
||||
ElectricityPack packConsumed = UEElectricAdapter.museEnergyToElectricityPack(energyConsumed, getVoltage(itemStack));
|
||||
return packConsumed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectricityPack onProvide(ElectricityPack electricityPack, ItemStack itemStack) {
|
||||
double energyRequested = UEElectricAdapter.museEnergyFromElectricityPack(electricityPack);
|
||||
double energyGiven = drainEnergyFrom(itemStack, energyRequested);
|
||||
ElectricityPack packGiven = UEElectricAdapter.museEnergyToElectricityPack(energyGiven, getVoltage(itemStack));
|
||||
return packGiven;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectricityPack getReceiveRequest(ItemStack itemStack) {
|
||||
return UEElectricAdapter.museEnergyToElectricityPack(getMaxEnergy(itemStack) - getCurrentEnergy(itemStack), getVoltage(itemStack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectricityPack getProvideRequest(ItemStack itemStack) {
|
||||
return UEElectricAdapter.museEnergyToElectricityPack(getMaxEnergy(itemStack) - getCurrentEnergy(itemStack), getVoltage(itemStack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(ItemStack itemStack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getChargedItemId(ItemStack itemStack) {
|
||||
return itemStack.itemID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEmptyItemId(ItemStack itemStack) {
|
||||
return itemStack.itemID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxCharge(ItemStack itemStack) {
|
||||
return (int) IC2ElectricAdapter.museEnergyToEU(getCurrentEnergy(itemStack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTier(ItemStack itemStack) {
|
||||
return IC2ElectricAdapter.getTier(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTransferLimit(ItemStack itemStack) {
|
||||
return (int) IC2ElectricAdapter.museEnergyToEU(Math.sqrt(getMaxEnergy(itemStack)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int charge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate) {
|
||||
double current = getCurrentEnergy(itemStack);
|
||||
double given = giveEnergyTo(itemStack, IC2ElectricAdapter.museEnergyFromEU(amount));
|
||||
if (simulate) {
|
||||
setCurrentEnergy(itemStack, current);
|
||||
}
|
||||
return (int) IC2ElectricAdapter.museEnergyToEU(given);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int discharge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate) {
|
||||
double current = getCurrentEnergy(itemStack);
|
||||
double taken = drainEnergyFrom(itemStack, IC2ElectricAdapter.museEnergyFromEU(amount));
|
||||
if (simulate) {
|
||||
setCurrentEnergy(itemStack, current);
|
||||
}
|
||||
return (int) IC2ElectricAdapter.museEnergyToEU(taken);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(ItemStack itemStack, int amount) {
|
||||
double requested = IC2ElectricAdapter.museEnergyFromEU(amount);
|
||||
return requested < getCurrentEnergy(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canShowChargeToolTip(ItemStack itemStack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float receiveEnergy(ItemStack theItem, float energy, boolean doReceive) {
|
||||
double receivedME = TEElectricAdapter.museEnergyFromMJ(energy);
|
||||
double eatenME = giveEnergyTo(theItem, receivedME);
|
||||
return (float) TEElectricAdapter.museEnergyToMJ(eatenME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float transferEnergy(ItemStack theItem, float energy, boolean doTransfer) {
|
||||
double requesteddME = TEElectricAdapter.museEnergyFromMJ(energy);
|
||||
double takenME = drainEnergyFrom(theItem, requesteddME);
|
||||
return (float) TEElectricAdapter.museEnergyToMJ(takenME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getEnergyStored(ItemStack theItem) {
|
||||
return (float) TEElectricAdapter.museEnergyToMJ(getCurrentEnergy(theItem));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxEnergyStored(ItemStack theItem) {
|
||||
return (float) TEElectricAdapter.museEnergyToMJ(getMaxEnergy(theItem));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEMP(ItemStack itemStack, Entity entity, IExplosive empExplosive) {
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package net.machinemuse.powersuits.item
|
||||
|
||||
import net.minecraft.item.EnumArmorMaterial
|
||||
import net.minecraft.item.ItemArmor
|
||||
import net.machinemuse.api.electricity.{UEElectricItem, TEElectricItem, IC2ElectricItem, EMPElectricItem}
|
||||
|
||||
abstract class ItemElectricArmor(id: Int, material: EnumArmorMaterial, index1: Int, index2: Int)
|
||||
extends ItemArmor(id, material, index1, index2)
|
||||
with IC2ElectricItem
|
||||
with TEElectricItem
|
||||
with EMPElectricItem
|
||||
with UEElectricItem {
|
||||
|
||||
}
|
|
@ -1,212 +0,0 @@
|
|||
package net.machinemuse.powersuits.item;
|
||||
|
||||
import ic2.api.ICustomElectricItem;
|
||||
import net.machinemuse.api.ModuleManager;
|
||||
import net.machinemuse.api.MuseItemUtils;
|
||||
import net.machinemuse.api.electricity.ElectricItemUtils;
|
||||
import net.machinemuse.api.electricity.IC2ElectricAdapter;
|
||||
import net.machinemuse.api.electricity.UEElectricAdapter;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.EnumToolMaterial;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemTool;
|
||||
import universalelectricity.core.electricity.ElectricityPack;
|
||||
import universalelectricity.core.item.IItemElectric;
|
||||
|
||||
public class ItemElectricTool extends ItemTool
|
||||
implements
|
||||
IItemElectric, // Universal Electricity
|
||||
ICustomElectricItem // Industrial Craft 2
|
||||
|
||||
// IEMPItem, // for ICBM EMP interfacing
|
||||
|
||||
// IChargeableItem // for Thermal Expansion
|
||||
{
|
||||
|
||||
protected ItemElectricTool(int par1, int par2, EnumToolMaterial par3EnumToolMaterial, Block[] par4ArrayOfBlock) {
|
||||
super(par1, par2, par3EnumToolMaterial, par4ArrayOfBlock);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call to get the energy of an item
|
||||
*
|
||||
* @param stack
|
||||
* ItemStack to set
|
||||
* @return Current energy level
|
||||
*/
|
||||
public double getCurrentEnergy(ItemStack stack) {
|
||||
return MuseItemUtils.getDoubleOrZero(stack, ElectricItemUtils.CURRENT_ENERGY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call to set the energy of an item
|
||||
*
|
||||
* @param stack
|
||||
* ItemStack to set
|
||||
* @return Maximum energy level
|
||||
*/
|
||||
public double getMaxEnergy(ItemStack stack) {
|
||||
return ModuleManager.computeModularProperty(stack, ElectricItemUtils.MAXIMUM_ENERGY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call to set the energy of an item
|
||||
*
|
||||
* @param stack
|
||||
* ItemStack to set
|
||||
* @param energy
|
||||
* Level to set it to
|
||||
*/
|
||||
public void setCurrentEnergy(ItemStack stack, double energy) {
|
||||
MuseItemUtils.setDoubleOrRemove(stack, ElectricItemUtils.CURRENT_ENERGY, energy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call to drain energy from an item
|
||||
*
|
||||
* @param stack
|
||||
* ItemStack being requested for energy
|
||||
* @param requested
|
||||
* Amount of energy to drain
|
||||
* @return Amount of energy successfully drained
|
||||
*/
|
||||
public double drainEnergyFrom(ItemStack stack, double requested) {
|
||||
double available = getCurrentEnergy(stack);
|
||||
if (available > requested) {
|
||||
setCurrentEnergy(stack, available - requested);
|
||||
return requested;
|
||||
} else {
|
||||
setCurrentEnergy(stack, 0);
|
||||
return available;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call to give energy to an item
|
||||
*
|
||||
* @param stack
|
||||
* ItemStack being requested for energy
|
||||
* @param provided
|
||||
* Amount of energy to drain
|
||||
* @return Amount of energy used
|
||||
*/
|
||||
public double giveEnergyTo(ItemStack stack, double provided) {
|
||||
double available = getCurrentEnergy(stack);
|
||||
double max = getMaxEnergy(stack);
|
||||
if (available + provided < max) {
|
||||
setCurrentEnergy(stack, available + provided);
|
||||
return provided;
|
||||
} else {
|
||||
setCurrentEnergy(stack, max);
|
||||
return max - available;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getJoules(ItemStack itemStack) {
|
||||
return UEElectricAdapter.museEnergyToJoules(getCurrentEnergy(itemStack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setJoules(double joules, ItemStack itemStack) {
|
||||
setCurrentEnergy(itemStack, UEElectricAdapter.museEnergyFromJoules(joules));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxJoules(ItemStack itemStack) {
|
||||
return UEElectricAdapter.museEnergyToJoules(getMaxEnergy(itemStack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getVoltage(ItemStack itemStack) {
|
||||
return 120;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectricityPack onReceive(ElectricityPack electricityPack, ItemStack itemStack) {
|
||||
double energyReceiving = UEElectricAdapter.museEnergyFromElectricityPack(electricityPack);
|
||||
double energyConsumed = giveEnergyTo(itemStack, energyReceiving);
|
||||
ElectricityPack packConsumed = UEElectricAdapter.museEnergyToElectricityPack(energyConsumed, getVoltage(itemStack));
|
||||
return packConsumed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectricityPack onProvide(ElectricityPack electricityPack, ItemStack itemStack) {
|
||||
double energyRequested = UEElectricAdapter.museEnergyFromElectricityPack(electricityPack);
|
||||
double energyGiven = drainEnergyFrom(itemStack, energyRequested);
|
||||
ElectricityPack packGiven = UEElectricAdapter.museEnergyToElectricityPack(energyGiven, getVoltage(itemStack));
|
||||
return packGiven;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectricityPack getReceiveRequest(ItemStack itemStack) {
|
||||
return UEElectricAdapter.museEnergyToElectricityPack(getMaxEnergy(itemStack) - getCurrentEnergy(itemStack), getVoltage(itemStack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectricityPack getProvideRequest(ItemStack itemStack) {
|
||||
return UEElectricAdapter.museEnergyToElectricityPack(getMaxEnergy(itemStack) - getCurrentEnergy(itemStack), getVoltage(itemStack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(ItemStack itemStack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getChargedItemId(ItemStack itemStack) {
|
||||
return itemStack.itemID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEmptyItemId(ItemStack itemStack) {
|
||||
return itemStack.itemID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxCharge(ItemStack itemStack) {
|
||||
return (int) IC2ElectricAdapter.museEnergyToEU(getCurrentEnergy(itemStack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTier(ItemStack itemStack) {
|
||||
return IC2ElectricAdapter.getTier(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTransferLimit(ItemStack itemStack) {
|
||||
return (int) IC2ElectricAdapter.museEnergyToEU(Math.sqrt(getMaxEnergy(itemStack)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int charge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate) {
|
||||
double current = getCurrentEnergy(itemStack);
|
||||
double given = giveEnergyTo(itemStack, IC2ElectricAdapter.museEnergyFromEU(amount));
|
||||
if (simulate) {
|
||||
setCurrentEnergy(itemStack, current);
|
||||
}
|
||||
return (int) IC2ElectricAdapter.museEnergyToEU(given);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int discharge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate) {
|
||||
double current = getCurrentEnergy(itemStack);
|
||||
double taken = drainEnergyFrom(itemStack, IC2ElectricAdapter.museEnergyFromEU(amount));
|
||||
if (simulate) {
|
||||
setCurrentEnergy(itemStack, current);
|
||||
}
|
||||
return (int) IC2ElectricAdapter.museEnergyToEU(taken);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(ItemStack itemStack, int amount) {
|
||||
double requested = IC2ElectricAdapter.museEnergyFromEU(amount);
|
||||
return requested < getCurrentEnergy(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canShowChargeToolTip(ItemStack itemStack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package net.machinemuse.powersuits.item
|
||||
|
||||
import net.machinemuse.api.electricity._
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.item.EnumToolMaterial
|
||||
import net.minecraft.item.ItemTool
|
||||
|
||||
class ItemElectricTool(par1: Int, par2: Int, par3EnumToolMaterial: EnumToolMaterial, par4ArrayOfBlock: Array[Block])
|
||||
extends ItemTool(par1, par2, par3EnumToolMaterial, par4ArrayOfBlock)
|
||||
with IC2ElectricItem
|
||||
with TEElectricItem
|
||||
with EMPElectricItem
|
||||
with UEElectricItem {
|
||||
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
package net.machinemuse.powersuits.item;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import atomicscience.api.IAntiPoisonArmor;
|
||||
import atomicscience.api.poison.Poison;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.machinemuse.api.*;
|
||||
import net.machinemuse.api.electricity.ElectricItemUtils;
|
||||
import net.machinemuse.general.MuseStringUtils;
|
||||
|
@ -23,299 +24,292 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraftforge.common.ISpecialArmor;
|
||||
import atomicscience.api.IAntiPoisonArmor;
|
||||
import atomicscience.api.poison.Poison;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Describes the 4 different modular armor pieces - head, torso, legs, feet.
|
||||
*
|
||||
*
|
||||
* @author MachineMuse
|
||||
*/
|
||||
public abstract class ItemPowerArmor extends ItemElectricArmor
|
||||
implements
|
||||
ISpecialArmor,
|
||||
IAntiPoisonArmor,
|
||||
IModularItem {
|
||||
implements
|
||||
ISpecialArmor,
|
||||
IAntiPoisonArmor,
|
||||
IModularItem {
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @param material
|
||||
* @param renderIndex
|
||||
* @param armorType
|
||||
* 0 = head; 1 = torso; 2 = legs; 3 = feet
|
||||
*/
|
||||
public ItemPowerArmor(int id, int renderIndex, int armorType) {
|
||||
super(id, EnumArmorMaterial.IRON, renderIndex, armorType);
|
||||
setMaxStackSize(1);
|
||||
setCreativeTab(Config.getCreativeTab());
|
||||
}
|
||||
/**
|
||||
* @param id
|
||||
* @param renderIndex
|
||||
* @param armorType 0 = head; 1 = torso; 2 = legs; 3 = feet
|
||||
*/
|
||||
public ItemPowerArmor(int id, int renderIndex, int armorType) {
|
||||
super(id, EnumArmorMaterial.IRON, renderIndex, armorType);
|
||||
setMaxStackSize(1);
|
||||
setCreativeTab(Config.getCreativeTab());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getArmorTexture(ItemStack itemstack, Entity entity, int slot, int layer) {
|
||||
@Override
|
||||
public String getArmorTexture(ItemStack itemstack, Entity entity, int slot, int layer) {
|
||||
|
||||
// if (itemstack != null) {
|
||||
// NBTTagCompound itemTag = MuseItemUtils.getMuseItemTag(itemstack);
|
||||
// // MinecraftForgeClient.getRenderPass()? nope
|
||||
// if (itemTag.hasKey("didColour")) {
|
||||
//
|
||||
// itemTag.removeTag("didColour");
|
||||
return Config.BLANK_ARMOR_MODEL_PATH;
|
||||
// } else {
|
||||
// if (MuseItemUtils.itemHasActiveModule(itemstack,
|
||||
// TransparentArmorModule.MODULE_TRANSPARENT_ARMOR)) {
|
||||
// return Config.BLANK_ARMOR_MODEL_PATH;
|
||||
// } else if (itemstack.getItem() instanceof ItemPowerArmorLeggings) {
|
||||
// if (MuseItemUtils.itemHasModule(itemstack,
|
||||
// CitizenJoeStyle.CITIZEN_JOE_STYLE)) {
|
||||
// return Config.CITIZENJOE_ARMORPANTS_PATH;
|
||||
// }
|
||||
//
|
||||
// return Config.SEBK_ARMORPANTS_PATH;
|
||||
// } else {
|
||||
// if (MuseItemUtils.itemHasModule(itemstack,
|
||||
// CitizenJoeStyle.CITIZEN_JOE_STYLE)) {
|
||||
// return Config.CITIZENJOE_ARMOR_PATH;
|
||||
// }
|
||||
// return Config.SEBK_ARMOR_PATH;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return Config.BLANK_ARMOR_MODEL_PATH;
|
||||
}
|
||||
// if (itemstack != null) {
|
||||
// NBTTagCompound itemTag = MuseItemUtils.getMuseItemTag(itemstack);
|
||||
// // MinecraftForgeClient.getRenderPass()? nope
|
||||
// if (itemTag.hasKey("didColour")) {
|
||||
//
|
||||
// itemTag.removeTag("didColour");
|
||||
return Config.BLANK_ARMOR_MODEL_PATH;
|
||||
// } else {
|
||||
// if (MuseItemUtils.itemHasActiveModule(itemstack,
|
||||
// TransparentArmorModule.MODULE_TRANSPARENT_ARMOR)) {
|
||||
// return Config.BLANK_ARMOR_MODEL_PATH;
|
||||
// } else if (itemstack.getItem() instanceof ItemPowerArmorLeggings) {
|
||||
// if (MuseItemUtils.itemHasModule(itemstack,
|
||||
// CitizenJoeStyle.CITIZEN_JOE_STYLE)) {
|
||||
// return Config.CITIZENJOE_ARMORPANTS_PATH;
|
||||
// }
|
||||
//
|
||||
// return Config.SEBK_ARMORPANTS_PATH;
|
||||
// } else {
|
||||
// if (MuseItemUtils.itemHasModule(itemstack,
|
||||
// CitizenJoeStyle.CITIZEN_JOE_STYLE)) {
|
||||
// return Config.CITIZENJOE_ARMOR_PATH;
|
||||
// }
|
||||
// return Config.SEBK_ARMOR_PATH;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return Config.BLANK_ARMOR_MODEL_PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public ModelBiped getArmorModel(EntityLiving entityLiving, ItemStack itemstack, int armorSlot) {
|
||||
ArmorModel model;
|
||||
if (armorSlot == 3) {
|
||||
model = ArmorBootsModel.getInstance();
|
||||
} else {
|
||||
model = ArmorModel.getInstance();
|
||||
}
|
||||
model.bipedHead.showModel = armorSlot == 0;
|
||||
model.bipedHeadwear.showModel = armorSlot == 0;
|
||||
model.bipedBody.showModel = armorSlot == 1;
|
||||
model.bipedRightArm.showModel = armorSlot == 1;
|
||||
model.bipedLeftArm.showModel = armorSlot == 1;
|
||||
model.bipedRightLeg.showModel = armorSlot == 2 || armorSlot == 3;
|
||||
model.bipedLeftLeg.showModel = armorSlot == 2 || armorSlot == 3;
|
||||
if (itemstack != null) {
|
||||
if (MuseItemUtils.itemHasActiveModule(itemstack,
|
||||
TransparentArmorModule.MODULE_TRANSPARENT_ARMOR)) {
|
||||
return null;
|
||||
}
|
||||
model.normalcolour = this.getColorFromItemStack(itemstack);
|
||||
model.glowcolour = this.getGlowFromItemStack(itemstack);
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public ModelBiped getArmorModel(EntityLiving entityLiving, ItemStack itemstack, int armorSlot) {
|
||||
ArmorModel model;
|
||||
if (armorSlot == 3) {
|
||||
model = ArmorBootsModel.getInstance();
|
||||
} else {
|
||||
model = ArmorModel.getInstance();
|
||||
}
|
||||
model.bipedHead.showModel = armorSlot == 0;
|
||||
model.bipedHeadwear.showModel = armorSlot == 0;
|
||||
model.bipedBody.showModel = armorSlot == 1;
|
||||
model.bipedRightArm.showModel = armorSlot == 1;
|
||||
model.bipedLeftArm.showModel = armorSlot == 1;
|
||||
model.bipedRightLeg.showModel = armorSlot == 2 || armorSlot == 3;
|
||||
model.bipedLeftLeg.showModel = armorSlot == 2 || armorSlot == 3;
|
||||
if (itemstack != null) {
|
||||
if (MuseItemUtils.itemHasActiveModule(itemstack,
|
||||
TransparentArmorModule.MODULE_TRANSPARENT_ARMOR)) {
|
||||
return null;
|
||||
}
|
||||
model.normalcolour = this.getColorFromItemStack(itemstack);
|
||||
model.glowcolour = this.getGlowFromItemStack(itemstack);
|
||||
|
||||
}
|
||||
return model;
|
||||
}
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
public Colour getColorFromItemStack(ItemStack stack) {
|
||||
if (!MuseItemUtils.itemHasActiveModule(stack, TintModule.MODULE_TINT)) {
|
||||
return Colour.WHITE;
|
||||
}
|
||||
double computedred = ModuleManager.computeModularProperty(stack, TintModule.RED_TINT);
|
||||
double computedgreen = ModuleManager.computeModularProperty(stack, TintModule.GREEN_TINT);
|
||||
double computedblue = ModuleManager.computeModularProperty(stack, TintModule.BLUE_TINT);
|
||||
Colour colour = new Colour(clampDouble(computedred, 0, 1), clampDouble(computedgreen, 0, 1), clampDouble(computedblue, 0, 1), 1.0F);
|
||||
return colour;
|
||||
}
|
||||
public Colour getColorFromItemStack(ItemStack stack) {
|
||||
if (!MuseItemUtils.itemHasActiveModule(stack, TintModule.MODULE_TINT)) {
|
||||
return Colour.WHITE;
|
||||
}
|
||||
double computedred = ModuleManager.computeModularProperty(stack, TintModule.RED_TINT);
|
||||
double computedgreen = ModuleManager.computeModularProperty(stack, TintModule.GREEN_TINT);
|
||||
double computedblue = ModuleManager.computeModularProperty(stack, TintModule.BLUE_TINT);
|
||||
Colour colour = new Colour(clampDouble(computedred, 0, 1), clampDouble(computedgreen, 0, 1), clampDouble(computedblue, 0, 1), 1.0F);
|
||||
return colour;
|
||||
}
|
||||
|
||||
private Colour getGlowFromItemStack(ItemStack stack) {
|
||||
if (!MuseItemUtils.itemHasActiveModule(stack, CosmeticGlowModule.MODULE_GLOW)) {
|
||||
return Colour.LIGHTBLUE;
|
||||
}
|
||||
double computedred = ModuleManager.computeModularProperty(stack, CosmeticGlowModule.RED_GLOW);
|
||||
double computedgreen = ModuleManager.computeModularProperty(stack, CosmeticGlowModule.GREEN_GLOW);
|
||||
double computedblue = ModuleManager.computeModularProperty(stack, CosmeticGlowModule.BLUE_GLOW);
|
||||
Colour colour = new Colour(clampDouble(computedred, 0, 1), clampDouble(computedgreen, 0, 1), clampDouble(computedblue, 0, 1), 0.8);
|
||||
return colour;
|
||||
}
|
||||
private Colour getGlowFromItemStack(ItemStack stack) {
|
||||
if (!MuseItemUtils.itemHasActiveModule(stack, CosmeticGlowModule.MODULE_GLOW)) {
|
||||
return Colour.LIGHTBLUE;
|
||||
}
|
||||
double computedred = ModuleManager.computeModularProperty(stack, CosmeticGlowModule.RED_GLOW);
|
||||
double computedgreen = ModuleManager.computeModularProperty(stack, CosmeticGlowModule.GREEN_GLOW);
|
||||
double computedblue = ModuleManager.computeModularProperty(stack, CosmeticGlowModule.BLUE_GLOW);
|
||||
Colour colour = new Colour(clampDouble(computedred, 0, 1), clampDouble(computedgreen, 0, 1), clampDouble(computedblue, 0, 1), 0.8);
|
||||
return colour;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherited from ISpecialArmor, allows significant customization of damage
|
||||
* calculations.
|
||||
*/
|
||||
@Override
|
||||
public ArmorProperties getProperties(EntityLiving player, ItemStack armor, DamageSource source, double damage, int slot) {
|
||||
// Order in which this armor is assessed for damage. Higher(?) priority
|
||||
// items take damage first, and if none spills over, the other items
|
||||
// take no damage.
|
||||
int priority = 1;
|
||||
if (source.isFireDamage() && !source.equals(MuseHeatUtils.overheatDamage)) {
|
||||
return new ArmorProperties(priority, 0.25, (int) (25 * damage));
|
||||
}
|
||||
double armorDouble;
|
||||
/**
|
||||
* Inherited from ISpecialArmor, allows significant customization of damage
|
||||
* calculations.
|
||||
*/
|
||||
@Override
|
||||
public ArmorProperties getProperties(EntityLiving player, ItemStack armor, DamageSource source, double damage, int slot) {
|
||||
// Order in which this armor is assessed for damage. Higher(?) priority
|
||||
// items take damage first, and if none spills over, the other items
|
||||
// take no damage.
|
||||
int priority = 1;
|
||||
if (source.isFireDamage() && !source.equals(MuseHeatUtils.overheatDamage)) {
|
||||
return new ArmorProperties(priority, 0.25, (int) (25 * damage));
|
||||
}
|
||||
double armorDouble;
|
||||
|
||||
if (player instanceof EntityPlayer) {
|
||||
armorDouble = getArmorDouble((EntityPlayer) player, armor);
|
||||
} else {
|
||||
armorDouble = 2;
|
||||
}
|
||||
if (player instanceof EntityPlayer) {
|
||||
armorDouble = getArmorDouble((EntityPlayer) player, armor);
|
||||
} else {
|
||||
armorDouble = 2;
|
||||
}
|
||||
|
||||
// How much of incoming damage is absorbed by this armor piece.
|
||||
// 1.0 = absorbs all damage
|
||||
// 0.5 = 50% damage to item, 50% damage carried over
|
||||
double absorbRatio = 0.04 * armorDouble;
|
||||
// How much of incoming damage is absorbed by this armor piece.
|
||||
// 1.0 = absorbs all damage
|
||||
// 0.5 = 50% damage to item, 50% damage carried over
|
||||
double absorbRatio = 0.04 * armorDouble;
|
||||
|
||||
// Maximum damage absorbed by this piece. Actual damage to this item
|
||||
// will be clamped between (damage * absorbRatio) and (absorbMax). Note
|
||||
// that a player has 20 hp (1hp = 1 half-heart)
|
||||
int absorbMax = (int) armorDouble * 75; // Not sure why this is
|
||||
// necessary but oh well
|
||||
if (source.isUnblockable()) {
|
||||
absorbMax = 0;
|
||||
absorbRatio = 0;
|
||||
}
|
||||
return new ArmorProperties(priority, absorbRatio, absorbMax);
|
||||
}
|
||||
// Maximum damage absorbed by this piece. Actual damage to this item
|
||||
// will be clamped between (damage * absorbRatio) and (absorbMax). Note
|
||||
// that a player has 20 hp (1hp = 1 half-heart)
|
||||
int absorbMax = (int) armorDouble * 75; // Not sure why this is
|
||||
// necessary but oh well
|
||||
if (source.isUnblockable()) {
|
||||
absorbMax = 0;
|
||||
absorbRatio = 0;
|
||||
}
|
||||
return new ArmorProperties(priority, absorbRatio, absorbMax);
|
||||
}
|
||||
|
||||
public static double clampDouble(double value, double min, double max) {
|
||||
if (value < min)
|
||||
return min;
|
||||
if (value > max)
|
||||
return max;
|
||||
return value;
|
||||
}
|
||||
public static double clampDouble(double value, double min, double max) {
|
||||
if (value < min)
|
||||
return min;
|
||||
if (value > max)
|
||||
return max;
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemEnchantability() {
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public int getItemEnchantability() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getColorFromItemStack(ItemStack stack, int par2) {
|
||||
Colour c = getColorFromItemStack(stack);
|
||||
return c.getInt();
|
||||
}
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getColorFromItemStack(ItemStack stack, int par2) {
|
||||
Colour c = getColorFromItemStack(stack);
|
||||
return c.getInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColor(ItemStack stack) {
|
||||
Colour c = getColorFromItemStack(stack);
|
||||
return c.getInt();
|
||||
}
|
||||
@Override
|
||||
public int getColor(ItemStack stack) {
|
||||
Colour c = getColorFromItemStack(stack);
|
||||
return c.getInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean requiresMultipleRenderPasses() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean requiresMultipleRenderPasses() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the specified armor ItemStack has a color.
|
||||
*/
|
||||
@Override
|
||||
public boolean hasColor(ItemStack stack) {
|
||||
NBTTagCompound itemTag = MuseItemUtils.getMuseItemTag(stack);
|
||||
return MuseItemUtils.tagHasModule(itemTag, TintModule.RED_TINT) || MuseItemUtils.tagHasModule(itemTag, TintModule.GREEN_TINT)
|
||||
|| MuseItemUtils.tagHasModule(itemTag, TintModule.BLUE_TINT);
|
||||
}
|
||||
/**
|
||||
* Return whether the specified armor ItemStack has a color.
|
||||
*/
|
||||
@Override
|
||||
public boolean hasColor(ItemStack stack) {
|
||||
NBTTagCompound itemTag = MuseItemUtils.getMuseItemTag(stack);
|
||||
return MuseItemUtils.tagHasModule(itemTag, TintModule.RED_TINT) || MuseItemUtils.tagHasModule(itemTag, TintModule.GREEN_TINT)
|
||||
|| MuseItemUtils.tagHasModule(itemTag, TintModule.BLUE_TINT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherited from ISpecialArmor, allows us to customize the calculations for
|
||||
* how much armor will display on the player's HUD.
|
||||
*/
|
||||
@Override
|
||||
public int getArmorDisplay(EntityPlayer player, ItemStack armor, int slot) {
|
||||
return (int) getArmorDouble(player, armor);
|
||||
}
|
||||
/**
|
||||
* Inherited from ISpecialArmor, allows us to customize the calculations for
|
||||
* how much armor will display on the player's HUD.
|
||||
*/
|
||||
@Override
|
||||
public int getArmorDisplay(EntityPlayer player, ItemStack armor, int slot) {
|
||||
return (int) getArmorDouble(player, armor);
|
||||
}
|
||||
|
||||
public double getHeatResistance(EntityPlayer player, ItemStack stack) {
|
||||
return MuseHeatUtils.getMaxHeat(stack);
|
||||
}
|
||||
public double getHeatResistance(EntityPlayer player, ItemStack stack) {
|
||||
return MuseHeatUtils.getMaxHeat(stack);
|
||||
}
|
||||
|
||||
public double getArmorDouble(EntityPlayer player, ItemStack stack) {
|
||||
double totalArmor = 0;
|
||||
NBTTagCompound props = MuseItemUtils.getMuseItemTag(stack);
|
||||
public double getArmorDouble(EntityPlayer player, ItemStack stack) {
|
||||
double totalArmor = 0;
|
||||
NBTTagCompound props = MuseItemUtils.getMuseItemTag(stack);
|
||||
|
||||
double energy = ElectricItemUtils.getPlayerEnergy(player);
|
||||
double physArmor = ModuleManager.computeModularProperty(stack, MuseCommonStrings.ARMOR_VALUE_PHYSICAL);
|
||||
double enerArmor = ModuleManager.computeModularProperty(stack, MuseCommonStrings.ARMOR_VALUE_ENERGY);
|
||||
double enerConsum = ModuleManager.computeModularProperty(stack, MuseCommonStrings.ARMOR_ENERGY_CONSUMPTION);
|
||||
double energy = ElectricItemUtils.getPlayerEnergy(player);
|
||||
double physArmor = ModuleManager.computeModularProperty(stack, MuseCommonStrings.ARMOR_VALUE_PHYSICAL);
|
||||
double enerArmor = ModuleManager.computeModularProperty(stack, MuseCommonStrings.ARMOR_VALUE_ENERGY);
|
||||
double enerConsum = ModuleManager.computeModularProperty(stack, MuseCommonStrings.ARMOR_ENERGY_CONSUMPTION);
|
||||
|
||||
totalArmor += physArmor;
|
||||
totalArmor += physArmor;
|
||||
|
||||
if (energy > enerConsum) {
|
||||
totalArmor += enerArmor;
|
||||
}
|
||||
// Make it so each armor piece can only contribute reduction up to the
|
||||
// configured amount.
|
||||
// Defaults to 6 armor points, or 24% reduction.
|
||||
totalArmor = Math.min(Config.getMaximumArmorPerPiece(), totalArmor);
|
||||
return totalArmor;
|
||||
}
|
||||
if (energy > enerConsum) {
|
||||
totalArmor += enerArmor;
|
||||
}
|
||||
// Make it so each armor piece can only contribute reduction up to the
|
||||
// configured amount.
|
||||
// Defaults to 6 armor points, or 24% reduction.
|
||||
totalArmor = Math.min(Config.getMaximumArmorPerPiece(), totalArmor);
|
||||
return totalArmor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherited from ISpecialArmor, allows us to customize how the armor
|
||||
* handles being damaged.
|
||||
*/
|
||||
@Override
|
||||
public void damageArmor(EntityLiving entity, ItemStack stack, DamageSource source, int damage, int slot) {
|
||||
NBTTagCompound itemProperties = MuseItemUtils.getMuseItemTag(stack);
|
||||
if (entity instanceof EntityPlayer) {
|
||||
if (source.equals(MuseHeatUtils.overheatDamage)) {
|
||||
} else if (source.isFireDamage()) {
|
||||
EntityPlayer player = (EntityPlayer) entity;
|
||||
MuseHeatUtils.heatPlayer(player, damage);
|
||||
} else {
|
||||
double enerConsum = ModuleManager.computeModularProperty(stack, MuseCommonStrings.ARMOR_ENERGY_CONSUMPTION);
|
||||
double drain = enerConsum * damage;
|
||||
if (entity instanceof EntityPlayer) {
|
||||
ElectricItemUtils.drainPlayerEnergy((EntityPlayer) entity, drain);
|
||||
} else {
|
||||
drainEnergyFrom(stack, drain);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Inherited from ISpecialArmor, allows us to customize how the armor
|
||||
* handles being damaged.
|
||||
*/
|
||||
@Override
|
||||
public void damageArmor(EntityLiving entity, ItemStack stack, DamageSource source, int damage, int slot) {
|
||||
NBTTagCompound itemProperties = MuseItemUtils.getMuseItemTag(stack);
|
||||
if (entity instanceof EntityPlayer) {
|
||||
if (source.equals(MuseHeatUtils.overheatDamage)) {
|
||||
} else if (source.isFireDamage()) {
|
||||
EntityPlayer player = (EntityPlayer) entity;
|
||||
MuseHeatUtils.heatPlayer(player, damage);
|
||||
} else {
|
||||
double enerConsum = ModuleManager.computeModularProperty(stack, MuseCommonStrings.ARMOR_ENERGY_CONSUMPTION);
|
||||
double drain = enerConsum * damage;
|
||||
if (entity instanceof EntityPlayer) {
|
||||
ElectricItemUtils.drainPlayerEnergy((EntityPlayer) entity, drain);
|
||||
} else {
|
||||
drainEnergyFrom(stack, drain);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds information to the item's tooltip when 'getting' it.
|
||||
*
|
||||
* @param stack
|
||||
* The itemstack to get the tooltip for
|
||||
* @param player
|
||||
* The player (client) viewing the tooltip
|
||||
* @param currentTipList
|
||||
* A list of strings containing the existing tooltip. When
|
||||
* passed, it will just contain the name of the item;
|
||||
* enchantments and lore are
|
||||
* appended afterwards.
|
||||
* @param advancedToolTips
|
||||
* Whether or not the player has 'advanced tooltips' turned on in
|
||||
* their settings.
|
||||
*/
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List currentTipList, boolean advancedToolTips) {
|
||||
MuseCommonStrings.addInformation(stack, player, currentTipList, advancedToolTips);
|
||||
}
|
||||
/**
|
||||
* Adds information to the item's tooltip when 'getting' it.
|
||||
*
|
||||
* @param stack The itemstack to get the tooltip for
|
||||
* @param player The player (client) viewing the tooltip
|
||||
* @param currentTipList A list of strings containing the existing tooltip. When
|
||||
* passed, it will just contain the name of the item;
|
||||
* enchantments and lore are
|
||||
* appended afterwards.
|
||||
* @param advancedToolTips Whether or not the player has 'advanced tooltips' turned on in
|
||||
* their settings.
|
||||
*/
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List currentTipList, boolean advancedToolTips) {
|
||||
MuseCommonStrings.addInformation(stack, player, currentTipList, advancedToolTips);
|
||||
}
|
||||
|
||||
public static String formatInfo(String string, double value) {
|
||||
return string + '\t' + MuseStringUtils.formatNumberShort(value);
|
||||
}
|
||||
public static String formatInfo(String string, double value) {
|
||||
return string + '\t' + MuseStringUtils.formatNumberShort(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getLongInfo(EntityPlayer player, ItemStack stack) {
|
||||
List<String> info = new ArrayList();
|
||||
NBTTagCompound itemProperties = MuseItemUtils.getMuseItemTag(stack);
|
||||
info.add("Detailed Summary");
|
||||
info.add(formatInfo("Armor", getArmorDouble(player, stack)));
|
||||
info.add(formatInfo("Energy Storage", getMaxJoules(stack)) + 'J');
|
||||
info.add(formatInfo("Weight", MuseCommonStrings.getTotalWeight(stack)) + 'g');
|
||||
return info;
|
||||
}
|
||||
@Override
|
||||
public List<String> getLongInfo(EntityPlayer player, ItemStack stack) {
|
||||
List<String> info = new ArrayList();
|
||||
NBTTagCompound itemProperties = MuseItemUtils.getMuseItemTag(stack);
|
||||
info.add("Detailed Summary");
|
||||
info.add(formatInfo("Armor", getArmorDouble(player, stack)));
|
||||
info.add(formatInfo("Energy Storage", getMaxJoules(stack)) + 'J');
|
||||
info.add(formatInfo("Weight", MuseCommonStrings.getTotalWeight(stack)) + 'g');
|
||||
return info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProtectedFromPoison(ItemStack itemStack, EntityLiving entityLiving, Poison type) {
|
||||
return MuseItemUtils.itemHasActiveModule(itemStack, HazmatModule.MODULE_HAZMAT);
|
||||
}
|
||||
@Override
|
||||
public boolean isProtectedFromPoison(ItemStack itemStack, EntityLiving entityLiving, Poison type) {
|
||||
return MuseItemUtils.itemHasActiveModule(itemStack, HazmatModule.MODULE_HAZMAT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProtectFromPoison(ItemStack itemStack, EntityLiving entityLiving, Poison type) {
|
||||
}
|
||||
@Override
|
||||
public void onProtectFromPoison(ItemStack itemStack, EntityLiving entityLiving, Poison type) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue