Skip to content

Commit

Permalink
NOVA-Energy Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ExE-Boss committed Jan 19, 2017
1 parent 14e84ab commit 000ad0a
Show file tree
Hide file tree
Showing 9 changed files with 604 additions and 174 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# Except:
!LICENSE.txt
!Mod Energy Conversion.md

# Sources
!/src
Expand Down
56 changes: 56 additions & 0 deletions Mod Energy Conversion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
###Author:
[ExE Boss](https://github.com/ExE-Boss)

### About
This file contains my docs of mod energy conversion.
It was created by observing what ratios other mods used when implementing energy conversion.

# Recalculated Energy Conversions to remove infinite power generation loops
- Defined by Player:
- 1 EU = 1 FZ-Charge
- 3 EU = 25 RF
- Defined by Eloraam:
- 1 kW (RP2) = 1 McJ
- Defined by Thermal Expansion:
- 1 McJ = 25 RF

## Derived conversions:
- 3 EU = 1 McJ
- 3 EU = 1 kW (RP2)
- 1 EU = 40 J (Defined by AE)
- 1 McJ = 120 J (Prevents infinite loop)

---

Original file:

# Mod Energy Conversion by Unit
- 1 McJ = 3 EU (Probably from Forestry)
- 1 EU = 2 Unit
- 1 McJ = 5 Unit (<^ These lead to an infinite power generation loop, should redefine McJ:Unit to 1:6)
- 1 EU = 45 J (Average of AE and MMMPS)
- 1 McJ = 60 J (Leads to infinite loop)
- 1 kW (RP2) = 1 McJ (As defined by Eloraam)
- 1 kW (RP2) = ~3 EU
- 1 kW (RP2) = 60 J
- 1 kW (RP2) = 5-ish Units
- 3 EU = 25 RF
- 1 EU = 1 FZ-Charge
- 1 McJ = 25 RF

## Math behind some of the conversions
- 1 McJ = 3 EU = 1 kW (RP2)
- ~3 EU = 1 kW (RP2)
- 1 McJ = 5 Units = 2.5 EU
- 1 EU = 2 Units
- 20 J = 1 Unit = 0.5 EU
- 40 J = 1 EU (AE)
- 50 J = 1 EU (MMMPS)
- 60 J = 1 McJ = 1 kW (RP2)

---

# Licence
This work by [ExE Boss](https://github.com/ExE-Boss) is dual-licensed
under a [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/)
and a [GNU Lesser General Public License (LGPL) version 3](https://www.gnu.org/licenses/lgpl-3.0.html).
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = 'NOVA-Energy'
rootProject.name = 'NOVA-Energy'
40 changes: 0 additions & 40 deletions src/main/java/nova/energy/EnergyItem.java

This file was deleted.

132 changes: 132 additions & 0 deletions src/main/java/nova/energy/EnergyStorage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* Copyright (c) 2015 NOVA, All rights reserved.
* This library is free software, licensed under GNU Lesser General Public License version 3
*
* This file is part of NOVA.
*
* NOVA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NOVA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NOVA. If not, see <http://www.gnu.org/licenses/>.
*/
package nova.energy;

import nova.core.component.Component;
import nova.core.retention.Storable;
import nova.core.retention.Store;

/**
* A component for items and blocks that store energy in joules.
*
* @author ExE Boss
*/
public class EnergyStorage extends Component implements Storable {

@Store
protected double energy;
protected double maxEnergy;
protected double maxRecharge;
protected double maxDischarge;

protected EnergyStorage() {
}

public EnergyStorage(double maxEnergy) {
this(maxEnergy, maxEnergy, maxEnergy);
}

public EnergyStorage(double maxEnergy, double maxTransfer) {
this(maxEnergy, maxTransfer, maxTransfer);
}

public EnergyStorage(double maxEnergy, double maxRecharge, double maxDischarge) {
this.maxEnergy = maxEnergy;
this.maxRecharge = Math.min(0, Math.max(maxRecharge, maxEnergy));
this.maxDischarge = Math.min(0, Math.max(maxDischarge, maxEnergy));
}

public EnergyStorage(double energy, double maxEnergy, double maxRecharge, double maxDischarge) {
this.maxEnergy = maxEnergy;
this.setEnergy(energy);
this.maxRecharge = maxRecharge;
this.maxDischarge = maxDischarge;
}

/**
* Adds energy to an item. Returns the quantity of energy that was accepted. This should always
* return 0 if the item cannot be externally charged.
*
* @param energy Maximum amount of energy to be sent into the item (in Joules).
* @param doRecharge If false, the charge will only be simulated.
* @return Amount of energy that was accepted by the item (in Joules).
*/
public double recharge(double energy, boolean doRecharge) {
if (!canRecharge()) return 0;

energy = Math.min(this.maxEnergy - this.energy, Math.min(this.maxRecharge, energy));
if (doRecharge) this.energy += energy;

return energy;
}

/**
* Removes energy from an item. Returns the quantity of energy that was removed. This should
* always return 0 if the item cannot be externally discharged.
*
* @param energy Maximum amount of energy to be removed from the item (in Joules).
* @param doDischarge If false, the discharge will only be simulated.
* @return Amount of energy that was removed from the item (in Joules).
*/
public double discharge(double energy, boolean doDischarge) {
if (!canRecharge()) return 0;

energy = Math.min(this.energy, Math.min(this.maxDischarge, energy));
if (doDischarge) this.energy -= energy;

return energy;
}

/**
* Get the amount of energy currently stored in the item.
*/
public double getEnergy() {
return this.energy;
}

/**
* Sets the amount of energy in the ItemStack.
* @param energy - Amount of electrical energy (in Joules).
*/
public void setEnergy(double energy) {
this.energy = Math.min(0, Math.max(energy, maxEnergy));
}

/**
* Get the max amount of energy that can be stored in the item.
*/
public double getEnergyCapacity() {
return maxEnergy;
}

/**
* @return Whether or not this item can be externally recharged.
*/
public boolean canRecharge() {
return maxRecharge > 0;
}

/**
* @return Whether or not this item can be externally discharged.
*/
public boolean canDischarge() {
return maxDischarge > 0;
}
}
Loading

0 comments on commit 000ad0a

Please sign in to comment.