aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com
diff options
context:
space:
mode:
authorTec <daniel112092@gmail.com>2019-07-14 09:17:57 +0200
committerTec <daniel112092@gmail.com>2019-07-14 09:17:57 +0200
commite522d6463b002731ecb656dcdcf39e2773f33aa7 (patch)
treeff2474c0526fbb771c7441435ce94039100b16a1 /src/main/java/com
parent830aa335beda244bb5199e2cbcfd9072d1570066 (diff)
downloadGT5-Unofficial-e522d6463b002731ecb656dcdcf39e2773f33aa7.tar.gz
GT5-Unofficial-e522d6463b002731ecb656dcdcf39e2773f33aa7.tar.bz2
GT5-Unofficial-e522d6463b002731ecb656dcdcf39e2773f33aa7.zip
Implement data syncing
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/github/technus/tectech/TecTech.java6
-rw-r--r--src/main/java/com/github/technus/tectech/Util.java7
-rw-r--r--src/main/java/com/github/technus/tectech/chunkData/ChunkDataHandler.java (renamed from src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkDataHandler.java)165
-rw-r--r--src/main/java/com/github/technus/tectech/chunkData/ChunkMetaDataHandler.java (renamed from src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkMetaDataHandler.java)13
-rw-r--r--src/main/java/com/github/technus/tectech/loader/network/ChunkDataMessage.java101
-rw-r--r--src/main/java/com/github/technus/tectech/loader/network/NetworkDispatcher.java2
-rw-r--r--src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java53
7 files changed, 269 insertions, 78 deletions
diff --git a/src/main/java/com/github/technus/tectech/TecTech.java b/src/main/java/com/github/technus/tectech/TecTech.java
index 0e6e5ecf5c..cfe8662a21 100644
--- a/src/main/java/com/github/technus/tectech/TecTech.java
+++ b/src/main/java/com/github/technus/tectech/TecTech.java
@@ -5,7 +5,7 @@ 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.anomaly.AnomalyHandler;
-import com.github.technus.tectech.mechanics.chunkData.ChunkDataHandler;
+import com.github.technus.tectech.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;
@@ -94,10 +94,10 @@ public class TecTech {
if(configTecTech.DISABLE_MATERIAL_LOADING_FFS){
try {
- Field field= GT_Proxy.class.getDeclaredField("mEvents");
- field.setAccessible(true);
Field modifiersField = Field.class.getDeclaredField( "modifiers" );
modifiersField.setAccessible( true );
+ Field field= GT_Proxy.class.getDeclaredField("mEvents");
+ field.setAccessible(true);
modifiersField.setInt( field, field.getModifiers() & ~Modifier.FINAL );
field.set(GT_Mod.gregtechproxy, new Collection() {
@Override
diff --git a/src/main/java/com/github/technus/tectech/Util.java b/src/main/java/com/github/technus/tectech/Util.java
index e333e70137..7746d8dd41 100644
--- a/src/main/java/com/github/technus/tectech/Util.java
+++ b/src/main/java/com/github/technus/tectech/Util.java
@@ -20,6 +20,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
+import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
import org.apache.commons.lang3.StringUtils;
@@ -1450,4 +1451,10 @@ public final class Util {
}
return Double.toString(value);
}
+
+ public static boolean checkChunkExist(World world, ChunkCoordIntPair chunk){
+ int x=chunk.getCenterXPos();
+ int z=chunk.getCenterZPosition();
+ return world.checkChunksExist(x, 0, z, x, 0, z);
+ }
}
diff --git a/src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkDataHandler.java b/src/main/java/com/github/technus/tectech/chunkData/ChunkDataHandler.java
index f0a1c5488c..cd6002e7fc 100644
--- a/src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkDataHandler.java
+++ b/src/main/java/com/github/technus/tectech/chunkData/ChunkDataHandler.java
@@ -1,12 +1,14 @@
-package com.github.technus.tectech.mechanics.chunkData;
+package com.github.technus.tectech.chunkData;
+import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
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 net.minecraftforge.event.world.ChunkEvent;
import java.util.*;
@@ -16,105 +18,123 @@ public class ChunkDataHandler {
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<>();
+ @SideOnly(Side.CLIENT)
+ private final ArrayList<ChunkMetaDataHandler> clientHandlers=new ArrayList<>();
+ @SideOnly(Side.CLIENT)
private final ArrayList<ChunkMetaDataHandler> renderHandlers=new ArrayList<>();
+ @SideOnly(Side.CLIENT)
+ private final ArrayList<ChunkMetaDataHandler> clientSyncHandlers =new ArrayList<>();
+ @SideOnly(Side.SERVER)
@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;
- if(chunkData==null) {
+ 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(BASE_TAG_NAME);
} else {
- chunkData.isLoaded=true;
- event.getData().setTag(BASE_TAG_NAME,chunkData.data);
+ chunkData.isLoaded = true;
+ event.getData().setTag(BASE_TAG_NAME, chunkData.data);
}
}
+ @SideOnly(Side.SERVER)
@SubscribeEvent
public void handleChunkLoadEvent(ChunkDataEvent.Load event) {
- NBTTagCompound loadedTag=event.getData().getCompoundTag(BASE_TAG_NAME);
- if(loadedTag.hasNoTags()){
+ NBTTagCompound loadedTag = event.getData().getCompoundTag(BASE_TAG_NAME);
+ if (loadedTag.hasNoTags()) {
return;
}
- int dimId=event.world.provider.dimensionId;
- HashMap<ChunkCoordIntPair, NBTChunk> dimensionMemory=
+ int dimId = event.world.provider.dimensionId;
+ HashMap<ChunkCoordIntPair, NBTChunk> dimensionMemory =
dimensionWiseChunkData.computeIfAbsent(dimId, this::createDimensionData);
- ChunkCoordIntPair chunkCoordIntPair=event.getChunk().getChunkCoordIntPair();
- Set<String> loadedKeys=loadedTag.func_150296_c();
- NBTChunk chunkMemory =dimensionMemory.get(chunkCoordIntPair);
- if(chunkMemory==null) {
- chunkMemory=new NBTChunk(loadedTag,true);
- dimensionMemory.put(chunkCoordIntPair,chunkMemory);
- for (String s :loadedKeys) {
+ ChunkCoordIntPair chunkCoordIntPair = event.getChunk().getChunkCoordIntPair();
+ Set<String> loadedKeys = loadedTag.func_150296_c();
+ NBTChunk chunkMemory = dimensionMemory.get(chunkCoordIntPair);
+ if (chunkMemory == null) {
+ chunkMemory = new NBTChunk(loadedTag, true);
+ dimensionMemory.put(chunkCoordIntPair, chunkMemory);
+ for (String s : loadedKeys) {
dimensionWiseMetaChunkData.get(s).get(dimId).putLoaded(chunkCoordIntPair, loadedTag.getCompoundTag(s));
}
- }else if(!chunkMemory.isLoaded) {
- chunkMemory.isLoaded=true;
+ } else if (!chunkMemory.isLoaded) {
+ chunkMemory.isLoaded = true;
- Set<String> tagsDuplicated=new HashSet(loadedKeys);
+ Set<String> tagsDuplicated = new HashSet(loadedKeys);
tagsDuplicated.retainAll(chunkMemory.data.func_150296_c());
if (tagsDuplicated.isEmpty()) {
- for (String s:loadedKeys) {
- NBTTagCompound tag=loadedTag.getCompoundTag(s);
- chunkMemory.data.setTag(s,tag);
- dimensionWiseMetaChunkData.get(s).get(dimId).putLoaded(chunkCoordIntPair,tag);
+ for (String s : loadedKeys) {
+ NBTTagCompound tag = loadedTag.getCompoundTag(s);
+ chunkMemory.data.setTag(s, tag);
+ dimensionWiseMetaChunkData.get(s).get(dimId).putLoaded(chunkCoordIntPair, tag);
}
} else {
for (String s : loadedKeys) {
- NBTTagCompound memory=chunkMemory.data.getCompoundTag(s);
- if(tagsDuplicated.contains(s)){
- metaDataHandlerHashMap.get(s).mergeData(memory,loadedTag.getCompoundTag(s));
- }else {
- chunkMemory.data.setTag(s,loadedTag.getCompoundTag(s));
- dimensionWiseMetaChunkData.get(s).get(dimId).putLoaded(chunkCoordIntPair,memory);
+ NBTTagCompound memory = chunkMemory.data.getCompoundTag(s);
+ if (tagsDuplicated.contains(s)) {
+ metaDataHandlerHashMap.get(s).mergeData(memory, loadedTag.getCompoundTag(s));
+ } else {
+ chunkMemory.data.setTag(s, loadedTag.getCompoundTag(s));
+ dimensionWiseMetaChunkData.get(s).get(dimId).putLoaded(chunkCoordIntPair, memory);
}
}
}
}
}
+ @SideOnly(Side.CLIENT)
+ @SubscribeEvent
+ public void onLoadChunk(ChunkEvent.Load aEvent){
+ clientSyncHandlers.forEach(chunkMetaDataHandler -> chunkMetaDataHandler.requestData(aEvent));
+ }
+
+ @SideOnly(Side.CLIENT)
+ @SubscribeEvent
+ public void onUnLoadChunk(ChunkEvent.Unload aEvent){
+ clientSyncHandlers.forEach(chunkMetaDataHandler -> dimensionWiseMetaChunkData
+ .get(chunkMetaDataHandler.getTagName())
+ .get(aEvent.world.provider.dimensionId)
+ .remove(aEvent.getChunk().getChunkCoordIntPair()));
+ }
+
+ @SideOnly(Side.CLIENT)
@SubscribeEvent
public void onClientTickEvent(TickEvent.ClientTickEvent aEvent) {
clientHandlers.forEach(chunkMetaDataHandler ->
chunkMetaDataHandler.tickClient(
- dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName()),
- aEvent));
+ dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName()), aEvent));
+ }
+
+ @SideOnly(Side.CLIENT)
+ @SubscribeEvent
+ public void onRenderTickEvent(TickEvent.RenderTickEvent aEvent) {
+ renderHandlers.forEach(chunkMetaDataHandler ->
+ chunkMetaDataHandler.tickRender(
+ dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName()), aEvent));
}
@SubscribeEvent
public void onServerTickEvent(TickEvent.ServerTickEvent aEvent) {
serverHandlers.forEach(chunkMetaDataHandler ->
chunkMetaDataHandler.tickServer(
- dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName()),
- aEvent));
+ dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName()), aEvent));
}
@SubscribeEvent
public void onWorldTickEvent(TickEvent.WorldTickEvent aEvent) {
worldHandlers.forEach(chunkMetaDataHandler ->
chunkMetaDataHandler.tickWorld(
- dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName()),
- aEvent));
+ 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));
+ dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName()), aEvent));
}
@@ -123,14 +143,15 @@ public class ChunkDataHandler {
dimensionWiseMetaChunkData.forEach((k,v)->v.clear());
}
+ public ChunkMetaDataHandler getChunkMetaDataHandler(String s){
+ return metaDataHandlerHashMap.get(s);
+ }
+
public void registerChunkMetaDataHandler(ChunkMetaDataHandler handler){
metaDataHandlerHashMap.put(handler.getTagName(),handler);
dimensionWiseMetaChunkData.put(handler.getTagName(),new HashMap<>());
+ Class clazz=handler.getClass();
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);
}
@@ -140,27 +161,34 @@ public class ChunkDataHandler {
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!");
+ throw new RuntimeException("Cannot register common event handlers!");
+ }
+ if(FMLCommonHandler.instance().getEffectiveSide().isClient()) {
+ try {
+ if (clazz.getMethod("tickClient", HashMap.class, TickEvent.ClientTickEvent.class).getDeclaringClass() != ChunkMetaDataHandler.class) {
+ clientHandlers.add(handler);
+ }
+ if (clazz.getMethod("tickRender", HashMap.class, TickEvent.RenderTickEvent.class).getDeclaringClass() != ChunkMetaDataHandler.class) {
+ renderHandlers.add(handler);
+ }
+ if (clazz.getMethod("requestData", int.class, ChunkCoordIntPair.class).getDeclaringClass() != ChunkMetaDataHandler.class) {
+ clientSyncHandlers.add(handler);
+ }
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException("Cannot register client event handlers!");
+ }
}
- }
-
- public NBTTagCompound getChunkData(ChunkMetaDataHandler handler, World world, Chunk chunk){
- return getChunkData(handler,world.provider.dimensionId,chunk.getChunkCoordIntPair());
}
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 putChunkData(ChunkMetaDataHandler handler, int world, ChunkCoordIntPair chunk,NBTTagCompound data){
+ return dimensionWiseMetaChunkData.get(handler.getTagName()).get(world).put(chunk,data);
}
-
- public NBTTagCompound computeIfAbsentChunkData(ChunkMetaDataHandler handler, int world, ChunkCoordIntPair chunk){
+ public NBTTagCompound createIfAbsentChunkData(ChunkMetaDataHandler handler, int world, ChunkCoordIntPair chunk){
return dimensionWiseMetaChunkData.get(handler.getTagName()).get(world)
.computeIfAbsent(chunk,chunkCoordIntPair -> handler.createData());
}
@@ -169,10 +197,6 @@ public class ChunkDataHandler {
return dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName());
}
- public ChunkHashMap getChunkData(ChunkMetaDataHandler chunkMetaDataHandler,World world){
- return dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName()).get(world.provider.dimensionId);
- }
-
public ChunkHashMap getChunkData(ChunkMetaDataHandler chunkMetaDataHandler,int world){
return dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName()).get(world);
}
@@ -214,6 +238,9 @@ public class ChunkDataHandler {
@Override
public NBTTagCompound put(ChunkCoordIntPair key, NBTTagCompound value) {
+ if(value==null){
+ return remove(key);
+ }
NBTChunk chunk = storage.get(key);
if(chunk==null){
NBTTagCompound base=new NBTTagCompound();
diff --git a/src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkMetaDataHandler.java b/src/main/java/com/github/technus/tectech/chunkData/ChunkMetaDataHandler.java
index e16f19b681..479f8ddb37 100644
--- a/src/main/java/com/github/technus/tectech/mechanics/chunkData/ChunkMetaDataHandler.java
+++ b/src/main/java/com/github/technus/tectech/chunkData/ChunkMetaDataHandler.java
@@ -1,7 +1,11 @@
-package com.github.technus.tectech.mechanics.chunkData;
+package com.github.technus.tectech.chunkData;
import cpw.mods.fml.common.gameevent.TickEvent;
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.world.ChunkCoordIntPair;
+import net.minecraftforge.event.world.ChunkEvent;
import java.util.HashMap;
@@ -9,10 +13,15 @@ public interface ChunkMetaDataHandler {
String getTagName();
void mergeData(NBTTagCompound target, NBTTagCompound loadedData);
NBTTagCompound createData();
+ @SideOnly(Side.CLIENT)
+ default void requestData(ChunkEvent.Load aEvent){}
+ default void pushData(int world, ChunkCoordIntPair chunk){}
+ @SideOnly(Side.CLIENT)
+ default void tickRender(HashMap<Integer, ChunkDataHandler.ChunkHashMap> data, TickEvent.RenderTickEvent aEvent){}
+ @SideOnly(Side.CLIENT)
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/loader/network/ChunkDataMessage.java b/src/main/java/com/github/technus/tectech/loader/network/ChunkDataMessage.java
new file mode 100644
index 0000000000..daa6195944
--- /dev/null
+++ b/src/main/java/com/github/technus/tectech/loader/network/ChunkDataMessage.java
@@ -0,0 +1,101 @@
+package com.github.technus.tectech.loader.network;
+
+import com.github.technus.tectech.TecTech;
+import com.github.technus.tectech.Util;
+import com.github.technus.tectech.chunkData.ChunkMetaDataHandler;
+import cpw.mods.fml.common.network.ByteBufUtils;
+import cpw.mods.fml.common.network.simpleimpl.IMessage;
+import cpw.mods.fml.common.network.simpleimpl.MessageContext;
+import eu.usrv.yamcore.network.client.AbstractClientMessageHandler;
+import eu.usrv.yamcore.network.server.AbstractServerMessageHandler;
+import io.netty.buffer.ByteBuf;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.world.ChunkCoordIntPair;
+import net.minecraftforge.event.world.ChunkEvent;
+
+public class ChunkDataMessage implements IMessage {
+ int worldId;
+ ChunkCoordIntPair chunk;
+ NBTTagCompound data;
+ ChunkMetaDataHandler handler;
+
+ public ChunkDataMessage(){}
+
+ @Override
+ public void fromBytes(ByteBuf pBuffer) {
+ NBTTagCompound tag = ByteBufUtils.readTag(pBuffer);
+ worldId = tag.getInteger("wId");
+ chunk=new ChunkCoordIntPair(
+ tag.getInteger("posx"),
+ tag.getInteger("posz"));
+ handler = TecTech.chunkDataHandler.getChunkMetaDataHandler(
+ tag.getString("handle"));
+ if(tag.hasKey("data")){
+ data=tag.getCompoundTag("data");
+ }
+ }
+
+ @Override
+ public void toBytes(ByteBuf pBuffer) {
+ NBTTagCompound tag = new NBTTagCompound();
+ tag.setInteger("wId",worldId);
+ tag.setInteger("posx",chunk.chunkXPos);
+ tag.setInteger("posz",chunk.chunkZPos);
+ tag.setString("handle",handler.getTagName());
+ if(data!=null){
+ tag.setTag("data",data);
+ }
+ ByteBufUtils.writeTag(pBuffer, tag);
+ }
+
+ public static class ChunkDataQuery extends ChunkDataMessage {
+ public ChunkDataQuery() {
+ }
+ public ChunkDataQuery(ChunkEvent.Load aEvent,ChunkMetaDataHandler handler) {
+ worldId=aEvent.world.provider.dimensionId;
+ chunk=aEvent.getChunk().getChunkCoordIntPair();
+ this.handler=handler;
+ }
+ }
+
+ public static class ChunkDataData extends ChunkDataMessage {
+ public ChunkDataData() {
+ }
+
+ public ChunkDataData(int worldId,ChunkCoordIntPair chunk,ChunkMetaDataHandler handler){
+ this.worldId=worldId;
+ this.chunk=chunk;
+ this.handler=handler;
+ this.data=TecTech.chunkDataHandler.getChunkData(handler,worldId,chunk);
+ }
+
+ public ChunkDataData(ChunkDataQuery query){
+ worldId=query.worldId;
+ chunk=query.chunk;
+ handler=query.handler;
+ data=TecTech.chunkDataHandler.getChunkData(handler,worldId,chunk);
+ }
+ }
+
+ public static class ClientHandler extends AbstractClientMessageHandler<ChunkDataData> {
+ @Override
+ public IMessage handleClientMessage(EntityPlayer pPlayer, ChunkDataData pMessage, MessageContext pCtx) {
+ if(Util.checkChunkExist(pPlayer.worldObj,pMessage.chunk)){
+ TecTech.chunkDataHandler.putChunkData(pMessage.handler, pMessage.worldId,pMessage.chunk, pMessage.data);
+ }
+ return null;
+ }
+ }
+
+ public static class ServerHandler extends AbstractServerMessageHandler<ChunkDataQuery> {
+ @Override
+ public IMessage handleServerMessage(EntityPlayer pPlayer, ChunkDataQuery pMessage, MessageContext pCtx) {
+ if(pPlayer instanceof EntityPlayerMP){
+ NetworkDispatcher.INSTANCE.sendTo(new ChunkDataData(pMessage),(EntityPlayerMP) pPlayer);
+ }
+ return null;
+ }
+ }
+}
diff --git a/src/main/java/com/github/technus/tectech/loader/network/NetworkDispatcher.java b/src/main/java/com/github/technus/tectech/loader/network/NetworkDispatcher.java
index 2ee027ddc8..56455a13c4 100644
--- a/src/main/java/com/github/technus/tectech/loader/network/NetworkDispatcher.java
+++ b/src/main/java/com/github/technus/tectech/loader/network/NetworkDispatcher.java
@@ -17,5 +17,7 @@ public class NetworkDispatcher extends eu.usrv.yamcore.network.PacketDispatcher
registerMessage(PipeActivityMessage.ClientHandler.class, PipeActivityMessage.PipeActivityData.class);
registerMessage(RotationMessage.ServerHandler.class, RotationMessage.RotationQuery.class);
registerMessage(RotationMessage.ClientHandler.class, RotationMessage.RotationData.class);
+ registerMessage(ChunkDataMessage.ServerHandler.class, ChunkDataMessage.ChunkDataQuery.class);
+ registerMessage(ChunkDataMessage.ClientHandler.class, ChunkDataMessage.ChunkDataData.class);
}
}
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 c5060c8709..b69fa5f76e 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,9 +1,16 @@
package com.github.technus.tectech.mechanics.anomaly;
-import com.github.technus.tectech.mechanics.chunkData.ChunkDataHandler;
-import com.github.technus.tectech.mechanics.chunkData.ChunkMetaDataHandler;
+import com.github.technus.tectech.TecTech;
+import com.github.technus.tectech.loader.network.ChunkDataMessage;
+import com.github.technus.tectech.loader.network.NetworkDispatcher;
+import com.github.technus.tectech.chunkData.ChunkDataHandler;
+import com.github.technus.tectech.chunkData.ChunkMetaDataHandler;
import cpw.mods.fml.common.gameevent.TickEvent;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.world.ChunkCoordIntPair;
+import net.minecraft.world.World;
+import net.minecraftforge.event.world.ChunkEvent;
import java.util.HashMap;
@@ -17,8 +24,8 @@ public class AnomalyHandler implements ChunkMetaDataHandler {
@Override
public void mergeData(NBTTagCompound target, NBTTagCompound loadedData) {
- int intensity=target.getInteger(INTENSITY)+loadedData.getInteger(INTENSITY);
- target.setInteger(INTENSITY,intensity);
+ double intensity=target.getDouble(INTENSITY)+loadedData.getDouble(INTENSITY);
+ target.setDouble(INTENSITY,intensity);
}
@Override
@@ -30,4 +37,42 @@ public class AnomalyHandler implements ChunkMetaDataHandler {
public void tickServer(HashMap<Integer, ChunkDataHandler.ChunkHashMap> data, TickEvent.ServerTickEvent event) {
}
+
+ @Override
+ public void tickClient(HashMap<Integer, ChunkDataHandler.ChunkHashMap> data, TickEvent.ClientTickEvent aEvent) {
+
+ }
+
+ @Override
+ public void requestData(ChunkEvent.Load aEvent) {
+ NetworkDispatcher.INSTANCE.sendToServer(new ChunkDataMessage.ChunkDataQuery(aEvent,this));
+ }
+
+ @Override
+ public void pushData(int world, ChunkCoordIntPair chunk) {
+ NetworkDispatcher.INSTANCE.sendToDimension(new ChunkDataMessage.ChunkDataData(world,chunk,this),world);
+ }
+
+ public void addAnomaly(IGregTechTileEntity iGregTechTileEntity, double amount) {
+ World w=iGregTechTileEntity.getWorld();
+ addAnomaly(w.provider.dimensionId,
+ w.getChunkFromBlockCoords(
+ iGregTechTileEntity.getXCoord(),
+ iGregTechTileEntity.getZCoord())
+ .getChunkCoordIntPair(),
+ amount);
+ }
+
+ public void addAnomaly(int world, ChunkCoordIntPair chunk,double amount) {
+ NBTTagCompound old=TecTech.chunkDataHandler.getChunkData(this,world,chunk);
+ if(old==null){
+ NBTTagCompound data=new NBTTagCompound();
+ data.setDouble(INTENSITY,amount);
+ TecTech.chunkDataHandler.putChunkData(this,world,chunk,data);
+ //todo update client on threshold reach
+ }else {
+ old.setDouble(INTENSITY,old.getDouble(INTENSITY)+amount);
+ //todo update client on threshold change
+ }
+ }
}