Population of Equivalency Groups from the OreDicitonary
This commit is contained in:
parent
8db11a7c8c
commit
6749a3a68e
|
@ -167,6 +167,6 @@ public class EquivalentExchange3 {
|
|||
// Initialize the Addon Handler
|
||||
AddonHandler.init();
|
||||
|
||||
DynEMC.getInstance();
|
||||
DynEMC.getInstance().toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,35 +1,48 @@
|
|||
package com.pahimar.ee3.emc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import com.pahimar.ee3.core.util.ItemUtil;
|
||||
import com.pahimar.ee3.item.CustomStackWrapper;
|
||||
|
||||
public class DynEMC {
|
||||
|
||||
private static DynEMC dynEMC = null;
|
||||
|
||||
private ArrayList<CustomStackWrapper> discoveredItems = new ArrayList<CustomStackWrapper>();
|
||||
private ArrayList<CustomStackWrapper> discoveredItems;
|
||||
private HashMap<EquivalencyGroup, EmcValue> emcMap;
|
||||
|
||||
private DynEMC() {
|
||||
|
||||
|
||||
discoveredItems = new ArrayList<CustomStackWrapper>();
|
||||
emcMap = new HashMap<EquivalencyGroup, EmcValue>();
|
||||
|
||||
init();
|
||||
|
||||
for (String oreName : OreDictionary.getOreNames()) {
|
||||
emcMap.put(new EquivalencyGroup(OreDictionary.getOres(oreName)), new EmcValue());
|
||||
}
|
||||
}
|
||||
|
||||
public static DynEMC getInstance() {
|
||||
|
||||
if (dynEMC == null) {
|
||||
dynEMC = new DynEMC();
|
||||
dynEMC.init();
|
||||
}
|
||||
|
||||
|
||||
return dynEMC;
|
||||
}
|
||||
|
||||
|
||||
public List<CustomStackWrapper> getDiscoveredItems() {
|
||||
|
||||
|
||||
return discoveredItems;
|
||||
}
|
||||
|
||||
|
@ -38,7 +51,8 @@ public class DynEMC {
|
|||
ArrayList<ItemStack> subItems = new ArrayList<ItemStack>();
|
||||
|
||||
/*
|
||||
* For every possible item (and sub item), add them to the discovered items list
|
||||
* For every possible item (and sub item), add them to the discovered
|
||||
* items list
|
||||
*/
|
||||
for (int i = 0; i < Item.itemsList.length; i++) {
|
||||
if (Item.itemsList[i] != null) {
|
||||
|
@ -60,7 +74,7 @@ public class DynEMC {
|
|||
else {
|
||||
|
||||
ItemStack itemStack = new ItemStack(Item.itemsList[i]);
|
||||
|
||||
|
||||
CustomStackWrapper customStackWrapper = new CustomStackWrapper(itemStack);
|
||||
if (!discoveredItems.contains(customStackWrapper)) {
|
||||
discoveredItems.add(customStackWrapper);
|
||||
|
@ -70,7 +84,8 @@ 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()) {
|
||||
|
||||
|
@ -79,4 +94,19 @@ public class DynEMC {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
Set<EquivalencyGroup> keySet = emcMap.keySet();
|
||||
Iterator<EquivalencyGroup> iter = keySet.iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
System.out.println(iter.next());
|
||||
}
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,10 +38,6 @@ public class EmcBlackList {
|
|||
|
||||
public void add(ItemStack itemStack) {
|
||||
|
||||
if (itemStack != null) {
|
||||
itemStack.stackSize = 1;
|
||||
}
|
||||
|
||||
CustomStackWrapper customStackWrapper = new CustomStackWrapper(itemStack);
|
||||
|
||||
if (!stackBlackList.contains(customStackWrapper)) {
|
||||
|
@ -101,10 +97,6 @@ public class EmcBlackList {
|
|||
|
||||
public void remove(ItemStack itemStack) {
|
||||
|
||||
if (itemStack != null) {
|
||||
itemStack.stackSize = 1;
|
||||
}
|
||||
|
||||
CustomStackWrapper customStackWrapper = new CustomStackWrapper(itemStack);
|
||||
|
||||
while (stackBlackList.contains(customStackWrapper)) {
|
||||
|
|
|
@ -20,6 +20,13 @@ public class EmcValue {
|
|||
|
||||
private float value, recoveryPercentage;
|
||||
private List<EmcComponent> emcComponents;
|
||||
|
||||
public EmcValue() {
|
||||
|
||||
value = 0F;;
|
||||
recoveryPercentage = 1F;
|
||||
emcComponents = new ArrayList<EmcComponent>();
|
||||
}
|
||||
|
||||
public EmcValue(float value) {
|
||||
|
||||
|
|
|
@ -1,43 +1,113 @@
|
|||
package com.pahimar.ee3.emc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.pahimar.ee3.item.CustomStackWrapper;
|
||||
|
||||
|
||||
public class EquivalencyGroup {
|
||||
|
||||
private EmcValue emcValue;
|
||||
|
||||
private List<CustomStackWrapper> equivalentItems;
|
||||
|
||||
|
||||
public EquivalencyGroup() {
|
||||
|
||||
|
||||
equivalentItems = new ArrayList<CustomStackWrapper>();
|
||||
}
|
||||
|
||||
@Override
|
||||
// TODO: Finish
|
||||
public boolean equals(Object object) {
|
||||
public EquivalencyGroup(List<ItemStack> equivalentItems) {
|
||||
|
||||
this.equivalentItems = new ArrayList<CustomStackWrapper>();
|
||||
|
||||
for (ItemStack itemStack : equivalentItems) {
|
||||
this.equivalentItems.add(new CustomStackWrapper(itemStack));
|
||||
}
|
||||
}
|
||||
|
||||
public List<CustomStackWrapper> getMembers() {
|
||||
|
||||
return equivalentItems;
|
||||
}
|
||||
|
||||
public boolean containsMember(ItemStack itemStack) {
|
||||
|
||||
return containsMember(new CustomStackWrapper(itemStack));
|
||||
}
|
||||
|
||||
public boolean containsMember(CustomStackWrapper customStackWrapper) {
|
||||
|
||||
return equivalentItems.contains(customStackWrapper);
|
||||
}
|
||||
|
||||
public void addMember(ItemStack itemStack) {
|
||||
|
||||
this.addMember(new CustomStackWrapper(itemStack));
|
||||
}
|
||||
|
||||
public void addMember(CustomStackWrapper customStackWrapper) {
|
||||
|
||||
if (!containsMember(customStackWrapper)) {
|
||||
equivalentItems.add(customStackWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
public void setEquivalentItems(List<CustomStackWrapper> equivalentItems) {
|
||||
|
||||
this.equivalentItems = equivalentItems;
|
||||
}
|
||||
|
||||
public void removeMember(ItemStack itemStack) {
|
||||
|
||||
removeMember(new CustomStackWrapper(itemStack));
|
||||
}
|
||||
|
||||
public void removeMember(CustomStackWrapper customStackWrapper) {
|
||||
|
||||
while (containsMember(customStackWrapper)) {
|
||||
equivalentItems.remove(customStackWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearMembers() {
|
||||
|
||||
equivalentItems = new ArrayList<CustomStackWrapper>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
|
||||
if (!(object instanceof EquivalencyGroup)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
EquivalencyGroup equivalencyGroup = (EquivalencyGroup) object;
|
||||
|
||||
return (equivalentItems.equals(equivalencyGroup.equivalentItems));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
// TODO: Finish
|
||||
public String toString() {
|
||||
|
||||
return "";
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
stringBuilder.append("Equivalent Group Members: ");
|
||||
for (CustomStackWrapper customStackWrapper : equivalentItems) {
|
||||
stringBuilder.append(String.format("%s ", customStackWrapper));
|
||||
}
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
// TODO: Finish
|
||||
public int hashCode() {
|
||||
|
||||
|
||||
int hashCode = 1;
|
||||
|
||||
|
||||
for (CustomStackWrapper customStackWrapper : equivalentItems) {
|
||||
hashCode = 37 * hashCode + customStackWrapper.hashCode();
|
||||
}
|
||||
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,12 @@ public class CustomStackWrapper {
|
|||
public ItemStack itemStack;
|
||||
|
||||
public CustomStackWrapper(ItemStack itemStack) {
|
||||
|
||||
|
||||
this.itemStack = itemStack;
|
||||
|
||||
if (this.itemStack != null) {
|
||||
this.itemStack.stackSize = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue