Merge branch 'master' of https://github.com/MachineMuse/MachineMusePowersuits
This commit is contained in:
commit
1fd796cad5
12 changed files with 109 additions and 68 deletions
|
@ -21,4 +21,28 @@ public interface IModularItem
|
|||
*/
|
||||
public List<String> getLongInfo(EntityPlayer player, ItemStack stack);
|
||||
|
||||
/**
|
||||
* Returns the amount of energy contained in the player's inventory.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public double getPlayerEnergy(EntityPlayer player);
|
||||
|
||||
/**
|
||||
* Drains the amount of energy from the player's inventory.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public void drainPlayerEnergy(EntityPlayer player, double drainAmount);
|
||||
|
||||
/**
|
||||
* Adds the amount of energy to the player's inventory.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public void givePlayerEnergy(EntityPlayer player, double joulesToGive);
|
||||
|
||||
}
|
||||
|
|
|
@ -4,8 +4,6 @@ import net.machinemuse.api.moduletrigger.IBlockBreakingModule;
|
|||
import net.machinemuse.api.moduletrigger.IPlayerTickModule;
|
||||
import net.machinemuse.api.moduletrigger.IRightClickModule;
|
||||
import net.machinemuse.api.moduletrigger.IToggleableModule;
|
||||
import net.machinemuse.utils.MuseItemTag;
|
||||
import net.machinemuse.utils.MuseItemUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -17,6 +15,8 @@ import java.util.Map;
|
|||
|
||||
public class ModuleManager {
|
||||
|
||||
public static final String ONLINE = "Active";
|
||||
|
||||
protected static final Map<String, IPowerModule> moduleMap = new HashMap<String, IPowerModule>();
|
||||
protected static final List<IPowerModule> moduleList = new ArrayList<IPowerModule>();
|
||||
protected static final List<IPlayerTickModule> playerTickModules = new ArrayList<IPlayerTickModule>();
|
||||
|
@ -92,9 +92,9 @@ public class ModuleManager {
|
|||
}
|
||||
|
||||
public static boolean isModuleOnline(NBTTagCompound itemTag, String moduleName) {
|
||||
if (tagHasModule(itemTag, moduleName) && !itemTag.getCompoundTag(moduleName).hasKey(MuseItemUtils.ONLINE)) {
|
||||
if (tagHasModule(itemTag, moduleName) && !itemTag.getCompoundTag(moduleName).hasKey(ONLINE)) {
|
||||
return true;
|
||||
} else if (tagHasModule(itemTag, moduleName) && itemTag.getCompoundTag(moduleName).getBoolean(MuseItemUtils.ONLINE)) {
|
||||
} else if (tagHasModule(itemTag, moduleName) && itemTag.getCompoundTag(moduleName).getBoolean(ONLINE)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -103,12 +103,12 @@ public class ModuleManager {
|
|||
public static void toggleModule(NBTTagCompound itemTag, String name, boolean toggleval) {
|
||||
if (tagHasModule(itemTag, name)) {
|
||||
NBTTagCompound moduleTag = itemTag.getCompoundTag(name);
|
||||
moduleTag.setBoolean(MuseItemUtils.ONLINE, toggleval);
|
||||
moduleTag.setBoolean(ONLINE, toggleval);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean itemHasModule(ItemStack stack, String moduleName) {
|
||||
return tagHasModule(MuseItemUtils.getMuseItemTag(stack), moduleName);
|
||||
return tagHasModule(MuseItemTag.getMuseItemTag(stack), moduleName);
|
||||
}
|
||||
|
||||
public static void tagAddModule(NBTTagCompound tag, IPowerModule module) {
|
||||
|
@ -116,7 +116,7 @@ public class ModuleManager {
|
|||
}
|
||||
|
||||
public static void itemAddModule(ItemStack stack, IPowerModule moduleType) {
|
||||
tagAddModule(MuseItemUtils.getMuseItemTag(stack), moduleType);
|
||||
tagAddModule(MuseItemTag.getMuseItemTag(stack), moduleType);
|
||||
}
|
||||
|
||||
public static boolean removeModule(NBTTagCompound tag, String moduleName) {
|
||||
|
@ -129,7 +129,7 @@ public class ModuleManager {
|
|||
}
|
||||
|
||||
public static boolean removeModule(ItemStack stack, String moduleName) {
|
||||
return removeModule(MuseItemUtils.getMuseItemTag(stack), moduleName);
|
||||
return removeModule(MuseItemTag.getMuseItemTag(stack), moduleName);
|
||||
}
|
||||
|
||||
public static boolean itemHasActiveModule(ItemStack itemStack, String moduleName) {
|
||||
|
@ -142,9 +142,9 @@ public class ModuleManager {
|
|||
// MuseLogger.logDebug("Module: " + moduleName + " vs Mode: " +
|
||||
// MuseItemUtils.getActiveMode(itemStack));
|
||||
|
||||
return moduleName.equals(MuseItemUtils.getActiveMode(itemStack));
|
||||
return moduleName.equals(MuseItemTag.getActiveMode(itemStack));
|
||||
} else {
|
||||
return isModuleOnline(MuseItemUtils.getMuseItemTag(itemStack), moduleName);
|
||||
return isModuleOnline(MuseItemTag.getMuseItemTag(itemStack), moduleName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package net.machinemuse.utils
|
||||
package net.machinemuse.api
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.item.ItemStack
|
||||
|
@ -30,4 +30,8 @@ object MuseItemTag {
|
|||
properties
|
||||
}
|
||||
|
||||
def getActiveMode(stack: ItemStack): String = {
|
||||
val active : String = getMuseItemTag(stack).getString("Mode")
|
||||
active
|
||||
}
|
||||
}
|
|
@ -7,7 +7,6 @@ import net.minecraft.entity.player.EntityPlayer
|
|||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.entity.item.EntityMinecart
|
||||
import buildcraft.api.tools.IToolWrench
|
||||
import universalelectricity.prefab.implement.IToolConfigurator
|
||||
import cpw.mods.fml.common.FMLCommonHandler
|
||||
import mods.mffs.api.IFieldTeleporter
|
||||
import powercrystals.minefactoryreloaded.api.IToolHammerAdvanced
|
||||
|
@ -56,8 +55,7 @@ trait ModularCrowbar extends IToolCrowbar {
|
|||
|
||||
trait ModularWrench
|
||||
extends IToolWrench // Buildcraft wrench
|
||||
with IToolConfigurator {
|
||||
// Universal Electricity wrench
|
||||
{
|
||||
|
||||
def canWrench(player: EntityPlayer, x: Int, y: Int, z: Int): Boolean = {
|
||||
if (player.getCurrentEquippedItem != null && player.getCurrentEquippedItem.getItem.isInstanceOf[IModularItem]) {
|
||||
|
|
|
@ -62,21 +62,19 @@ class TEElectricAdapter(val stack: ItemStack) extends ElectricAdapter {
|
|||
class UEElectricAdapter(val stack: ItemStack) extends ElectricAdapter {
|
||||
val item = stack.getItem.asInstanceOf[IItemElectric]
|
||||
|
||||
def getCurrentEnergy: Double = museEnergyFromJoules(item.getJoules(stack))
|
||||
def getCurrentEnergy: Double = museEnergyFromJoules(item.getElectricityStored(stack))
|
||||
|
||||
def getMaxEnergy: Double = museEnergyFromJoules(item.getMaxJoules(stack))
|
||||
def getMaxEnergy: Double = museEnergyFromJoules(item.getMaxElectricityStored(stack))
|
||||
|
||||
def drainEnergy(requested: Double): Double = {
|
||||
val voltage: Double = item.getVoltage(stack)
|
||||
val requestedPack: ElectricityPack = museEnergyToElectricityPack(requested, voltage)
|
||||
val receivedPack: ElectricityPack = item.onProvide(requestedPack, stack)
|
||||
museEnergyFromElectricityPack(receivedPack)
|
||||
val joules: Double = museEnergyToJoules(requested)
|
||||
val received: Float = item.discharge(stack, joules.toFloat, true)
|
||||
museEnergyFromJoules(received)
|
||||
}
|
||||
|
||||
def giveEnergy(provided: Double): Double = {
|
||||
val voltage: Double = item.getVoltage(stack)
|
||||
val packToProvide: ElectricityPack = museEnergyToElectricityPack(provided, voltage)
|
||||
val eatenPack: ElectricityPack = item.onReceive(packToProvide, stack)
|
||||
museEnergyFromElectricityPack(eatenPack)
|
||||
val joulesToProvide: Double = museEnergyToJoules(provided)
|
||||
val eatenJoules: Float = item.recharge(stack, joulesToProvide.toFloat, true)
|
||||
museEnergyFromJoules(eatenJoules)
|
||||
}
|
||||
}
|
|
@ -25,11 +25,11 @@ object ElectricConversions {
|
|||
def museEnergyFromMJ(mj: Double): Double = mj * ModCompatability.getBCRatio
|
||||
|
||||
// UE
|
||||
def museEnergyToElectricityPack(museEnergy: Double, voltage: Double): ElectricityPack = new ElectricityPack(museEnergyToJoules(museEnergy) * 20.0 / voltage, voltage)
|
||||
def museEnergyToElectricityPack(museEnergy: Double, voltage: Float): ElectricityPack = new ElectricityPack(museEnergyToJoules(museEnergy) * 20.F / voltage, voltage)
|
||||
|
||||
def museEnergyFromElectricityPack(pack: ElectricityPack): Double = museEnergyFromJoules(pack.amperes / 20.0 * pack.voltage)
|
||||
def museEnergyFromElectricityPack(pack: ElectricityPack): Double = museEnergyFromJoules(pack.amperes / 20.F * pack.voltage)
|
||||
|
||||
def museEnergyToJoules(energy: Double): Double = energy / ModCompatability.getUERatio
|
||||
def museEnergyToJoules(energy: Double): Float = (energy / ModCompatability.getUERatio).toFloat
|
||||
|
||||
def museEnergyFromJoules(energy: Double): Double = energy * ModCompatability.getUERatio
|
||||
def museEnergyFromJoules(energy: Float): Double = energy * ModCompatability.getUERatio
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import universalelectricity.core.item.IItemElectric
|
|||
import universalelectricity.core.electricity.ElectricityPack
|
||||
import thermalexpansion.api.item.IChargeableItem
|
||||
import net.machinemuse.api.electricity.ElectricConversions._
|
||||
import icbm.api.explosion.{IExplosive, IEMPItem}
|
||||
import icbm.api.explosion.{IExplosion, IEMPItem}
|
||||
import net.minecraft.entity.Entity
|
||||
import net.machinemuse.api.ModuleManager
|
||||
|
||||
|
@ -134,41 +134,49 @@ trait MuseElectricItem
|
|||
def canShowChargeToolTip(itemStack: ItemStack): Boolean = false
|
||||
|
||||
// ICBM
|
||||
def onEMP(itemStack: ItemStack, entity: Entity, empExplosive: IExplosive) {
|
||||
def onEMP(itemStack: ItemStack, entity: Entity, empExplosive: IExplosion) {
|
||||
setCurrentEnergy(itemStack, 0)
|
||||
}
|
||||
|
||||
// UE
|
||||
def getJoules(itemStack: ItemStack): Double = museEnergyToJoules(getCurrentEnergy(itemStack))
|
||||
def getElectricityStored(itemStack: ItemStack): Float = museEnergyToJoules(getCurrentEnergy(itemStack))
|
||||
|
||||
def setJoules(joules: Double, itemStack: ItemStack) {
|
||||
def setElectricity(itemStack: ItemStack, joules: Float) {
|
||||
setCurrentEnergy(itemStack, museEnergyFromJoules(joules))
|
||||
}
|
||||
|
||||
def getMaxJoules(itemStack: ItemStack): Double = museEnergyToJoules(getMaxEnergy(itemStack))
|
||||
def getMaxElectricityStored(itemStack: ItemStack): Float = museEnergyToJoules(getMaxEnergy(itemStack))
|
||||
|
||||
def getVoltage(itemStack: ItemStack): Double = 120
|
||||
def getVoltage(itemStack: ItemStack): Float = 120
|
||||
|
||||
def onReceive(electricityPack: ElectricityPack, itemStack: ItemStack): ElectricityPack = {
|
||||
val energyReceiving: Double = museEnergyFromElectricityPack(electricityPack)
|
||||
def recharge(itemStack: ItemStack, energy: Float, doCharge: Boolean): Float = {
|
||||
var joulesConsumed : Float = 0
|
||||
val energyReceiving: Double = museEnergyFromJoules(energy)
|
||||
if (doCharge) {
|
||||
val energyConsumed: Double = giveEnergyTo(itemStack, energyReceiving)
|
||||
val packConsumed: ElectricityPack = museEnergyToElectricityPack(energyConsumed, getVoltage(itemStack))
|
||||
packConsumed
|
||||
joulesConsumed = museEnergyToJoules(energyConsumed)
|
||||
} else {
|
||||
val energyChargeable: Double = getMaxEnergy(itemStack) - getCurrentEnergy(itemStack)
|
||||
joulesConsumed = museEnergyToJoules(math.min(energyReceiving, energyChargeable))
|
||||
}
|
||||
joulesConsumed
|
||||
}
|
||||
|
||||
def onProvide(electricityPack: ElectricityPack, itemStack: ItemStack): ElectricityPack = {
|
||||
val energyRequested: Double = museEnergyFromElectricityPack(electricityPack)
|
||||
def discharge(itemStack: ItemStack, energy: Float, doCharge: Boolean): Float = {
|
||||
val energyRequested: Double = museEnergyFromJoules(energy)
|
||||
var joulesGiven: Float = 0
|
||||
if (doCharge) {
|
||||
val energyGiven: Double = drainEnergyFrom(itemStack, energyRequested)
|
||||
val packGiven: ElectricityPack = museEnergyToElectricityPack(energyGiven, getVoltage(itemStack))
|
||||
packGiven
|
||||
joulesGiven = museEnergyToJoules(energyGiven)
|
||||
} else {
|
||||
val energyAvailable: Double = getCurrentEnergy(itemStack)
|
||||
joulesGiven = museEnergyToJoules(math.min(energyAvailable, energyRequested))
|
||||
}
|
||||
joulesGiven
|
||||
}
|
||||
|
||||
def getReceiveRequest(itemStack: ItemStack): ElectricityPack = {
|
||||
museEnergyToElectricityPack(getMaxEnergy(itemStack) - getCurrentEnergy(itemStack), getVoltage(itemStack))
|
||||
}
|
||||
|
||||
def getProvideRequest(itemStack: ItemStack): ElectricityPack = {
|
||||
museEnergyToElectricityPack(getMaxEnergy(itemStack) - getCurrentEnergy(itemStack), getVoltage(itemStack))
|
||||
def getTransfer(itemStack: ItemStack): Float = {
|
||||
museEnergyToJoules(getMaxEnergy(itemStack) - getCurrentEnergy(itemStack))
|
||||
}
|
||||
|
||||
// TE
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package net.machinemuse.powersuits.item
|
||||
|
||||
import micdoodle8.mods.galacticraft.API.EnumGearType
|
||||
import micdoodle8.mods.galacticraft.API.IBreathableArmor
|
||||
import micdoodle8.mods.galacticraft.api.item.IBreathableArmor.EnumGearType
|
||||
import micdoodle8.mods.galacticraft.api.item.IBreathableArmor
|
||||
import net.machinemuse.powersuits.powermodule.misc.AirtightSealModule
|
||||
import net.minecraft.client.renderer.texture.IconRegister
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
|
|
|
@ -169,7 +169,7 @@ with OmniWrench {
|
|||
* Called when the right click button is released
|
||||
*/
|
||||
override def onPlayerStoppedUsing(itemStack: ItemStack, world: World, player: EntityPlayer, par4: Int) {
|
||||
val mode: String = MuseItemUtils.getActiveMode(itemStack)
|
||||
val mode: String = MuseItemTag.getActiveMode(itemStack)
|
||||
val module: IPowerModule = ModuleManager.getModule(mode)
|
||||
if (module.isInstanceOf[IRightClickModule]) {
|
||||
(module.asInstanceOf[IRightClickModule]).onPlayerStoppedUsing(itemStack, world, player, par4)
|
||||
|
@ -181,7 +181,7 @@ with OmniWrench {
|
|||
}
|
||||
|
||||
override def onItemUseFirst(itemStack: ItemStack, player: EntityPlayer, world: World, x: Int, y: Int, z: Int, side: Int, hitX: Float, hitY: Float, hitZ: Float): Boolean = {
|
||||
val mode: String = MuseItemUtils.getActiveMode(itemStack)
|
||||
val mode: String = MuseItemTag.getActiveMode(itemStack)
|
||||
val module: IPowerModule = ModuleManager.getModule(mode)
|
||||
if (module.isInstanceOf[IRightClickModule]) {
|
||||
return (module.asInstanceOf[IRightClickModule]).onItemUseFirst(itemStack, player, world, x, y, z, side, hitX, hitY, hitZ)
|
||||
|
@ -190,7 +190,7 @@ with OmniWrench {
|
|||
}
|
||||
|
||||
override def onItemUse(itemStack: ItemStack, player: EntityPlayer, world: World, x: Int, y: Int, z: Int, side: Int, hitX: Float, hitY: Float, hitZ: Float): Boolean = {
|
||||
val mode: String = MuseItemUtils.getActiveMode(itemStack)
|
||||
val mode: String = MuseItemTag.getActiveMode(itemStack)
|
||||
val module: IPowerModule = ModuleManager.getModule(mode)
|
||||
if (module.isInstanceOf[IRightClickModule]) {
|
||||
(module.asInstanceOf[IRightClickModule]).onItemUse(itemStack, player, world, x, y, z, side, hitX, hitY, hitZ)
|
||||
|
|
|
@ -11,6 +11,7 @@ import net.machinemuse.utils.MuseMathUtils._
|
|||
import net.machinemuse.api.electricity.MuseElectricItem
|
||||
import net.machinemuse.api.{ModuleManager, IModularItem}
|
||||
import net.machinemuse.api.ModuleManager.itemHasActiveModule
|
||||
import net.machinemuse.utils.ElectricItemUtils
|
||||
|
||||
/**
|
||||
* Author: MachineMuse (Claire Semple)
|
||||
|
@ -73,4 +74,10 @@ trait ModularItemBase extends Item with IModularItem with MuseElectricItem {
|
|||
}
|
||||
|
||||
def getArmorDouble(player: EntityPlayer, stack: ItemStack): Double = 0
|
||||
|
||||
def getPlayerEnergy(player: EntityPlayer): Double = ElectricItemUtils.getPlayerEnergy(player)
|
||||
|
||||
def drainPlayerEnergy(player: EntityPlayer, drainEnergy: Double) = ElectricItemUtils.drainPlayerEnergy(player, drainEnergy)
|
||||
|
||||
def givePlayerEnergy(player: EntityPlayer, joulesToGive: Double) = ElectricItemUtils.givePlayerEnergy(player, joulesToGive)
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ public class MultimeterModule extends PowerModuleBase implements IRightClickModu
|
|||
@Override
|
||||
public boolean onItemUseFirst(ItemStack itemStack, EntityPlayer player, World worldObj, int x, int y, int z, int side, float hitX, float hitY,
|
||||
float hitZ) {
|
||||
if (ModCompatability.isBasicComponentsLoaded()) {
|
||||
/* if (ModCompatability.isBasicComponentsLoaded()) {
|
||||
if (!worldObj.isRemote) {
|
||||
TileEntity tileEntity = worldObj.getBlockTileEntity(x, y, z);
|
||||
if (tileEntity instanceof IConductor) {
|
||||
|
@ -71,7 +71,7 @@ public class MultimeterModule extends PowerModuleBase implements IRightClickModu
|
|||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -87,4 +87,9 @@ public class MultimeterModule extends PowerModuleBase implements IRightClickModu
|
|||
public void onPlayerStoppedUsing(ItemStack itemStack, World world, EntityPlayer player, int par4) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowed() {
|
||||
//This module can't work with the current state of UE
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
|||
import net.machinemuse.api.IModularItem;
|
||||
import net.machinemuse.api.IPowerModule;
|
||||
import net.machinemuse.api.ModuleManager;
|
||||
import net.machinemuse.api.MuseItemTag;
|
||||
import net.machinemuse.api.moduletrigger.IRightClickModule;
|
||||
import net.machinemuse.general.MuseLogger;
|
||||
import net.machinemuse.powersuits.client.render.modelspec.DefaultModelSpec;
|
||||
|
@ -423,10 +424,6 @@ public class MuseItemUtils {
|
|||
|
||||
}
|
||||
|
||||
public static String getActiveMode(ItemStack itemStack) {
|
||||
return getMuseItemTag(itemStack).getString("Mode");
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for making recipes. Returns a copy of the itemstack with
|
||||
* the specified stacksize.
|
||||
|
|
Loading…
Reference in a new issue