Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NOVA-Energy Implementation #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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).
19 changes: 14 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
plugins {
id "java"
id "nova.gradle" version "0.2.5"
id "nova.gradle" version "0.2.6"
id "maven-publish"
id "com.jfrog.artifactory" version "3.1.1"
}


apply from: "https://raw.githubusercontent.com/NOVA-Team/NOVA-Gradle/master/shared-scripts/java.gradle"

dependencies {
compile "nova.core:NovaCore:$novaVersion"
testCompile "nova.core:NovaCore:$novaVersion:wrappertests"
compile nova(nova_version)
}

nova {
wrappers {
"17" {
wrapper "nova.core:NOVA-Core-Wrapper-MC1.7:$nova_version"
}
"18" {
wrapper "nova.core:NOVA-Core-Wrapper-MC1.8:$nova_version"
}
}
}

publishing {
Expand All @@ -35,4 +44,4 @@ artifactory {
publishPom = true
}
}
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version = 0.0.1-SNAPSHOT
group = nova.energy
novaVersion = 0.1.0-SNAPSHOT
nova_version = 0.1.0-SNAPSHOT

packaging = jar
info.inceptionYear = 2016
Expand Down
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'
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