mirror of
https://github.com/GTNewHorizons/Gadomancy.git
synced 2026-11-23 21:39:47 +00:00
Added Sync for ModConfig
This commit is contained in:
1 parent
c5a4afd204
commit
8b1bca020d
6 files changed
+129
-7
No files matched your search
@@ -16,12 +16,15 @@ public class ModConfig {
|
||||
|
||||
private static Configuration config;
|
||||
|
||||
@Sync
|
||||
public static int golemDatawatcherId = 29;
|
||||
@Sync
|
||||
public static int dimOuterId = -73;
|
||||
public static boolean doLightCalculations = true;
|
||||
public static int maxMazeCount = -1;
|
||||
|
||||
//Skyblock stuff
|
||||
@Sync
|
||||
public static boolean ancientStoneRecipes = false;
|
||||
|
||||
private ModConfig() {}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package makeo.gadomancy.common.data;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod
|
||||
* Gadomancy is Open Source and distributed under the
|
||||
* GNU LESSER GENERAL PUBLIC LICENSE
|
||||
* for more read the LICENSE file
|
||||
* <p/>
|
||||
* Created by makeo @ 15.11.2015 22:00
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(value={FIELD})
|
||||
public @interface Sync {
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
import makeo.gadomancy.common.Gadomancy;
|
||||
import makeo.gadomancy.common.network.PacketHandler;
|
||||
import makeo.gadomancy.common.network.packets.PacketFamiliar;
|
||||
import makeo.gadomancy.common.network.packets.PacketSyncConfigs;
|
||||
import makeo.gadomancy.common.network.packets.PacketUpdateGolemTypeOrder;
|
||||
import makeo.gadomancy.common.utils.GolemEnumHelper;
|
||||
import makeo.gadomancy.common.utils.world.TCMazeHandler;
|
||||
@@ -27,6 +28,7 @@ public class EventHandlerNetwork {
|
||||
PacketHandler.INSTANCE.sendTo(new PacketUpdateGolemTypeOrder(GolemEnumHelper.getCurrentMapping()), p);
|
||||
Gadomancy.proxy.familiarHandler.checkPlayerEquipment(p);
|
||||
PacketHandler.INSTANCE.sendTo(new PacketFamiliar.PacketFamiliarSyncCompletely(Gadomancy.proxy.familiarHandler.getCurrentActiveFamiliars()), p);
|
||||
PacketHandler.INSTANCE.sendTo(new PacketSyncConfigs(), p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,12 +4,7 @@ import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import makeo.gadomancy.common.Gadomancy;
|
||||
import makeo.gadomancy.common.network.packets.PacketAnimationAbsorb;
|
||||
import makeo.gadomancy.common.network.packets.PacketFamiliar;
|
||||
import makeo.gadomancy.common.network.packets.PacketStartAnimation;
|
||||
import makeo.gadomancy.common.network.packets.PacketTCNodeBolt;
|
||||
import makeo.gadomancy.common.network.packets.PacketTCWispyLine;
|
||||
import makeo.gadomancy.common.network.packets.PacketUpdateGolemTypeOrder;
|
||||
import makeo.gadomancy.common.network.packets.*;
|
||||
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod
|
||||
@@ -34,5 +29,7 @@ public class PacketHandler {
|
||||
INSTANCE.registerMessage(PacketFamiliar.PacketFamiliarBolt.class, PacketFamiliar.PacketFamiliarBolt.class, id++, Side.CLIENT);
|
||||
INSTANCE.registerMessage(PacketFamiliar.PacketFamiliarSyncCompletely.class, PacketFamiliar.PacketFamiliarSyncCompletely.class, id++, Side.CLIENT);
|
||||
INSTANCE.registerMessage(PacketFamiliar.PacketFamiliarSyncSingle.class, PacketFamiliar.PacketFamiliarSyncSingle.class, id++, Side.CLIENT);
|
||||
|
||||
INSTANCE.registerMessage(PacketSyncConfigs.class, PacketSyncConfigs.class, id++, Side.CLIENT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package makeo.gadomancy.common.network.packets;
|
||||
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import makeo.gadomancy.common.data.ModConfig;
|
||||
import makeo.gadomancy.common.data.Sync;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod
|
||||
* Gadomancy is Open Source and distributed under the
|
||||
* GNU LESSER GENERAL PUBLIC LICENSE
|
||||
* for more read the LICENSE file
|
||||
* <p/>
|
||||
* Created by makeo @ 15.11.2015 21:10
|
||||
*/
|
||||
public class PacketSyncConfigs implements IMessage, IMessageHandler<PacketSyncConfigs, IMessage> {
|
||||
private Tuple[] fieldData;
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
int count = buf.readByte();
|
||||
fieldData = new Tuple[count];
|
||||
|
||||
for(int i = 0; i < count; i++) {
|
||||
byte[] data = new byte[buf.readShort()];
|
||||
buf.readBytes(data);
|
||||
|
||||
ByteArrayInputStream bain = new ByteArrayInputStream(data);
|
||||
Tuple tuple = null;
|
||||
try {
|
||||
tuple = new Tuple();
|
||||
tuple.field = new DataInputStream(bain).readUTF();
|
||||
tuple.value = new ObjectInputStream(bain).readObject();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
if(tuple == null) {
|
||||
fieldData = null;
|
||||
break;
|
||||
}
|
||||
fieldData[i] = tuple;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
List<byte[]> fieldData = new ArrayList<byte[]>();
|
||||
|
||||
for(Field field : ModConfig.class.getFields()) {
|
||||
if(Modifier.isStatic(field.getModifiers()) && field.isAnnotationPresent(Sync.class)) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try {
|
||||
new DataOutputStream(baos).writeUTF(field.getName());
|
||||
new ObjectOutputStream(baos).writeObject(field.get(null));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
fieldData.add(baos.toByteArray());
|
||||
|
||||
try {
|
||||
baos.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buf.writeByte(fieldData.size());
|
||||
for(byte[] data : fieldData) {
|
||||
buf.writeShort(data.length);
|
||||
buf.writeBytes(data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketSyncConfigs message, MessageContext ctx) {
|
||||
try {
|
||||
for(Tuple tuple : message.fieldData) {
|
||||
Field field = ModConfig.class.getField(tuple.field);
|
||||
field.set(null, tuple.value);
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
throw new RuntimeException(ignored);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static class Tuple {
|
||||
private String field;
|
||||
private Object value;
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -60,7 +60,9 @@ public class PacketUpdateGolemTypeOrder implements IMessage, IMessageHandler<Pac
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketUpdateGolemTypeOrder message, MessageContext ctx) {
|
||||
GolemEnumHelper.reorderEnum(message.mapping);
|
||||
if(message.mapping != null) {
|
||||
GolemEnumHelper.reorderEnum(message.mapping);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user