From a77d155745ba329a0eff044ea01dc00141311b95 Mon Sep 17 00:00:00 2001 From: Tec Date: Sat, 13 Jul 2019 10:04:51 +0200 Subject: Anomaly work --- .../java/com/github/technus/tectech/TecTech.java | 8 +++ .../tectech/mechanics/anomaly/AnomalyHandler.java | 4 ++ .../mechanics/chunkData/ChunkDataHandler.java | 67 ++++++++++++++++++++++ .../mechanics/chunkData/ChunkMetaDataHandler.java | 10 ++++ .../github/technus/tectech/proxy/CommonProxy.java | 13 +++++ .../multi/GT_MetaTileEntity_EM_collider.java | 48 +++++++--------- 6 files changed, 123 insertions(+), 27 deletions(-) create mode 100644 src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java create mode 100644 src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkDataHandler.java create mode 100644 src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkMetaDataHandler.java (limited to 'src/main/java/com') diff --git a/src/main/java/com/github/technus/tectech/TecTech.java b/src/main/java/com/github/technus/tectech/TecTech.java index 6f1c4fc7a0..e7dc6859dd 100644 --- a/src/main/java/com/github/technus/tectech/TecTech.java +++ b/src/main/java/com/github/technus/tectech/TecTech.java @@ -4,6 +4,7 @@ import com.github.technus.tectech.loader.MainLoader; import com.github.technus.tectech.loader.TecTechConfig; import com.github.technus.tectech.mechanics.ConvertFloat; import com.github.technus.tectech.mechanics.ConvertInteger; +import com.github.technus.tectech.mechanics.chunkData.ChunkDataHandler; import com.github.technus.tectech.mechanics.elementalMatter.core.commands.GiveEM; import com.github.technus.tectech.mechanics.elementalMatter.core.commands.ListEM; import com.github.technus.tectech.proxy.CommonProxy; @@ -34,6 +35,8 @@ public class TecTech { private static IngameErrorLog moduleAdminErrorLogs; public static TecTechConfig configTecTech; + public static ChunkDataHandler chunkDataHandler=new ChunkDataHandler();; + /** * For Loader.isModLoaded checks during the runtime */ @@ -93,4 +96,9 @@ public class TecTech { pEvent.registerServerCommand(new GiveEM()); } } + + @Mod.EventHandler + public void onServerStarting(FMLServerStartingEvent aEvent) { + chunkDataHandler.onServerStarting(); + } } diff --git a/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java b/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java new file mode 100644 index 0000000000..8751a80dd9 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java @@ -0,0 +1,4 @@ +package com.github.technus.tectech.mechanics.anomaly; + +public class AnomalyHandler { +} diff --git a/src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkDataHandler.java b/src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkDataHandler.java new file mode 100644 index 0000000000..8bed59ae35 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkDataHandler.java @@ -0,0 +1,67 @@ +package com.github.technus.tectech.mechanics.chunkData; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.ChunkCoordIntPair; +import net.minecraftforge.event.world.ChunkDataEvent; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; + +public class ChunkDataHandler { + private final String TEC_TAG="TecTechTag"; + private final HashMap> dimensionWiseChunkData=new HashMap<>(); + private final HashMap metaDataHandlerHashMap =new HashMap<>(); + + public void handleChunkSaveEvent(ChunkDataEvent.Save event) { + HashMap dimensionData=dimensionWiseChunkData.get(event.world.provider.dimensionId); + NBTChunk chunkData =dimensionData!=null?dimensionData.get(event.getChunk().getChunkCoordIntPair()):null; + if(chunkData==null) { + event.getData().removeTag(TEC_TAG); + } else { + event.getData().setTag(TEC_TAG,chunkData.getData()); + } + } + + public void handleChunkLoadEvent(ChunkDataEvent.Load event) { + HashMap dimensionData= + dimensionWiseChunkData.computeIfAbsent(event.world.provider.dimensionId,k->new HashMap<>(1024)); + ChunkCoordIntPair chunkCoordIntPair=event.getChunk().getChunkCoordIntPair(); + NBTChunk chunkData =dimensionData.get(chunkCoordIntPair); + if(chunkData==null) { + dimensionData.put(chunkCoordIntPair,new NBTChunk(event.getData().getCompoundTag(TEC_TAG),true)); + }else if(!chunkData.isLoaded) { + chunkData.isLoaded=true; + Set tags=new HashSet<>(); + tags.addAll(chunkData.getData().func_150296_c()); + tags.addAll(event.getData().func_150296_c()); + NBTTagCompound compound=new NBTTagCompound(); + } + } + + public void onServerStarting() { + dimensionWiseChunkData.clear(); + } + + public void registerChunkMetaDataHandler(ChunkMetaDataHandler handler){ + metaDataHandlerHashMap.put(handler.getTagName(),handler); + } + + public static class NBTChunk { + private final NBTTagCompound data; + private boolean isLoaded; + + private NBTChunk(NBTTagCompound data, boolean isLoaded) { + this.data = data; + this.isLoaded = isLoaded; + } + + public boolean isLoaded(){ + return isLoaded; + } + + public NBTTagCompound getData(){ + return data; + } + } +} diff --git a/src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkMetaDataHandler.java b/src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkMetaDataHandler.java new file mode 100644 index 0000000000..baa7bfba13 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkMetaDataHandler.java @@ -0,0 +1,10 @@ +package com.github.technus.tectech.mechanics.chunkData; + +import net.minecraft.nbt.NBTTagCompound; + +public interface ChunkMetaDataHandler { + String getTagName(); + void mergeData(NBTTagCompound inMemory,NBTTagCompound loaded,NBTTagCompound result); + NBTTagCompound createData(); +} + diff --git a/src/main/java/com/github/technus/tectech/proxy/CommonProxy.java b/src/main/java/com/github/technus/tectech/proxy/CommonProxy.java index 598a8b148f..9a9c644af9 100644 --- a/src/main/java/com/github/technus/tectech/proxy/CommonProxy.java +++ b/src/main/java/com/github/technus/tectech/proxy/CommonProxy.java @@ -1,5 +1,7 @@ package com.github.technus.tectech.proxy; +import com.github.technus.tectech.TecTech; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.network.IGuiHandler; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.block.Block; @@ -9,6 +11,7 @@ import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.ChatComponentText; import net.minecraft.world.World; import net.minecraft.world.WorldServer; +import net.minecraftforge.event.world.ChunkDataEvent; public class CommonProxy implements IGuiHandler { public void registerRenderInfo() {} @@ -81,4 +84,14 @@ public class CommonProxy implements IGuiHandler { } return false; } + + @SubscribeEvent + public void handleChunkSaveEvent(ChunkDataEvent.Save event) { + TecTech.chunkDataHandler.handleChunkSaveEvent(event); + } + + @SubscribeEvent + public void handleChunkLoadEvent(ChunkDataEvent.Load event) { + TecTech.chunkDataHandler.handleChunkLoadEvent(event); + } } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_collider.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_collider.java index 06f1866826..b9b589c409 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_collider.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_collider.java @@ -173,35 +173,29 @@ public class GT_MetaTileEntity_EM_collider extends GT_MetaTileEntity_MultiblockB } }); - PRIMITIVE_FUSE_HANDLERS.put(eQuarkDefinition.class.getName() + '\0' + eQuarkDefinition.class.getName(), new PrimitiveColliderHandler() { - @Override - public void collide(cElementalInstanceStack in1, cElementalInstanceStack in2, cElementalInstanceStackMap out) { - try { - cElementalMutableDefinitionStackMap defs=new cElementalMutableDefinitionStackMap(); - defs.putUnify(in1.definition.getStackForm(1)); - defs.putUnify(in2.definition.getStackForm(1)); - dHadronDefinition hadron = new dHadronDefinition(defs.toImmutable_optimized_unsafeLeavesExposedElementalTree()); - out.putUnify(new cElementalInstanceStack(hadron,Math.min(in1.amount,in2.amount))); - }catch (Exception e){ - out.putUnifyAll(in1,in2); - return; - } - if(in1.amount>in2.amount){ - out.putUnify(new cElementalInstanceStack(in1.definition,in1.amount-in2.amount)); - }else if (in2.amount>in1.amount){ - out.putUnify(new cElementalInstanceStack(in2.definition,in2.amount-in1.amount)); - } + PRIMITIVE_FUSE_HANDLERS.put(eQuarkDefinition.class.getName() + '\0' + eQuarkDefinition.class.getName(), (in1, in2, out) -> { + try { + cElementalMutableDefinitionStackMap defs=new cElementalMutableDefinitionStackMap(); + defs.putUnify(in1.definition.getStackForm(1)); + defs.putUnify(in2.definition.getStackForm(1)); + dHadronDefinition hadron = new dHadronDefinition(defs.toImmutable_optimized_unsafeLeavesExposedElementalTree()); + out.putUnify(new cElementalInstanceStack(hadron,Math.min(in1.amount,in2.amount))); + }catch (Exception e){ + out.putUnifyAll(in1,in2); + return; + } + if(in1.amount>in2.amount){ + out.putUnify(new cElementalInstanceStack(in1.definition,in1.amount-in2.amount)); + }else if (in2.amount>in1.amount){ + out.putUnify(new cElementalInstanceStack(in2.definition,in2.amount-in1.amount)); } }); - PRIMITIVE_FUSE_HANDLERS.put(ePrimalAspectDefinition.class.getName() + '\0' + ePrimalAspectDefinition.class.getName(), new PrimitiveColliderHandler() { - @Override - public void collide(cElementalInstanceStack in1, cElementalInstanceStack in2, cElementalInstanceStackMap out) { - if (fuseAspects(in1, in2, out)) return; - if(in1.amount>in2.amount){ - out.putUnify(new cElementalInstanceStack(in1.definition,in1.amount-in2.amount)); - }else if (in2.amount>in1.amount){ - out.putUnify(new cElementalInstanceStack(in2.definition,in2.amount-in1.amount)); - } + PRIMITIVE_FUSE_HANDLERS.put(ePrimalAspectDefinition.class.getName() + '\0' + ePrimalAspectDefinition.class.getName(), (in1, in2, out) -> { + if (fuseAspects(in1, in2, out)) return; + if(in1.amount>in2.amount){ + out.putUnify(new cElementalInstanceStack(in1.definition,in1.amount-in2.amount)); + }else if (in2.amount>in1.amount){ + out.putUnify(new cElementalInstanceStack(in2.definition,in2.amount-in1.amount)); } }); } -- cgit From f59ccc47d72842a731bd220c68b2faee8987aef4 Mon Sep 17 00:00:00 2001 From: Tec Date: Sat, 13 Jul 2019 11:12:00 +0200 Subject: Cleanup --- .../java/com/github/technus/tectech/TecTech.java | 2 +- src/main/java/com/github/technus/tectech/Util.java | 4 ++-- .../definitions/AspectDefinitionCompatEnabled.java | 2 +- .../github/technus/tectech/loader/MainLoader.java | 11 ++++----- .../tectech/loader/thing/MachineLoader.java | 1 - .../elementalMatter/core/cElementalDecay.java | 2 +- .../elementalMatter/core/cElementalStackMap.java | 4 ++-- .../elementalMatter/core/commands/GiveEM.java | 3 +-- .../elementalMatter/core/commands/ListEM.java | 2 +- .../elementalMatter/core/rElementalRecipe.java | 8 +------ .../elementalMatter/core/rElementalRecipeMap.java | 6 +---- .../core/templates/cElementalPrimitive.java | 8 +------ .../definitions/complex/atom/dAtomDefinition.java | 28 +++++++++------------- .../definitions/complex/atom/iaeaNuclide.java | 4 ++-- .../complex/hadron/dHadronDefinition.java | 2 +- .../tectech/nei/TT_NEI_ResearchHandler.java | 2 +- .../technus/tectech/nei/TT_NEI_ScannerHandler.java | 2 +- .../github/technus/tectech/recipe/TT_recipe.java | 4 ++-- .../technus/tectech/recipe/TT_recipeAdder.java | 2 +- .../GT_MetaTileEntity_Hatch_OverflowElemental.java | 4 ++-- .../multi/GT_MetaTileEntity_EM_quantizer.java | 4 ++-- .../multi/GT_MetaTileEntity_EM_research.java | 8 +++---- .../multi/GT_MetaTileEntity_TM_microwave.java | 2 -- .../multi/GT_MetaTileEntity_TM_teslaCoil.java | 2 +- 24 files changed, 44 insertions(+), 73 deletions(-) (limited to 'src/main/java/com') diff --git a/src/main/java/com/github/technus/tectech/TecTech.java b/src/main/java/com/github/technus/tectech/TecTech.java index e7dc6859dd..337f493801 100644 --- a/src/main/java/com/github/technus/tectech/TecTech.java +++ b/src/main/java/com/github/technus/tectech/TecTech.java @@ -35,7 +35,7 @@ public class TecTech { private static IngameErrorLog moduleAdminErrorLogs; public static TecTechConfig configTecTech; - public static ChunkDataHandler chunkDataHandler=new ChunkDataHandler();; + public static ChunkDataHandler chunkDataHandler=new ChunkDataHandler(); /** * For Loader.isModLoaded checks during the runtime diff --git a/src/main/java/com/github/technus/tectech/Util.java b/src/main/java/com/github/technus/tectech/Util.java index c550203874..e333e70137 100644 --- a/src/main/java/com/github/technus/tectech/Util.java +++ b/src/main/java/com/github/technus/tectech/Util.java @@ -41,7 +41,7 @@ public final class Util { @SuppressWarnings("ComparatorMethodParameterNotUsed") public static > SortedSet> entriesSortedByValues(Map map) { - SortedSet> sortedEntries = new TreeSet>( + SortedSet> sortedEntries = new TreeSet<>( (e1, e2) -> { int res = e1.getValue().compareTo(e2.getValue()); return res != 0 ? res : 1; // Special fix to preserve items with equal values @@ -1159,7 +1159,7 @@ public final class Util { c++;//depth } output.add("}"); - return output.toArray(new String[output.size()]); + return output.toArray(new String[0]); } private static final Pattern matchE_ = Pattern.compile("(E,(E,)+)"); diff --git a/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/elementalMatter/definitions/AspectDefinitionCompatEnabled.java b/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/elementalMatter/definitions/AspectDefinitionCompatEnabled.java index 91523326db..da930a1d79 100644 --- a/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/elementalMatter/definitions/AspectDefinitionCompatEnabled.java +++ b/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/elementalMatter/definitions/AspectDefinitionCompatEnabled.java @@ -30,7 +30,7 @@ public final class AspectDefinitionCompatEnabled extends AspectDefinitionCompat aspectToDef.put("perditio",magic_entropy); ArrayList list=Aspect.getCompoundAspects(); - Aspect[] array= list.toArray(new Aspect[list.size()]); + Aspect[] array= list.toArray(new Aspect[0]); while (!list.isEmpty()) { for (Aspect aspect : array) { if (list.contains(aspect)) { diff --git a/src/main/java/com/github/technus/tectech/loader/MainLoader.java b/src/main/java/com/github/technus/tectech/loader/MainLoader.java index b1a71afb2f..473045d665 100644 --- a/src/main/java/com/github/technus/tectech/loader/MainLoader.java +++ b/src/main/java/com/github/technus/tectech/loader/MainLoader.java @@ -234,14 +234,11 @@ public final class MainLoader { } public static void addAfterGregTechPostLoadRunner() { - GregTech_API.sAfterGTPostload.add(new Runnable() { - @Override - public void run() { - if(TecTech.configTecTech.NERF_FUSION) { - FixBrokenFusionRecipes(); - } - GT_MetaTileEntity_EM_collider.setValues(getFuelValue(Materials.Helium.getPlasma(125))); + GregTech_API.sAfterGTPostload.add(() -> { + if(TecTech.configTecTech.NERF_FUSION) { + FixBrokenFusionRecipes(); } + GT_MetaTileEntity_EM_collider.setValues(getFuelValue(Materials.Helium.getPlasma(125))); }); } diff --git a/src/main/java/com/github/technus/tectech/loader/thing/MachineLoader.java b/src/main/java/com/github/technus/tectech/loader/thing/MachineLoader.java index 3f4bab98f0..e734a4f8a3 100644 --- a/src/main/java/com/github/technus/tectech/loader/thing/MachineLoader.java +++ b/src/main/java/com/github/technus/tectech/loader/thing/MachineLoader.java @@ -17,7 +17,6 @@ import net.minecraft.item.ItemStack; import static com.github.technus.tectech.CommonValues.V; import static com.github.technus.tectech.thing.CustomItemList.*; -import static com.github.technus.tectech.thing.CustomItemList.eM_dynamotunnel9001; /** * Created by danie_000 on 16.11.2016. diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/cElementalDecay.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/cElementalDecay.java index 7f56ee8e5b..7d5e079876 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/cElementalDecay.java +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/cElementalDecay.java @@ -8,7 +8,7 @@ import com.github.technus.tectech.mechanics.elementalMatter.core.templates.iElem * Created by danie_000 on 22.10.2016. */ public final class cElementalDecay { - public static final cElementalDecay[] noDecay = (cElementalDecay[]) null; + public static final cElementalDecay[] noDecay = null; //DECAY IMPOSSIBLE!!! //Do not use regular NULL java will not make it work with varargs!!! //Or cast null into ARRAY type but this static is more convenient!!! diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/cElementalStackMap.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/cElementalStackMap.java index 19f5789804..fb6acec084 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/cElementalStackMap.java +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/cElementalStackMap.java @@ -48,12 +48,12 @@ abstract class cElementalStackMap implements Comparable { public final cElementalDefinitionStack[] values() { Collection var = map.values(); - return var.toArray(new cElementalDefinitionStack[var.size()]); + return var.toArray(new cElementalDefinitionStack[0]); } public final iElementalDefinition[] keys() { Set var = map.keySet(); - return var.toArray(new iElementalDefinition[var.size()]); + return var.toArray(new iElementalDefinition[0]); } public long getCountOfAllAmounts(){ diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/commands/GiveEM.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/commands/GiveEM.java index ad8d1ad8c8..333359949f 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/commands/GiveEM.java +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/commands/GiveEM.java @@ -45,8 +45,7 @@ public class GiveEM implements ICommand { }else{ TecTech.LOGGER.info("Spawninig EM for "+((EntityPlayerMP) sender).getDisplayName()+" - "+Arrays.toString(args)); - ArrayList list=new ArrayList<>(); - list.addAll(Arrays.asList(args)); + ArrayList list = new ArrayList<>(Arrays.asList(args)); String energy=list.remove(0); cElementalDefinitionStack def= getDefinitionStack(list); diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/commands/ListEM.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/commands/ListEM.java index 9e034f4655..20110c0b0d 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/commands/ListEM.java +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/commands/ListEM.java @@ -29,7 +29,7 @@ public class ListEM implements ICommand { sender.addChatMessage(new ChatComponentText(" Available Classes: tag - name")); Map binds= cElementalDefinition.getBindsComplex(); for (Map.Entry e:binds.entrySet()) { - sender.addChatMessage(new ChatComponentText(String.valueOf((char)e.getKey().byteValue())+" - "+e.getValue().getReturnType().getSimpleName())); + 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")); diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/rElementalRecipe.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/rElementalRecipe.java index c2fd9a81d4..e191cc0e0a 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/rElementalRecipe.java +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/rElementalRecipe.java @@ -38,13 +38,7 @@ public class rElementalRecipe implements Comparable { if(compare!=0) { return compare; } - if(ID>o.ID) { - return 1; - } - if(ID r = recipes.get(in.inEM); - if (r == null) { - r = new HashMap<>(); - recipes.put(in.inEM, r); - } + HashMap r = recipes.computeIfAbsent(in.inEM, k -> new HashMap<>()); return r.put(in.ID, in);//IF THIS RETURN SHIT, it means that inputs are using the exact same types of matter as input - (non amount wise collision) //It is either bad, or unimportant if you use different id's } diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/templates/cElementalPrimitive.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/templates/cElementalPrimitive.java index bcd46c579a..749d5c687b 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/templates/cElementalPrimitive.java +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/templates/cElementalPrimitive.java @@ -251,13 +251,7 @@ public abstract class cElementalPrimitive extends cElementalDefinition { public final int compareTo(iElementalDefinition o) { if (getClassType() == o.getClassType()) { int oID = ((cElementalPrimitive) o).ID; - if (ID > oID) { - return 1; - } - if (ID < oID) { - return -1; - } - return 0; + return Integer.compare(ID, oID); } return compareClassID(o); } diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/definitions/complex/atom/dAtomDefinition.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/definitions/complex/atom/dAtomDefinition.java index 99e80b7be2..86d31bfb1b 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/definitions/complex/atom/dAtomDefinition.java +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/definitions/complex/atom/dAtomDefinition.java @@ -396,35 +396,35 @@ public final class dAtomDefinition extends cElementalDefinition { switch (decayMode) { case -2: if(TecTech.RANDOM.nextBoolean() && ElectronCapture(decaysList)) { - return decaysList.toArray(new cElementalDecay[decaysList.size()]); + return decaysList.toArray(new cElementalDecay[0]); } else if(PbetaDecay(decaysList)) { - return decaysList.toArray(new cElementalDecay[decaysList.size()]); + return decaysList.toArray(new cElementalDecay[0]); } break; case -1: if(Emmision(decaysList, dHadronDefinition.hadron_p1)) { - return decaysList.toArray(new cElementalDecay[decaysList.size()]); + return decaysList.toArray(new cElementalDecay[0]); } break; case 0: if(alphaDecay(decaysList)) { - return decaysList.toArray(new cElementalDecay[decaysList.size()]); + return decaysList.toArray(new cElementalDecay[0]); } break; case 1: if(Emmision(decaysList, dHadronDefinition.hadron_n1)) { - return decaysList.toArray(new cElementalDecay[decaysList.size()]); + return decaysList.toArray(new cElementalDecay[0]); } break; case 2: if(MbetaDecay(decaysList)) { - return decaysList.toArray(new cElementalDecay[decaysList.size()]); + return decaysList.toArray(new cElementalDecay[0]); } break; default: if(decayMode>8){ if(iaeaDecay(decaysList,0)) { - return decaysList.toArray(new cElementalDecay[decaysList.size()]); + return decaysList.toArray(new cElementalDecay[0]); } return getDecayArray(decaysList,decayMode- BYTE_OFFSET,false); } @@ -1167,7 +1167,7 @@ public final class dAtomDefinition extends cElementalDefinition { if (iaeaDefinitionExistsAndHasEnergyLevels) { ArrayList decays=new ArrayList<>(4); if(iaeaDecay(decays,energyLevel)){ - return decays.toArray(new cElementalDecay[decays.size()]); + return decays.toArray(new cElementalDecay[0]); } } if(energyLevel< Math.abs(charge)/3+neutralCount) { @@ -1257,7 +1257,7 @@ public final class dAtomDefinition extends cElementalDefinition { decaysInto.add(new cElementalDefinitionStack(boson_Y__, 2)); } } - return new cElementalDecay[]{new cElementalDecay(0.75F, decaysInto.toArray(new cElementalDefinitionStack[decaysInto.size()])), deadEnd}; + return new cElementalDecay[]{new cElementalDecay(0.75F, decaysInto.toArray(new cElementalDefinitionStack[0])), deadEnd}; } //@Override @@ -1357,10 +1357,7 @@ public final class dAtomDefinition extends cElementalDefinition { float rawLifeTime = calculateLifeTime(izoDiff, izoDiffAbs, element, isotope, false); iaeaNuclide nuclide = iaeaNuclide.get(element, isotope); if (rawLifeTime >= STABLE_RAW_LIFE_TIME || nuclide != null && nuclide.halfTime >= STABLE_RAW_LIFE_TIME) { - TreeSet isotopes = stableIsotopes.get(element); - if (isotopes == null) { - stableIsotopes.put(element, isotopes = new TreeSet<>()); - } + TreeSet isotopes = stableIsotopes.computeIfAbsent(element, k -> new TreeSet<>()); isotopes.add(isotope); } } @@ -1375,10 +1372,7 @@ public final class dAtomDefinition extends cElementalDefinition { int izoDiff = isotope - Isotope; int izoDiffAbs = Math.abs(izoDiff); float rawLifeTime = calculateLifeTime(izoDiff, izoDiffAbs, element, isotope, false); - TreeMap isotopes = mostStableUnstableIsotopes.get(element); - if (isotopes == null) { - mostStableUnstableIsotopes.put(element, isotopes = new TreeMap<>()); - } + TreeMap isotopes = mostStableUnstableIsotopes.computeIfAbsent(element, k -> new TreeMap<>()); isotopes.put(rawLifeTime, isotope); } } diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/definitions/complex/atom/iaeaNuclide.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/definitions/complex/atom/iaeaNuclide.java index 10c537ed55..ac44f9242e 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/definitions/complex/atom/iaeaNuclide.java +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/definitions/complex/atom/iaeaNuclide.java @@ -134,7 +134,7 @@ public final class iaeaNuclide { if(energeticStates==null || energeticStates.isEmpty()) { energeticStatesArray = empty; } else { - energeticStatesArray = energeticStates.values().toArray(new energeticState[energeticStates.size()]); + energeticStatesArray = energeticStates.values().toArray(new energeticState[0]); } } @@ -273,7 +273,7 @@ public final class iaeaNuclide { //if(DEBUG_MODE){ // System.out.println("INVALID SUM?\t"+normalization+"\t"+decay1+"\t"+chance1+"\t"+decay2+"\t"+chance2+"\t"+decay3+"\t"+chance3); //} - return decays.values().toArray(new iaeaDecay[decays.size()]); + return decays.values().toArray(new iaeaDecay[0]); } public static final class iaeaDecay{ diff --git a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/definitions/complex/hadron/dHadronDefinition.java b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/definitions/complex/hadron/dHadronDefinition.java index 6b98cd2a99..1d617fcdb9 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/definitions/complex/hadron/dHadronDefinition.java +++ b/src/main/java/com/github/technus/tectech/mechanics/elementalMatter/definitions/complex/hadron/dHadronDefinition.java @@ -198,7 +198,7 @@ public final class dHadronDefinition extends cElementalDefinition {//TODO Optimi } } return new cElementalDecay[]{ - new cElementalDecay(0.75F, decaysInto.toArray(new cElementalDefinitionStack[decaysInto.size()])), + new cElementalDecay(0.75F, decaysInto.toArray(new cElementalDefinitionStack[0])), eBosonDefinition.deadEnd }; } diff --git a/src/main/java/com/github/technus/tectech/nei/TT_NEI_ResearchHandler.java b/src/main/java/com/github/technus/tectech/nei/TT_NEI_ResearchHandler.java index a797a65d09..1c75dceec7 100644 --- a/src/main/java/com/github/technus/tectech/nei/TT_NEI_ResearchHandler.java +++ b/src/main/java/com/github/technus/tectech/nei/TT_NEI_ResearchHandler.java @@ -365,7 +365,7 @@ public class TT_NEI_ResearchHandler extends TemplateRecipeHandler { } } } - items = tDisplayStacks.toArray(new ItemStack[tDisplayStacks.size()]); + items = tDisplayStacks.toArray(new ItemStack[0]); if (items.length == 0) { items = new ItemStack[]{new ItemStack(Blocks.fire)}; } diff --git a/src/main/java/com/github/technus/tectech/nei/TT_NEI_ScannerHandler.java b/src/main/java/com/github/technus/tectech/nei/TT_NEI_ScannerHandler.java index 8154816cfc..e9624f1b33 100644 --- a/src/main/java/com/github/technus/tectech/nei/TT_NEI_ScannerHandler.java +++ b/src/main/java/com/github/technus/tectech/nei/TT_NEI_ScannerHandler.java @@ -365,7 +365,7 @@ public class TT_NEI_ScannerHandler extends TemplateRecipeHandler { } } } - items = tDisplayStacks.toArray(new ItemStack[tDisplayStacks.size()]); + items = tDisplayStacks.toArray(new ItemStack[0]); if (items.length == 0) { items = new ItemStack[]{new ItemStack(Blocks.fire)}; } diff --git a/src/main/java/com/github/technus/tectech/recipe/TT_recipe.java b/src/main/java/com/github/technus/tectech/recipe/TT_recipe.java index 57d479a705..b5b5dd82b9 100644 --- a/src/main/java/com/github/technus/tectech/recipe/TT_recipe.java +++ b/src/main/java/com/github/technus/tectech/recipe/TT_recipe.java @@ -165,8 +165,8 @@ public class TT_recipe extends GT_Recipe { } public static class GT_Recipe_MapTT extends GT_Recipe.GT_Recipe_Map { - public static GT_Recipe_MapTT sResearchableFakeRecipes =new GT_Recipe_MapTT(new HashSet(32), "gt.recipe.researchStation", "Research station", (String)null, "gregtech:textures/gui/multimachines/ResearchFake", 1, 1,1,0,1,"", 1, "", true, false);//nei to false - using custom handler - public static GT_Recipe_MapTT sScannableFakeRecipes = new GT_Recipe_MapTT(new HashSet(32),"gt.recipe.em_scanner","EM Scanner Research",(String)null,"gregtech:textures/gui/multimachines/ResearchFake",1,1,1,0,1,"",1,"",true,false); + public static GT_Recipe_MapTT sResearchableFakeRecipes =new GT_Recipe_MapTT(new HashSet<>(32), "gt.recipe.researchStation", "Research station", null, "gregtech:textures/gui/multimachines/ResearchFake", 1, 1,1,0,1,"", 1, "", true, false);//nei to false - using custom handler + public static GT_Recipe_MapTT sScannableFakeRecipes = new GT_Recipe_MapTT(new HashSet<>(32),"gt.recipe.em_scanner","EM Scanner Research", null,"gregtech:textures/gui/multimachines/ResearchFake",1,1,1,0,1,"",1,"",true,false); public GT_Recipe_MapTT(Collection aRecipeList, String aUnlocalizedName, String aLocalName, String aNEIName, String aNEIGUIPath, int aUsualInputCount, int aUsualOutputCount, int aMinimalInputItems, int aMinimalInputFluids, int aAmperage, String aNEISpecialValuePre, int aNEISpecialValueMultiplier, String aNEISpecialValuePost, boolean aShowVoltageAmperageInNEI, boolean aNEIAllowed) { super(aRecipeList, aUnlocalizedName, aLocalName, aNEIName, aNEIGUIPath, aUsualInputCount, aUsualOutputCount, aMinimalInputItems, aMinimalInputFluids, aAmperage, aNEISpecialValuePre, aNEISpecialValueMultiplier, aNEISpecialValuePost, aShowVoltageAmperageInNEI, aNEIAllowed); diff --git a/src/main/java/com/github/technus/tectech/recipe/TT_recipeAdder.java b/src/main/java/com/github/technus/tectech/recipe/TT_recipeAdder.java index 4e352a7610..61efea1a0e 100644 --- a/src/main/java/com/github/technus/tectech/recipe/TT_recipeAdder.java +++ b/src/main/java/com/github/technus/tectech/recipe/TT_recipeAdder.java @@ -115,7 +115,7 @@ public class TT_recipeAdder extends GT_RecipeAdder { computationRequiredPerSec = Short.MAX_VALUE; } TT_recipe.GT_Recipe_MapTT.sResearchableFakeRecipes.addFakeRecipe(false, new ItemStack[]{aResearchItem}, new ItemStack[]{aOutput}, new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Writes Research result")}, null, null, totalComputationRequired, researchEUt, researchAmperage| computationRequiredPerSec<<16); - GT_Recipe.GT_Recipe_Map.sAssemblylineVisualRecipes.addFakeRecipe(false,tInputs,new ItemStack[]{aOutput},new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Reads Research result", new Object[0])},aFluidInputs,null,assDuration,assEUt,0,tAlts,true); + GT_Recipe.GT_Recipe_Map.sAssemblylineVisualRecipes.addFakeRecipe(false,tInputs,new ItemStack[]{aOutput},new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Reads Research result")},aFluidInputs,null,assDuration,assEUt,0,tAlts,true); GT_Recipe.GT_Recipe_AssemblyLine.sAssemblylineRecipes.add(new GT_Recipe.GT_Recipe_AssemblyLine( CustomItemList.UnusedStuff.get(1), totalComputationRequired/computationRequiredPerSec, tInputs, aFluidInputs, aOutput, assDuration, assEUt, tAlts)); return true; } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_OverflowElemental.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_OverflowElemental.java index 867f814b63..63321a03a4 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_OverflowElemental.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_OverflowElemental.java @@ -40,7 +40,7 @@ public class GT_MetaTileEntity_Hatch_OverflowElemental extends GT_MetaTileEntity private static Textures.BlockIcons.CustomIcon EM_T_ACTIVE; private static Textures.BlockIcons.CustomIcon MufflerEM; private static Textures.BlockIcons.CustomIcon MufflerEMidle; - private float overflowMatter = 0f; + private float overflowMatter; public final float overflowMax; private final float overflowDisperse; @@ -195,7 +195,7 @@ public class GT_MetaTileEntity_Hatch_OverflowElemental extends GT_MetaTileEntity "Contained mass:", EnumChatFormatting.RED + Double.toString(overflowMatter) + EnumChatFormatting.RESET + " eV/c\u00b2 /", EnumChatFormatting.GREEN + Double.toString(overflowMax) + EnumChatFormatting.RESET + " eV/c\u00b2", - "Mass Disposal speed: " + EnumChatFormatting.BLUE + Double.toString(overflowDisperse) + EnumChatFormatting.RESET + " (eV/c\u00b2)/s" + "Mass Disposal speed: " + EnumChatFormatting.BLUE + overflowDisperse + EnumChatFormatting.RESET + " (eV/c\u00b2)/s" }; } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_quantizer.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_quantizer.java index 381df4b893..d34acd1534 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_quantizer.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_quantizer.java @@ -117,7 +117,7 @@ public class GT_MetaTileEntity_EM_quantizer extends GT_MetaTileEntity_Multiblock public boolean checkRecipe_EM(ItemStack itemStack) {//TODO implement instance quantization if (GregTech_API.sPostloadFinished) { ArrayList storedInputs = getStoredInputs(); - ItemStack[] inI = storedInputs.toArray(new ItemStack[storedInputs.size()]); + ItemStack[] inI = storedInputs.toArray(new ItemStack[0]); if (inI.length > 0) { for (ItemStack is : inI) { //ITEM STACK quantization @@ -156,7 +156,7 @@ public class GT_MetaTileEntity_EM_quantizer extends GT_MetaTileEntity_Multiblock } } ArrayList storedFluids = getStoredFluids(); - FluidStack[] inF = storedFluids.toArray(new FluidStack[storedFluids.size()]); + FluidStack[] inF = storedFluids.toArray(new FluidStack[0]); if (inF.length > 0) { for (FluidStack fs : inF) { aFluidQuantizationInfo aFQI = bTransformationInfo.fluidQuantization.get(fs.getFluid().getID()); diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_research.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_research.java index 88b24d11ae..e74cef7a34 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_research.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_research.java @@ -515,20 +515,20 @@ public class GT_MetaTileEntity_EM_research extends GT_MetaTileEntity_MultiblockB return new String[]{ "Energy Hatches:", EnumChatFormatting.GREEN + Long.toString(storedEnergy) + EnumChatFormatting.RESET + " EU / " + - EnumChatFormatting.YELLOW + Long.toString(maxEnergy) + EnumChatFormatting.RESET + " EU", + EnumChatFormatting.YELLOW + maxEnergy + EnumChatFormatting.RESET + " EU", (mEUt <= 0 ? "Probably uses: " : "Probably makes: ") + - EnumChatFormatting.RED + Integer.toString(Math.abs(mEUt)) + EnumChatFormatting.RESET + " EU/t at " + + EnumChatFormatting.RED + Math.abs(mEUt) + EnumChatFormatting.RESET + " EU/t at " + EnumChatFormatting.RED + eAmpereFlow + EnumChatFormatting.RESET + " A", "Tier Rating: " + EnumChatFormatting.YELLOW + VN[getMaxEnergyInputTier_EM()] + EnumChatFormatting.RESET + " / " + EnumChatFormatting.GREEN + VN[getMinEnergyInputTier_EM()] + EnumChatFormatting.RESET + " Amp Rating: " + EnumChatFormatting.GREEN + eMaxAmpereFlow + EnumChatFormatting.RESET + " A", "Problems: " + EnumChatFormatting.RED + (getIdealStatus() - getRepairStatus()) + EnumChatFormatting.RESET + - " Efficiency: " + EnumChatFormatting.YELLOW + Float.toString(mEfficiency / 100.0F) + EnumChatFormatting.RESET + " %", + " Efficiency: " + EnumChatFormatting.YELLOW + mEfficiency / 100.0F + EnumChatFormatting.RESET + " %", "PowerPass: " + EnumChatFormatting.BLUE + ePowerPass + EnumChatFormatting.RESET + " SafeVoid: " + EnumChatFormatting.BLUE + eSafeVoid, "Computation Available: " + EnumChatFormatting.GREEN + eAvailableData + EnumChatFormatting.RESET, "Computation Remaining:", EnumChatFormatting.GREEN + Long.toString(computationRemaining / 20L) + EnumChatFormatting.RESET + " / " + - EnumChatFormatting.YELLOW + Long.toString(computationRequired / 20L) + EnumChatFormatting.YELLOW + computationRequired / 20L }; } } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_microwave.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_microwave.java index 7894a7fa37..7cb6bbab53 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_microwave.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_microwave.java @@ -4,8 +4,6 @@ import com.github.technus.tectech.CommonValues; import com.github.technus.tectech.Reference; import com.github.technus.tectech.thing.metaTileEntity.IConstructable; import com.github.technus.tectech.thing.metaTileEntity.multi.base.*; -import com.github.technus.tectech.thing.metaTileEntity.multi.base.NameFunction; -import com.github.technus.tectech.thing.metaTileEntity.multi.base.StatusFunction; import com.github.technus.tectech.thing.metaTileEntity.multi.base.render.TT_RenderedTexture; import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java index 2c58006360..f62951bf48 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java @@ -288,7 +288,7 @@ public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_Multiblock float yPos = mte.getYCoord() + 0.5f; float zPos = mte.getZCoord() + 0.5f; long reqSum = 0; - for (GT_MetaTileEntity_TM_teslaCoil Rx : eTeslaList.toArray(new GT_MetaTileEntity_TM_teslaCoil[eTeslaList.size()])) { + for (GT_MetaTileEntity_TM_teslaCoil Rx : eTeslaList.toArray(new GT_MetaTileEntity_TM_teslaCoil[0])) { try { reqSum += Rx.maxEUStore() - Rx.getEUVar(); } catch (Exception e) { -- cgit From 9d238f79f8caf9add7a7b8fb7ee026765d8ba94e Mon Sep 17 00:00:00 2001 From: Tec Date: Sat, 13 Jul 2019 13:07:04 +0200 Subject: Chunk data handler --- .../mechanics/chunkData/ChunkDataHandler.java | 105 ++++++++++++++++----- .../mechanics/chunkData/ChunkMetaDataHandler.java | 2 +- 2 files changed, 84 insertions(+), 23 deletions(-) (limited to 'src/main/java/com') diff --git a/src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkDataHandler.java b/src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkDataHandler.java index 8bed59ae35..8b5a7c870a 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkDataHandler.java +++ b/src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkDataHandler.java @@ -2,6 +2,8 @@ package com.github.technus.tectech.mechanics.chunkData; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.ChunkCoordIntPair; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; import net.minecraftforge.event.world.ChunkDataEvent; import java.util.HashMap; @@ -11,7 +13,8 @@ import java.util.Set; public class ChunkDataHandler { private final String TEC_TAG="TecTechTag"; private final HashMap> dimensionWiseChunkData=new HashMap<>(); - private final HashMap metaDataHandlerHashMap =new HashMap<>(); + private final HashMap>> dimensionWiseMetaChunkData=new HashMap<>(); + private final HashMap metaDataHandlerHashMap =new HashMap<>(); public void handleChunkSaveEvent(ChunkDataEvent.Save event) { HashMap dimensionData=dimensionWiseChunkData.get(event.world.provider.dimensionId); @@ -19,49 +22,107 @@ public class ChunkDataHandler { if(chunkData==null) { event.getData().removeTag(TEC_TAG); } else { - event.getData().setTag(TEC_TAG,chunkData.getData()); + chunkData.isLoaded=true; + event.getData().setTag(TEC_TAG,chunkData.data); } } public void handleChunkLoadEvent(ChunkDataEvent.Load event) { - HashMap dimensionData= - dimensionWiseChunkData.computeIfAbsent(event.world.provider.dimensionId,k->new HashMap<>(1024)); + NBTTagCompound loadedTag=event.getData().getCompoundTag(TEC_TAG); + if(loadedTag.hasNoTags()){ + return; + } + + int dimId=event.world.provider.dimensionId; + HashMap dimensionMemory= + dimensionWiseChunkData.computeIfAbsent(dimId,dim->{ + for (String meta : metaDataHandlerHashMap.keySet()) { + dimensionWiseMetaChunkData.get(meta).put(dim, new HashMap<>(1024)); + } + return new HashMap<>(1024); + }); + ChunkCoordIntPair chunkCoordIntPair=event.getChunk().getChunkCoordIntPair(); - NBTChunk chunkData =dimensionData.get(chunkCoordIntPair); - if(chunkData==null) { - dimensionData.put(chunkCoordIntPair,new NBTChunk(event.getData().getCompoundTag(TEC_TAG),true)); - }else if(!chunkData.isLoaded) { - chunkData.isLoaded=true; - Set tags=new HashSet<>(); - tags.addAll(chunkData.getData().func_150296_c()); - tags.addAll(event.getData().func_150296_c()); - NBTTagCompound compound=new NBTTagCompound(); + NBTChunk chunkMemory =dimensionMemory.get(chunkCoordIntPair); + Set loadedKeys=loadedTag.func_150296_c(); + + if(chunkMemory==null) { + chunkMemory=new NBTChunk(/*(NBTTagCompound)*/loadedTag/*.copy()*/,true); + for (String s :loadedKeys) { + if (metaDataHandlerHashMap.containsKey(s)) { + dimensionWiseMetaChunkData.get(s).get(dimId).put(chunkCoordIntPair,chunkMemory.data.getCompoundTag(s)); + } else { + throw new RuntimeException("Missing meta handler!" + s); + } + } + dimensionMemory.put(chunkCoordIntPair,chunkMemory); + }else if(!chunkMemory.isLoaded) { + chunkMemory.isLoaded=true; + + Set tagsDuplicated=new HashSet(loadedKeys); + tagsDuplicated.retainAll(chunkMemory.data.func_150296_c()); + + if (tagsDuplicated.isEmpty()) { + for (String s:loadedKeys) { + if (metaDataHandlerHashMap.containsKey(s)) { + chunkMemory.data.setTag(s,loadedTag.getTag(s)/*.copy()*/); + dimensionWiseMetaChunkData.get(s).get(dimId).put(chunkCoordIntPair,chunkMemory.data.getCompoundTag(s)); + } else { + throw new RuntimeException("Missing meta handler!" + s); + } + } + } else { + for (String s : loadedKeys) { + if(tagsDuplicated.contains(s)){ + ChunkMetaDataHandler metaDataHandler = metaDataHandlerHashMap.get(s); + if (metaDataHandler == null) { + throw new RuntimeException("Missing meta handler!" + s); + } else { + metaDataHandler.mergeData( + chunkMemory.data.getCompoundTag(s), + loadedTag.getCompoundTag(s)); + } + }else { + if (metaDataHandlerHashMap.containsKey(s)) { + chunkMemory.data.setTag(s,loadedTag.getTag(s)); + dimensionWiseMetaChunkData.get(s).get(dimId).put(chunkCoordIntPair,chunkMemory.data.getCompoundTag(s)); + } else { + throw new RuntimeException("Missing meta handler!" + s); + } + } + } + } } } public void onServerStarting() { dimensionWiseChunkData.clear(); + dimensionWiseMetaChunkData.clear(); } public void registerChunkMetaDataHandler(ChunkMetaDataHandler handler){ metaDataHandlerHashMap.put(handler.getTagName(),handler); + dimensionWiseMetaChunkData.put(handler.getTagName(),new HashMap<>()); } - public static class NBTChunk { + public NBTTagCompound getChunkData(ChunkMetaDataHandler handler, World world, Chunk chunk){ + return dimensionWiseMetaChunkData.get(handler.getTagName()).get(world.provider.dimensionId).get(chunk.getChunkCoordIntPair()); + } + + public NBTTagCompound getChunkData(ChunkMetaDataHandler handler, Integer world, ChunkCoordIntPair chunk){ + return dimensionWiseMetaChunkData.get(handler.getTagName()).get(world).get(chunk); + } + + private static class NBTChunk { private final NBTTagCompound data; private boolean isLoaded; private NBTChunk(NBTTagCompound data, boolean isLoaded) { + if(data==null){ + data=new NBTTagCompound(); + } this.data = data; this.isLoaded = isLoaded; } - - public boolean isLoaded(){ - return isLoaded; - } - - public NBTTagCompound getData(){ - return data; - } } } diff --git a/src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkMetaDataHandler.java b/src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkMetaDataHandler.java index baa7bfba13..369a623998 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkMetaDataHandler.java +++ b/src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkMetaDataHandler.java @@ -4,7 +4,7 @@ import net.minecraft.nbt.NBTTagCompound; public interface ChunkMetaDataHandler { String getTagName(); - void mergeData(NBTTagCompound inMemory,NBTTagCompound loaded,NBTTagCompound result); + void mergeData(NBTTagCompound target, NBTTagCompound loadedData); NBTTagCompound createData(); } -- cgit From a9500b54641cddefef8a3510a57a6172d48e0a03 Mon Sep 17 00:00:00 2001 From: Tec Date: Sat, 13 Jul 2019 13:57:19 +0200 Subject: Add wtf status --- .../base/GT_MetaTileEntity_MultiblockBase_EM.java | 4 +-- .../thing/metaTileEntity/multi/base/LedStatus.java | 30 +++++++++++++--------- 2 files changed, 20 insertions(+), 14 deletions(-) (limited to 'src/main/java/com') diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java index 3b7d4233f2..c2d3ffcf06 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java @@ -441,7 +441,7 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt EnumChatFormatting.YELLOW+ ":" + EnumChatFormatting.AQUA+paramID + EnumChatFormatting.YELLOW+ ":"+ - EnumChatFormatting.AQUA+"I "+parametrization.getStatusIn(hatchNo, paramID).name); + EnumChatFormatting.AQUA+"I "+parametrization.getStatusIn(hatchNo, paramID).name.get()); list.add(EnumChatFormatting.WHITE+"Value: "+ EnumChatFormatting.AQUA+ Util.doubleToString(parametrization.getIn(hatchNo,paramID))); try{ @@ -465,7 +465,7 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt EnumChatFormatting.YELLOW+ ":" + EnumChatFormatting.AQUA+paramID + EnumChatFormatting.YELLOW+ ":"+ - EnumChatFormatting.AQUA+"O "+parametrization.getStatusOut(hatchNo, paramID).name); + EnumChatFormatting.AQUA+"O "+parametrization.getStatusOut(hatchNo, paramID).name.get()); list.add(EnumChatFormatting.WHITE+"Value: "+ EnumChatFormatting.AQUA+Util.doubleToString(parametrization.getOut(hatchNo,paramID))); try{ diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/LedStatus.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/LedStatus.java index f2eebe3f4b..5fce024cfc 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/LedStatus.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/LedStatus.java @@ -1,22 +1,28 @@ package com.github.technus.tectech.thing.metaTileEntity.multi.base; +import com.github.technus.tectech.TecTech; import net.minecraft.util.EnumChatFormatting; +import java.util.function.Supplier; + public enum LedStatus { - STATUS_UNUSED(EnumChatFormatting.DARK_GRAY +"Unused",true),// - STATUS_TOO_LOW(EnumChatFormatting.BLUE+"Too Low",false),// - STATUS_LOW(EnumChatFormatting.AQUA+"Low",true),// - STATUS_WRONG(EnumChatFormatting.DARK_PURPLE+"Wrong",false),// - STATUS_OK(EnumChatFormatting.GREEN+"Valid",true),// - STATUS_TOO_HIGH(EnumChatFormatting.RED+"Too High",false),// - STATUS_HIGH(EnumChatFormatting.GOLD+"High",true),// - STATUS_UNDEFINED(EnumChatFormatting.GRAY+"Unknown",false), - STATUS_NEUTRAL(EnumChatFormatting.WHITE+"Neutral",true);// - - public final String name; + STATUS_UNUSED(()->EnumChatFormatting.DARK_GRAY +"Unused",true),// + STATUS_TOO_LOW(()->EnumChatFormatting.BLUE+"Too Low",false),// + STATUS_LOW(()->EnumChatFormatting.AQUA+"Low",true),// + STATUS_WRONG(()->EnumChatFormatting.DARK_PURPLE+"Wrong",false),// + STATUS_OK(()->EnumChatFormatting.GREEN+"Valid",true),// + STATUS_TOO_HIGH(()->EnumChatFormatting.RED+"Too High",false),// + STATUS_HIGH(()->EnumChatFormatting.GOLD+"High",true),// + STATUS_UNDEFINED(()->EnumChatFormatting.GRAY+"Unknown",false), + STATUS_NEUTRAL(()->EnumChatFormatting.WHITE+"Neutral",true),// + STATUS_WTF(()->{ + return LedStatus.values()[TecTech.RANDOM.nextInt(9)].name.get(); + },false);// + + public final Supplier name; public final boolean isOk; - LedStatus(String name,boolean ok){ + LedStatus(Supplier name, boolean ok){ this.name=name; this.isOk=ok; } -- cgit From d723e1e4fb87dd7e9230d532b30b85f59b86cb95 Mon Sep 17 00:00:00 2001 From: Tec Date: Sat, 13 Jul 2019 14:02:04 +0200 Subject: Tick handling for chunkdata --- .../tectech/mechanics/anomaly/AnomalyHandler.java | 30 +++++++++++++++++++++- .../mechanics/chunkData/ChunkDataHandler.java | 30 ++++++++++++++++++++-- .../mechanics/chunkData/ChunkMetaDataHandler.java | 5 ++++ .../github/technus/tectech/proxy/CommonProxy.java | 8 ++++++ 4 files changed, 70 insertions(+), 3 deletions(-) (limited to 'src/main/java/com') diff --git a/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java b/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java index 8751a80dd9..aad1fbd4ee 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java +++ b/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java @@ -1,4 +1,32 @@ package com.github.technus.tectech.mechanics.anomaly; -public class AnomalyHandler { +import com.github.technus.tectech.mechanics.chunkData.ChunkMetaDataHandler; +import cpw.mods.fml.common.gameevent.TickEvent; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.ChunkCoordIntPair; + +import java.util.HashMap; + +public class AnomalyHandler implements ChunkMetaDataHandler { + + @Override + public String getTagName() { + return "Anomaly"; + } + + @Override + public void mergeData(NBTTagCompound target, NBTTagCompound loadedData) { + target.setInteger("intensity", + target.getInteger("intensity")+loadedData.getInteger("intensity")); + } + + @Override + public NBTTagCompound createData() { + return new NBTTagCompound(); + } + + @Override + public void TickData(HashMap> data, TickEvent.ServerTickEvent event) { + + } } diff --git a/src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkDataHandler.java b/src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkDataHandler.java index 8b5a7c870a..22f776f311 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkDataHandler.java +++ b/src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkDataHandler.java @@ -1,5 +1,6 @@ package com.github.technus.tectech.mechanics.chunkData; +import cpw.mods.fml.common.gameevent.TickEvent; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.World; @@ -95,6 +96,10 @@ public class ChunkDataHandler { } } + public void tick(TickEvent.ServerTickEvent event){ + dimensionWiseMetaChunkData.forEach((k,v)-> metaDataHandlerHashMap.get(k).TickData(v,event)); + } + public void onServerStarting() { dimensionWiseChunkData.clear(); dimensionWiseMetaChunkData.clear(); @@ -106,13 +111,34 @@ public class ChunkDataHandler { } public NBTTagCompound getChunkData(ChunkMetaDataHandler handler, World world, Chunk chunk){ - return dimensionWiseMetaChunkData.get(handler.getTagName()).get(world.provider.dimensionId).get(chunk.getChunkCoordIntPair()); + return getChunkData(handler,world.provider.dimensionId,chunk.getChunkCoordIntPair()); } - public NBTTagCompound getChunkData(ChunkMetaDataHandler handler, Integer world, ChunkCoordIntPair chunk){ + public NBTTagCompound getChunkData(ChunkMetaDataHandler handler, int world, ChunkCoordIntPair chunk){ return dimensionWiseMetaChunkData.get(handler.getTagName()).get(world).get(chunk); } + public NBTTagCompound computeIfAbsentChunkData(ChunkMetaDataHandler handler, World world, Chunk chunk){ + return computeIfAbsentChunkData(handler,world.provider.dimensionId,chunk.getChunkCoordIntPair()); + } + + public NBTTagCompound computeIfAbsentChunkData(ChunkMetaDataHandler handler, int world, ChunkCoordIntPair chunk){ + return dimensionWiseMetaChunkData.get(handler.getTagName()).get(world) + .computeIfAbsent(chunk,chunkCoordIntPair -> handler.createData()); + } + + public HashMap> getChunkData(ChunkMetaDataHandler chunkMetaDataHandler){ + return dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName()); + } + + public HashMap getChunkData(ChunkMetaDataHandler chunkMetaDataHandler,World world){ + return dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName()).get(world.provider.dimensionId); + } + + public HashMap getChunkData(ChunkMetaDataHandler chunkMetaDataHandler,int world){ + return dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName()).get(world); + } + private static class NBTChunk { private final NBTTagCompound data; private boolean isLoaded; diff --git a/src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkMetaDataHandler.java b/src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkMetaDataHandler.java index 369a623998..4ac4cd1b23 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkMetaDataHandler.java +++ b/src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkMetaDataHandler.java @@ -1,10 +1,15 @@ package com.github.technus.tectech.mechanics.chunkData; +import cpw.mods.fml.common.gameevent.TickEvent; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.ChunkCoordIntPair; + +import java.util.HashMap; public interface ChunkMetaDataHandler { String getTagName(); void mergeData(NBTTagCompound target, NBTTagCompound loadedData); NBTTagCompound createData(); + void TickData(HashMap