aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTec <daniel112092@gmail.com>2019-07-13 23:02:46 +0200
committerTec <daniel112092@gmail.com>2019-07-13 23:02:46 +0200
commit830aa335beda244bb5199e2cbcfd9072d1570066 (patch)
treea89a19493b88456d3e1e7ffb8519d439745ee08d
parent2c2adfa79ccd2db8a7bbe77563239ce1b92735d0 (diff)
downloadGT5-Unofficial-830aa335beda244bb5199e2cbcfd9072d1570066.tar.gz
GT5-Unofficial-830aa335beda244bb5199e2cbcfd9072d1570066.tar.bz2
GT5-Unofficial-830aa335beda244bb5199e2cbcfd9072d1570066.zip
Cleanup chunk data tick handler
-rw-r--r--src/main/java/com/github/technus/tectech/TecTech.java18
-rw-r--r--src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java2
-rw-r--r--src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkDataHandler.java71
-rw-r--r--src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkMetaDataHandler.java6
-rw-r--r--src/main/java/com/github/technus/tectech/proxy/ClientProxy.java18
-rw-r--r--src/main/java/com/github/technus/tectech/proxy/CommonProxy.java19
6 files changed, 84 insertions, 50 deletions
diff --git a/src/main/java/com/github/technus/tectech/TecTech.java b/src/main/java/com/github/technus/tectech/TecTech.java
index 5383b9cf62..0e6e5ecf5c 100644
--- a/src/main/java/com/github/technus/tectech/TecTech.java
+++ b/src/main/java/com/github/technus/tectech/TecTech.java
@@ -9,17 +9,16 @@ 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;
+import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
-import cpw.mods.fml.common.event.FMLInitializationEvent;
-import cpw.mods.fml.common.event.FMLPostInitializationEvent;
-import cpw.mods.fml.common.event.FMLPreInitializationEvent;
-import cpw.mods.fml.common.event.FMLServerStartingEvent;
+import cpw.mods.fml.common.event.*;
import eu.usrv.yamcore.auxiliary.IngameErrorLog;
import eu.usrv.yamcore.auxiliary.LogHelper;
import gregtech.GT_Mod;
import gregtech.common.GT_Proxy;
+import net.minecraftforge.common.MinecraftForge;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
@@ -80,6 +79,11 @@ public class TecTech {
moduleAdminErrorLogs = new IngameErrorLog();
}
+ chunkDataHandler=new ChunkDataHandler();
+ chunkDataHandler.registerChunkMetaDataHandler(anomalyHandler=new AnomalyHandler());
+ FMLCommonHandler.instance().bus().register(chunkDataHandler);
+ MinecraftForge.EVENT_BUS.register(chunkDataHandler);
+
MainLoader.preLoad();
}
@@ -184,8 +188,6 @@ public class TecTech {
@Mod.EventHandler
public void PostLoad(FMLPostInitializationEvent PostEvent) {
MainLoader.postLoad();
- chunkDataHandler=new ChunkDataHandler();
- chunkDataHandler.registerChunkMetaDataHandler(anomalyHandler=new AnomalyHandler());
}
@Mod.EventHandler
@@ -199,7 +201,7 @@ public class TecTech {
}
@Mod.EventHandler
- public void onServerStarting(FMLServerStartingEvent aEvent) {
- chunkDataHandler.onServerStarting();
+ public void onServerAboutToStart(FMLServerAboutToStartEvent aEvent) {
+ chunkDataHandler.clearData();
}
}
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 29d3ff663a..c5060c8709 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
@@ -27,7 +27,7 @@ public class AnomalyHandler implements ChunkMetaDataHandler {
}
@Override
- public void TickData(HashMap<Integer, ChunkDataHandler.ChunkHashMap> data, TickEvent.ServerTickEvent event) {
+ public void tickServer(HashMap<Integer, ChunkDataHandler.ChunkHashMap> 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 8dc60248ef..f0a1c5488c 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.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.ChunkCoordIntPair;
@@ -14,7 +15,13 @@ public class ChunkDataHandler {
private final HashMap<Integer,HashMap<ChunkCoordIntPair, NBTChunk>> dimensionWiseChunkData=new HashMap<>();
private final HashMap<String,HashMap<Integer,ChunkHashMap >> dimensionWiseMetaChunkData=new HashMap<>();
private final HashMap<String,ChunkMetaDataHandler> metaDataHandlerHashMap =new HashMap<>();
+ private final ArrayList<ChunkMetaDataHandler> serverHandlers=new ArrayList<>();
+ private final ArrayList<ChunkMetaDataHandler> clientHandlers=new ArrayList<>();
+ private final ArrayList<ChunkMetaDataHandler> worldHandlers=new ArrayList<>();
+ private final ArrayList<ChunkMetaDataHandler> playerHandlers=new ArrayList<>();
+ private final ArrayList<ChunkMetaDataHandler> renderHandlers=new ArrayList<>();
+ @SubscribeEvent
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;
@@ -26,6 +33,7 @@ public class ChunkDataHandler {
}
}
+ @SubscribeEvent
public void handleChunkLoadEvent(ChunkDataEvent.Load event) {
NBTTagCompound loadedTag=event.getData().getCompoundTag(BASE_TAG_NAME);
if(loadedTag.hasNoTags()){
@@ -69,11 +77,48 @@ public class ChunkDataHandler {
}
}
- public void tickData(TickEvent.ServerTickEvent event){
- dimensionWiseMetaChunkData.forEach((k, v) -> metaDataHandlerHashMap.get(k).TickData(v, event));
+ @SubscribeEvent
+ public void onClientTickEvent(TickEvent.ClientTickEvent aEvent) {
+ clientHandlers.forEach(chunkMetaDataHandler ->
+ chunkMetaDataHandler.tickClient(
+ dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName()),
+ aEvent));
}
- public void onServerStarting() {
+ @SubscribeEvent
+ public void onServerTickEvent(TickEvent.ServerTickEvent aEvent) {
+ serverHandlers.forEach(chunkMetaDataHandler ->
+ chunkMetaDataHandler.tickServer(
+ dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName()),
+ aEvent));
+ }
+
+ @SubscribeEvent
+ public void onWorldTickEvent(TickEvent.WorldTickEvent aEvent) {
+ worldHandlers.forEach(chunkMetaDataHandler ->
+ chunkMetaDataHandler.tickWorld(
+ dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName()),
+ aEvent));
+ }
+
+ @SubscribeEvent
+ public void onPlayerTickEvent(TickEvent.PlayerTickEvent aEvent) {
+ playerHandlers.forEach(chunkMetaDataHandler ->
+ chunkMetaDataHandler.tickPlayer(
+ dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName()),
+ aEvent));
+ }
+
+ @SubscribeEvent
+ public void onRenderTickEvent(TickEvent.RenderTickEvent aEvent) {
+ renderHandlers.forEach(chunkMetaDataHandler ->
+ chunkMetaDataHandler.tickRender(
+ dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName()),
+ aEvent));
+ }
+
+
+ public void clearData() {
dimensionWiseChunkData.clear();
dimensionWiseMetaChunkData.forEach((k,v)->v.clear());
}
@@ -81,6 +126,26 @@ public class ChunkDataHandler {
public void registerChunkMetaDataHandler(ChunkMetaDataHandler handler){
metaDataHandlerHashMap.put(handler.getTagName(),handler);
dimensionWiseMetaChunkData.put(handler.getTagName(),new HashMap<>());
+ try {
+ Class clazz=handler.getClass();
+ if(clazz.getMethod("tickClient", HashMap.class, TickEvent.ClientTickEvent.class).getDeclaringClass()!=ChunkMetaDataHandler.class){
+ clientHandlers.add(handler);
+ }
+ if(clazz.getMethod("tickServer", HashMap.class, TickEvent.ServerTickEvent.class).getDeclaringClass()!=ChunkMetaDataHandler.class){
+ serverHandlers.add(handler);
+ }
+ if(clazz.getMethod("tickWorld", HashMap.class, TickEvent.WorldTickEvent.class).getDeclaringClass()!=ChunkMetaDataHandler.class){
+ worldHandlers.add(handler);
+ }
+ if(clazz.getMethod("tickPlayer", HashMap.class, TickEvent.PlayerTickEvent.class).getDeclaringClass()!=ChunkMetaDataHandler.class){
+ playerHandlers.add(handler);
+ }
+ if(clazz.getMethod("tickRender", HashMap.class, TickEvent.RenderTickEvent.class).getDeclaringClass()!=ChunkMetaDataHandler.class){
+ renderHandlers.add(handler);
+ }
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException("Cannot register event handlers!");
+ }
}
public NBTTagCompound getChunkData(ChunkMetaDataHandler handler, World world, Chunk chunk){
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 420f24f46d..e16f19b681 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
@@ -9,6 +9,10 @@ public interface ChunkMetaDataHandler {
String getTagName();
void mergeData(NBTTagCompound target, NBTTagCompound loadedData);
NBTTagCompound createData();
- void TickData(HashMap<Integer, ChunkDataHandler.ChunkHashMap> data, TickEvent.ServerTickEvent event);
+ default void tickClient(HashMap<Integer, ChunkDataHandler.ChunkHashMap> data, TickEvent.ClientTickEvent aEvent){}
+ default void tickServer(HashMap<Integer, ChunkDataHandler.ChunkHashMap> data, TickEvent.ServerTickEvent event){}
+ default void tickWorld(HashMap<Integer, ChunkDataHandler.ChunkHashMap> data, TickEvent.WorldTickEvent aEvent){}
+ default void tickPlayer(HashMap<Integer, ChunkDataHandler.ChunkHashMap> data, TickEvent.PlayerTickEvent aEvent){}
+ default void tickRender(HashMap<Integer, ChunkDataHandler.ChunkHashMap> data, TickEvent.RenderTickEvent aEvent){}
}
diff --git a/src/main/java/com/github/technus/tectech/proxy/ClientProxy.java b/src/main/java/com/github/technus/tectech/proxy/ClientProxy.java
index 8299f815e0..255cf56e96 100644
--- a/src/main/java/com/github/technus/tectech/proxy/ClientProxy.java
+++ b/src/main/java/com/github/technus/tectech/proxy/ClientProxy.java
@@ -11,8 +11,6 @@ import com.github.technus.tectech.thing.block.QuantumStuffRender;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.Loader;
-import cpw.mods.fml.common.eventhandler.SubscribeEvent;
-import cpw.mods.fml.common.gameevent.TickEvent;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
@@ -25,7 +23,6 @@ import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChatComponentText;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
-import net.minecraftforge.event.world.ChunkDataEvent;
import org.lwjgl.opengl.GL11;
public class ClientProxy extends CommonProxy {
@@ -141,19 +138,4 @@ public class ClientProxy extends CommonProxy {
public void renderAABB(AxisAlignedBB box) {
renderAABB(Minecraft.getMinecraft().theWorld,box);
}
-
- @SubscribeEvent
- public void handleChunkSaveEvent(ChunkDataEvent.Save event) {
- super.handleChunkSaveEvent(event);
- }
-
- @SubscribeEvent
- public void handleChunkLoadEvent(ChunkDataEvent.Load event) {
- super.handleChunkLoadEvent(event);
- }
-
- @SubscribeEvent
- public void onServerTickEvent(TickEvent.ServerTickEvent aEvent) {
- super.onServerTickEvent(aEvent);
- }
}
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 31b1b1824c..598a8b148f 100644
--- a/src/main/java/com/github/technus/tectech/proxy/CommonProxy.java
+++ b/src/main/java/com/github/technus/tectech/proxy/CommonProxy.java
@@ -1,8 +1,5 @@
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;
@@ -12,7 +9,6 @@ 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() {}
@@ -85,19 +81,4 @@ 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);
- }
-
- @SubscribeEvent
- public void onServerTickEvent(TickEvent.ServerTickEvent aEvent) {
- TecTech.chunkDataHandler.tickData(aEvent);
- }
}