Restructuring how EMC stuffs are stored

This commit is contained in:
pahimar 2013-05-26 23:02:24 -04:00
parent 4acc41c2c8
commit 8db11a7c8c
7 changed files with 249 additions and 128 deletions

View file

@ -1,20 +1,11 @@
package com.pahimar.ee3.emc; package com.pahimar.ee3.emc;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.logging.Level;
import net.minecraft.block.Block;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraftforge.oredict.OreDictionary;
import com.pahimar.ee3.core.util.ItemUtil;
import com.pahimar.ee3.core.util.LogHelper;
import com.pahimar.ee3.core.util.RecipeHelper;
import com.pahimar.ee3.item.CustomStackWrapper; import com.pahimar.ee3.item.CustomStackWrapper;
public class DynEMC { public class DynEMC {
@ -81,7 +72,7 @@ public class DynEMC {
/** /**
* Now that we have discovered as many items as possible, trim out the items that are black listed * Now that we have discovered as many items as possible, trim out the items that are black listed
*/ */
for (CustomStackWrapper customStackWrapper : EMCBlackList.getInstance().getBlackListStacks()) { for (CustomStackWrapper customStackWrapper : EmcBlackList.getInstance().getBlackListStacks()) {
while (discoveredItems.contains(customStackWrapper)) { while (discoveredItems.contains(customStackWrapper)) {
discoveredItems.remove(customStackWrapper); discoveredItems.remove(customStackWrapper);

View file

@ -10,21 +10,21 @@ import net.minecraftforge.oredict.OreDictionary;
import com.pahimar.ee3.item.CustomStackWrapper; import com.pahimar.ee3.item.CustomStackWrapper;
public class EMCBlackList { public class EmcBlackList {
private static EMCBlackList emcBlackList = null; private static EmcBlackList emcBlackList = null;
private ArrayList<CustomStackWrapper> stackBlackList = new ArrayList<CustomStackWrapper>(); private ArrayList<CustomStackWrapper> stackBlackList = new ArrayList<CustomStackWrapper>();
private EMCBlackList() { private EmcBlackList() {
} }
public static EMCBlackList getInstance() { public static EmcBlackList getInstance() {
if (emcBlackList == null) { if (emcBlackList == null) {
emcBlackList = new EMCBlackList(); emcBlackList = new EmcBlackList();
emcBlackList.init(); emcBlackList.init();
} }

View file

@ -1,113 +0,0 @@
package com.pahimar.ee3.emc;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* Equivalent-Exchange-3
*
* EMCEntry
*
* @author pahimar
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
*
*/
public class EMCEntry {
public enum EMCType {
CORPOREAL, KINETIC, TEMPORAL, ESSENTIA, AMORPHOUS, VOID, OMNI;
}
private float cost, recoveryPercentage;
private boolean learnable, recoverable;
private Map<EMCType, Float> breakdown;
public EMCEntry(float cost) {
this.cost = cost;
recoveryPercentage = 1F;
learnable = true;
recoverable = true;
breakdown = Collections.synchronizedMap(new HashMap<EMCType, Float>());
}
public EMCEntry(float cost, float recoveryPercentage, boolean learnable, boolean recoverable) {
this.cost = cost;
this.recoveryPercentage = recoveryPercentage;
this.learnable = learnable;
this.recoverable = recoverable;
breakdown = Collections.synchronizedMap(new HashMap<EMCType, Float>());
}
public float getCost() {
return cost;
}
public float getRecoveryPercentage() {
return recoveryPercentage;
}
public boolean isLearnable() {
return learnable;
}
public boolean isRecoverable() {
return recoverable;
}
public Map<EMCType, Float> getEMCBreakDown() {
return breakdown;
}
public float getEMCBreakdownByType(EMCType emcType) {
if (breakdown.containsKey(emcType)) {
if (breakdown.get(emcType) != null)
return breakdown.get(emcType).floatValue();
}
return -1F;
}
public void setCost(float cost) {
this.cost = cost;
}
public void setRecoveryPercentage(float recoveryPercentage) {
this.recoveryPercentage = recoveryPercentage;
}
public void setLearnable(boolean learnable) {
this.learnable = learnable;
}
public void setRecoverable(boolean recoverable) {
this.recoverable = recoverable;
}
public void addEMCBreakDown(EMCType emcType, Float breakdownPercentage) {
if (!breakdown.containsKey(emcType)) {
breakdown.put(emcType, breakdownPercentage);
}
}
public void setEMCBreakDown(EMCType emcType, Float breakdownPercentage) {
if (breakdown.containsKey(emcType)) {
breakdown.put(emcType, breakdownPercentage);
}
}
}

View file

@ -0,0 +1,47 @@
package com.pahimar.ee3.emc;
public class EmcComponent {
private final EmcType emcType;
private final float percentage;
public EmcComponent(EmcType emcType, float percentage) {
this.emcType = emcType;
this.percentage = percentage;
}
public EmcType getEmcType() {
return emcType;
}
public float getPercentage() {
return percentage;
}
@Override
public boolean equals(Object object) {
if (!(object instanceof EmcComponent)) {
return false;
}
EmcComponent emcBreakDown = (EmcComponent) object;
return ((this.emcType == emcBreakDown.emcType) && (this.percentage == emcBreakDown.percentage));
}
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(String.format("<EMC Type: %s, Percentage: %s>", emcType, (percentage * 100)));
return stringBuilder.toString();
}
}

View file

@ -0,0 +1,6 @@
package com.pahimar.ee3.emc;
public enum EmcType {
CORPOREAL, KINETIC, TEMPORAL, ESSENTIA, AMORPHOUS, VOID, OMNI;
}

View file

@ -0,0 +1,147 @@
package com.pahimar.ee3.emc;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Equivalent-Exchange-3
*
* EMCEntry
*
* @author pahimar
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
*
*/
public class EmcValue {
private float value, recoveryPercentage;
private List<EmcComponent> emcComponents;
public EmcValue(float value) {
this.value = value;
recoveryPercentage = 1F;
emcComponents = new ArrayList<EmcComponent>();
}
public EmcValue(float value, float recoveryPercentage) {
this.value = value;
this.recoveryPercentage = recoveryPercentage;
emcComponents = new ArrayList<EmcComponent>();
}
public EmcValue(float value, float recoveryPercentage, List<EmcComponent> emcComponents) {
this.value = value;
this.recoveryPercentage = recoveryPercentage;
this.emcComponents = emcComponents;
}
public float getValue() {
return value;
}
public float getRecoveryPercentage() {
return recoveryPercentage;
}
public List<EmcComponent> getComponents() {
return emcComponents;
}
public EmcComponent getComponent(EmcType emcType) {
for (EmcComponent emcComponent : emcComponents) {
if (emcComponent.getEmcType().equals(emcType)) {
return emcComponent;
}
}
return null;
}
public boolean containsEmcType(EmcType emcType) {
for (EmcComponent emcComponent : emcComponents) {
if (emcComponent.getEmcType().equals(emcType)) {
return true;
}
}
return false;
}
public void setValue(float cost) {
this.value = cost;
}
public void setRecoveryPercentage(float recoveryPercentage) {
this.recoveryPercentage = recoveryPercentage;
}
public void addEmcComponent(EmcComponent emcComponent) {
if (!containsEmcType(emcComponent.getEmcType())) {
emcComponents.add(emcComponent);
}
}
public void addEmcComponent(EmcType emcType, float percentage) {
addEmcComponent(new EmcComponent(emcType, percentage));
}
@Override
public boolean equals(Object object) {
if (!(object instanceof EmcValue)) {
return false;
}
EmcValue emcValue = (EmcValue) object;
if (value == emcValue.value) {
if (recoveryPercentage == emcValue.recoveryPercentage) {
return emcComponents.equals(emcValue.getComponents());
}
}
return false;
}
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(String.format("EMC Value: %s, Recovery Percentage: %s, ", value, (recoveryPercentage * 100)));
for (EmcComponent emcComponent : emcComponents) {
stringBuilder.append(String.format("%s ", emcComponent));
}
return stringBuilder.toString();
}
@Override
public int hashCode() {
int hashCode = 1;
hashCode = 37 * hashCode + Float.floatToIntBits(value);
hashCode = 37 * hashCode + Float.floatToIntBits(recoveryPercentage);
hashCode = 37 * hashCode + emcComponents.hashCode();
return hashCode;
}
}

View file

@ -0,0 +1,43 @@
package com.pahimar.ee3.emc;
import java.util.List;
import com.pahimar.ee3.item.CustomStackWrapper;
public class EquivalencyGroup {
private EmcValue emcValue;
private List<CustomStackWrapper> equivalentItems;
public EquivalencyGroup() {
}
@Override
// TODO: Finish
public boolean equals(Object object) {
if (!(object instanceof EquivalencyGroup)) {
return false;
}
return false;
}
@Override
// TODO: Finish
public String toString() {
return "";
}
@Override
// TODO: Finish
public int hashCode() {
int hashCode = 1;
return hashCode;
}
}