mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-27 23:33:08 +00:00
* First pass reformatting code to be more readable (common still not done) * Replace google common collect calls with Java calls where possible * Remove a bunch of unnecessary parenthesis leaving clarifying ones * Add some missing @Nonnull annotations * Fix checking wrong type * Remove unnecessary continue/return statements and simplify comparision check * Pass exception instead of directly printing stack trace * Work on cleaning up common, through config so far * Work on cleaning up common, through integration so far * Work on cleaning up common, through network so far * Work on cleaning up common, through tier so far * Remove empty constructors that get created by default anyways * Work on cleaning up common, through transmitters so far * Work on cleaning up common, through utils so far * Finish cleaning up spacing for common
66 lines
2.2 KiB
Java
66 lines
2.2 KiB
Java
package mekanism.common.network;
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
import mekanism.common.Mekanism;
|
|
import mekanism.common.base.IModule;
|
|
import mekanism.common.config.MekanismConfig;
|
|
import mekanism.common.network.PacketConfigSync.ConfigSyncMessage;
|
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
|
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
|
import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
public class PacketConfigSync implements IMessageHandler<ConfigSyncMessage, IMessage> {
|
|
|
|
private static final Logger LOGGER = LogManager.getLogger("Mekanism-PacketConfigSync");
|
|
|
|
@Override
|
|
public IMessage onMessage(ConfigSyncMessage message, MessageContext context) {
|
|
MekanismConfig.setSyncedConfig(message.config);
|
|
Mekanism.proxy.onConfigSync(true);
|
|
return null;
|
|
}
|
|
|
|
public static class ConfigSyncMessage implements IMessage {
|
|
|
|
private MekanismConfig config;
|
|
|
|
public ConfigSyncMessage() {
|
|
config = new MekanismConfig();
|
|
config.client = null;
|
|
}
|
|
|
|
public ConfigSyncMessage(MekanismConfig config) {
|
|
this.config = config;
|
|
}
|
|
|
|
@Override
|
|
public void toBytes(ByteBuf dataStream) {
|
|
config.general.write(dataStream);
|
|
config.usage.write(dataStream);
|
|
config.storage.write(dataStream);
|
|
try {
|
|
for (IModule module : Mekanism.modulesLoaded) {
|
|
module.writeConfig(dataStream, config);
|
|
}
|
|
} catch (Exception e) {
|
|
LOGGER.fatal("Something went wrong", e);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void fromBytes(ByteBuf dataStream) {
|
|
config.general.read(dataStream);
|
|
config.usage.read(dataStream);
|
|
config.storage.read(dataStream);
|
|
try {
|
|
for (IModule module : Mekanism.modulesLoaded) {
|
|
module.readConfig(dataStream, config);
|
|
}
|
|
} catch (Exception e) {
|
|
LOGGER.fatal("Something went wrong", e);
|
|
}
|
|
}
|
|
}
|
|
} |