diff options
9 files changed, 188 insertions, 381 deletions
diff --git a/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalDefinition.java b/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalDefinition.java index cac239c894..8cf92f20fd 100644 --- a/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalDefinition.java +++ b/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalDefinition.java @@ -8,9 +8,8 @@ import net.minecraft.nbt.NBTTagCompound; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; -import java.util.TreeMap; -import static com.github.technus.tectech.elementalMatter.definitions.cPrimitiveDefinition.debug__; +import static com.github.technus.tectech.elementalMatter.definitions.cPrimitiveDefinition.nbtE__; /** * Created by danie_000 on 23.01.2017. @@ -35,7 +34,7 @@ public abstract class cElementalDefinition implements iElementalDefinition { return (iElementalDefinition) nbtCreationBind.get(nbt.getByte("t")).invoke(null, nbt); } catch (Exception e) { if (TecTechConfig.DEBUG_MODE) e.printStackTrace(); - return debug__; + return nbtE__; } } diff --git a/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalDefinitionStack.java b/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalDefinitionStack.java index 1bff45172a..daaa0ebc2c 100644 --- a/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalDefinitionStack.java +++ b/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalDefinitionStack.java @@ -9,7 +9,7 @@ import static com.github.technus.tectech.elementalMatter.definitions.cPrimitiveD /** * Created by danie_000 on 20.11.2016. */ -public final class cElementalDefinitionStack implements iHasElementalDefinition { +public final class cElementalDefinitionStack implements iHasElementalDefinition {//TODO unify checks for amount? public final iElementalDefinition definition; public final int amount; @@ -79,6 +79,6 @@ public final class cElementalDefinitionStack implements iHasElementalDefinition @Override public int hashCode() { - return amount+81*definition.hashCode(); + return definition.hashCode(); } } diff --git a/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalDefinitionStackMap.java b/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalDefinitionStackMap.java index d41554c5ef..d793054b4c 100644 --- a/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalDefinitionStackMap.java +++ b/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalDefinitionStackMap.java @@ -1,254 +1,54 @@ package com.github.technus.tectech.elementalMatter.classes; import com.github.technus.tectech.elementalMatter.interfaces.iElementalDefinition; -import com.github.technus.tectech.elementalMatter.interfaces.iHasElementalDefinition; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumChatFormatting; import java.util.Map; +import java.util.TreeMap; -import static com.github.technus.tectech.elementalMatter.definitions.cPrimitiveDefinition.debug__; +import static com.github.technus.tectech.elementalMatter.definitions.cPrimitiveDefinition.nbtE__; /** * Created by Tec on 12.05.2017. */ -public class cElementalDefinitionStackMap/*IMMUTABLE*/ extends cElementalMutableDefinitionStackMap {//TODO MAKE IMMUTABLE - public cElementalDefinitionStackMap(cElementalMutableDefinitionStackMap mutable) { - map=mutable.Clone().map; - } +public final class cElementalDefinitionStackMap/*IMMUTABLE*/ extends cElementalStackMap { + //Constructors + Clone, all make a whole new OBJ. - //IMMUTABLES DONT NEED IT - @Override - protected Object clone() { - return this; + @Deprecated + public cElementalDefinitionStackMap(iElementalDefinition... in) { + map=new TreeMap<>(); + for (iElementalDefinition definition : in) + map.put(definition, new cElementalDefinitionStack(definition, 1)); } - @Override - @Deprecated - public final cElementalMutableDefinitionStackMap Clone() { - return null; + public cElementalDefinitionStackMap(cElementalDefinitionStack... in) { + map=new TreeMap<>(); + for (cElementalDefinitionStack stack : in) + map.put(stack.definition, stack); } - @Override - public final cElementalMutableDefinitionStackMap mutable() { - return new cElementalMutableDefinitionStackMap(map); + public cElementalDefinitionStackMap(Map<iElementalDefinition, cElementalDefinitionStack> in) { + map = new TreeMap<>(); + for (cElementalDefinitionStack stack : in.values()) + map.put(stack.definition, stack); } + //IMMUTABLE DON'T NEED IT @Override - public cElementalDefinitionStackMap immutable() { + public cElementalDefinitionStackMap Clone() { return this; } - @Deprecated - public Map<iElementalDefinition,cElementalDefinitionStack> getRawMap() { - return mutable().getRawMap(); + public cElementalMutableDefinitionStackMap toMutable() { + return new cElementalMutableDefinitionStackMap(map); } @Override - public int compareTo(cElementalMutableDefinitionStackMap o) { - if (map.size() != o.map.size()) return map.size() - o.map.size(); - cElementalDefinitionStack[] ofThis = values(), ofThat = o.values(); - for (int i = 0; i < ofThat.length; i++) { - int result = ofThis[i].compareTo(ofThat[i]); - if (result != 0) return result; - } - return 0; - } - - //Removers - public void clear() { - map.clear(); - } - - public cElementalDefinitionStack remove(iElementalDefinition def) { - return map.remove(def); - } - - @Deprecated - public cElementalDefinitionStack remove(iHasElementalDefinition has) { - return map.remove(has.getDefinition()); - } - - public void removeAll(iElementalDefinition... definitions) { - for (iElementalDefinition def : definitions) - map.remove(def); - } - @Deprecated - private void removeAll(iHasElementalDefinition... hasElementals) { - for (iHasElementalDefinition has : hasElementals) - map.remove(has.getDefinition()); - } - - //Remove amounts - public boolean removeAmount(boolean testOnly, cElementalInstanceStack instance) { - final cElementalDefinitionStack target = map.get(instance.definition); - if (target == null) - return false; - if (testOnly) - return target.amount >= instance.amount; - else { - final int diff = target.amount - instance.amount; - if (diff > 0) { - map.put(target.definition, new cElementalDefinitionStack(target.definition, diff)); - return true; - } else if (diff == 0) { - map.remove(instance.definition); - return true; - } - } - return false; - } - - public boolean removeAmount(boolean testOnly, cElementalDefinitionStack stack) { - final cElementalDefinitionStack target = map.get(stack.definition); - if (target == null) - return false; - if (testOnly) - return target.amount >= stack.amount; - else { - final int diff = target.amount - stack.amount; - if (diff > 0) { - map.put(target.definition, new cElementalDefinitionStack(target.definition, diff)); - return true; - } else if (diff == 0) { - map.remove(stack.definition); - return true; - } - } - return false; - } - - @Deprecated - public boolean removeAmount(boolean testOnly, iElementalDefinition def) { - return removeAmount(testOnly, new cElementalDefinitionStack(def, 1)); - } - - public boolean removeAllAmounts(boolean testOnly, cElementalInstanceStack... instances) { - boolean test = true; - for (cElementalInstanceStack stack : instances) - test &= removeAmount(true, stack); - if (testOnly || !test) return test; - for (cElementalInstanceStack stack : instances) - removeAmount(false, stack); - return true; - } - - public boolean removeAllAmounts(boolean testOnly, cElementalDefinitionStack... stacks) { - boolean test = true; - for (cElementalDefinitionStack stack : stacks) - test &= removeAmount(true, stack); - if (testOnly || !test) return test; - for (cElementalDefinitionStack stack : stacks) - removeAmount(false, stack); - return true; - } - - @Deprecated - public boolean removeAllAmounts(boolean testOnly, iElementalDefinition... definitions) { - final cElementalDefinitionStack[] stacks = new cElementalDefinitionStack[definitions.length]; - for (int i = 0; i < stacks.length; i++) - stacks[i] = new cElementalDefinitionStack(definitions[i], 1); - return removeAllAmounts(testOnly, stacks); - } - - public boolean removeAllAmounts(boolean testOnly, cElementalMutableDefinitionStackMap container) { - return removeAllAmounts(testOnly, container.values()); - } - - public boolean removeAllAmounts(boolean testOnly, cElementalInstanceStackMap container) { - return removeAllAmounts(testOnly, container.values()); - } - - //Put replace - public cElementalDefinitionStack putReplace(cElementalDefinitionStack defStackUnsafe) { - return map.put(defStackUnsafe.definition, defStackUnsafe); - } - - public void putReplaceAll(cElementalDefinitionStack... defStacks) { - for (cElementalDefinitionStack defStack : defStacks) - this.map.put(defStack.definition, defStack); - } - - private void putReplaceAll(Map<iElementalDefinition, cElementalDefinitionStack> inTreeUnsafe) { - this.map.putAll(inTreeUnsafe); - } - - public void putReplaceAll(cElementalMutableDefinitionStackMap inContainerUnsafe) { - putReplaceAll(inContainerUnsafe.map); - } - - //Put unify - public cElementalDefinitionStack putUnify(cElementalDefinitionStack def) { - return map.put(def.definition, def.unifyIntoNew(map.get(def.definition))); - } - - @Deprecated - public cElementalDefinitionStack putUnify(iElementalDefinition def) { - return putUnify(new cElementalDefinitionStack(def, 1)); - } - - public void putUnifyAll(cElementalDefinitionStack... defs) { - for (cElementalDefinitionStack def : defs) - putUnify(def); - } - - @Deprecated - public void putUnifyAll(iElementalDefinition... defs) { - for (iElementalDefinition def : defs) - putUnify(def); - } - - private void putUnifyAll(Map<iElementalDefinition, cElementalDefinitionStack> inTreeUnsafe) { - for (cElementalDefinitionStack in : inTreeUnsafe.values()) - putUnify(in); - } - - public void putUnifyAll(cElementalMutableDefinitionStackMap containerUnsafe) { - putUnifyAll(containerUnsafe.map); - } - - //Getters - public cElementalDefinitionStack getDefinitionStack(iElementalDefinition def) { - return map.get(def); - } - - public String[] getElementalInfo() { - final String[] info = new String[map.size() * 3]; - int i = 0; - for (cElementalDefinitionStack defStack : map.values()) { - info[i] = EnumChatFormatting.BLUE + defStack.definition.getName(); - info[i + 1] = EnumChatFormatting.AQUA + defStack.definition.getSymbol(); - info[i + 2] = "Amount " + EnumChatFormatting.GREEN + defStack.amount; - i += 3; - } - return info; - } - - public cElementalDefinitionStack[] values() { - return map.values().toArray(new cElementalDefinitionStack[0]); - } - - public iElementalDefinition[] keys() { - return map.keySet().toArray(new iElementalDefinition[0]); - } - - //Tests - public boolean containsDefinition(iElementalDefinition def) { - return map.containsKey(def); - } - - public boolean containsDefinitionStack(cElementalDefinitionStack inst) { - return map.containsValue(inst); - } - - public int size() { - return map.size(); + public Map<iElementalDefinition,cElementalDefinitionStack> getRawMap() { + return toMutable().getRawMap(); } - public boolean hasStacks() { - return map.size() > 0; - } //NBT public NBTTagCompound getInfoNBT() { @@ -280,25 +80,9 @@ public class cElementalDefinitionStackMap/*IMMUTABLE*/ extends cElementalMutable final cElementalDefinitionStack[] defStacks = new cElementalDefinitionStack[nbt.getInteger("i")]; for (int i = 0; i < defStacks.length; i++) { defStacks[i] = cElementalDefinitionStack.fromNBT(nbt.getCompoundTag(Integer.toString(i))); - if (defStacks[i].definition.equals(debug__)) + if (defStacks[i].definition.equals(nbtE__)) throw new tElementalException("Something went Wrong"); } return new cElementalMutableDefinitionStackMap(defStacks); } - - //stackUp - @Deprecated - public static cElementalMutableDefinitionStackMap stackUpTree(iElementalDefinition... in) { - final cElementalMutableDefinitionStackMap inTree = new cElementalMutableDefinitionStackMap(); - for (iElementalDefinition def : in) { - inTree.putUnify(new cElementalDefinitionStack(def, 1)); - } - return inTree; - } - - public static cElementalMutableDefinitionStackMap stackUpTree(cElementalDefinitionStack... in) { - final cElementalMutableDefinitionStackMap inTree = new cElementalMutableDefinitionStackMap(); - inTree.putUnifyAll(in); - return inTree; - } } diff --git a/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalInstanceStack.java b/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalInstanceStack.java index a2ac4948cf..bb5fcf744c 100644 --- a/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalInstanceStack.java +++ b/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalInstanceStack.java @@ -10,7 +10,7 @@ import static com.github.technus.tectech.elementalMatter.definitions.cPrimitiveD /** * Created by danie_000 on 22.10.2016. */ -public class cElementalInstanceStack implements iHasElementalDefinition { +public class cElementalInstanceStack implements iHasElementalDefinition {//TODO unify checks for amount? public final iElementalDefinition definition; //energy - if positive then particle should try to decay public int energy; @@ -270,4 +270,9 @@ public class cElementalInstanceStack implements iHasElementalDefinition { instance.setColor(nbt.getByte("c")); return instance; } + + @Override + public int hashCode() { + return definition.hashCode(); + } } diff --git a/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalInstanceStackMap.java b/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalInstanceStackMap.java index 196dcefaec..52185929de 100644 --- a/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalInstanceStackMap.java +++ b/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalInstanceStackMap.java @@ -8,7 +8,7 @@ import net.minecraft.util.EnumChatFormatting; import java.util.Map; import java.util.TreeMap; -import static com.github.technus.tectech.elementalMatter.definitions.cPrimitiveDefinition.debug__; +import static com.github.technus.tectech.elementalMatter.definitions.cPrimitiveDefinition.nbtE__; /** * Created by danie_000 on 22.01.2017. @@ -354,7 +354,7 @@ public class cElementalInstanceStackMap implements Comparable<cElementalInstance final cElementalInstanceStack[] instances = new cElementalInstanceStack[nbt.getInteger("i")]; for (int i = 0; i < instances.length; i++) { instances[i] = cElementalInstanceStack.fromNBT(nbt.getCompoundTag(Integer.toString(i))); - if (instances[i].definition.equals(debug__)) + if (instances[i].definition.equals(nbtE__)) throw new tElementalException("Something went Wrong"); } return new cElementalInstanceStackMap(false, instances); diff --git a/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalMutableDefinitionStackMap.java b/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalMutableDefinitionStackMap.java index eb105870d8..242f9bc936 100644 --- a/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalMutableDefinitionStackMap.java +++ b/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalMutableDefinitionStackMap.java @@ -3,21 +3,21 @@ package com.github.technus.tectech.elementalMatter.classes; import com.github.technus.tectech.elementalMatter.interfaces.iElementalDefinition; import com.github.technus.tectech.elementalMatter.interfaces.iHasElementalDefinition; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumChatFormatting; import java.util.Map; import java.util.TreeMap; -import static com.github.technus.tectech.elementalMatter.definitions.cPrimitiveDefinition.debug__; +import static com.github.technus.tectech.elementalMatter.definitions.cPrimitiveDefinition.nbtE__; /** * Created by danie_000 on 22.01.2017. */ -public class cElementalMutableDefinitionStackMap implements Comparable<cElementalMutableDefinitionStackMap> {//TODO MAKE MUTABLE AF - protected Map<iElementalDefinition, cElementalDefinitionStack> map; +public final class cElementalMutableDefinitionStackMap extends cElementalStackMap { //Constructors + Clone, all make a whole new OBJ. - public cElementalMutableDefinitionStackMap() {map=new TreeMap<>();} + public cElementalMutableDefinitionStackMap() { + map=new TreeMap<>(); + } @Deprecated public cElementalMutableDefinitionStackMap(iElementalDefinition... in) { @@ -47,35 +47,20 @@ public class cElementalMutableDefinitionStackMap implements Comparable<cElementa } @Override - protected Object clone() {//Equal to making new obj... - return Clone(); - } - public cElementalMutableDefinitionStackMap Clone(){ return new cElementalMutableDefinitionStackMap(map); } - public cElementalDefinitionStackMap immutable() { - return new cElementalDefinitionStackMap(this); + public cElementalDefinitionStackMap toImmutable() { + return new cElementalDefinitionStackMap(map); } - public cElementalMutableDefinitionStackMap mutable() {return this;} - + @Override @Deprecated public Map<iElementalDefinition,cElementalDefinitionStack> getRawMap() { return map; } - @Override - public int compareTo(cElementalMutableDefinitionStackMap o) { - if (map.size() != o.map.size()) return map.size() - o.map.size(); - cElementalDefinitionStack[] ofThis = values(), ofThat = o.values(); - for (int i = 0; i < ofThat.length; i++) { - int result = ofThis[i].compareTo(ofThat[i]); - if (result != 0) return result; - } - return 0; - } //Removers public void clear() { @@ -97,7 +82,7 @@ public class cElementalMutableDefinitionStackMap implements Comparable<cElementa } @Deprecated - private void removeAll(iHasElementalDefinition... hasElementals) { + public void removeAll(iHasElementalDefinition... hasElementals) { for (iHasElementalDefinition has : hasElementals) map.remove(has.getDefinition()); } @@ -192,12 +177,8 @@ public class cElementalMutableDefinitionStackMap implements Comparable<cElementa this.map.put(defStack.definition, defStack); } - private void putReplaceAll(Map<iElementalDefinition, cElementalDefinitionStack> inTreeUnsafe) { - this.map.putAll(inTreeUnsafe); - } - public void putReplaceAll(cElementalMutableDefinitionStackMap inContainerUnsafe) { - putReplaceAll(inContainerUnsafe.map); + this.map.putAll(inContainerUnsafe.map); } //Put unify @@ -227,100 +208,7 @@ public class cElementalMutableDefinitionStackMap implements Comparable<cElementa } public void putUnifyAll(cElementalMutableDefinitionStackMap containerUnsafe) { - putUnifyAll(containerUnsafe.map); - } - - //Getters - public cElementalDefinitionStack getDefinitionStack(iElementalDefinition def) { - return map.get(def); - } - - public String[] getElementalInfo() { - final String[] info = new String[map.size() * 3]; - int i = 0; - for (cElementalDefinitionStack defStack : map.values()) { - info[i] = EnumChatFormatting.BLUE + defStack.definition.getName(); - info[i + 1] = EnumChatFormatting.AQUA + defStack.definition.getSymbol(); - info[i + 2] = "Amount " + EnumChatFormatting.GREEN + defStack.amount; - i += 3; - } - return info; - } - - public cElementalDefinitionStack[] values() { - return map.values().toArray(new cElementalDefinitionStack[0]); - } - - public iElementalDefinition[] keys() { - return map.keySet().toArray(new iElementalDefinition[0]); - } - - //Tests - public boolean containsDefinition(iElementalDefinition def) { - return map.containsKey(def); - } - - public boolean containsDefinitionStack(cElementalDefinitionStack inst) { - return map.containsValue(inst); - } - - public int size() { - return map.size(); - } - - public boolean hasStacks() { - return map.size() > 0; - } - - //NBT - public NBTTagCompound getInfoNBT() { - final NBTTagCompound nbt = new NBTTagCompound(); - final String[] info = getElementalInfo(); - nbt.setInteger("i", info.length); - for (int i = 0; i < info.length; i++) - nbt.setString(Integer.toString(i), info[i]); - return nbt; - } - - public static String[] infoFromNBT(NBTTagCompound nbt) { - final String[] strings = new String[nbt.getInteger("i")]; - for (int i = 0; i < strings.length; i++) - strings[i] = nbt.getString(Integer.toString(i)); - return strings; - } - - public NBTTagCompound toNBT() { - final NBTTagCompound nbt = new NBTTagCompound(); - nbt.setInteger("i", map.size()); - int i = 0; - for (cElementalDefinitionStack defStack : map.values()) - nbt.setTag(Integer.toString(i++), defStack.toNBT()); - return nbt; - } - - public static cElementalMutableDefinitionStackMap fromNBT(NBTTagCompound nbt) throws tElementalException { - final cElementalDefinitionStack[] defStacks = new cElementalDefinitionStack[nbt.getInteger("i")]; - for (int i = 0; i < defStacks.length; i++) { - defStacks[i] = cElementalDefinitionStack.fromNBT(nbt.getCompoundTag(Integer.toString(i))); - if (defStacks[i].definition.equals(debug__)) - throw new tElementalException("Something went Wrong"); - } - return new cElementalMutableDefinitionStackMap(defStacks); - } - - //stackUp - @Deprecated - public static cElementalMutableDefinitionStackMap stackUpTree(iElementalDefinition... in) { - final cElementalMutableDefinitionStackMap inTree = new cElementalMutableDefinitionStackMap(); - for (iElementalDefinition def : in) { - inTree.putUnify(new cElementalDefinitionStack(def, 1)); - } - return inTree; - } - - public static cElementalMutableDefinitionStackMap stackUpTree(cElementalDefinitionStack... in) { - final cElementalMutableDefinitionStackMap inTree = new cElementalMutableDefinitionStackMap(); - inTree.putUnifyAll(in); - return inTree; + for (cElementalDefinitionStack in : containerUnsafe.map.values()) + putUnify(in); } } diff --git a/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalPrimitive.java b/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalPrimitive.java index 8aaceee368..7e86852c34 100644 --- a/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalPrimitive.java +++ b/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalPrimitive.java @@ -12,6 +12,8 @@ import java.util.HashMap; import java.util.Map; import java.util.TreeMap; +import static com.github.technus.tectech.elementalMatter.definitions.cPrimitiveDefinition.null__; + /** * Created by danie_000 on 22.10.2016. * EXTEND THIS TO ADD NEW PRIMITIVES, WATCH OUT FOR ID'S!!! (-1 to 32 can be assumed as used) @@ -34,6 +36,7 @@ public abstract class cElementalPrimitive extends cElementalDefinition { public final byte color; //-1/-2/-3 anti matter generations, +1/+2/+3 matter generations, 0 self anti public final byte type; + private cElementalPrimitive anti;//IMMUTABLE private cElementalDecay[] elementalDecays; private byte naturalDecayInstant; @@ -148,7 +151,8 @@ public abstract class cElementalPrimitive extends cElementalDefinition { } public static iElementalDefinition fromNBT(NBTTagCompound content) { - return bindsBO.get(content.getInteger("c")); + iElementalDefinition primitive= bindsBO.get(content.getInteger("c")); + return primitive==null?null__:primitive; } @Override diff --git a/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalStackMap.java b/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalStackMap.java new file mode 100644 index 0000000000..44af95991e --- /dev/null +++ b/src/main/java/com/github/technus/tectech/elementalMatter/classes/cElementalStackMap.java @@ -0,0 +1,132 @@ +package com.github.technus.tectech.elementalMatter.classes; + +import com.github.technus.tectech.elementalMatter.interfaces.iElementalDefinition; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; + +import java.util.Map; + +import static com.github.technus.tectech.elementalMatter.definitions.cPrimitiveDefinition.nbtE__; + +/** + * Created by Tec on 12.05.2017. + */ +abstract class cElementalStackMap implements Comparable<cElementalStackMap> { + protected Map<iElementalDefinition, cElementalDefinitionStack> map; + + public int compareTo(cElementalStackMap o) { + if (map.size() != o.map.size()) return map.size() - o.map.size(); + cElementalDefinitionStack[] ofThis = values(), ofThat = o.values(); + for (int i = 0; i < ofThat.length; i++) { + int result = ofThis[i].compareTo(ofThat[i]); + if (result != 0) return result; + } + return 0; + } + + @Override + protected final Object clone() {//Equal to making new obj... + return Clone(); + } + + public cElementalStackMap Clone(){ + return this; + } + + @Deprecated + public abstract Map<iElementalDefinition,cElementalDefinitionStack> getRawMap(); + + //Getters + public final cElementalDefinitionStack getDefinitionStack(iElementalDefinition def) { + return map.get(def); + } + + public final String[] getElementalInfo() { + final String[] info = new String[map.size() * 3]; + int i = 0; + for (cElementalDefinitionStack defStack : map.values()) { + info[i] = EnumChatFormatting.BLUE + defStack.definition.getName(); + info[i + 1] = EnumChatFormatting.AQUA + defStack.definition.getSymbol(); + info[i + 2] = "Amount " + EnumChatFormatting.GREEN + defStack.amount; + i += 3; + } + return info; + } + + public final cElementalDefinitionStack[] values() { + return map.values().toArray(new cElementalDefinitionStack[0]); + } + + public final iElementalDefinition[] keys() { + return map.keySet().toArray(new iElementalDefinition[0]); + } + + //Tests + public final boolean containsDefinition(iElementalDefinition def) { + return map.containsKey(def); + } + + public final boolean containsDefinitionStack(cElementalDefinitionStack inst) { + return map.containsValue(inst); + } + + public final int size() { + return map.size(); + } + + public final boolean hasStacks() { + return map.size() > 0; + } + + //stackUp + @Deprecated + public static cElementalMutableDefinitionStackMap stackUpTree(iElementalDefinition... in) { + final cElementalMutableDefinitionStackMap inTree = new cElementalMutableDefinitionStackMap(); + for (iElementalDefinition def : in) { + inTree.putUnify(new cElementalDefinitionStack(def, 1)); + } + return inTree; + } + + public static cElementalMutableDefinitionStackMap stackUpTree(cElementalDefinitionStack... in) { + final cElementalMutableDefinitionStackMap inTree = new cElementalMutableDefinitionStackMap(); + inTree.putUnifyAll(in); + return inTree; + } + + //NBT + public NBTTagCompound getInfoNBT() { + final NBTTagCompound nbt = new NBTTagCompound(); + final String[] info = getElementalInfo(); + nbt.setInteger("i", info.length); + for (int i = 0; i < info.length; i++) + nbt.setString(Integer.toString(i), info[i]); + return nbt; + } + + public static String[] infoFromNBT(NBTTagCompound nbt) { + final String[] strings = new String[nbt.getInteger("i")]; + for (int i = 0; i < strings.length; i++) + strings[i] = nbt.getString(Integer.toString(i)); + return strings; + } + + public NBTTagCompound toNBT() { + final NBTTagCompound nbt = new NBTTagCompound(); + nbt.setInteger("i", map.size()); + int i = 0; + for (cElementalDefinitionStack defStack : map.values()) + nbt.setTag(Integer.toString(i++), defStack.toNBT()); + return nbt; + } + + public static cElementalMutableDefinitionStackMap fromNBT(NBTTagCompound nbt) throws tElementalException { + final cElementalDefinitionStack[] defStacks = new cElementalDefinitionStack[nbt.getInteger("i")]; + for (int i = 0; i < defStacks.length; i++) { + defStacks[i] = cElementalDefinitionStack.fromNBT(nbt.getCompoundTag(Integer.toString(i))); + if (defStacks[i].definition.equals(nbtE__)) + throw new tElementalException("Something went Wrong"); + } + return new cElementalMutableDefinitionStackMap(defStacks); + } +} diff --git a/src/main/java/com/github/technus/tectech/elementalMatter/definitions/cPrimitiveDefinition.java b/src/main/java/com/github/technus/tectech/elementalMatter/definitions/cPrimitiveDefinition.java index 941b5c27fa..52ad2db6bc 100644 --- a/src/main/java/com/github/technus/tectech/elementalMatter/definitions/cPrimitiveDefinition.java +++ b/src/main/java/com/github/technus/tectech/elementalMatter/definitions/cPrimitiveDefinition.java @@ -12,9 +12,8 @@ import static com.github.technus.tectech.elementalMatter.classes.cElementalDecay */ public final class cPrimitiveDefinition extends cElementalPrimitive { public static final cPrimitiveDefinition - debug__ = new cPrimitiveDefinition("Fallback of a bug", "!", 0, 0f, 0, Integer.MIN_VALUE, Integer.MIN_VALUE), - //Never create null__ particle - if u need fallback use debug__ - null__ = new cPrimitiveDefinition("This is a bug", ".", 0, 0F, 0, -3, Integer.MAX_VALUE), + nbtE__ = new cPrimitiveDefinition("NBT ERROR", "!", 0, 0f, 0, Integer.MIN_VALUE, Integer.MIN_VALUE), + null__ = new cPrimitiveDefinition("NULL POINTER", ".", 0, 0F, 0, -3, Integer.MAX_VALUE), space__ = new cPrimitiveDefinition("Space", "_", 0, 0F, 0, -4, 0), magic = new cPrimitiveDefinition("Magic", "Ma", 4, -1F, 0, 0, 1), magic_ = new cPrimitiveDefinition("Antimagic", "~Ma", -4, -1F, 0, 0, 2); @@ -23,12 +22,8 @@ public final class cPrimitiveDefinition extends cElementalPrimitive { super(name, symbol, type, mass, charge, color, ID); } - public static iElementalDefinition fromNBT(NBTTagCompound content) { - return bindsBO.get(content.getInteger("c")); - } - public static void run() { - debug__.init(null__, -1F, -1, -1, noDecay); + nbtE__.init(null__, -1F, -1, -1, noDecay); null__.init(null__, -1F, -1, -1, noProduct); space__.init(space__, -1F, -1, -1, noProduct); magic.init(magic_, -1F, -1, -1, noDecay); |