From 88eb3d0c4472e38bb14797074dd2003def57c7c2 Mon Sep 17 00:00:00 2001 From: Technus Date: Fri, 15 Dec 2017 06:15:18 +0100 Subject: Rework iaea decay branching, some refactoring, remove trinium from bloody loader. --- .../tectech/compatibility/gtpp/GtppAtomLoader.java | 2 +- .../definitions/complex/atom/dAtomDefinition.java | 1441 ++++++++++++++++++++ .../definitions/complex/atom/iaeaNuclide.java | 266 ++++ .../definitions/complex/dAtomDefinition.java | 1441 -------------------- .../definitions/complex/dHadronDefinition.java | 418 ------ .../complex/hadron/dHadronDefinition.java | 418 ++++++ .../definitions/complex/iaea/iaeaNuclide.java | 243 ---- .../technus/tectech/loader/BloodyRecipeLoader.java | 4 +- .../technus/tectech/loader/ElementalLoader.java | 6 +- .../technus/tectech/loader/RecipeLoader.java | 4 +- .../multi/GT_MetaTileEntity_EM_dequantizer.java | 4 +- .../multi/GT_MetaTileEntity_EM_quantizer.java | 4 +- .../entity/projectiles/projectileEM.java | 2 +- 13 files changed, 2138 insertions(+), 2115 deletions(-) create mode 100644 src/main/java/com/github/technus/tectech/elementalMatter/definitions/complex/atom/dAtomDefinition.java create mode 100644 src/main/java/com/github/technus/tectech/elementalMatter/definitions/complex/atom/iaeaNuclide.java delete mode 100644 src/main/java/com/github/technus/tectech/elementalMatter/definitions/complex/dAtomDefinition.java delete mode 100644 src/main/java/com/github/technus/tectech/elementalMatter/definitions/complex/dHadronDefinition.java create mode 100644 src/main/java/com/github/technus/tectech/elementalMatter/definitions/complex/hadron/dHadronDefinition.java delete mode 100644 src/main/java/com/github/technus/tectech/elementalMatter/definitions/complex/iaea/iaeaNuclide.java (limited to 'src/main/java') diff --git a/src/main/java/com/github/technus/tectech/compatibility/gtpp/GtppAtomLoader.java b/src/main/java/com/github/technus/tectech/compatibility/gtpp/GtppAtomLoader.java index 5ca890929c..aa6590c8ea 100644 --- a/src/main/java/com/github/technus/tectech/compatibility/gtpp/GtppAtomLoader.java +++ b/src/main/java/com/github/technus/tectech/compatibility/gtpp/GtppAtomLoader.java @@ -5,7 +5,7 @@ import gregtech.api.enums.OrePrefixes; import gtPlusPlus.core.material.ELEMENT; import gtPlusPlus.core.material.MaterialGenerator; -import static com.github.technus.tectech.elementalMatter.definitions.complex.dAtomDefinition.*; +import static com.github.technus.tectech.elementalMatter.definitions.complex.atom.dAtomDefinition.*; public class GtppAtomLoader implements Runnable{ @Override diff --git a/src/main/java/com/github/technus/tectech/elementalMatter/definitions/complex/atom/dAtomDefinition.java b/src/main/java/com/github/technus/tectech/elementalMatter/definitions/complex/atom/dAtomDefinition.java new file mode 100644 index 0000000000..199931793b --- /dev/null +++ b/src/main/java/com/github/technus/tectech/elementalMatter/definitions/complex/atom/dAtomDefinition.java @@ -0,0 +1,1441 @@ +package com.github.technus.tectech.elementalMatter.definitions.complex.atom; + +import com.github.technus.tectech.TecTech; +import com.github.technus.tectech.Util; +import com.github.technus.tectech.XSTR; +import com.github.technus.tectech.compatibility.gtpp.GtppAtomLoader; +import com.github.technus.tectech.elementalMatter.core.cElementalDecay; +import com.github.technus.tectech.elementalMatter.core.cElementalDefinitionStackMap; +import com.github.technus.tectech.elementalMatter.core.cElementalMutableDefinitionStackMap; +import com.github.technus.tectech.elementalMatter.core.stacks.cElementalDefinitionStack; +import com.github.technus.tectech.elementalMatter.core.tElementalException; +import com.github.technus.tectech.elementalMatter.core.templates.cElementalDefinition; +import com.github.technus.tectech.elementalMatter.core.templates.iElementalDefinition; +import com.github.technus.tectech.elementalMatter.core.transformations.aFluidDequantizationInfo; +import com.github.technus.tectech.elementalMatter.core.transformations.aItemDequantizationInfo; +import com.github.technus.tectech.elementalMatter.core.transformations.aOredictDequantizationInfo; +import com.github.technus.tectech.elementalMatter.core.transformations.bTransformationInfo; +import com.github.technus.tectech.elementalMatter.definitions.complex.hadron.dHadronDefinition; +import com.github.technus.tectech.elementalMatter.definitions.primitive.eBosonDefinition; +import com.github.technus.tectech.elementalMatter.definitions.primitive.eLeptonDefinition; +import com.github.technus.tectech.elementalMatter.definitions.primitive.eNeutrinoDefinition; +import cpw.mods.fml.common.Loader; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import net.minecraft.nbt.NBTTagCompound; + +import java.util.*; + +import static com.github.technus.tectech.XSTR.XSTR_INSTANCE; +import static com.github.technus.tectech.auxiliary.TecTechConfig.DEBUG_MODE; +import static com.github.technus.tectech.elementalMatter.definitions.primitive.eBosonDefinition.boson_Y__; +import static com.github.technus.tectech.elementalMatter.definitions.primitive.eBosonDefinition.deadEnd; +import static com.github.technus.tectech.thing.metaTileEntity.multi.GT_MetaTileEntity_EM_scanner.*; +import static gregtech.api.enums.OrePrefixes.dust; + +/** + * Created by danie_000 on 18.11.2016. + */ +public final class dAtomDefinition extends cElementalDefinition { + public static final long ATOM_COMPLEXITY_LIMIT=65536L; + private static final byte BYTE_OFFSET=32; + + private final int hash; + public static final bTransformationInfo transformation=new bTransformationInfo(16,0,64); + public static float refMass, refUnstableMass; + + private static final byte nbtType = (byte) 'a'; + private static final Random xstr = new XSTR();//NEEDS SEPARATE! + private static Map> stableIsotopes = new HashMap<>(); + private static final Map stableAtoms = new HashMap<>(); + private static Map> mostStableUnstableIsotopes = new HashMap<>(); + private static final Map unstableAtoms = new HashMap<>(); + private static cElementalDefinitionStack alpha,deuterium,tritium,helium_3,beryllium_8,carbon_14,neon_24,silicon_34; + private static final HashMap lifetimeOverrides = new HashMap<>(); + public static final ArrayList overrides = new ArrayList<>(); + + public final iaeaNuclide iaea; + + public static void addOverride(dAtomDefinition atom, float rawLifeTime){ + lifetimeOverrides.put(atom,rawLifeTime); + } + + //float-mass in eV/c^2 + public final float mass; + //public final int charge; + public final int charge; + //int -electric charge in 1/3rds of electron charge for optimization + public final int chargeLeptons; + private float rawLifeTime; + //generation max present inside - minus if contains any anti quark + public final byte type; + + public final byte decayMode;//t neutron to proton+,0,f proton to neutron + //public final boolean stable; + + public final int neutralCount; + public final int element; + + private final boolean iaeaDefinitionExistsAndHasEnergyLevels; + + private final cElementalDefinitionStackMap elementalStacks; + + //stable is rawLifeTime>=10^9 + + @Deprecated + public dAtomDefinition(iElementalDefinition... things) throws tElementalException { + this(true, new cElementalDefinitionStackMap(things)); + } + + @Deprecated + private dAtomDefinition(boolean check, iElementalDefinition... things) throws tElementalException { + this(check, new cElementalDefinitionStackMap(things)); + } + + public dAtomDefinition(cElementalDefinitionStack... things) throws tElementalException { + this(true, new cElementalDefinitionStackMap(things)); + } + + private dAtomDefinition(boolean check, cElementalDefinitionStack... things) throws tElementalException { + this(check, new cElementalDefinitionStackMap(things)); + } + + public dAtomDefinition(cElementalDefinitionStackMap things) throws tElementalException { + this(true, things); + } + + private dAtomDefinition(boolean check, cElementalDefinitionStackMap things) throws tElementalException { + if (check && !canTheyBeTogether(things)) throw new tElementalException("Atom Definition error"); + this.elementalStacks = things; + + float mass = 0; + int cLeptons = 0; + int cNucleus = 0; + int neutralCount = 0, element = 0; + int type = 0; + boolean containsAnti = false; + for (cElementalDefinitionStack stack : elementalStacks.values()) { + iElementalDefinition def = stack.definition; + int amount = (int)stack.amount; + mass += stack.getMass(); + if (def.getType() < 0) containsAnti = true; + type = Math.max(type, Math.abs(def.getType())); + + if (def instanceof eLeptonDefinition) { + cLeptons += stack.getCharge(); + } else { + cNucleus += stack.getCharge(); + if (def.getCharge() == 3) element += amount; + else if (def.getCharge() == -3) element -= amount; + else if (def.getCharge() == 0) neutralCount += amount; + } + } + this.type = containsAnti ? (byte) -type : (byte) type; + //this.mass = mass; + this.chargeLeptons = cLeptons; + this.charge = cNucleus + cLeptons; + this.neutralCount = neutralCount; + this.element = element; + + element = Math.abs(element); + + //stability curve + int StableIsotope = stableIzoCurve(element); + int izoDiff = neutralCount - StableIsotope; + int izoDiffAbs = Math.abs(izoDiff); + + xstr.setSeed((element + 1L) * (neutralCount + 100L)); + this.iaea=iaeaNuclide.get(element,neutralCount); + if(iaea!=null){ + if(Float.isNaN(iaea.mass)) this.mass=mass; + else this.mass=iaea.mass; + + if(Float.isNaN(iaea.halfTime)) { + Float overriddenLifeTime=lifetimeOverrides.get(this); + float rawLifeTimeTemp; + if(overriddenLifeTime!=null) + rawLifeTimeTemp = overriddenLifeTime; + else { + rawLifeTimeTemp = calculateLifeTime(izoDiff, izoDiffAbs, element, neutralCount, containsAnti); + } + this.rawLifeTime=rawLifeTimeTemp> STABLE_RAW_LIFE_TIME ? STABLE_RAW_LIFE_TIME :rawLifeTimeTemp; + }else { + this.rawLifeTime = containsAnti ? iaea.halfTime * 1.5514433E-21f * (1f + xstr.nextFloat() * 9f) : iaea.halfTime; + } + this.iaeaDefinitionExistsAndHasEnergyLevels =iaea.energeticStatesArray.length>1; + }else{ + this.mass=mass; + + Float overriddenLifeTime=lifetimeOverrides.get(this); + float rawLifeTimeTemp; + if(overriddenLifeTime!=null) + rawLifeTimeTemp = overriddenLifeTime; + else { + rawLifeTimeTemp = calculateLifeTime(izoDiff, izoDiffAbs, element, neutralCount, containsAnti); + } + this.rawLifeTime=rawLifeTimeTemp> STABLE_RAW_LIFE_TIME ? STABLE_RAW_LIFE_TIME :rawLifeTimeTemp; + + this.iaeaDefinitionExistsAndHasEnergyLevels =false; + } + + if(iaea==null || iaea.energeticStatesArray[0].energy!=0) { + if (izoDiff == 0) + this.decayMode = 0; + else + this.decayMode = izoDiff > 0 ? (byte) Math.min(2, 1 + izoDiffAbs / 4) : (byte) -Math.min(2, 1 + izoDiffAbs / 4); + }else{ + this.decayMode = izoDiff > 0 ? (byte) (Math.min(2, 1 + izoDiffAbs / 4)+ BYTE_OFFSET) : (byte) (-Math.min(2, 1 + izoDiffAbs / 4) + BYTE_OFFSET); + } + //this.stable = this.rawLifeTime >= STABLE_RAW_LIFE_TIME; + + hash=super.hashCode(); + } + + private static int stableIzoCurve(int element) { + return (int) Math.round(-1.19561E-06 * Math.pow(element, 4D) + + 1.60885E-04 * Math.pow(element, 3D) + + 3.76604E-04 * Math.pow(element, 2D) + + 1.08418E+00 * (double) element); + } + + private static float calculateLifeTime(int izoDiff, int izoDiffAbs, int element, int isotope, boolean containsAnti) { + float rawLifeTime; + + if (element <= 83 && isotope < 127 && (izoDiffAbs == 0 || + (element == 1 && isotope == 0) || + (element == 2 && isotope == 1) || + (izoDiffAbs == 1 && element > 2 && element % 2 == 1) || + (izoDiffAbs == 3 && element > 30 && element % 2 == 0) || + (izoDiffAbs == 5 && element > 30 && element % 2 == 0) || + (izoDiffAbs == 2 && element > 20 && element % 2 == 1))) { + rawLifeTime = containsAnti ? 2.381e4f * (1f + xstr.nextFloat() * 9f) : (1f + xstr.nextFloat() * 9f) * 1.5347e25F; + } else { + //Y = (X-A)/(B-A) * (D-C) + C + float unstabilityEXP = 0; + if (element == 0) { + return 1e-35f; + } else if (element == 1) { + unstabilityEXP = 1.743f - (Math.abs(izoDiff - 1) * 9.743f); + } else if (element == 2) { + switch (isotope) { + case 4: + unstabilityEXP = 1.61f; + break; + case 5: + unstabilityEXP = -7.523F; + break; + case 6: + unstabilityEXP = -1.51f; + break; + default: + unstabilityEXP = -(izoDiffAbs * 6.165F); + break; + } + } else if (element <= 83 || (isotope <= 127 && element <= 120)) { + float elementPow4 = (float) Math.pow(element, 4f); + + unstabilityEXP = Math.min(element / 2.4f, 6 + ((element + 1) % 2) * 3e6F / elementPow4) + (((float) -izoDiff * elementPow4) / 1e8F) - (Math.abs(izoDiff - 1 + element / 60F) * (3f - (element / 12.5f) + ((element * element) / 1500f))); + } else if (element < 180) { + unstabilityEXP = Math.min((element - 85) * 2, 16 + ((isotope + 1) % 2) * 2.5F - (element - 85) / 3F) - (Math.abs(izoDiff) * (3f - (element / 13f) + ((element * element) / 1600f))); + } else return -1; + if ((isotope == 127 || isotope == 128) && (element < 120 && element > 83)) unstabilityEXP -= 1.8f; + if (element > 83 && element < 93 && isotope % 2 == 0 && izoDiff == 3) unstabilityEXP += 6; + if (element > 93 && element < 103 && isotope % 2 == 0 && izoDiff == 4) unstabilityEXP += 6; + rawLifeTime = (containsAnti ? 1e-8f : 1f) * (float) (Math.pow(10F, unstabilityEXP)) * (1f + xstr.nextFloat() * 9f); + } + + if (rawLifeTime < 8e-15) return 1e-35f; + if (rawLifeTime > 8e28) return 8e30f; + return rawLifeTime; + } + + private static boolean canTheyBeTogether(cElementalDefinitionStackMap stacks) { + boolean nuclei = false; + long qty=0; + for (cElementalDefinitionStack stack : stacks.values()) { + if (stack.definition instanceof dHadronDefinition) { + if (((dHadronDefinition) stack.definition).amount != 3) return false; + nuclei = true; + } else if (!(stack.definition instanceof eLeptonDefinition)) return false; + qty+=stack.amount; + } + return nuclei && qty=iaea.energeticStatesArray.length){ + return iaea.energeticStatesArray[iaea.energeticStatesArray.length-1].Thalf/(currentEnergy-iaea.energeticStatesArray.length+1); + } + return iaea.energeticStatesArray[(int)currentEnergy].Thalf; + } + return rawLifeTime/(currentEnergy+1); + } + + @Override + public boolean isTimeSpanHalfLife() { + return true; + } + + @Override + public byte getColor() { + return -10; + } + + @Override + public String getName() { + final int element = Math.abs(this.element); + final boolean negative = element < 0; + try { + if (type != 1) return (negative ? "~? " : "? ") + nomenclature.Name[element]; + return negative ? "~" + nomenclature.Name[-element] : nomenclature.Name[element]; + } catch (Exception e) { + if (DEBUG_MODE) e.printStackTrace(); + return (negative ? "Element: ~" : "Element: ") + element; + } + } + + @Override + public String getSymbol() { + final int element = Math.abs(this.element); + final boolean negative = element < 0; + try { + return (negative ? "~" : "") + nomenclature.Symbol[element] + " N:" + neutralCount + " I:" + (neutralCount+element) + " C: " + getCharge(); + } catch (Exception e) { + if (DEBUG_MODE) e.printStackTrace(); + try { + int s100 = element / 100, s1 = (element / 10) % 10, s10 = (element) % 10; + return (negative ? "~" : "") + nomenclature.SymbolIUPAC[10 + s100] + nomenclature.SymbolIUPAC[s10] + nomenclature.SymbolIUPAC[s1] + " N:" + neutralCount + " I:" + (neutralCount+element) + " C: " + getCharge(); + } catch (Exception E) { + if (DEBUG_MODE) e.printStackTrace(); + return (negative ? "~" : "") + "? N:" + neutralCount + " I:" + (neutralCount+element) + " C: " + getCharge(); + } + } + } + + @Override + public cElementalDefinitionStackMap getSubParticles() { + return elementalStacks.clone(); + } + + @Override + public cElementalDecay[] getDecayArray() { + ArrayList decaysList=new ArrayList<>(4); + return getDecayArray(decaysList,decayMode,true); + } + + private cElementalDecay[] getDecayArray(ArrayList decaysList,int decayMode,boolean tryAnti) { + if (this.type == 1) { + switch (decayMode) { + case -2: + if(TecTech.Rnd.nextBoolean() && ElectronCapture(decaysList)) + return decaysList.toArray(new cElementalDecay[decaysList.size()]); + else if(PbetaDecay(decaysList)) + return decaysList.toArray(new cElementalDecay[decaysList.size()]); + break; + case -1: + if(Emmision(decaysList, dHadronDefinition.hadron_p1)) + return decaysList.toArray(new cElementalDecay[decaysList.size()]); + break; + case 0: + if(alphaDecay(decaysList)) + return decaysList.toArray(new cElementalDecay[decaysList.size()]); + break; + case 1: + if(Emmision(decaysList, dHadronDefinition.hadron_n1)) + return decaysList.toArray(new cElementalDecay[decaysList.size()]); + break; + case 2: + if(MbetaDecay(decaysList)) + return decaysList.toArray(new cElementalDecay[decaysList.size()]); + break; + default: + if(decayMode>8){ + if(iaeaDecay(decaysList,0)) + return decaysList.toArray(new cElementalDecay[decaysList.size()]); + return getDecayArray(decaysList,decayMode-BYTE_OFFSET,false); + } + } + return cElementalDecay.noDecay; + }else if(this.type==-1){ + dAtomDefinition anti=getAnti(); + if(anti!=null) return anti.getDecayArray(decaysList,decayMode,false); + } + return getNaturalDecayInstant(); + } + + private boolean iaeaDecay(ArrayList decaysList,long energy){ + iaeaNuclide.energeticState state; + if(energy>iaea.energeticStatesArray.length) state = iaea.energeticStatesArray[iaea.energeticStatesArray.length-1]; + else if(energy<=0) state = iaea.energeticStatesArray[0]; + else state=iaea.energeticStatesArray[(int)energy]; + for (int i=0;i0; + } + + private boolean getDecayFromIaea(ArrayList decaysList, iaeaNuclide.iaeaDecay decay, long energy){ + cElementalMutableDefinitionStackMap withThis=elementalStacks.toMutable(),newStuff=new cElementalMutableDefinitionStackMap(); + switch (decay.decayName){ + case "D": { + if (withThis.removeAllAmounts(false, deuterium.definition.getSubParticles())){ + withThis.putReplace(deuterium); + decaysList.add(new cElementalDecay(decay.chance,withThis.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + } + } break; + case "3H": { + if (withThis.removeAllAmounts(false, tritium.definition.getSubParticles())){ + withThis.putReplace(tritium); + decaysList.add(new cElementalDecay(decay.chance,withThis.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + } + } break; + case "3HE": { + if (withThis.removeAllAmounts(false, helium_3.definition.getSubParticles())){ + withThis.putReplace(helium_3); + decaysList.add(new cElementalDecay(decay.chance,withThis.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + } + } break; + case "8BE": { + if (withThis.removeAllAmounts(false, beryllium_8.definition.getSubParticles())){ + withThis.putReplace(beryllium_8); + decaysList.add(new cElementalDecay(decay.chance,withThis.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + } + } break; + case "14C": { + if (withThis.removeAllAmounts(false, carbon_14.definition.getSubParticles())){ + newStuff.putReplace(carbon_14); + try{ + newStuff.putReplace(new dAtomDefinition(withThis.toImmutable_unsafeMightLeaveExposedElementalTree()).getStackForm(1)); + decaysList.add(new cElementalDecay(decay.chance,newStuff.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "24NE": { + if (withThis.removeAllAmounts(false, neon_24.definition.getSubParticles())){ + newStuff.putReplace(neon_24); + try{ + newStuff.putReplace(new dAtomDefinition(withThis.toImmutable_unsafeMightLeaveExposedElementalTree()).getStackForm(1)); + decaysList.add(new cElementalDecay(decay.chance,newStuff.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "34SI": { + if (withThis.removeAllAmounts(false, silicon_34.definition.getSubParticles())){ + newStuff.putReplace(silicon_34); + try{ + newStuff.putReplace(new dAtomDefinition(withThis.toImmutable_unsafeMightLeaveExposedElementalTree()).getStackForm(1)); + decaysList.add(new cElementalDecay(decay.chance,newStuff.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "A": case "A?": { + if (withThis.removeAllAmounts(false, dHadronDefinition.hadron_n2,dHadronDefinition.hadron_p2)){ + newStuff.putReplace(alpha); + try{ + newStuff.putReplace(new dAtomDefinition(withThis.toImmutable_unsafeMightLeaveExposedElementalTree()).getStackForm(1)); + decaysList.add(new cElementalDecay(decay.chance,newStuff.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "B+": { + if (withThis.removeAllAmounts(false, dHadronDefinition.hadron_p1)){ + withThis.putUnify(dHadronDefinition.hadron_n1); + newStuff.putReplace(eLeptonDefinition.lepton_e_1); + newStuff.putReplace(eNeutrinoDefinition.lepton_Ve1); + try{ + newStuff.putReplace(new dAtomDefinition(withThis.toImmutable_unsafeMightLeaveExposedElementalTree()).getStackForm(1)); + decaysList.add(new cElementalDecay(decay.chance,newStuff.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "2B+": { + if (withThis.removeAllAmounts(false, dHadronDefinition.hadron_p2)){ + withThis.putUnify(dHadronDefinition.hadron_n2); + newStuff.putReplace(eLeptonDefinition.lepton_e_2); + newStuff.putReplace(eNeutrinoDefinition.lepton_Ve2); + try{ + newStuff.putReplace(new dAtomDefinition(withThis.toImmutable_unsafeMightLeaveExposedElementalTree()).getStackForm(1)); + decaysList.add(new cElementalDecay(decay.chance,newStuff.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "B-": { + if (withThis.removeAllAmounts(false, dHadronDefinition.hadron_n1)){ + withThis.putUnify(dHadronDefinition.hadron_p1); + newStuff.putReplace(eLeptonDefinition.lepton_e1); + newStuff.putReplace(eNeutrinoDefinition.lepton_Ve_1); + try{ + newStuff.putReplace(new dAtomDefinition(withThis.toImmutable_unsafeMightLeaveExposedElementalTree()).getStackForm(1)); + decaysList.add(new cElementalDecay(decay.chance,newStuff.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "2B-": { + if (withThis.removeAllAmounts(false, dHadronDefinition.hadron_n2)){ + withThis.putUnify(dHadronDefinition.hadron_p2); + newStuff.putReplace(eLeptonDefinition.lepton_e2); + newStuff.putReplace(eNeutrinoDefinition.lepton_Ve_2); + try{ + newStuff.putReplace(new dAtomDefinition(withThis.toImmutable_unsafeMightLeaveExposedElementalTree()).getStackForm(1)); + decaysList.add(new cElementalDecay(decay.chance,newStuff.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "EC": { + if (withThis.removeAllAmounts(false, dHadronDefinition.hadron_p1,eLeptonDefinition.lepton_e1)){ + withThis.putUnify(dHadronDefinition.hadron_n1); + newStuff.putReplace(eNeutrinoDefinition.lepton_Ve1); + try{ + newStuff.putReplace(new dAtomDefinition(withThis.toImmutable_unsafeMightLeaveExposedElementalTree()).getStackForm(1)); + decaysList.add(new cElementalDecay(decay.chance,newStuff.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "2EC": { + if (withThis.removeAllAmounts(false, dHadronDefinition.hadron_p2,eLeptonDefinition.lepton_e2)){ + withThis.putUnify(dHadronDefinition.hadron_n2); + newStuff.putReplace(eNeutrinoDefinition.lepton_Ve2); + try{ + newStuff.putReplace(new dAtomDefinition(withThis.toImmutable_unsafeMightLeaveExposedElementalTree()).getStackForm(1)); + decaysList.add(new cElementalDecay(decay.chance,newStuff.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "B++EC": case "EC+B+": { + if (withThis.removeAllAmounts(false, dHadronDefinition.hadron_p2,eLeptonDefinition.lepton_e1)){ + withThis.putUnify(dHadronDefinition.hadron_n2); + newStuff.putReplace(eLeptonDefinition.lepton_e_1); + newStuff.putReplace(eNeutrinoDefinition.lepton_Ve2); + try{ + newStuff.putReplace(new dAtomDefinition(withThis.toImmutable_unsafeMightLeaveExposedElementalTree()).getStackForm(1)); + decaysList.add(new cElementalDecay(decay.chance,newStuff.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "B+A": { + if (withThis.removeAllAmounts(false, dHadronDefinition.hadron_p3, dHadronDefinition.hadron_n1)){ + newStuff.putReplace(eLeptonDefinition.lepton_e_1); + newStuff.putReplace(eNeutrinoDefinition.lepton_Ve1); + newStuff.putReplace(alpha); + try{ + newStuff.putReplace(new dAtomDefinition(withThis.toImmutable_unsafeMightLeaveExposedElementalTree()).getStackForm(1)); + decaysList.add(new cElementalDecay(decay.chance,newStuff.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "B+P": { + if (withThis.removeAllAmounts(false, dHadronDefinition.hadron_p2)){ + withThis.putUnify(dHadronDefinition.hadron_n1); + newStuff.putReplace(eLeptonDefinition.lepton_e_1); + newStuff.putReplace(eNeutrinoDefinition.lepton_Ve1); + newStuff.putReplace(dHadronDefinition.hadron_p1); + try{ + newStuff.putReplace(new dAtomDefinition(withThis.toImmutable_unsafeMightLeaveExposedElementalTree()).getStackForm(1)); + decaysList.add(new cElementalDecay(decay.chance,newStuff.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "B+2P": { + if (withThis.removeAllAmounts(false, dHadronDefinition.hadron_p3)){ + withThis.putUnify(dHadronDefinition.hadron_n1); + newStuff.putReplace(eLeptonDefinition.lepton_e_1); + newStuff.putReplace(eNeutrinoDefinition.lepton_Ve1); + newStuff.putReplace(dHadronDefinition.hadron_p2); + try{ + newStuff.putReplace(new dAtomDefinition(withThis.toImmutable_unsafeMightLeaveExposedElementalTree()).getStackForm(1)); + decaysList.add(new cElementalDecay(decay.chance,newStuff.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "B-A": { + if (withThis.removeAllAmounts(false, dHadronDefinition.hadron_n3, dHadronDefinition.hadron_p1)){ + newStuff.putReplace(eLeptonDefinition.lepton_e1); + newStuff.putReplace(eNeutrinoDefinition.lepton_Ve_1); + newStuff.putReplace(alpha); + try{ + newStuff.putReplace(new dAtomDefinition(withThis.toImmutable_unsafeMightLeaveExposedElementalTree()).getStackForm(1)); + decaysList.add(new cElementalDecay(decay.chance,newStuff.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "B-N": { + if (withThis.removeAllAmounts(false, dHadronDefinition.hadron_n2)){ + withThis.putUnify(dHadronDefinition.hadron_p1); + newStuff.putReplace(eLeptonDefinition.lepton_e1); + newStuff.putReplace(eNeutrinoDefinition.lepton_Ve_1); + newStuff.putReplace(dHadronDefinition.hadron_n1); + try{ + newStuff.putReplace(new dAtomDefinition(withThis.toImmutable_unsafeMightLeaveExposedElementalTree()).getStackForm(1)); + decaysList.add(new cElementalDecay(decay.chance,newStuff.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "B-2N": { + if (withThis.removeAllAmounts(false, dHadronDefinition.hadron_n3)){ + withThis.putUnify(dHadronDefinition.hadron_p1); + newStuff.putReplace(eLeptonDefinition.lepton_e1); + newStuff.putReplace(eNeutrinoDefinition.lepton_Ve_1); + newStuff.putReplace(dHadronDefinition.hadron_n2); + try{ + newStuff.putReplace(new dAtomDefinition(withThis.toImmutable_unsafeMightLeaveExposedElementalTree()).getStackForm(1)); + decaysList.add(new cElementalDecay(decay.chance,newStuff.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "B-P": { + if (withThis.removeAllAmounts(false, dHadronDefinition.hadron_n1)){ + newStuff.putReplace(eLeptonDefinition.lepton_e1); + newStuff.putReplace(eNeutrinoDefinition.lepton_Ve_1); + newStuff.putReplace(dHadronDefinition.hadron_p1); + try{ + newStuff.putReplace(new dAtomDefinition(withThis.toImmutable_unsafeMightLeaveExposedElementalTree()).getStackForm(1)); + decaysList.add(new cElementalDecay(decay.chance,newStuff.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "ECA": { + if (withThis.removeAllAmounts(false, dHadronDefinition.hadron_n1,eLeptonDefinition.lepton_e1,dHadronDefinition.hadron_p3)){ + newStuff.putReplace(eNeutrinoDefinition.lepton_Ve1); + newStuff.putReplace(alpha); + try{ + newStuff.putReplace(new dAtomDefinition(withThis.toImmutable_unsafeMightLeaveExposedElementalTree()).getStackForm(1)); + decaysList.add(new cElementalDecay(decay.chance,newStuff.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "ECP": { + if (withThis.removeAllAmounts(false, eLeptonDefinition.lepton_e1,dHadronDefinition.hadron_p2)){ + withThis.putUnify(dHadronDefinition.hadron_n1); + newStuff.putReplace(eNeutrinoDefinition.lepton_Ve1); + newStuff.putReplace(dHadronDefinition.hadron_p1); + try{ + newStuff.putReplace(new dAtomDefinition(withThis.toImmutable_unsafeMightLeaveExposedElementalTree()).getStackForm(1)); + decaysList.add(new cElementalDecay(decay.chance,newStuff.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "EC2P": { + if (withThis.removeAllAmounts(false, eLeptonDefinition.lepton_e1,dHadronDefinition.hadron_p3)){ + withThis.putUnify(dHadronDefinition.hadron_n1); + newStuff.putReplace(eNeutrinoDefinition.lepton_Ve1); + newStuff.putReplace(dHadronDefinition.hadron_p2); + try{ + newStuff.putReplace(new dAtomDefinition(withThis.toImmutable_unsafeMightLeaveExposedElementalTree()).getStackForm(1)); + decaysList.add(new cElementalDecay(decay.chance,newStuff.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "ECP+EC2P": {//todo look at branching ratios + if (withThis.removeAllAmounts(false, eLeptonDefinition.lepton_e2,dHadronDefinition.hadron_p5)){ + withThis.putUnify(dHadronDefinition.hadron_n1); + newStuff.putReplace(eNeutrinoDefinition.lepton_Ve2); + newStuff.putReplace(dHadronDefinition.hadron_p3); + try{ + newStuff.putReplace(new dAtomDefinition(withThis.toImmutable_unsafeMightLeaveExposedElementalTree()).getStackForm(1)); + decaysList.add(new cElementalDecay(decay.chance,newStuff.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "N": { + if (withThis.removeAllAmounts(false, dHadronDefinition.hadron_n1)){ + newStuff.putReplace(dHadronDefinition.hadron_n1); + try{ + newStuff.putReplace(new dAtomDefinition(withThis.toImmutable_unsafeMightLeaveExposedElementalTree()).getStackForm(1)); + decaysList.add(new cElementalDecay(decay.chance,newStuff.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "2N": { + if (withThis.removeAllAmounts(false, dHadronDefinition.hadron_n2)){ + newStuff.putReplace(dHadronDefinition.hadron_n2); + try{ + newStuff.putReplace(new dAtomDefinition(withThis.toImmutable_unsafeMightLeaveExposedElementalTree()).getStackForm(1)); + decaysList.add(new cElementalDecay(decay.chance,newStuff.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "P": { + if (withThis.removeAllAmounts(false, dHadronDefinition.hadron_p1)){ + newStuff.putReplace(dHadronDefinition.hadron_p1); + try{ + newStuff.putReplace(new dAtomDefinition(withThis.toImmutable_unsafeMightLeaveExposedElementalTree()).getStackForm(1)); + decaysList.add(new cElementalDecay(decay.chance,newStuff.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "2P": { + if (withThis.removeAllAmounts(false, dHadronDefinition.hadron_p2)){ + newStuff.putReplace(dHadronDefinition.hadron_p2); + try{ + newStuff.putReplace(new dAtomDefinition(withThis.toImmutable_unsafeMightLeaveExposedElementalTree()).getStackForm(1)); + decaysList.add(new cElementalDecay(decay.chance,newStuff.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "SF": + if(Fission(decaysList,withThis,newStuff,decay.chance,false)) return true; + case "B-F": { + if (withThis.removeAllAmounts(false, dHadronDefinition.hadron_n1)){ + withThis.putUnify(dHadronDefinition.hadron_p1); + newStuff.putReplace(eLeptonDefinition.lepton_e1); + newStuff.putReplace(eNeutrinoDefinition.lepton_Ve_1); + try{ + if(Fission(decaysList,withThis,newStuff,decay.chance,false)) return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "ECF": case "ECSF": case "EC(+SF)": { + if (withThis.removeAllAmounts(false, dHadronDefinition.hadron_p1,eLeptonDefinition.lepton_e1)){ + withThis.putUnify(dHadronDefinition.hadron_n1); + newStuff.putReplace(eNeutrinoDefinition.lepton_Ve1); + try{ + if(Fission(decaysList,withThis,newStuff,decay.chance,false)) return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "SF(+EC+B+)": case "SF+EC+B+": { + if (withThis.removeAllAmounts(false, dHadronDefinition.hadron_p2,eLeptonDefinition.lepton_e1)){ + withThis.putUnify(dHadronDefinition.hadron_n2); + newStuff.putReplace(eLeptonDefinition.lepton_e_1); + newStuff.putReplace(eNeutrinoDefinition.lepton_Ve2); + try{ + if(Fission(decaysList,withThis,newStuff,decay.chance,false)) return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "SF+EC+B-": { + if (withThis.removeAllAmounts(false, eLeptonDefinition.lepton_e1)){ + newStuff.putReplace(eLeptonDefinition.lepton_e1); + newStuff.putReplace(eNeutrinoDefinition.lepton_Ve1); + newStuff.putReplace(eNeutrinoDefinition.lepton_Ve_1); + try{ + if(Fission(decaysList,withThis,newStuff,decay.chance,false)) return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "IT": case "IT?": case "G": { + if(energy>0){ + decaysList.add(new cElementalDecay(decay.chance, this, eBosonDefinition.boson_Y__)); + return true; + }else{ + if(DEBUG_MODE) TecTech.Logger.info("Tried to emit Gamma from ground state"); + decaysList.add(new cElementalDecay(decay.chance, this)); + return true; + } + } //break; + case "IT+EC+B+": { + if (withThis.removeAllAmounts(false, dHadronDefinition.hadron_p2,eLeptonDefinition.lepton_e1)){ + withThis.putUnify(dHadronDefinition.hadron_n2); + newStuff.putReplace(eLeptonDefinition.lepton_e_1); + newStuff.putReplace(eNeutrinoDefinition.lepton_Ve2); + newStuff.putReplace(eBosonDefinition.boson_Y__1); + try{ + newStuff.putReplace(new dAtomDefinition(withThis.toImmutable_unsafeMightLeaveExposedElementalTree()).getStackForm(1)); + decaysList.add(new cElementalDecay(decay.chance,newStuff.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + }catch (Exception e){ + if(DEBUG_MODE) e.printStackTrace(); + } + } + } break; + case "DEAD_END": + decaysList.add(deadEnd); + return true; + default: throw new Error("Unsupported decay mode: " + decay.decayName + " "+ neutralCount+" "+element); + } + if(DEBUG_MODE) TecTech.Logger.info("Failed to decay "+element+" "+neutralCount+" "+decay.decayName); + return false; + } + + private boolean Emmision(ArrayList decaysList, cElementalDefinitionStack emit) { + final cElementalMutableDefinitionStackMap tree = elementalStacks.toMutable(); + if (tree.removeAmount(false, emit)) { + try { + decaysList.add(new cElementalDecay((float) 1, new cElementalDefinitionStack(new dAtomDefinition(tree.toImmutable_unsafeMightLeaveExposedElementalTree()), 1), emit)); + return true; + } catch (Exception e) { + if (DEBUG_MODE) e.printStackTrace(); + } + } + return false; + } + + private boolean alphaDecay(ArrayList decaysList) { + final cElementalMutableDefinitionStackMap tree = elementalStacks.toMutable(); + if (tree.removeAllAmounts(false, alpha.definition.getSubParticles())) { + try { + decaysList.add(new cElementalDecay((float) 1, new cElementalDefinitionStack(new dAtomDefinition(tree.toImmutable_unsafeMightLeaveExposedElementalTree()), 1), alpha)); + return true; + } catch (Exception e) { + if (DEBUG_MODE) e.printStackTrace(); + } + } + return false; + } + + private boolean MbetaDecay(ArrayList decaysList) { + final cElementalMutableDefinitionStackMap tree = elementalStacks.toMutable(); + if (tree.removeAmount(false, dHadronDefinition.hadron_n1)) { + try { + tree.putUnify(dHadronDefinition.hadron_p1); + decaysList.add(new cElementalDecay((float) 1, new cElementalDefinitionStack(new dAtomDefinition(tree.toImmutable_unsafeMightLeaveExposedElementalTree()), 1), eLeptonDefinition.lepton_e1, eNeutrinoDefinition.lepton_Ve_1)); + return true; + } catch (Exception e) { + if (DEBUG_MODE) e.printStackTrace(); + } + } + return false; + } + + private boolean PbetaDecay(ArrayList decaysList) { + final cElementalMutableDefinitionStackMap tree = elementalStacks.toMutable(); + if (tree.removeAmount(false, dHadronDefinition.hadron_p1)) { + try { + tree.putUnify(dHadronDefinition.hadron_n1); + decaysList.add(new cElementalDecay((float) 1, new cElementalDefinitionStack(new dAtomDefinition(tree.toImmutable_unsafeMightLeaveExposedElementalTree()), 1), eLeptonDefinition.lepton_e_1, eNeutrinoDefinition.lepton_Ve1)); + return true; + } catch (Exception e) { + if (DEBUG_MODE) e.printStackTrace(); + } + } + return false; + } + + private boolean ElectronCapture(ArrayList decaysList) { + final cElementalMutableDefinitionStackMap tree = elementalStacks.toMutable(); + if (tree.removeAllAmounts(false, dHadronDefinition.hadron_p1,eLeptonDefinition.lepton_e1)) { + try { + tree.putUnify(dHadronDefinition.hadron_n1); + decaysList.add(new cElementalDecay((float) 1, new cElementalDefinitionStack(new dAtomDefinition(tree.toImmutable_unsafeMightLeaveExposedElementalTree()), 1), eNeutrinoDefinition.lepton_Ve1)); + return true; + } catch (Exception e) { + if (DEBUG_MODE) e.printStackTrace(); + } + } + return false; + } + + private boolean Fission(ArrayList decaysList, cElementalMutableDefinitionStackMap fissile, cElementalMutableDefinitionStackMap particles,float probability,boolean spontaneousCheck) { + final cElementalMutableDefinitionStackMap heavy = new cElementalMutableDefinitionStackMap(); + final double[] liquidDrop=liquidDropFunction(Math.abs(element)<=97); + + for(cElementalDefinitionStack stack: fissile.values()){ + if(spontaneousCheck && stack.definition instanceof dHadronDefinition && + (stack.amount<=80 || (stack.amount<90 && XSTR_INSTANCE.nextInt(10)XSTR_INSTANCE.nextDouble()?1:0; + particles.putUnify(new cElementalDefinitionStack(stack.definition, neutrals_cnt)); + + int heavy_cnt=(int)Math.ceil(stack.amount*liquidDrop[1]); + while(heavy_cnt+neutrals_cnt>stack.amount) + heavy_cnt--; + fissile.removeAmount(false,new cElementalDefinitionStack(stack.definition,heavy_cnt+neutrals_cnt)); + heavy.putReplace(new cElementalDefinitionStack(stack.definition, heavy_cnt)); + //}else{ + // particles.add(stack); + // light.remove(stack.definition); + //} + }else{ + int heavy_cnt=(int)Math.ceil(stack.amount*liquidDrop[0]); + if(heavy_cnt%2==1 && XSTR_INSTANCE.nextFloat()>0.05f) + heavy_cnt--; + cElementalDefinitionStack new_stack=new cElementalDefinitionStack(stack.definition, heavy_cnt); + fissile.removeAmount(false,new_stack); + heavy.putReplace(new_stack); + } + } + + try { + particles.putReplace(new cElementalDefinitionStack(new dAtomDefinition(fissile.toImmutable_unsafeMightLeaveExposedElementalTree()),1)); + particles.putReplace(new cElementalDefinitionStack(new dAtomDefinition(heavy.toImmutable_unsafeMightLeaveExposedElementalTree()),1)); + decaysList.add(new cElementalDecay(probability, particles.toImmutable_unsafeMightLeaveExposedElementalTree())); + return true; + } catch (Exception e) { + if(DEBUG_MODE) e.printStackTrace(); + } + return false; + } + + private static double[] liquidDropFunction(boolean asymmetric) { + double[] out = new double[3]; + + out[0] = XSTR_INSTANCE.nextGaussian(); + + if (out[0] < 1 && out[0] >= -1) + if (XSTR_INSTANCE.nextBoolean()) + out[0] = XSTR_INSTANCE.nextDouble() * 2d - 1d; + + if (asymmetric && out[0] > XSTR_INSTANCE.nextDouble() && XSTR_INSTANCE.nextInt(4) == 0) + out[0] = -out[0]; + + //scale to splitting ratio + out[0] = out[0] * 0.05d + .6d; + + if (out[0] < 0 || out[0] > 1) + return liquidDropFunction(asymmetric); + if (out[0] < .5d) + out[0] = 1d - out[0]; + + //extra neutrals + out[2] = 0.012d + XSTR_INSTANCE.nextDouble() * 0.01d; + + if (asymmetric) + out[1] = out[0]; + else + out[1] = out[0] - out[2] * .5d; + + return out; + } + + @Override + public cElementalDecay[] getEnergyInducedDecay(long energyLevel) { + if (iaeaDefinitionExistsAndHasEnergyLevels) { + ArrayList decays=new ArrayList<>(4); + if(iaeaDecay(decays,energyLevel)){ + return decays.toArray(new cElementalDecay[decays.size()]); + } + } + if(energyLevel< Math.abs(charge)/3+neutralCount) { + return new cElementalDecay[]{new cElementalDecay(1, this, eBosonDefinition.boson_Y__)}; + } + return getNaturalDecayInstant(); + } + + @Override + public float getEnergyDiffBetweenStates(long currentEnergyLevel,long newEnergyLevel) { + if(iaeaDefinitionExistsAndHasEnergyLevels){ + float result=0; + boolean backwards=newEnergyLevel=iaea.energeticStatesArray.length){ + if(currentEnergyLevel>=iaea.energeticStatesArray.length) return DEFAULT_ENERGY_REQUIREMENT*(newEnergyLevel-currentEnergyLevel); + else result+=DEFAULT_ENERGY_REQUIREMENT*(newEnergyLevel-iaea.energeticStatesArray.length+1); + result+=iaea.energeticStatesArray[iaea.energeticStatesArray.length-1].energy; + }else result+=iaea.energeticStatesArray[(int)Math.max(0,newEnergyLevel)].energy; + + return backwards?-result:result; + } + return DEFAULT_ENERGY_REQUIREMENT*(newEnergyLevel-currentEnergyLevel); + } + + @Override + public boolean usesSpecialEnergeticDecayHandling() { + return iaeaDefinitionExistsAndHasEnergyLevels; + } + + @Override + public cElementalDecay[] getNaturalDecayInstant() { + //disembody + ArrayList decaysInto = new ArrayList<>(); + for (cElementalDefinitionStack elementalStack : elementalStacks.values()) { + if (elementalStack.definition.getType() == 1 || elementalStack.definition.getType() == -1) { + //covers both quarks and antiquarks + decaysInto.add(elementalStack); + } else { + //covers both quarks and antiquarks + decaysInto.add(new cElementalDefinitionStack(boson_Y__, 2)); + } + } + return new cElementalDecay[]{new cElementalDecay(0.75F, decaysInto.toArray(new cElementalDefinitionStack[decaysInto.size()])), eBosonDefinition.deadEnd}; + } + + //@Override + //public iElementalDefinition getAnti() { + // cElementalDefinitionStack[] stacks = this.elementalStacks.values(); + // cElementalDefinitionStack[] antiElements = new cElementalDefinitionStack[stacks.length]; + // for (int i = 0; i < antiElements.length; i++) { + // antiElements[i] = new cElementalDefinitionStack(stacks[i].definition.getAnti(), stacks[i].amount); + // } + // try { + // return new dAtomDefinition(false, antiElements); + // } catch (tElementalException e) { + // if (DEBUG_MODE) e.printStackTrace(); + // return null; + // } + //} + + @Override + public dAtomDefinition getAnti() { + cElementalMutableDefinitionStackMap anti = new cElementalMutableDefinitionStackMap(); + for (cElementalDefinitionStack stack : elementalStacks.values()) + anti.putReplace(new cElementalDefinitionStack(stack.definition.getAnti(), stack.amount)); + try { + return new dAtomDefinition(anti.toImmutable_unsafeMightLeaveExposedElementalTree()); + } catch (tElementalException e) { + if (DEBUG_MODE) e.printStackTrace(); + return null; + } + } + + @Override + public aFluidDequantizationInfo someAmountIntoFluidStack() { + return transformation.fluidDequantization.get(this); + } + + @Override + public aItemDequantizationInfo someAmountIntoItemsStack() { + return null; + } + + @Override + public aOredictDequantizationInfo someAmountIntoOredictStack() { + return transformation.oredictDequantization.get(this); + } + + private final static class nomenclature { + private nomenclature(){} + static final private String[] Symbol = new String[]{"Nt", "H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na", "Mg", "Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca", "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr", "Rb", "Sr", "Y", "Zr", "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn", "Sb", "Te", "I", "Xe", "Cs", "Ba", "La", "Ce", "Pr", "Nd", "Pm", "Sm", "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb", "Lu", "Hf", "Ta", "W", "Re", "Os", "Ir", "Pt", "Au", "Hg", "Tl", "Pb", "Bi", "Po", "At", "Rn", "Fr", "Ra", "Ac", "Th", "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm", "Md", "No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ds", "Rg", "Cn", "Nh", "Fl", "Mc", "Lv", "Ts", "Og"}; + static final private String[] Name = new String[]{"Neutronium", "Hydrogen", "Helium", "Lithium", "Beryllium", "Boron", "Carbon", "Nitrogen", "Oxygen", "Fluorine", "Neon", "Sodium", "Magnesium", "Aluminium", "Silicon", "Phosphorus", "Sulfur", "Chlorine", "Argon", "Potassium", "Calcium", "Scandium", "Titanium", "Vanadium", "Chromium", "Manganese", "Iron", "Cobalt", "Nickel", "Copper", "Zinc", "Gallium", "Germanium", "Arsenic", "Selenium", "Bromine", "Krypton", "Rubidium", "Strontium", "Yttrium", "Zirconium", "Niobium", "Molybdenum", "Technetium", "Ruthenium", "Rhodium", "Palladium", "Silver", "Cadmium", "Indium", "Tin", "Antimony", "Tellurium", "Iodine", "Xenon", "Caesium", "Barium", "Lanthanum", "Cerium", "Praseodymium", "Neodymium", "Promethium", "Samarium", "Europium", "Gadolinium", "Terbium", "Dysprosium", "Holmium", "Erbium", "Thulium", "Ytterbium", "Lutetium", "Hafnium", "Tantalum", "Tungsten", "Rhenium", "Osmium", "Iridium", "Platinum", "Gold", "Mercury", "Thallium", "Lead", "Bismuth", "Polonium", "Astatine", "Radon", "Francium", "Radium", "Actinium", "Thorium", "Protactinium", "Uranium", "Neptunium", "Plutonium", "Americium", "Curium", "Berkelium", "Californium", "Einsteinium", "Fermium", "Mendelevium", "Nobelium", "Lawrencium", "Rutherfordium", "Dubnium", "Seaborgium", "Bohrium", "Hassium", "Meitnerium", "Darmstadtium", "Roentgenium", "Copernicium", "Nihonium", "Flerovium", "Moscovium", "Livermorium", "Tennessine", "Oganesson"}; + static final private String[] SymbolIUPAC = new String[]{"n", "u", "b", "t", "q", "p", "h", "s", "o", "e", "N", "U", "B", "T", "Q", "P", "H", "S", "O", "E"}; + } + + @Override + public NBTTagCompound toNBT() { + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setByte("t", nbtType); + cElementalDefinitionStack[] elementalStacksValues = elementalStacks.values(); + nbt.setInteger("i", elementalStacksValues.length); + for (int i = 0; i < elementalStacksValues.length; i++) + nbt.setTag(Integer.toString(i), elementalStacksValues[i].toNBT()); + return nbt; + } + + public static iElementalDefinition fromNBT(NBTTagCompound nbt) { + cElementalDefinitionStack[] stacks = new cElementalDefinitionStack[nbt.getInteger("i")]; + for (int i = 0; i < stacks.length; i++) + stacks[i] = cElementalDefinitionStack.fromNBT(nbt.getCompoundTag(Integer.toString(i))); + try { + return new dAtomDefinition(stacks); + } catch (tElementalException e) { + if (DEBUG_MODE) e.printStackTrace(); + return null; + } + } + + public static void run() { + for (Runnable r : overrides) r.run(); + + for(Map.Entry entry:lifetimeOverrides.entrySet()){ + try { + lifetimeOverrides.put(new dAtomDefinition(entry.getKey().elementalStacks), entry.getValue()); + }catch (tElementalException e){ + e.printStackTrace(); //Impossible + } + } + + //populate stable isotopes + for (int element = 1; element < 83; element++)//Up to Bismuth exclusive + for (int isotope = 0; isotope < 130; isotope++) { + xstr.setSeed((long) (element + 1) * (isotope + 100)); + //stability curve + final int StableIsotope = stableIzoCurve(element); + final int izoDiff = isotope - StableIsotope; + final int izoDiffAbs = Math.abs(izoDiff); + final float rawLifeTime = calculateLifeTime(izoDiff, izoDiffAbs, element, isotope, false); + iaeaNuclide nuclide=iaeaNuclide.get(element,isotope); + if (rawLifeTime>= STABLE_RAW_LIFE_TIME || (nuclide