From 3dcc0761ab6247cb20dbe16a83e19abe675a13ed Mon Sep 17 00:00:00 2001 From: Tec Date: Tue, 18 Jan 2022 21:57:53 +0100 Subject: Cleanup serialization of EM (cherry picked from commit 44c86af58ecb24de8ba66fa6cf8fa81324a32a28) --- .../entity/projectiles/projectileEM.java | 4 +- .../definitions/EMComplexAspectDefinition.java | 30 +-- .../definitions/EMPrimalAspectDefinition.java | 4 +- .../transformations/AspectDefinitionCompat.java | 2 +- .../AspectDefinitionCompatEnabled.java | 4 +- .../thing/metaTileEntity/multi/EssentiaCompat.java | 2 +- .../multi/EssentiaCompatEnabled.java | 2 +- .../GT_MetaTileEntity_EM_essentiaQuantizer.java | 2 +- .../technus/tectech/loader/ElementalLoader.java | 3 - .../elementalMatter/core/EMException.java | 17 +- .../elementalMatter/core/commands/EMGive.java | 15 +- .../elementalMatter/core/commands/EMList.java | 14 +- .../elementalMatter/core/decay/EMDecay.java | 2 +- .../core/definitions/EMComplexTemplate.java | 73 ++++++ .../core/definitions/EMDefinitionsRegistry.java | 110 ++++++++ .../core/definitions/EMPrimitiveTemplate.java | 243 ++++++++++++++++++ .../core/definitions/IEMDefinition.java | 85 +++++++ .../core/maps/EMConstantStackMap.java | 2 +- .../core/maps/EMDefinitionStackMap.java | 2 +- .../core/maps/EMInstanceStackMap.java | 2 +- .../elementalMatter/core/maps/EMStackMap.java | 2 +- .../elementalMatter/core/maps/IEMMapRead.java | 39 ++- .../elementalMatter/core/maps/IEMMapWrite.java | 2 +- .../core/maps/IEMMapWriteExact.java | 2 +- .../core/stacks/EMDefinitionStack.java | 6 +- .../core/stacks/EMInstanceStack.java | 7 +- .../elementalMatter/core/stacks/IEMStack.java | 2 +- .../elementalMatter/core/templates/EMComplex.java | 135 ---------- .../core/templates/EMPrimitive.java | 283 --------------------- .../core/templates/IEMDefinition.java | 84 ------ .../core/transformations/EMTransformationInfo.java | 25 +- .../definitions/complex/EMAtomDefinition.java | 34 +-- .../definitions/complex/EMHadronDefinition.java | 50 ++-- .../definitions/complex/EMNuclideIAEA.java | 2 +- .../definitions/primitive/EMBosonDefinition.java | 4 +- .../definitions/primitive/EMLeptonDefinition.java | 4 +- .../primitive/EMNeutrinoDefinition.java | 4 +- .../primitive/EMPrimitiveDefinition.java | 10 +- .../definitions/primitive/EMQuarkDefinition.java | 4 +- .../github/technus/tectech/recipe/TT_recipe.java | 6 +- .../technus/tectech/recipe/TT_recipeAdder.java | 2 +- .../item/DebugElementalInstanceContainer_EM.java | 7 +- .../multi/GT_MetaTileEntity_EM_collider.java | 10 +- .../multi/GT_MetaTileEntity_EM_dequantizer.java | 2 +- .../multi/GT_MetaTileEntity_EM_quantizer.java | 4 +- 45 files changed, 692 insertions(+), 656 deletions(-) create mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/definitions/EMComplexTemplate.java create mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/definitions/EMDefinitionsRegistry.java create mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/definitions/EMPrimitiveTemplate.java create mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/definitions/IEMDefinition.java delete mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/templates/EMComplex.java delete mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/templates/EMPrimitive.java delete mode 100644 src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/templates/IEMDefinition.java (limited to 'src') diff --git a/src/main/java/com/github/technus/tectech/compatibility/openmodularturrets/entity/projectiles/projectileEM.java b/src/main/java/com/github/technus/tectech/compatibility/openmodularturrets/entity/projectiles/projectileEM.java index d594a826bc..785b59f093 100644 --- a/src/main/java/com/github/technus/tectech/compatibility/openmodularturrets/entity/projectiles/projectileEM.java +++ b/src/main/java/com/github/technus/tectech/compatibility/openmodularturrets/entity/projectiles/projectileEM.java @@ -52,10 +52,10 @@ public class projectileEM extends LaserProjectile { charge=projectileContent.getCharge(); massFactor =(float) (projectileContent.getDefinition().getMass()/ EMHadronDefinition.hadron_n_.getMass()); - if(projectileContent.getDefinition().getType()>1 || projectileContent.getDefinition().getType()<-1) { + if(projectileContent.getDefinition().getMatterType()>1 || projectileContent.getDefinition().getMatterType()<-1) { strange = true; } - if(projectileContent.getDefinition().getType()<0) { + if(projectileContent.getDefinition().getMatterType()<0) { antiMatter = true; } diff --git a/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/elementalMatter/definitions/EMComplexAspectDefinition.java b/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/elementalMatter/definitions/EMComplexAspectDefinition.java index 432d151b80..e56e31f166 100644 --- a/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/elementalMatter/definitions/EMComplexAspectDefinition.java +++ b/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/elementalMatter/definitions/EMComplexAspectDefinition.java @@ -2,13 +2,14 @@ package com.github.technus.tectech.compatibility.thaumcraft.elementalMatter.defi import com.github.technus.tectech.TecTech; import com.github.technus.tectech.compatibility.thaumcraft.elementalMatter.transformations.AspectDefinitionCompat; +import com.github.technus.tectech.mechanics.elementalMatter.core.definitions.EMDefinitionsRegistry; import com.github.technus.tectech.util.Util; import com.github.technus.tectech.mechanics.elementalMatter.core.decay.EMDecay; import com.github.technus.tectech.mechanics.elementalMatter.core.maps.EMConstantStackMap; import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.EMDefinitionStack; import com.github.technus.tectech.mechanics.elementalMatter.core.EMException; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.EMComplex; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.IEMDefinition; +import com.github.technus.tectech.mechanics.elementalMatter.core.definitions.EMComplexTemplate; +import com.github.technus.tectech.mechanics.elementalMatter.core.definitions.IEMDefinition; import com.github.technus.tectech.mechanics.elementalMatter.core.transformations.EMFluidDequantizationInfo; import com.github.technus.tectech.mechanics.elementalMatter.core.transformations.EMItemDequantizationInfo; import com.github.technus.tectech.mechanics.elementalMatter.core.transformations.EMOredictDequantizationInfo; @@ -25,7 +26,7 @@ import static net.minecraft.util.StatCollector.translateToLocal; /** * Created by Tec on 06.05.2017. */ -public final class EMComplexAspectDefinition extends EMComplex { +public final class EMComplexAspectDefinition extends EMComplexTemplate { private final int hash; private final double mass; @@ -123,19 +124,8 @@ public final class EMComplexAspectDefinition extends EMComplex { } @Override - public NBTTagCompound toNBT() { - return getNbtTagCompound(nbtType, aspectStacks); - } - - public static NBTTagCompound getNbtTagCompound(byte nbtType, EMConstantStackMap aspectStacks) { - NBTTagCompound nbt = new NBTTagCompound(); - nbt.setByte("t", nbtType); - EMDefinitionStack[] quarkStacksValues = aspectStacks.valuesToArray(); - nbt.setInteger("i", quarkStacksValues.length); - for (int i = 0; i < quarkStacksValues.length; i++) { - nbt.setTag(Integer.toString(i), quarkStacksValues[i].toNBT()); - } - return nbt; + protected int getIndirectTagValue() { + return nbtType; } public static EMComplexAspectDefinition fromNBT(NBTTagCompound nbt) { @@ -169,7 +159,7 @@ public final class EMComplexAspectDefinition extends EMComplex { } @Override - public byte getType() { + public byte getMatterType() { return 0; } @@ -250,20 +240,20 @@ public final class EMComplexAspectDefinition extends EMComplex { public static void run() { try { - EMComplex.addCreatorFromNBT(nbtType, EMComplexAspectDefinition.class.getMethod("fromNBT", NBTTagCompound.class), (byte) -96); + EMDefinitionsRegistry.registerDefinitionClass(nbtType, EMComplexAspectDefinition::fromNBT,EMComplexAspectDefinition.class, getClassTypeStatic()); } catch (Exception e) { if (DEBUG_MODE) { e.printStackTrace(); } } if (DEBUG_MODE) { - TecTech.LOGGER.info("Registered Elemental Matter Class: ComplexAspect " + nbtType + ' ' + -96); + TecTech.LOGGER.info("Registered Elemental Matter Class: ComplexAspect " + nbtType + ' ' + getClassTypeStatic()); } } @Override public byte getClassType() { - return -96; + return getClassTypeStatic(); } public static byte getClassTypeStatic() { diff --git a/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/elementalMatter/definitions/EMPrimalAspectDefinition.java b/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/elementalMatter/definitions/EMPrimalAspectDefinition.java index bf9703d6d7..e62c2e5278 100644 --- a/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/elementalMatter/definitions/EMPrimalAspectDefinition.java +++ b/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/elementalMatter/definitions/EMPrimalAspectDefinition.java @@ -1,6 +1,6 @@ package com.github.technus.tectech.compatibility.thaumcraft.elementalMatter.definitions; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.EMPrimitive; +import com.github.technus.tectech.mechanics.elementalMatter.core.definitions.EMPrimitiveTemplate; import static com.github.technus.tectech.mechanics.elementalMatter.core.decay.EMDecay.NO_DECAY; import static net.minecraft.util.StatCollector.translateToLocal; @@ -8,7 +8,7 @@ import static net.minecraft.util.StatCollector.translateToLocal; /** * Created by Tec on 06.05.2017. */ -public final class EMPrimalAspectDefinition extends EMPrimitive { +public final class EMPrimalAspectDefinition extends EMPrimitiveTemplate { public static final EMPrimalAspectDefinition magic_air = new EMPrimalAspectDefinition(translateToLocal("tt.keyword.Air"), "a`", 1e1D, 35), magic_earth = new EMPrimalAspectDefinition(translateToLocal("tt.keyword.Earth"), "e`", 1e9D, 34), diff --git a/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/elementalMatter/transformations/AspectDefinitionCompat.java b/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/elementalMatter/transformations/AspectDefinitionCompat.java index c7f38eb21d..a4328d2e03 100644 --- a/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/elementalMatter/transformations/AspectDefinitionCompat.java +++ b/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/elementalMatter/transformations/AspectDefinitionCompat.java @@ -1,7 +1,7 @@ package com.github.technus.tectech.compatibility.thaumcraft.elementalMatter.transformations; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.IEMDefinition; +import com.github.technus.tectech.mechanics.elementalMatter.core.definitions.IEMDefinition; import java.util.HashMap; diff --git a/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/elementalMatter/transformations/AspectDefinitionCompatEnabled.java b/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/elementalMatter/transformations/AspectDefinitionCompatEnabled.java index c9ca5d7b9f..ead8a5fdef 100644 --- a/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/elementalMatter/transformations/AspectDefinitionCompatEnabled.java +++ b/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/elementalMatter/transformations/AspectDefinitionCompatEnabled.java @@ -2,13 +2,13 @@ package com.github.technus.tectech.compatibility.thaumcraft.elementalMatter.tran import com.github.technus.tectech.compatibility.thaumcraft.elementalMatter.definitions.EMComplexAspectDefinition; import com.github.technus.tectech.mechanics.elementalMatter.core.EMException; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.IEMDefinition; +import com.github.technus.tectech.mechanics.elementalMatter.core.definitions.IEMDefinition; import thaumcraft.api.aspects.Aspect; import java.util.ArrayList; import static com.github.technus.tectech.compatibility.thaumcraft.elementalMatter.definitions.EMPrimalAspectDefinition.*; -import static com.github.technus.tectech.thing.item.DebugElementalInstanceContainer_EM.STACKS_REGISTERED; +import static com.github.technus.tectech.mechanics.elementalMatter.core.definitions.EMDefinitionsRegistry.STACKS_REGISTERED; /** * Created by Tec on 21.05.2017. diff --git a/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/EssentiaCompat.java b/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/EssentiaCompat.java index d51bc8dc2d..35d3a1b91f 100644 --- a/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/EssentiaCompat.java +++ b/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/EssentiaCompat.java @@ -1,6 +1,6 @@ package com.github.technus.tectech.compatibility.thaumcraft.thing.metaTileEntity.multi; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.IEMDefinition; +import com.github.technus.tectech.mechanics.elementalMatter.core.definitions.IEMDefinition; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; import net.minecraft.tileentity.TileEntity; diff --git a/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/EssentiaCompatEnabled.java b/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/EssentiaCompatEnabled.java index ab682ba1a5..37df2c48cc 100644 --- a/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/EssentiaCompatEnabled.java +++ b/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/EssentiaCompatEnabled.java @@ -1,6 +1,6 @@ package com.github.technus.tectech.compatibility.thaumcraft.thing.metaTileEntity.multi; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.IEMDefinition; +import com.github.technus.tectech.mechanics.elementalMatter.core.definitions.IEMDefinition; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; import net.minecraft.tileentity.TileEntity; import thaumcraft.api.aspects.Aspect; diff --git a/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_essentiaQuantizer.java b/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_essentiaQuantizer.java index 5606442c37..5fe8c973fe 100644 --- a/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_essentiaQuantizer.java +++ b/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_essentiaQuantizer.java @@ -5,7 +5,7 @@ import com.github.technus.tectech.compatibility.thaumcraft.elementalMatter.defin import com.github.technus.tectech.mechanics.constructable.IConstructable; import com.github.technus.tectech.mechanics.elementalMatter.core.maps.EMInstanceStackMap; import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.EMInstanceStack; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.IEMDefinition; +import com.github.technus.tectech.mechanics.elementalMatter.core.definitions.IEMDefinition; import com.github.technus.tectech.mechanics.structure.Structure; import com.github.technus.tectech.mechanics.structure.adders.IHatchAdder; import com.github.technus.tectech.thing.block.QuantumGlassBlock; diff --git a/src/main/java/com/github/technus/tectech/loader/ElementalLoader.java b/src/main/java/com/github/technus/tectech/loader/ElementalLoader.java index 7ce371e57e..61989e7b13 100644 --- a/src/main/java/com/github/technus/tectech/loader/ElementalLoader.java +++ b/src/main/java/com/github/technus/tectech/loader/ElementalLoader.java @@ -2,7 +2,6 @@ package com.github.technus.tectech.loader; import com.github.technus.tectech.compatibility.thaumcraft.elementalMatter.definitions.EMComplexAspectDefinition; import com.github.technus.tectech.compatibility.thaumcraft.elementalMatter.definitions.EMPrimalAspectDefinition; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.EMPrimitive; import com.github.technus.tectech.mechanics.elementalMatter.definitions.complex.EMAtomDefinition; import com.github.technus.tectech.mechanics.elementalMatter.definitions.complex.EMHadronDefinition; import com.github.technus.tectech.mechanics.elementalMatter.definitions.complex.EMNuclideIAEA; @@ -18,8 +17,6 @@ public class ElementalLoader implements Runnable { // Definition init // =================================================================================================== - EMPrimitive.run(); - EMPrimitiveDefinition.run(); EMQuarkDefinition.run(); diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/EMException.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/EMException.java index 23ca5d77d9..e00e72446d 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/EMException.java +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/EMException.java @@ -3,8 +3,23 @@ package com.github.technus.tectech.mechanics.elementalMatter.core; /** * Created by danie_000 on 19.11.2016. */ -public final class EMException extends Exception { +public final class EMException extends RuntimeException { public EMException(String message) { super(message); } + + public EMException(String message, Throwable cause) { + super(message, cause); + } + + public EMException(Throwable cause) { + super(cause); + } + + public EMException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } + + public EMException() { + } } diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/commands/EMGive.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/commands/EMGive.java index 64e9bcea1e..af4caf854b 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/commands/EMGive.java +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/commands/EMGive.java @@ -5,9 +5,8 @@ import com.github.technus.tectech.mechanics.elementalMatter.core.maps.EMInstance import com.github.technus.tectech.mechanics.elementalMatter.core.maps.EMDefinitionStackMap; import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.EMDefinitionStack; import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.EMInstanceStack; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.EMComplex; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.EMPrimitive; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.IEMDefinition; +import com.github.technus.tectech.mechanics.elementalMatter.core.definitions.EMPrimitiveTemplate; +import com.github.technus.tectech.mechanics.elementalMatter.core.definitions.IEMDefinition; import com.github.technus.tectech.thing.item.DebugElementalInstanceContainer_EM; import net.minecraft.command.ICommand; import net.minecraft.command.ICommandSender; @@ -77,11 +76,11 @@ public class EMGive implements ICommand { try{ int id=Integer.parseInt(args.get(0)); args.remove(0); - IEMDefinition primitive = EMPrimitive.getBindsPrimitive().get(id); + IEMDefinition primitive = IEMDefinition.getBindsPrimitive().get(id); return new EMDefinitionStack(primitive,amount); }catch (NumberFormatException e){ byte clazz = (byte) args.remove(0).charAt(0); - Method constructor = EMComplex.getBindsComplex().get(clazz); + Method constructor = IEMDefinition.getBindsComplex().get(clazz); EMDefinitionStackMap stacks =new EMDefinitionStackMap(); while(args.size()>0){ @@ -129,12 +128,12 @@ public class EMGive implements ICommand { private List completionsForClassOrID(){ ArrayList strings=new ArrayList<>(8); - Map binds= EMComplex.getBindsComplex(); + Map binds= IEMDefinition.getBindsComplex(); for (Map.Entry e:binds.entrySet()) { strings.add(String.valueOf((char)e.getKey().byteValue())); } - Map bindsBO = EMPrimitive.getBindsPrimitive(); - for (Map.Entry e:bindsBO.entrySet()) { + Map bindsBO = IEMDefinition.getBindsPrimitive(); + for (Map.Entry e:bindsBO.entrySet()) { strings.add(String.valueOf(e.getKey().byteValue())); } return strings; diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/commands/EMList.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/commands/EMList.java index 395592036f..13531dbf85 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/commands/EMList.java +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/commands/EMList.java @@ -1,7 +1,7 @@ package com.github.technus.tectech.mechanics.elementalMatter.core.commands; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.EMComplex; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.EMPrimitive; +import com.github.technus.tectech.mechanics.elementalMatter.core.definitions.EMPrimitiveTemplate; +import com.github.technus.tectech.mechanics.elementalMatter.core.definitions.IEMDefinition; import net.minecraft.command.ICommand; import net.minecraft.command.ICommandSender; import net.minecraft.util.ChatComponentText; @@ -27,15 +27,15 @@ public class EMList implements ICommand { if (!sender.getEntityWorld().isRemote) { if(args.length == 0) { sender.addChatMessage(new ChatComponentText(" Available Classes: tag - name")); - Map binds= EMComplex.getBindsComplex(); + Map binds= IEMDefinition.getBindsComplex(); for (Map.Entry e:binds.entrySet()) { sender.addChatMessage(new ChatComponentText((char) e.getKey().byteValue() +" - "+e.getValue().getReturnType().getSimpleName())); } }else if(args.length==1){ sender.addChatMessage(new ChatComponentText(" Available Primitives: symbol - name")); - if(args[0].equals(String.valueOf((char) EMPrimitive.nbtType))){ - Map bindsBO = EMPrimitive.getBindsPrimitive(); - for (Map.Entry e:bindsBO.entrySet()) { + if(args[0].equals(String.valueOf((char) EMPrimitiveTemplate.nbtType))){ + Map bindsBO = IEMDefinition.getBindsPrimitive(); + for (Map.Entry e:bindsBO.entrySet()) { sender.addChatMessage(new ChatComponentText(e.getKey() + " - "+e.getValue().getLocalizedName())); } }else{ @@ -65,7 +65,7 @@ public class EMList implements ICommand { @Override public List addTabCompletionOptions(ICommandSender sender, String[] args) { if(args.length==0){ - Map binds= EMComplex.getBindsComplex(); + Map binds= IEMDefinition.getBindsComplex(); ArrayList strings=new ArrayList<>(binds.size()); for (Map.Entry e:binds.entrySet()) { strings.add(String.valueOf((char)e.getKey().byteValue())+' '+e.getValue().getReturnType().getSimpleName()); diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/decay/EMDecay.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/decay/EMDecay.java index bed49a5040..a6bd623414 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/decay/EMDecay.java +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/decay/EMDecay.java @@ -4,7 +4,7 @@ import com.github.technus.tectech.mechanics.elementalMatter.core.maps.EMConstant import com.github.technus.tectech.mechanics.elementalMatter.core.maps.EMInstanceStackMap; import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.EMDefinitionStack; import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.EMInstanceStack; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.IEMDefinition; +import com.github.technus.tectech.mechanics.elementalMatter.core.definitions.IEMDefinition; import static com.github.technus.tectech.util.DoubleCount.mul; diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/definitions/EMComplexTemplate.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/definitions/EMComplexTemplate.java new file mode 100644 index 0000000000..94a50ce322 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/definitions/EMComplexTemplate.java @@ -0,0 +1,73 @@ +package com.github.technus.tectech.mechanics.elementalMatter.core.definitions; + +import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.EMDefinitionStack; +import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.IEMStack; +import net.minecraft.nbt.NBTTagCompound; + +/** + * Created by danie_000 on 23.01.2017. + */ +public abstract class EMComplexTemplate implements IEMDefinition { + /** + * Just empty array? + */ + public static final IEMDefinition[] nothing = new EMPrimitiveTemplate[0]; + + @Override + public final EMComplexTemplate clone() { + return this;//IMMUTABLE + } + + @Override + public int compareTo(IEMDefinition o) { + int classCompare = compareClassID(o); + if (classCompare != 0) { + return classCompare; + } + //that allows neat check if the same thing and + //top hierarchy amount can be used to store amount info + return getSubParticles().compareWithAmountsInternal(o.getSubParticles()); + } + + @Override + public final EMDefinitionStack getStackForm(double amount) { + return new EMDefinitionStack(this, amount); + } + + @Override + public final boolean equals(Object obj) { + if(this==obj) { + return true; + } + if (obj instanceof IEMDefinition) { + return compareTo((IEMDefinition) obj) == 0; + } + if (obj instanceof IEMStack) { + return compareTo(((IEMStack) obj).getDefinition()) == 0; + } + return false; + } + + @Override + public int hashCode() {//Internal amounts should be also hashed + int hash = -(getSubParticles().size() << 4); + for (EMDefinitionStack stack : getSubParticles().valuesToArray()) { + int amount=(int) stack.getAmount(); + hash += ((amount & 0x1) == 0 ? -amount : amount) + stack.getDefinition().hashCode(); + } + return hash; + } + + @Override + public String toString() { + return getLocalizedName()+ '\n' + getSymbol(); + } + + public NBTTagCompound toNBT() { + NBTTagCompound nbtTagCompound = getSubParticles().toNBT(); + nbtTagCompound.setInteger(EMDefinitionsRegistry.getIndirectTagName(), getIndirectTagValue()); + return nbtTagCompound; + } + + protected abstract int getIndirectTagValue(); +} diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/definitions/EMDefinitionsRegistry.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/definitions/EMDefinitionsRegistry.java new file mode 100644 index 0000000000..c0f9df32f2 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/definitions/EMDefinitionsRegistry.java @@ -0,0 +1,110 @@ +package com.github.technus.tectech.mechanics.elementalMatter.core.definitions; + +import com.github.technus.tectech.mechanics.elementalMatter.core.EMException; +import net.minecraft.nbt.NBTTagCompound; + +import java.util.*; +import java.util.function.Function; + +import static com.github.technus.tectech.loader.TecTechConfig.DEBUG_MODE; +import static com.github.technus.tectech.mechanics.elementalMatter.definitions.primitive.EMPrimitiveDefinition.nbtE__; +import static com.github.technus.tectech.mechanics.elementalMatter.definitions.primitive.EMPrimitiveDefinition.null__; + +public class EMDefinitionsRegistry { + private static final NavigableSet STACKS_REGISTERED = new TreeSet<>(); + private static final Map DIRECT_BINDS = new HashMap<>(); + private static final Map> CLASS_BINDS = new HashMap<>();//creator methods in subclasses + private static final Map> CLASSES = new HashMap<>(); + private static final Map, Integer> CLASS_TYPES = new HashMap<>(); + private static final String INDIRECT_TAG = "t"; + private static final String DIRECT_TAG = "c"; + + private EMDefinitionsRegistry() { + } + + static { + CLASS_BINDS.put(0, EMDefinitionsRegistry::getDefinitionDirect); + CLASS_BINDS.put((int) 'p', EMDefinitionsRegistry::getDefinitionDirect); + } + + private static IEMDefinition getDefinitionDirect(NBTTagCompound nbt) { + return DIRECT_BINDS.get(nbt.getInteger(getDirectTagName())); + } + + public static IEMDefinition fromNBT(NBTTagCompound nbt) { + IEMDefinition apply; + try { + apply = CLASS_BINDS.get(nbt.getInteger(getIndirectTagName())).apply(nbt); + } catch (Exception e) { + EMException emException = new EMException("Failed to create from: " + nbt.toString(), e); + if (DEBUG_MODE) { + emException.printStackTrace(); + return nbtE__; + } else { + throw emException; + } + } + if (!DEBUG_MODE) { + if (apply == nbtE__) { + throw new EMException("Deserialized to NBT ERROR!"); + } else if (apply == null__ || apply == null) { + throw new EMException("Deserialized to NULL POINTER!"); + } + } + if (apply == null) { + return null__; + } + return apply; + } + + public static void registerDefinitionClass(int shortcutNBT, Function creator, Class clazz, int classID) { + if (CLASS_BINDS.put(shortcutNBT, creator) != null) { + EMException e = new EMException("Duplicate NBT shortcut! " + shortcutNBT + " used for NBT based creation"); + if (DEBUG_MODE) { + e.printStackTrace(); + } else { + throw e; + } + } + if (CLASSES.put(classID, clazz) != null) { + EMException e = new EMException("Duplicate Class ID! " + classID + " used for class comparison"); + if (DEBUG_MODE) { + e.printStackTrace(); + } else { + throw e; + } + } + CLASS_TYPES.put(clazz, classID); + } + + public static void registerDirectDefinition(IEMDefinition definition, int id) { + IEMDefinition old = DIRECT_BINDS.put(id, definition); + if (old != null) { + EMException e = new EMException("Duplicate primitive EM ID: " + id + + " for " + definition.getLocalizedName() + + " and " + old.getLocalizedName()); + if (DEBUG_MODE) { + e.printStackTrace(); + } else { + throw e; + } + } + } + + public static NavigableSet getStacksRegisteredForDisplay() { + return STACKS_REGISTERED; + } + + public static void registerForDisplay(IEMDefinition definition){ + STACKS_REGISTERED.add(definition); + STACKS_REGISTERED.add(definition.getAnti()); + } + + public static String getIndirectTagName() { + return INDIRECT_TAG; + } + + public static String getDirectTagName() { + return DIRECT_TAG; + } +} diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/definitions/EMPrimitiveTemplate.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/definitions/EMPrimitiveTemplate.java new file mode 100644 index 0000000000..f3ce34dd1d --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/definitions/EMPrimitiveTemplate.java @@ -0,0 +1,243 @@ +package com.github.technus.tectech.mechanics.elementalMatter.core.definitions; + +import com.github.technus.tectech.mechanics.elementalMatter.core.decay.EMDecay; +import com.github.technus.tectech.mechanics.elementalMatter.core.maps.EMConstantStackMap; +import com.github.technus.tectech.mechanics.elementalMatter.core.transformations.EMFluidDequantizationInfo; +import com.github.technus.tectech.mechanics.elementalMatter.core.transformations.EMItemDequantizationInfo; +import com.github.technus.tectech.mechanics.elementalMatter.core.transformations.EMOredictDequantizationInfo; +import net.minecraft.nbt.NBTTagCompound; + +import java.util.ArrayList; + +import static com.github.technus.tectech.thing.metaTileEntity.multi.GT_MetaTileEntity_EM_scanner.*; +import static com.github.technus.tectech.util.Util.areBitsSet; + +/** + * Created by danie_000 on 22.10.2016. + * EXTEND THIS TO ADD NEW PRIMITIVES, WATCH OUT FOR ID'S!!! + */ +public abstract class EMPrimitiveTemplate extends EMComplexTemplate { + private final String name; + private final String symbol; + //float-mass in eV/c^2 + private final double mass; + //int -electric charge in 1/3rds of electron charge for optimization + private final int charge; + //byte color; 0=Red 1=Green 2=Blue 0=Cyan 1=Magenta 2=Yellow, else ignored (-1 - uncolorable) + private final byte color; + //-1/-2/-3 anti matter generations, +1/+2/+3 matter generations, 0 self anti + private final byte type; + + private EMPrimitiveTemplate anti;//IMMUTABLE + private EMDecay[] elementalDecays; + private byte naturalDecayInstant; + private byte energeticDecayInstant; + private double rawLifeTime; + + private final int ID; + + //no _ at end - normal particle + // _ at end - anti particle + // __ at end - self is antiparticle + + protected EMPrimitiveTemplate(String name, String symbol, int type, double mass, int charge, int color, int ID) { + this.name = name; + this.symbol = symbol; + this.type = (byte) type; + this.mass = mass; + this.charge = charge; + this.color = (byte) color; + this.ID = ID; + EMDefinitionsRegistry.registerDirectDefinition(this,ID); + } + + // + protected void init(EMPrimitiveTemplate antiParticle, double rawLifeTime, int naturalInstant, int energeticInstant, EMDecay... elementalDecaysArray) { + anti = antiParticle; + this.rawLifeTime = rawLifeTime; + naturalDecayInstant = (byte) naturalInstant; + energeticDecayInstant = (byte) energeticInstant; + elementalDecays =elementalDecaysArray; + EMDefinitionsRegistry.registerForDisplay(this); + } + + @Override + public String getLocalizedName() { + return "Undefined: " + getName(); + } + + @Override + public String getSymbol() { + return symbol; + } + + @Override + public String getShortSymbol() { + return getSymbol(); + } + + @Override + public IEMDefinition getAnti() { + return anti;//no need for copy + } + + @Override + public int getCharge() { + return charge; + } + + @Override + public byte getColor() { + return color; + } + + @Override + public double getMass() { + return mass; + } + + @Override + public EMDecay[] getNaturalDecayInstant() { + if (naturalDecayInstant < 0) { + return elementalDecays; + }else if (naturalDecayInstant>=elementalDecays.length){ + return EMDecay.NO_PRODUCT; + } + return new EMDecay[]{elementalDecays[naturalDecayInstant]}; + } + + @Override + public EMDecay[] getEnergyInducedDecay(long energyLevel) { + if (energeticDecayInstant < 0) { + return elementalDecays; + }else if (energeticDecayInstant>=elementalDecays.length){ + return EMDecay.NO_PRODUCT; + } + return new EMDecay[]{elementalDecays[energeticDecayInstant]}; + } + + @Override + public double getEnergyDiffBetweenStates(long currentEnergyLevel, long newEnergyLevel) { + return IEMDefinition.DEFAULT_ENERGY_REQUIREMENT *(newEnergyLevel-currentEnergyLevel); + } + + @Override + public boolean usesSpecialEnergeticDecayHandling() { + return false; + } + + @Override + public boolean usesMultipleDecayCalls(long energyLevel) { + return false; + } + + @Override + public boolean decayMakesEnergy(long energyLevel) { + return false; + } + + @Override + public boolean fusionMakesEnergy(long energyLevel) { + return false; + } + + @Override + public EMDecay[] getDecayArray() { + return elementalDecays; + } + + @Override + public double getRawTimeSpan(long currentEnergy) { + return rawLifeTime; + } + + @Override + public final EMConstantStackMap getSubParticles() { + return null; + } + + @Override + public EMFluidDequantizationInfo someAmountIntoFluidStack() { + return null; + } + + @Override + public EMItemDequantizationInfo someAmountIntoItemsStack() { + return null; + } + + @Override + public EMOredictDequantizationInfo someAmountIntoOredictStack() { + return null; + } + + @Override + public byte getMatterType() { + return type; + } + + @Override + public final NBTTagCompound toNBT() { + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setInteger(EMDefinitionsRegistry.getDirectTagName(), ID); + return nbt; + } + + @Override + public final byte getClassType() { + return getClassTypeStatic(); + } + + public static byte getClassTypeStatic(){ + return -128; + } + + @Override + public void addScanShortSymbols(ArrayList lines, int capabilities, long energyLevel) { + if(areBitsSet(SCAN_GET_NOMENCLATURE|SCAN_GET_CHARGE|SCAN_GET_MASS|SCAN_GET_TIMESPAN_INFO, capabilities)) { + lines.add(getShortSymbol()); + } + } + + @Override + public void addScanResults(ArrayList lines, int capabilities, long energyLevel) { + if(areBitsSet(SCAN_GET_CLASS_TYPE, capabilities)) { + lines.add("CLASS = " + EMDefinitionsRegistry.getDirectTagName() + ' ' + getClassType()); + } + if(areBitsSet(SCAN_GET_NOMENCLATURE|SCAN_GET_CHARGE|SCAN_GET_MASS|SCAN_GET_TIMESPAN_INFO, capabilities)) { + lines.add("NAME = "+ getLocalizedName()); + lines.add("SYMBOL = "+getSymbol()); + } + if(areBitsSet(SCAN_GET_CHARGE,capabilities)) { + lines.add("CHARGE = " + getCharge() / 3D + " e"); + } + if(areBitsSet(SCAN_GET_COLOR,capabilities)) { + lines.add(getColor() < 0 ? "COLORLESS" : "CARRIES COLOR"); + } + if(areBitsSet(SCAN_GET_MASS,capabilities)) { + lines.add("MASS = " + getMass() + " eV/c\u00b2"); + } + if(areBitsSet(SCAN_GET_TIMESPAN_INFO, capabilities)){ + lines.add((isTimeSpanHalfLife()?"HALF LIFE = ":"LIFE TIME = ")+getRawTimeSpan(energyLevel)+ " s"); + lines.add(" "+"At current energy level"); + } + } + + @Override + public final int compareTo(IEMDefinition o) { + if (getClassType() == o.getClassType()) { + int oID = ((EMPrimitiveTemplate) o).ID; + return Integer.compare(ID, oID); + } + return compareClassID(o); + } + + @Override + public final int hashCode() { + return ID; + } + + public String getName() { + return name; + } +} \ No newline at end of file diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/definitions/IEMDefinition.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/definitions/IEMDefinition.java new file mode 100644 index 0000000000..06bfc61737 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/definitions/IEMDefinition.java @@ -0,0 +1,85 @@ +package com.github.technus.tectech.mechanics.elementalMatter.core.definitions; + +import com.github.technus.tectech.mechanics.elementalMatter.core.decay.EMDecay; +import com.github.technus.tectech.mechanics.elementalMatter.core.maps.EMConstantStackMap; +import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.EMDefinitionStack; +import com.github.technus.tectech.mechanics.elementalMatter.core.transformations.EMFluidDequantizationInfo; +import com.github.technus.tectech.mechanics.elementalMatter.core.transformations.EMItemDequantizationInfo; +import com.github.technus.tectech.mechanics.elementalMatter.core.transformations.EMOredictDequantizationInfo; +import net.minecraft.nbt.NBTTagCompound; + +import java.util.ArrayList; + +/** + * Created by danie_000 on 11.11.2016. + */ +public interface IEMDefinition extends Comparable,Cloneable {//IMMUTABLE + double STABLE_RAW_LIFE_TIME =1.5e36D; + double NO_DECAY_RAW_LIFE_TIME =-1D; + long DEFAULT_ENERGY_LEVEL =0; + double DEFAULT_ENERGY_REQUIREMENT =25000D;//legit cuz normal atoms should only emit a gamma if they don't have defined energy levels + //add text based creators for recipe formula input? + + //Nomenclature + String getLocalizedName(); + + String getSymbol(); + + String getShortSymbol(); + + void addScanShortSymbols(ArrayList lines, int capabilities, long energyLevel); + + void addScanResults(ArrayList lines, int capabilities, long energyLevel); + + byte getMatterType(); + + byte getClassType();//bigger number means bigger things usually, but it is just used to differentiate between classes of iED + + //Not dynamically changing stuff + IEMDefinition getAnti();//gives new anti particle def + + EMDecay[] getDecayArray();//possible decays + + EMDecay[] getNaturalDecayInstant();//natural decay if lifespan <1tick + + EMDecay[] getEnergyInducedDecay(long energyLevel);//energetic decay + + boolean usesSpecialEnergeticDecayHandling(); + + boolean usesMultipleDecayCalls(long energyLevel); + + boolean decayMakesEnergy(long energyLevel); + + boolean fusionMakesEnergy(long energyLevel); + + double getEnergyDiffBetweenStates(long currentEnergy, long newEnergyLevel);//positive or negative + + double getMass();//mass... MeV/c^2 + + int getCharge();//charge 1/3 electron charge + + //dynamically changing stuff + byte getColor();//-1 nope cannot 0 it can but undefined + + double getRawTimeSpan(long currentEnergy);//defined in static fields or generated + + boolean isTimeSpanHalfLife(); + + EMConstantStackMap getSubParticles();//contents... null if none + + EMFluidDequantizationInfo someAmountIntoFluidStack(); + + EMItemDequantizationInfo someAmountIntoItemsStack(); + + EMOredictDequantizationInfo someAmountIntoOredictStack(); + + NBTTagCompound toNBT(); + + EMDefinitionStack getStackForm(double amount); + + IEMDefinition clone(); + + default int compareClassID(IEMDefinition obj) { + return (int) getClassType() - obj.getClassType(); + } +} diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/EMConstantStackMap.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/EMConstantStackMap.java index d9297436a0..e6cfa7d03e 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/EMConstantStackMap.java +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/EMConstantStackMap.java @@ -2,7 +2,7 @@ package com.github.technus.tectech.mechanics.elementalMatter.core.maps; import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.EMDefinitionStack; import com.github.technus.tectech.mechanics.elementalMatter.core.EMException; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.IEMDefinition; +import com.github.technus.tectech.mechanics.elementalMatter.core.definitions.IEMDefinition; import net.minecraft.nbt.NBTTagCompound; import java.util.Collections; diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/EMDefinitionStackMap.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/EMDefinitionStackMap.java index 45ce50d5c7..78bb8d740a 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/EMDefinitionStackMap.java +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/EMDefinitionStackMap.java @@ -2,7 +2,7 @@ package com.github.technus.tectech.mechanics.elementalMatter.core.maps; import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.EMDefinitionStack; import com.github.technus.tectech.mechanics.elementalMatter.core.EMException; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.IEMDefinition; +import com.github.technus.tectech.mechanics.elementalMatter.core.definitions.IEMDefinition; import net.minecraft.nbt.NBTTagCompound; import java.util.NavigableMap; diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/EMInstanceStackMap.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/EMInstanceStackMap.java index c15142787f..69dc53f83d 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/EMInstanceStackMap.java +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/EMInstanceStackMap.java @@ -4,7 +4,7 @@ import com.github.technus.tectech.mechanics.elementalMatter.core.decay.EMDecayRe import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.EMDefinitionStack; import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.EMInstanceStack; import com.github.technus.tectech.mechanics.elementalMatter.core.EMException; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.IEMDefinition; +import com.github.technus.tectech.mechanics.elementalMatter.core.definitions.IEMDefinition; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/EMStackMap.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/EMStackMap.java index 4c798499b5..795ac3d3bf 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/EMStackMap.java +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/EMStackMap.java @@ -1,7 +1,7 @@ package com.github.technus.tectech.mechanics.elementalMatter.core.maps; import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.IEMStack; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.IEMDefinition; +import com.github.technus.tectech.mechanics.elementalMatter.core.definitions.IEMDefinition; import java.util.NavigableMap; import java.util.TreeMap; diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/IEMMapRead.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/IEMMapRead.java index 392d06f5cf..1322566914 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/IEMMapRead.java +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/IEMMapRead.java @@ -2,7 +2,7 @@ package com.github.technus.tectech.mechanics.elementalMatter.core.maps; import com.github.technus.tectech.TecTech; import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.IEMStack; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.IEMDefinition; +import com.github.technus.tectech.mechanics.elementalMatter.core.definitions.IEMDefinition; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; @@ -136,8 +136,8 @@ public interface IEMMapRead extends Comparable NBTTagCompound nbt = new NBTTagCompound(); nbt.setInteger("i", size()); int i = 0; - for (T stack : values()) { - nbt.setTag(Integer.toString(i++), stack.toNBT()); + for (Map.Entry entry : entrySet()) { + nbt.setTag(Integer.toString(i++), entry.getValue().toNBT()); } return nbt; } @@ -161,6 +161,39 @@ public interface IEMMapRead extends Comparable return 0; } + /** + * use only for nested operations! + * @param o + * @return + */ + default int compareWithAmountsInternal(IEMMapRead o) { + if (o == null) { + return 1; + } + + int lenDiff = size() - o.size(); + if (lenDiff != 0) { + return lenDiff; + } + + Iterator> iterator = entrySet().iterator(); + Iterator> iteratorO = o.entrySet().iterator(); + + while (iterator.hasNext()) { + T first = iterator.next().getValue(); + IEMStack second = iteratorO.next().getValue(); + int result = first.compareTo(second); + if (result != 0) { + return result; + } + result=Double.compare(first.getAmount(),second.getAmount()); + if (result != 0) { + return result; + } + } + return 0; + } + default double getMass(){ double mass=0; for (Map.Entry entry : entrySet()) { diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/IEMMapWrite.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/IEMMapWrite.java index cc22267474..f13e82fb26 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/IEMMapWrite.java +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/IEMMapWrite.java @@ -1,7 +1,7 @@ package com.github.technus.tectech.mechanics.elementalMatter.core.maps; import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.IEMStack; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.IEMDefinition; +import com.github.technus.tectech.mechanics.elementalMatter.core.definitions.IEMDefinition; import com.github.technus.tectech.mechanics.elementalMatter.core.transformations.EMTransformationInfo; import java.util.Map; diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/IEMMapWriteExact.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/IEMMapWriteExact.java index 7b8853a2f4..167ec8451d 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/IEMMapWriteExact.java +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/maps/IEMMapWriteExact.java @@ -1,7 +1,7 @@ package com.github.technus.tectech.mechanics.elementalMatter.core.maps; import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.IEMStack; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.IEMDefinition; +import com.github.technus.tectech.mechanics.elementalMatter.core.definitions.IEMDefinition; import java.util.Map; diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/stacks/EMDefinitionStack.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/stacks/EMDefinitionStack.java index fe0c73e795..f868dbe0ad 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/stacks/EMDefinitionStack.java +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/stacks/EMDefinitionStack.java @@ -1,7 +1,7 @@ package com.github.technus.tectech.mechanics.elementalMatter.core.stacks; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.EMComplex; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.IEMDefinition; +import com.github.technus.tectech.mechanics.elementalMatter.core.definitions.EMDefinitionsRegistry; +import com.github.technus.tectech.mechanics.elementalMatter.core.definitions.IEMDefinition; import net.minecraft.nbt.NBTTagCompound; import static com.github.technus.tectech.mechanics.elementalMatter.definitions.primitive.EMPrimitiveDefinition.null__; @@ -50,7 +50,7 @@ public final class EMDefinitionStack implements IEMStack { public static EMDefinitionStack fromNBT(NBTTagCompound nbt) { return new EMDefinitionStack( - EMComplex.fromNBT(nbt.getCompoundTag("d")), + EMDefinitionsRegistry.fromNBT(nbt.getCompoundTag("d")), nbt.getLong("q")+nbt.getDouble("Q")); } diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/stacks/EMInstanceStack.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/stacks/EMInstanceStack.java index b73bd21f02..6347cd2144 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/stacks/EMInstanceStack.java +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/stacks/EMInstanceStack.java @@ -1,12 +1,12 @@ package com.github.technus.tectech.mechanics.elementalMatter.core.stacks; import com.github.technus.tectech.TecTech; +import com.github.technus.tectech.mechanics.elementalMatter.core.definitions.EMDefinitionsRegistry; import com.github.technus.tectech.mechanics.elementalMatter.core.decay.EMDecay; import com.github.technus.tectech.mechanics.elementalMatter.core.decay.EMDecayResult; import com.github.technus.tectech.mechanics.elementalMatter.core.maps.EMConstantStackMap; import com.github.technus.tectech.mechanics.elementalMatter.core.maps.EMInstanceStackMap; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.EMComplex; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.IEMDefinition; +import com.github.technus.tectech.mechanics.elementalMatter.core.definitions.IEMDefinition; import com.github.technus.tectech.util.Util; import net.minecraft.client.Minecraft; import net.minecraft.crash.CrashReport; @@ -558,9 +558,8 @@ public final class EMInstanceStack implements IEMStack { } public static EMInstanceStack fromNBT(NBTTagCompound nbt) { - NBTTagCompound definition = nbt.getCompoundTag("d"); EMInstanceStack instance = new EMInstanceStack( - EMComplex.fromNBT(definition), + EMDefinitionsRegistry.fromNBT(nbt.getCompoundTag("d")), nbt.getLong("q") + nbt.getDouble("Q"), nbt.getFloat("m") + nbt.getDouble("M"), nbt.getLong("a") + nbt.getDouble("A"), diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/stacks/IEMStack.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/stacks/IEMStack.java index 94c76634d9..5672b31c04 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/stacks/IEMStack.java +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/stacks/IEMStack.java @@ -1,6 +1,6 @@ package com.github.technus.tectech.mechanics.elementalMatter.core.stacks; -import com.github.technus.tectech.mechanics.elementalMatter.core.templates.IEMDefinition; +import com.github.technus.tectech.mechanics.elementalMatter.core.definitions.IEMDefinition; import net.minecraft.nbt.NBTTagCompound; /** diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/templates/EMComplex.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/templates/EMComplex.java deleted file mode 100644 index 7fc074bded..0000000000 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/templates/EMComplex.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.github.technus.tectech.mechanics.elementalMatter.core.templates; - -import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.EMDefinitionStack; -import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.IEMStack; -import net.minecraft.nbt.NBTTagCompound; - -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; - -import static com.github.technus.tectech.loader.TecTechConfig.DEBUG_MODE; -import static com.github.technus.tectech.mechanics.elementalMatter.definitions.primitive.EMPrimitiveDefinition.nbtE__; - -/** - * Created by danie_000 on 23.01.2017. - */ -public abstract class EMComplex implements IEMDefinition { - //Nothing array - public static final IEMDefinition[] nothing = new EMPrimitive[0]; - - //add text based creators for recipe formula input? - private static final Map nbtCreationBind = new HashMap<>();//creator methods in subclasses - private static final HashSet classSet = new HashSet<>(); - - protected static void addCreatorFromNBT(byte shortcutNBT, Method constructorFromNBT,byte classID) { - if(nbtCreationBind.put(shortcutNBT, constructorFromNBT)!=null) { - throw new Error("Duplicate NBT shortcut! " + shortcutNBT + " used for NBT based creation"); - } - if(!classSet.add(classID)) { - throw new Error("Duplicate Class ID! " + classID + " used for class comparison"); - } - } - - public static Map getBindsComplex(){ - return nbtCreationBind; - } - - @Override - public final EMComplex clone() { - return this;//IMMUTABLE - } - - public static IEMDefinition fromNBT(NBTTagCompound nbt) { - try { - return (IEMDefinition) nbtCreationBind.get(nbt.getByte("t")).invoke(null, nbt); - } catch (Exception e) { - if (DEBUG_MODE) { - e.printStackTrace(); - } - return nbtE__; - } - } - - @Override - public int compareTo(IEMDefinition o) { - int classCompare = compareClassID(o); - if (classCompare != 0) { - return classCompare; - } - - //only of the internal def stacks!!! - //that allows neat check if the same thing and - //top hierarchy amount can be used to store amount info - return compareInnerContentsWithAmounts(getSubParticles().valuesToArray(), o.getSubParticles().valuesToArray()); - } - - //use only for nested operations! - private static int compareInnerContentsWithAmounts(EMDefinitionStack[] tc, EMDefinitionStack[] sc) { - if (tc == null) { - if (sc == null) { - return 0; - } else { - return -1; - } - } - if (sc == null) { - return 1; - } - - int lenDiff = tc.length - sc.length; - if (lenDiff != 0) { - return lenDiff; - } - - for (int i = 0; i < tc.length; i++) { - int cn = tc[i].getDefinition().compareTo(sc[i].getDefinition()); - if (cn != 0) { - return cn; - } - - if (tc[i].getAmount() > sc[i].getAmount()) { - return 1; - } - if (tc[i].getAmount() < sc[i].getAmount()) { - return -1; - } - } - return 0; - } - - @Override - public final EMDefinitionStack getStackForm(double amount) { - return new EMDefinitionStack(this, amount); - } - - @Override - public final boolean equals(Object obj) { - if(this==obj) { - return true; - } - if (obj instanceof IEMDefinition) { - return compareTo((IEMDefinition) obj) == 0; - } - if (obj instanceof IEMStack) { - return compareTo(((IEMStack) obj).getDefinition()) == 0; - } - return false; - } - - @Override - public int hashCode() {//Internal amounts should be also hashed - int hash = -(getSubParticles().size() << 4); - for (EMDefinitionStack stack : getSubParticles().valuesToArray()) { - int amount=(int) stack.getAmount(); - hash += ((amount & 0x1) == 0 ? -amount : amount) + stack.getDefinition().hashCode(); - } - return hash; - } - - @Override - public String toString() { - return getLocalizedName()+ '\n' + getSymbol(); - } -} diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/templates/EMPrimitive.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/templates/EMPrimitive.java deleted file mode 100644 index 587affd0f1..0000000000 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/templates/EMPrimitive.java +++ /dev/null @@ -1,283 +0,0 @@ -package com.github.technus.tectech.mechanics.elementalMatter.core.templates; - -import com.github.technus.tectech.TecTech; -import com.github.technus.tectech.mechanics.elementalMatter.core.decay.EMDecay; -import com.github.technus.tectech.mechanics.elementalMatter.core.maps.EMConstantStackMap; -import com.github.technus.tectech.mechanics.elementalMatter.core.EMException; -import com.github.technus.tectech.mechanics.elementalMatter.core.transformations.EMFluidDequantizationInfo; -import com.github.technus.tectech.mechanics.elementalMatter.core.transformations.EMItemDequantizationInfo; -import com.github.technus.tectech.mechanics.elementalMatter.core.transformations.EMOredictDequantizationInfo; -import net.minecraft.client.Minecraft; -import net.minecraft.crash.CrashReport; -import net.minecraft.nbt.NBTTagCompound; - -import java.util.*; - -import static com.github.technus.tectech.util.Util.areBitsSet; -import static com.github.technus.tectech.loader.TecTechConfig.DEBUG_MODE; -import static