From c82522576d27ba1b0fdaf7fe1283489cb9f40744 Mon Sep 17 00:00:00 2001 From: Tec Date: Sat, 15 Jan 2022 00:16:05 +0100 Subject: cherry pick Cleanup EM maps --- .../tileentity/turret/TileTurretHeadEM.java | 27 +- .../tileentity/turretbase/TileTurretBaseEM.java | 4 +- .../definitions/dComplexAspectDefinition.java | 42 +- .../definitions/ePrimalAspectDefinition.java | 2 +- .../GT_MetaTileEntity_EM_essentiaDequantizer.java | 6 +- .../GT_MetaTileEntity_EM_essentiaQuantizer.java | 4 +- .../elementalMatter/core/cElementalDecay.java | 75 --- .../core/cElementalDecayResult.java | 41 -- .../core/cElementalDefinitionStackMap.java | 65 --- .../core/cElementalInstanceStackMap.java | 565 --------------------- .../core/cElementalMutableDefinitionStackMap.java | 278 ---------- .../elementalMatter/core/cElementalStackMap.java | 181 ------- .../elementalMatter/core/commands/GiveEM.java | 6 +- .../core/decay/cElementalDecay.java | 77 +++ .../core/decay/cElementalDecayResult.java | 43 ++ .../elementalMatter/core/iElementalContainer.java | 12 + .../core/iElementalInstanceContainer.java | 10 - .../core/maps/cElementalConstantStackMap.java | 58 +++ .../core/maps/cElementalDefinitionStackMap.java | 56 ++ .../core/maps/cElementalInstanceStackMap.java | 214 ++++++++ .../core/maps/cElementalStackMap.java | 50 ++ .../elementalMatter/core/maps/iElementalMapR.java | 187 +++++++ .../elementalMatter/core/maps/iElementalMapRW.java | 130 +++++ .../elementalMatter/core/rElementalRecipe.java | 56 -- .../elementalMatter/core/rElementalRecipeMap.java | 70 --- .../core/recipes/rElementalRecipe.java | 57 +++ .../core/recipes/rElementalRecipeMap.java | 73 +++ .../core/stacks/cElementalDefinitionStack.java | 35 +- .../core/stacks/cElementalInstanceStack.java | 54 +- .../core/stacks/iElementalStack.java | 23 + .../core/stacks/iHasElementalDefinition.java | 18 - .../core/templates/cElementalDefinition.java | 10 +- .../core/templates/cElementalPrimitive.java | 6 +- .../core/templates/iElementalDefinition.java | 6 +- .../transformations/aFluidDequantizationInfo.java | 14 +- .../transformations/aFluidQuantizationInfo.java | 14 +- .../transformations/aItemDequantizationInfo.java | 14 +- .../transformations/aItemQuantizationInfo.java | 16 +- .../aOredictDequantizationInfo.java | 18 +- .../transformations/aOredictQuantizationInfo.java | 18 +- .../core/transformations/bTransformationInfo.java | 16 +- .../definitions/complex/dAtomDefinition.java | 194 ++++--- .../definitions/complex/dHadronDefinition.java | 68 ++- .../primitive/cPrimitiveDefinition.java | 2 +- .../definitions/primitive/eBosonDefinition.java | 4 +- .../definitions/primitive/eLeptonDefinition.java | 2 +- .../definitions/primitive/eNeutrinoDefinition.java | 2 +- .../definitions/primitive/eQuarkDefinition.java | 2 +- .../github/technus/tectech/recipe/TT_recipe.java | 30 +- .../technus/tectech/recipe/TT_recipeAdder.java | 14 +- .../item/DebugElementalInstanceContainer_EM.java | 12 +- .../item/ElementalDefinitionContainer_EM.java | 18 +- .../item/ElementalDefinitionScanStorage_EM.java | 2 +- ...GT_MetaTileEntity_Hatch_ElementalContainer.java | 8 +- .../GT_MetaTileEntity_Hatch_OutputElemental.java | 2 +- .../multi/GT_MetaTileEntity_EM_collider.java | 109 ++-- .../multi/GT_MetaTileEntity_EM_decay.java | 100 ++-- .../multi/GT_MetaTileEntity_EM_dequantizer.java | 63 +-- .../multi/GT_MetaTileEntity_EM_junction.java | 6 +- .../multi/GT_MetaTileEntity_EM_quantizer.java | 14 +- .../multi/GT_MetaTileEntity_EM_scanner.java | 114 ++--- .../base/GT_MetaTileEntity_MultiblockBase_EM.java | 90 ++-- .../multi/em_machine/Behaviour_Centrifuge.java | 8 +- .../multi/em_machine/Behaviour_Electrolyzer.java | 2 +- .../Behaviour_ElectromagneticSeparator.java | 6 +- .../multi/em_machine/Behaviour_PrecisionLaser.java | 2 +- .../multi/em_machine/Behaviour_Recycler.java | 2 +- .../multi/em_machine/Behaviour_Scanner.java | 2 +- .../em_machine/GT_MetaTileEntity_EM_machine.java | 58 +-- 69 files changed, 1568 insertions(+), 2019 deletions(-) delete mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/cElementalDecay.java delete mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/cElementalDecayResult.java delete mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/cElementalDefinitionStackMap.java delete mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/cElementalInstanceStackMap.java delete mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/cElementalMutableDefinitionStackMap.java delete mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/cElementalStackMap.java create mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/decay/cElementalDecay.java create mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/decay/cElementalDecayResult.java create mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/iElementalContainer.java delete mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/iElementalInstanceContainer.java create mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/cElementalConstantStackMap.java create mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/cElementalDefinitionStackMap.java create mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/cElementalInstanceStackMap.java create mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/cElementalStackMap.java create mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/iElementalMapR.java create mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/iElementalMapRW.java delete mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/rElementalRecipe.java delete mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/rElementalRecipeMap.java create mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/recipes/rElementalRecipe.java create mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/recipes/rElementalRecipeMap.java create mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/stacks/iElementalStack.java delete mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/stacks/iHasElementalDefinition.java (limited to 'src/main/java/com') diff --git a/src/main/java/com/github/technus/tectech/compatibility/openmodularturrets/tileentity/turret/TileTurretHeadEM.java b/src/main/java/com/github/technus/tectech/compatibility/openmodularturrets/tileentity/turret/TileTurretHeadEM.java index fd039a0630..e027c83107 100644 --- a/src/main/java/com/github/technus/tectech/compatibility/openmodularturrets/tileentity/turret/TileTurretHeadEM.java +++ b/src/main/java/com/github/technus/tectech/compatibility/openmodularturrets/tileentity/turret/TileTurretHeadEM.java @@ -1,9 +1,8 @@ package com.github.technus.tectech.compatibility.openmodularturrets.tileentity.turret; -import com.github.technus.tectech.TecTech; import com.github.technus.tectech.compatibility.openmodularturrets.entity.projectiles.projectileEM; import com.github.technus.tectech.compatibility.openmodularturrets.tileentity.turretbase.TileTurretBaseEM; -import com.github.technus.tectech.mechanics.elementalMatter.core.cElementalInstanceStackMap; +import com.github.technus.tectech.mechanics.elementalMatter.core.maps.cElementalInstanceStackMap; import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.cElementalInstanceStack; import com.github.technus.tectech.thing.item.DebugElementalInstanceContainer_EM; import net.minecraft.entity.Entity; @@ -16,7 +15,6 @@ import openmodularturrets.tileentity.turrets.TurretHead; import openmodularturrets.util.TurretHeadUtil; import static com.github.technus.tectech.mechanics.elementalMatter.core.transformations.bTransformationInfo.AVOGADRO_CONSTANT; -import static com.github.technus.tectech.mechanics.elementalMatter.core.transformations.bTransformationInfo.AVOGADRO_CONSTANT_DIMINISHED; /** * Created by Bass on 27/07/2017. @@ -54,7 +52,7 @@ public class TileTurretHeadEM extends TurretHead{ @Override public boolean requiresAmmo() { - return hatchContentPointer == null || !hatchContentPointer.hasStacks(); + return hatchContentPointer == null || hatchContentPointer.isEmpty(); } @Override @@ -69,20 +67,15 @@ public class TileTurretHeadEM extends TurretHead{ @Override public final TurretProjectile createProjectile(World world, Entity target, ItemStack ammo) { - while(hatchContentPointer!=null && hatchContentPointer.hasStacks()) { - cElementalInstanceStack stack = hatchContentPointer.get(TecTech.RANDOM.nextInt(hatchContentPointer.size())); - if(stack.amount(); - } - - @Deprecated - public cElementalDefinitionStackMap(iElementalDefinition... in) { - map=new cElementalMutableDefinitionStackMap(in).map; - } - - public cElementalDefinitionStackMap(cElementalDefinitionStack... in) { - map=new cElementalMutableDefinitionStackMap(in).map; - } - - public cElementalDefinitionStackMap(TreeMap in) { - map = new TreeMap<>(in); - } - - cElementalDefinitionStackMap(cElementalMutableDefinitionStackMap unsafeMap){ - map=unsafeMap.map; - } - - //IMMUTABLE DON'T NEED IT - @Override - public cElementalDefinitionStackMap clone() { - return this; - } - - public cElementalMutableDefinitionStackMap toMutable() { - return new cElementalMutableDefinitionStackMap(map); - } - - @Override - @Deprecated//BETTER TO JUST MAKE A MUTABLE VERSION AND DO SHIT ON IT - public TreeMap getRawMap() { - return toMutable().getRawMap(); - } - - public static cElementalDefinitionStackMap fromNBT(NBTTagCompound nbt) throws tElementalException { - 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 cElementalDefinitionStackMap(defStacks); - } -} diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/cElementalInstanceStackMap.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/cElementalInstanceStackMap.java deleted file mode 100644 index e1fdc6a553..0000000000 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/cElementalInstanceStackMap.java +++ /dev/null @@ -1,565 +0,0 @@ -package com.github.technus.tectech.mechanics.elementalMatter.core; - -import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.cElementalDefinitionStack; -import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.cElementalInstanceStack; -import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.iHasElementalDefinition; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.iElementalDefinition; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumChatFormatting; - -import java.util.*; - -import static com.github.technus.tectech.mechanics.elementalMatter.core.transformations.bTransformationInfo.AVOGADRO_CONSTANT; -import static com.github.technus.tectech.mechanics.elementalMatter.core.transformations.bTransformationInfo.AVOGADRO_CONSTANT_UNCERTAINTY; -import static com.github.technus.tectech.mechanics.elementalMatter.definitions.primitive.cPrimitiveDefinition.nbtE__; -import static com.github.technus.tectech.util.DoubleCount.add; -import static com.github.technus.tectech.util.DoubleCount.sub; - -/** - * Created by danie_000 on 22.01.2017. - */ -public final class cElementalInstanceStackMap implements Comparable { - TreeMap map; - - //Constructors - public cElementalInstanceStackMap() { - map = new TreeMap<>(); - } - - public cElementalInstanceStackMap(cElementalInstanceStack... inSafe) { - this(true, inSafe); - } - - public cElementalInstanceStackMap(boolean clone, cElementalInstanceStack... in) { - map = new TreeMap<>(); - if (clone) { - cElementalInstanceStack[] stacks=new cElementalInstanceStack[in.length]; - for(int i=0;i inSafe) { - this(true, inSafe); - } - - @Deprecated - private cElementalInstanceStackMap(boolean clone, TreeMap in) { - if (clone) { - map = new TreeMap<>(); - for(cElementalInstanceStack stack:in.values()) { - putUnify(stack.clone()); - } - } else { - map = in; - } - } - - public cElementalInstanceStackMap(cElementalInstanceStackMap inSafe) { - this(true, inSafe.map); - } - - public cElementalInstanceStackMap(boolean copy, cElementalInstanceStackMap in) { - this(copy, in.map); - } - - @Override - public cElementalInstanceStackMap clone() { - return new cElementalInstanceStackMap(map); - } - - public cElementalMutableDefinitionStackMap toDefinitionMapForComparison() { - cElementalDefinitionStack[] list = new cElementalDefinitionStack[map.size()]; - int i = 0; - for (cElementalInstanceStack stack : map.values()) { - list[i++] = new cElementalDefinitionStack(stack.definition, stack.amount); - } - return new cElementalMutableDefinitionStackMap(list); - } - - //@Deprecated - //public cElementalStackMap toDefinitionMap(boolean mutable) { - // TreeMap newMap = new TreeMap<>(); - // for (cElementalInstanceStack stack : map.values()) { - // newMap.put(stack.definition, new cElementalDefinitionStack(stack.definition, stack.amount)); - // } - // if (mutable) { - // return new cElementalMutableDefinitionStackMap(newMap); - // } - // return new cElementalDefinitionStackMap(newMap); - //} - - @Deprecated - public Map getRawMap() { - return map; - } - - public Set> getEntrySet() { - return map.entrySet(); - } - - - //Removers - public void clear() { - map.clear(); - } - - public cElementalInstanceStack remove(iElementalDefinition def) { - return map.remove(def); - } - - @Deprecated - public cElementalInstanceStack 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... hasElementalDefinition) { - for (iHasElementalDefinition has : hasElementalDefinition) { - map.remove(has.getDefinition()); - } - } - - //Remove amounts - public boolean removeAmount(boolean testOnly, cElementalInstanceStack instance) { - cElementalInstanceStack target = map.get(instance.definition); - if (target == null) { - return false; - } - if (testOnly) { - return target.amount >= instance.amount; - } else { - double diff = sub(target.amount,instance.amount); - if (diff > 0) { - target.amount = diff; - return true; - } else if (diff == 0) { - map.remove(instance.definition); - return true; - } - } - return false; - } - - public boolean removeAmount(boolean testOnly, iHasElementalDefinition stack) { - cElementalInstanceStack target = map.get(stack.getDefinition()); - if (target == null) { - return false; - } - if (testOnly) { - return target.amount >= stack.getAmount(); - } else { - double diff = sub(target.amount,stack.getAmount()); - if (diff > 0) { - target.amount = diff; - return true; - } else if (diff == 0) { - map.remove(stack.getDefinition()); - return true; - } - } - return false; - } - - @Deprecated - public boolean removeAmount(boolean testOnly, iElementalDefinition def) { - return removeAmount(testOnly, new cElementalDefinitionStack(def, 1D)); - } - - 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, iHasElementalDefinition... stacks) { - boolean test = true; - for (iHasElementalDefinition stack : stacks) { - test &= removeAmount(true, stack); - } - if (testOnly || !test) { - return test; - } - for (iHasElementalDefinition stack : stacks) { - removeAmount(false, stack); - } - return true; - } - - @Deprecated - public boolean removeAllAmounts(boolean testOnly, iElementalDefinition... definitions) { - 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, cElementalStackMap container) { - boolean test=true; - for (Map.Entry entry : container.map.entrySet()) { - test &= removeAmount(true, entry.getValue()); - } - if (testOnly || !test) { - return test; - } - for (Map.Entry entry : container.map.entrySet()) { - removeAmount(false, entry.getValue()); - } - return true; - } - - public boolean removeAllAmounts(boolean testOnly, cElementalInstanceStackMap container) { - boolean test=true; - for (Map.Entry entry : container.map.entrySet()) { - test &= removeAmount(true, entry.getValue()); - } - if (testOnly || !test) { - return test; - } - for (Map.Entry entry : container.map.entrySet()) { - test &= removeAmount(false, entry.getValue()); - } - return true; - } - - //Remove overflow - public double removeOverflow(int stacksCount, double stackCapacity) { - double massRemoved = 0; - - if (map.size() > stacksCount) { - iElementalDefinition[] keys = keys(); - for (int i = stacksCount; i < keys.length; i++) { - massRemoved += map.get(keys[i]).getDefinitionStack().getMass(); - map.remove(keys[i]); - } - } - - for (cElementalInstanceStack instance : values()) { - if (instance.amount > stackCapacity) { - massRemoved += instance.definition.getMass() * (instance.amount - stackCapacity); - instance.amount = stackCapacity; - } - } - return massRemoved; - } - - //Put replace - public cElementalInstanceStack putReplace(cElementalInstanceStack instanceUnsafe) { - return map.put(instanceUnsafe.definition, instanceUnsafe); - } - - public void putReplaceAll(cElementalInstanceStack... instances) { - for (cElementalInstanceStack instance : instances) { - map.put(instance.definition, instance); - } - } - - private void putReplaceAll(Map inTreeUnsafe) { - map.putAll(inTreeUnsafe); - } - - public void putReplaceAll(cElementalInstanceStackMap inContainerUnsafe) { - putReplaceAll(inContainerUnsafe.map); - } - - //Put unify - public cElementalInstanceStack putUnify(cElementalInstanceStack instance) { - cElementalInstanceStack stack=map.get(instance.definition); - if(stack==null) { - return map.put(instance.definition, instance); - } - return map.put(instance.definition, stack.unifyIntoThis(instance)); - } - - public void putUnifyAll(cElementalInstanceStack... instances) { - for (cElementalInstanceStack instance : instances) { - putUnify(instance); - } - } - - private void putUnifyAll(Map inTreeUnsafe) { - for (cElementalInstanceStack in : inTreeUnsafe.values()) { - putUnify(in); - } - } - - public void putUnifyAll(cElementalInstanceStackMap containerUnsafe) { - putUnifyAll(containerUnsafe.map); - } - - //Getters - public cElementalInstanceStack getFirst(){ - return map.firstEntry().getValue(); - } - - public cElementalInstanceStack getLast(){ - return map.lastEntry().getValue(); - } - - public cElementalInstanceStack getInstance(iElementalDefinition def) { - return map.get(def); - } - - public cElementalInstanceStack get(int i){ - Collection var = map.values(); - return var.toArray(new cElementalInstanceStack[0])[i]; - } - - public String[] getShortSymbolsInfo() { - String[] info = new String[map.size()]; - int i = 0; - for (cElementalInstanceStack instance : map.values()) { - info[i++] = instance.definition.getShortSymbol(); - } - return info; - } - - public String[] getElementalInfo() { - String[] info = new String[map.size()]; - int i = 0; - for (cElementalInstanceStack instance : map.values()) { - info[i++] = EnumChatFormatting.BLUE + instance.definition.getName()+ - " "+ EnumChatFormatting.AQUA + instance.definition.getSymbol()+ EnumChatFormatting.RESET+ - " #: " + EnumChatFormatting.GREEN + String.format("%.3E",instance.amount/ AVOGADRO_CONSTANT) +" mol"+ EnumChatFormatting.RESET+ - " E: " + EnumChatFormatting.GREEN + instance.getEnergy() + EnumChatFormatting.RESET+ - " T: " + EnumChatFormatting.GREEN + (instance.getLifeTime()<0?"STABLE":String.format("%.3E",instance.getLifeTime())); - } - return info; - } - - public ArrayList getScanShortSymbols(int[] capabilities) { - ArrayList list=new ArrayList<>(16); - for(Map.Entry e:map.entrySet()){ - e.getValue().addScanShortSymbols(list,capabilities); - } - return list; - } - - public ArrayList getScanInfo(int[] capabilities) { - ArrayList list=new ArrayList<>(16); - for(Map.Entry e:map.entrySet()){ - e.getValue().addScanResults(list,capabilities); - } - return list; - } - - public cElementalInstanceStack[] values() { - Collection var = map.values(); - return var.toArray(new cElementalInstanceStack[0]); - } - - public iElementalDefinition[] keys() { - Set var = map.keySet(); - return var.toArray(new iElementalDefinition[0]); - } - - public double getMass() { - double mass = 0; - for (cElementalInstanceStack stack : map.values()) { - mass += stack.getMass(); - } - return mass; - } - - public double getCharge() { - double charge = 0; - for (cElementalInstanceStack stack : map.values()) { - charge += stack.getCharge(); - } - return charge; - } - - public double getCountOfAllAmounts(){ - double sum=0; - for(cElementalInstanceStack stack:map.values()){ - sum= add(sum,stack.amount); - } - return sum; - } - - //Tests - public boolean containsDefinition(iElementalDefinition def) { - return map.containsKey(def); - } - - public boolean containsInstance(cElementalInstanceStack inst) { - return map.containsValue(inst); - } - - public int size() { - return map.size(); - } - - public boolean hasStacks() { - return !map.isEmpty(); - } - - public boolean isEmpty(){ - return map.isEmpty(); - } - - //Tick Content - public double tickContentByOneSecond(double lifeTimeMult, int postEnergize) { - return tickContent(lifeTimeMult,postEnergize,1D); - } - - public double tickContent(double lifeTimeMult, int postEnergize, double seconds){ - cleanUp(); - double diff=0; - for (cElementalInstanceStack instance : values()) { - cElementalDecayResult newInstances = instance.decay(lifeTimeMult, instance.age += seconds, postEnergize); - if (newInstances == null) { - instance.nextColor(); - } else { - diff=add(diff,newInstances.getMassDiff()); - removeAmount(false,instance); - putUnifyAll(newInstances.getOutput()); - } - } - return diff; - } - - //NBT - public NBTTagCompound getShortSymbolsNBT() { - NBTTagCompound nbt = new NBTTagCompound(); - String[] info = getShortSymbolsInfo(); - nbt.setInteger("i", info.length); - for (int i = 0; i < info.length; i++) { - nbt.setString(Integer.toString(i), info[i]); - } - return nbt; - } - - public NBTTagCompound getInfoNBT() { - NBTTagCompound nbt = new NBTTagCompound(); - 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 NBTTagCompound getScanShortSymbolsNBT(int[] capabilities) { - NBTTagCompound nbt = new NBTTagCompound(); - ArrayList info = getScanShortSymbols(capabilities); - nbt.setInteger("i", info.size()); - for (int i = 0; i < info.size(); i++) { - nbt.setString(Integer.toString(i), info.get(i)); - } - return nbt; - } - - public NBTTagCompound getScanInfoNBT(int[] capabilities) { - NBTTagCompound nbt = new NBTTagCompound(); - ArrayList info = getScanInfo(capabilities); - nbt.setInteger("i", info.size()); - for (int i = 0; i < info.size(); i++) { - nbt.setString(Integer.toString(i), info.get(i)); - } - return nbt; - } - - public NBTTagCompound toNBT() { - NBTTagCompound nbt = new NBTTagCompound(); - nbt.setInteger("i", map.size()); - int i = 0; - for (cElementalInstanceStack instance : map.values()) { - nbt.setTag(Integer.toString(i++), instance.toNBT()); - } - return nbt; - } - - public static cElementalInstanceStackMap fromNBT(NBTTagCompound nbt) throws tElementalException { - 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(nbtE__)) { - throw new tElementalException("Something went Wrong"); - } - } - return new cElementalInstanceStackMap(false, instances); - } - - //stackUp - public static cElementalInstanceStack[] stackUp(cElementalInstanceStack... in) { - cElementalInstanceStackMap inTree = new cElementalInstanceStackMap(); - inTree.putUnifyAll(in); - return inTree.values(); - } - - @Override - public int compareTo(cElementalInstanceStackMap o) { - int sizeDiff = map.size() - o.map.size(); - if (sizeDiff != 0) { - return sizeDiff; - } - cElementalInstanceStack[] 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 - public boolean equals(Object obj) { - if (obj instanceof cElementalInstanceStackMap) { - return compareTo((cElementalInstanceStackMap) obj) == 0; - } - if (obj instanceof cElementalStackMap) { - return toDefinitionMapForComparison().compareTo((cElementalStackMap) obj) == 0; - } - return false; - } - - @Override - public int hashCode() {//Hash only definitions to compare contents not amounts or data - int hash = -(map.size() << 4); - for (cElementalInstanceStack stack : map.values()) { - hash += stack.definition.hashCode(); - } - return hash; - } - - @Override - public String toString() { - StringBuilder build=new StringBuilder("Instance Stack Map\n"); - for(cElementalInstanceStack stack:map.values()){ - build.append(stack.toString()).append('\n'); - } - return build.toString(); - } - - public cElementalInstanceStackMap takeAllToNewMap(){ - TreeMap map=this.map; - this.map=new TreeMap<>(); - return new cElementalInstanceStackMap(map); - } - - public void cleanUp(){ - map.entrySet().removeIf(entry -> entry.getValue().amount < AVOGADRO_CONSTANT_UNCERTAINTY); - } -} diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/cElementalMutableDefinitionStackMap.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/cElementalMutableDefinitionStackMap.java deleted file mode 100644 index 020f5a5f8c..0000000000 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/cElementalMutableDefinitionStackMap.java +++ /dev/null @@ -1,278 +0,0 @@ -package com.github.technus.tectech.mechanics.elementalMatter.core; - -import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.cElementalDefinitionStack; -import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.cElementalInstanceStack; -import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.iHasElementalDefinition; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.iElementalDefinition; -import net.minecraft.nbt.NBTTagCompound; - -import java.util.Map; -import java.util.TreeMap; - -import static com.github.technus.tectech.mechanics.elementalMatter.definitions.primitive.cPrimitiveDefinition.nbtE__; -import static com.github.technus.tectech.util.DoubleCount.sub; - -/** - * Created by danie_000 on 22.01.2017. - */ -public final class cElementalMutableDefinitionStackMap extends cElementalStackMap {//Transient class for construction of definitions/recipes - //Constructors + Clone, all make a whole new OBJ. - public cElementalMutableDefinitionStackMap() { - map = new TreeMap<>(); - } - - @Deprecated - public cElementalMutableDefinitionStackMap(iElementalDefinition... in) { - map=new TreeMap<>(); - for (iElementalDefinition def : in) { - putUnify(new cElementalDefinitionStack(def, 1)); - } - } - - public cElementalMutableDefinitionStackMap(cElementalDefinitionStack... in) { - map=new TreeMap<>(); - putUnifyAll(in); - } - - public cElementalMutableDefinitionStackMap(TreeMap in) { - this(true, in); - } - - public cElementalMutableDefinitionStackMap(boolean clone, TreeMap in) { - if (clone) { - map = new TreeMap<>(in); - } else { - map = in; - } - } - - @Override - public cElementalMutableDefinitionStackMap clone() { - return new cElementalMutableDefinitionStackMap(map); - } - - public cElementalDefinitionStackMap toImmutable() { - return new cElementalDefinitionStackMap(map); - } - public cElementalDefinitionStackMap toImmutable_optimized_unsafeLeavesExposedElementalTree() { - return new cElementalDefinitionStackMap(this); - } - - @Override - @Deprecated - public TreeMap getRawMap() { - return map; - } - - - //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 - public void removeAll(iHasElementalDefinition... hasElementalDefinition) { - for (iHasElementalDefinition has : hasElementalDefinition) { - map.remove(has.getDefinition()); - } - } - - //Remove amounts - public boolean removeAmount(boolean testOnly, cElementalInstanceStack instance) { - cElementalDefinitionStack target = map.get(instance.definition); - if (target == null) { - return false; - } - if (testOnly) { - return target.amount >= instance.amount; - } else { - double diff = sub(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, iHasElementalDefinition stack) { - cElementalDefinitionStack target = map.get(stack.getDefinition()); - if (target == null) { - return false; - } - if (testOnly) { - return target.amount >= stack.getAmount(); - } else { - double diff = sub(target.amount,stack.getAmount()); - if (diff > 0) { - map.put(target.definition, new cElementalDefinitionStack(target.definition, diff)); - return true; - } else if (diff == 0) { - map.remove(stack.getDefinition()); - 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, iHasElementalDefinition... stacks) { - boolean test = true; - for (iHasElementalDefinition stack : stacks) { - test &= removeAmount(true, stack); - } - if (testOnly || !test) { - return test; - } - for (iHasElementalDefinition stack : stacks) { - removeAmount(false, stack); - } - return true; - } - - @Deprecated - public boolean removeAllAmounts(boolean testOnly, iElementalDefinition... definitions) { - 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, cElementalStackMap container) { - boolean test=true; - for (Map.Entry entry : container.map.entrySet()) { - test &= removeAmount(true, entry.getValue()); - } - if (testOnly || !test) { - return test; - } - for (Map.Entry entry : container.map.entrySet()) { - removeAmount(false, entry.getValue()); - } - return true; - } - - public boolean removeAllAmounts(boolean testOnly, cElementalInstanceStackMap container) { - boolean test=true; - for (Map.Entry entry : container.map.entrySet()) { - test &= removeAmount(true, entry.getValue()); - } - if (testOnly || !test) { - return test; - } - for (Map.Entry entry : container.map.entrySet()) { - test &= removeAmount(false, entry.getValue()); - } - return true; - } - - //Put replace - public cElementalDefinitionStack putReplace(cElementalDefinitionStack defStackUnsafe) { - return map.put(defStackUnsafe.definition, defStackUnsafe); - } - - public void putReplaceAll(cElementalDefinitionStack... defStacks) { - for (cElementalDefinitionStack defStack : defStacks) { - map.put(defStack.definition, defStack); - } - } - - public void putReplaceAll(cElementalStackMap inContainerUnsafe) { - map.putAll(inContainerUnsafe.map); - } - - //Put unify - public cElementalDefinitionStack putUnify(cElementalDefinitionStack def) { - cElementalDefinitionStack stack=map.get(def.definition); - if(stack==null) { - return map.put(def.definition, def); - } - return map.put(def.definition, stack.addAmountIntoNewInstance(def.amount)); - } - - @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 inTreeUnsafe) { - for (cElementalDefinitionStack in : inTreeUnsafe.values()) { - putUnify(in); - } - } - - public void putUnifyAll(cElementalStackMap containerUnsafe) { - for (cElementalDefinitionStack in : containerUnsafe.map.values()) { - putUnify(in); - } - } - - public static cElementalMutableDefinitionStackMap fromNBT(NBTTagCompound nbt) throws tElementalException { - 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); - } - - public void cleanUp(){ - for(Map.Entry entry:map.entrySet()){ - if(entry.getValue().amount<=0) { - map.remove(entry.getKey()); - } - } - } -} diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/cElementalStackMap.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/cElementalStackMap.java deleted file mode 100644 index f8e7aa39e4..0000000000 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/cElementalStackMap.java +++ /dev/null @@ -1,181 +0,0 @@ -package com.github.technus.tectech.mechanics.elementalMatter.core; - -import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.cElementalDefinitionStack; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.iElementalDefinition; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumChatFormatting; - -import java.util.Collection; -import java.util.Set; -import java.util.TreeMap; - -import static com.github.technus.tectech.util.DoubleCount.add; - -/** - * Created by Tec on 12.05.2017. - */ -abstract class cElementalStackMap implements Comparable { - protected TreeMap map; - - @Override - public abstract cElementalStackMap clone(); - - @Deprecated - public abstract TreeMap getRawMap(); - - //Getters - public final cElementalDefinitionStack getFirst(){ - return map.firstEntry().getValue(); - } - - public final cElementalDefinitionStack getLast(){ - return map.lastEntry().getValue(); - } - - public final cElementalDefinitionStack getDefinitionStack(iElementalDefinition def) { - return map.get(def); - } - - public String[] getShortSymbolsInfo() { - String[] info = new String[map.size()]; - int i = 0; - for (cElementalDefinitionStack instance : map.values()) { - info[i++] = instance.definition.getShortSymbol(); - } - return info; - } - - public final String[] getElementalInfo() { - String[] info = new String[map.