aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTec <daniel112092@gmail.com>2019-07-13 10:04:51 +0200
committerTec <daniel112092@gmail.com>2019-07-13 10:04:51 +0200
commita77d155745ba329a0eff044ea01dc00141311b95 (patch)
treee8bea5faef7db8156160ed08be5552951063384d /src
parentac8e488356636f6e3e6e0f11e8bd784598d5b1aa (diff)
downloadGT5-Unofficial-a77d155745ba329a0eff044ea01dc00141311b95.tar.gz
GT5-Unofficial-a77d155745ba329a0eff044ea01dc00141311b95.tar.bz2
GT5-Unofficial-a77d155745ba329a0eff044ea01dc00141311b95.zip
Anomaly work
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/github/technus/tectech/TecTech.java8
-rw-r--r--src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java4
-rw-r--r--src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkDataHandler.java67
-rw-r--r--src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkMetaDataHandler.java10
-rw-r--r--src/main/java/com/github/technus/tectech/proxy/CommonProxy.java13
-rw-r--r--src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_collider.java48
6 files changed, 123 insertions, 27 deletions
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<Integer,HashMap<ChunkCoordIntPair, NBTChunk>> dimensionWiseChunkData=new HashMap<>();
+ private final HashMap<String, ChunkMetaDataHandler> metaDataHandlerHashMap =new HashMap<>();
+
+ public void handleChunkSaveEvent(ChunkDataEvent.Save event) {
+ HashMap<ChunkCoordIntPair, NBTChunk> 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<ChunkCoordIntPair, NBTChunk> 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<String> 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));
}
});
}