aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java30
-rw-r--r--src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkDataHandler.java30
-rw-r--r--src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkMetaDataHandler.java5
-rw-r--r--src/main/java/com/github/technus/tectech/proxy/CommonProxy.java8
4 files changed, 70 insertions, 3 deletions
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<Integer, HashMap<ChunkCoordIntPair, NBTTagCompound>> 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<Integer,HashMap<ChunkCoordIntPair, NBTTagCompound>> getChunkData(ChunkMetaDataHandler chunkMetaDataHandler){
+ return dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName());
+ }
+
+ public HashMap<ChunkCoordIntPair, NBTTagCompound> getChunkData(ChunkMetaDataHandler chunkMetaDataHandler,World world){
+ return dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName()).get(world.provider.dimensionId);
+ }
+
+ public HashMap<ChunkCoordIntPair, NBTTagCompound> 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<Integer,HashMap<ChunkCoordIntPair, NBTTagCompound>> data, TickEvent.ServerTickEvent event);
}
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 9a9c644af9..2b965b4d60 100644
--- a/src/main/java/com/github/technus/tectech/proxy/CommonProxy.java
+++ b/src/main/java/com/github/technus/tectech/proxy/CommonProxy.java
@@ -2,6 +2,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.gameevent.TickEvent;
import cpw.mods.fml.common.network.IGuiHandler;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import net.minecraft.block.Block;
@@ -94,4 +95,11 @@ public class CommonProxy implements IGuiHandler {
public void handleChunkLoadEvent(ChunkDataEvent.Load event) {
TecTech.chunkDataHandler.handleChunkLoadEvent(event);
}
+
+ @SubscribeEvent
+ public void onServerTickEvent(TickEvent.ServerTickEvent aEvent) {
+ if(aEvent.phase== TickEvent.Phase.START){
+ TecTech.chunkDataHandler.tick(aEvent);
+ }
+ }
}