From 90985663bb320821dcbbca45387d1e2e070cdb67 Mon Sep 17 00:00:00 2001 From: "Aidan C. Brady" Date: Sun, 22 Dec 2013 01:49:55 -0500 Subject: [PATCH] Sync server configs with client --- .../mekanism/client/ClientPlayerTracker.java | 7 ++ .../mekanism/client/model/ModelGasMask.java | 4 + .../mekanism/client/model/ModelJetpack.java | 4 + .../mekanism/client/model/ModelScubaTank.java | 4 +- .../client/render/ModelCustomArmor.java | 4 + .../client/render/RenderPartTransmitter.java | 3 + .../mekanism/common/CommonPlayerTracker.java | 19 ++- common/mekanism/common/Mekanism.java | 2 + .../multipart/PartLogisticalTransporter.java | 5 +- .../common/multipart/PartMechanicalPipe.java | 5 +- .../common/multipart/PartPressurizedTube.java | 5 +- .../common/multipart/PartUniversalCable.java | 5 +- .../multipart/TransmitterIcons.java} | 6 +- .../common/network/PacketConfigSync.java | 116 ++++++++++++++++++ 14 files changed, 163 insertions(+), 26 deletions(-) rename common/mekanism/{client/render/PartTransmitterIcons.java => common/multipart/TransmitterIcons.java} (87%) create mode 100644 common/mekanism/common/network/PacketConfigSync.java diff --git a/common/mekanism/client/ClientPlayerTracker.java b/common/mekanism/client/ClientPlayerTracker.java index 24e3aa963..837e7fde8 100644 --- a/common/mekanism/client/ClientPlayerTracker.java +++ b/common/mekanism/client/ClientPlayerTracker.java @@ -4,7 +4,10 @@ import mekanism.common.Mekanism; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import cpw.mods.fml.common.IPlayerTracker; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +@SideOnly(Side.CLIENT) public class ClientPlayerTracker implements IPlayerTracker { @Override @@ -31,6 +34,10 @@ public class ClientPlayerTracker implements IPlayerTracker Mekanism.jetpackOn.clear(); Mekanism.gasmaskOn.clear(); + + Mekanism.proxy.loadConfiguration(); + + System.out.println("[Mekanism] Reloaded config."); } } diff --git a/common/mekanism/client/model/ModelGasMask.java b/common/mekanism/client/model/ModelGasMask.java index aeb234864..4d0dd9aca 100644 --- a/common/mekanism/client/model/ModelGasMask.java +++ b/common/mekanism/client/model/ModelGasMask.java @@ -6,6 +6,10 @@ import net.minecraft.client.model.ModelRenderer; import org.lwjgl.opengl.GL11; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) public class ModelGasMask extends ModelBase { ModelRenderer helmetfeed; diff --git a/common/mekanism/client/model/ModelJetpack.java b/common/mekanism/client/model/ModelJetpack.java index fa0870c2b..d935533f4 100644 --- a/common/mekanism/client/model/ModelJetpack.java +++ b/common/mekanism/client/model/ModelJetpack.java @@ -6,6 +6,10 @@ import net.minecraft.client.model.ModelRenderer; import org.lwjgl.opengl.GL11; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) public class ModelJetpack extends ModelBase { ModelRenderer Packtop; diff --git a/common/mekanism/client/model/ModelScubaTank.java b/common/mekanism/client/model/ModelScubaTank.java index 5e02c89bd..963eb82b1 100644 --- a/common/mekanism/client/model/ModelScubaTank.java +++ b/common/mekanism/client/model/ModelScubaTank.java @@ -2,8 +2,10 @@ package mekanism.client.model; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelRenderer; -import net.minecraft.entity.Entity; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +@SideOnly(Side.CLIENT) public class ModelScubaTank extends ModelBase { ModelRenderer tankL; diff --git a/common/mekanism/client/render/ModelCustomArmor.java b/common/mekanism/client/render/ModelCustomArmor.java index cfb9b089f..e2d21ed6e 100644 --- a/common/mekanism/client/render/ModelCustomArmor.java +++ b/common/mekanism/client/render/ModelCustomArmor.java @@ -14,6 +14,10 @@ import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) public class ModelCustomArmor extends ModelBiped { public static ModelCustomArmor INSTANCE = new ModelCustomArmor(); diff --git a/common/mekanism/client/render/RenderPartTransmitter.java b/common/mekanism/client/render/RenderPartTransmitter.java index 031191c3e..6bf0ac14d 100644 --- a/common/mekanism/client/render/RenderPartTransmitter.java +++ b/common/mekanism/client/render/RenderPartTransmitter.java @@ -56,7 +56,10 @@ import codechicken.lib.render.TextureUtils.IIconRegister; import codechicken.lib.render.UV; import codechicken.lib.vec.Translation; import codechicken.lib.vec.Vector3; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +@SideOnly(Side.CLIENT) public class RenderPartTransmitter implements IIconRegister { public static RenderPartTransmitter INSTANCE; diff --git a/common/mekanism/common/CommonPlayerTracker.java b/common/mekanism/common/CommonPlayerTracker.java index bc84a32f9..a4dcadd97 100644 --- a/common/mekanism/common/CommonPlayerTracker.java +++ b/common/mekanism/common/CommonPlayerTracker.java @@ -1,5 +1,6 @@ package mekanism.common; import mekanism.common.PacketHandler.Transmission; +import mekanism.common.network.PacketConfigSync; import mekanism.common.network.PacketJetpackData; import mekanism.common.network.PacketJetpackData.JetpackPacket; import mekanism.common.network.PacketScubaTankData; @@ -14,8 +15,11 @@ public class CommonPlayerTracker implements IPlayerTracker { if(!player.worldObj.isRemote) { - PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketJetpackData().setParams(JetpackPacket.FULL), player.worldObj.provider.dimensionId); - PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketScubaTankData().setParams(ScubaTankPacket.FULL), player.worldObj.provider.dimensionId); + PacketHandler.sendPacket(Transmission.SINGLE_CLIENT, new PacketConfigSync().setParams(), player); + PacketHandler.sendPacket(Transmission.SINGLE_CLIENT, new PacketJetpackData().setParams(JetpackPacket.FULL), player); + PacketHandler.sendPacket(Transmission.SINGLE_CLIENT, new PacketScubaTankData().setParams(ScubaTankPacket.FULL), player); + + System.out.println("[Mekanism] Sent config to '" + player.username + ".'"); } } @@ -23,12 +27,7 @@ public class CommonPlayerTracker implements IPlayerTracker public void onPlayerLogout(EntityPlayer player) { Mekanism.jetpackOn.remove(player); - - if(!player.worldObj.isRemote) - { - PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketJetpackData().setParams(JetpackPacket.FULL), player.worldObj.provider.dimensionId); - PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketScubaTankData().setParams(ScubaTankPacket.FULL), player.worldObj.provider.dimensionId); - } + Mekanism.gasmaskOn.remove(player); } @Override @@ -38,8 +37,8 @@ public class CommonPlayerTracker implements IPlayerTracker if(!player.worldObj.isRemote) { - PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketJetpackData().setParams(JetpackPacket.FULL), player.worldObj.provider.dimensionId); - PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketScubaTankData().setParams(ScubaTankPacket.FULL), player.worldObj.provider.dimensionId); + PacketHandler.sendPacket(Transmission.SINGLE_CLIENT, new PacketJetpackData().setParams(JetpackPacket.FULL), player); + PacketHandler.sendPacket(Transmission.SINGLE_CLIENT, new PacketScubaTankData().setParams(ScubaTankPacket.FULL), player); } } diff --git a/common/mekanism/common/Mekanism.java b/common/mekanism/common/Mekanism.java index 24ac28b7c..c7cc33b56 100644 --- a/common/mekanism/common/Mekanism.java +++ b/common/mekanism/common/Mekanism.java @@ -70,6 +70,7 @@ import mekanism.common.item.ItemScubaTank; import mekanism.common.item.ItemWalkieTalkie; import mekanism.common.multipart.ItemPartTransmitter; import mekanism.common.multipart.MultipartMekanism; +import mekanism.common.network.PacketConfigSync; import mekanism.common.network.PacketConfigurationUpdate; import mekanism.common.network.PacketConfiguratorState; import mekanism.common.network.PacketDataRequest; @@ -1302,6 +1303,7 @@ public class Mekanism PacketHandler.registerPacket(PacketJetpackData.class); PacketHandler.registerPacket(PacketKey.class); PacketHandler.registerPacket(PacketScubaTankData.class); + PacketHandler.registerPacket(PacketConfigSync.class); //Donators donators.add("mrgreaper"); diff --git a/common/mekanism/common/multipart/PartLogisticalTransporter.java b/common/mekanism/common/multipart/PartLogisticalTransporter.java index a384cb421..8f8e4917c 100644 --- a/common/mekanism/common/multipart/PartLogisticalTransporter.java +++ b/common/mekanism/common/multipart/PartLogisticalTransporter.java @@ -7,7 +7,6 @@ import java.util.Set; import mekanism.api.Coord4D; import mekanism.api.EnumColor; import mekanism.api.transmitters.TransmissionType; -import mekanism.client.render.PartTransmitterIcons; import mekanism.client.render.RenderPartTransmitter; import mekanism.common.HashList; import mekanism.common.ILogisticalTransporter; @@ -48,7 +47,7 @@ import cpw.mods.fml.relauncher.SideOnly; public class PartLogisticalTransporter extends PartSidedPipe implements ILogisticalTransporter, IPipeTile { - public static PartTransmitterIcons transporterIcons; + public static TransmitterIcons transporterIcons; public static final int SPEED = 5; @@ -80,7 +79,7 @@ public class PartLogisticalTransporter extends PartSidedPipe implements ILogisti public static void registerIcons(IconRegister register) { - transporterIcons = new PartTransmitterIcons(3, 2); + transporterIcons = new TransmitterIcons(3, 2); transporterIcons.registerCenterIcons(register, new String[] {"LogisticalTransporter", "RestrictiveTransporter", "DiversionTransporter"}); transporterIcons.registerSideIcons(register, new String[] {"LogisticalTransporterSide", "RestrictiveTransporterSide"}); } diff --git a/common/mekanism/common/multipart/PartMechanicalPipe.java b/common/mekanism/common/multipart/PartMechanicalPipe.java index 75cc8d608..db0c68a15 100644 --- a/common/mekanism/common/multipart/PartMechanicalPipe.java +++ b/common/mekanism/common/multipart/PartMechanicalPipe.java @@ -4,7 +4,6 @@ import java.util.Set; import mekanism.api.transmitters.IGridTransmitter; import mekanism.api.transmitters.TransmissionType; -import mekanism.client.render.PartTransmitterIcons; import mekanism.client.render.RenderPartTransmitter; import mekanism.common.FluidNetwork; import mekanism.common.util.MekanismUtils; @@ -29,7 +28,7 @@ public class PartMechanicalPipe extends PartTransmitter implements /** The fake tank used for fluid transfer calculations. */ public FluidTank dummyTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME); - public static PartTransmitterIcons pipeIcons; + public static TransmitterIcons pipeIcons; public float currentScale; @@ -188,7 +187,7 @@ public class PartMechanicalPipe extends PartTransmitter implements public static void registerIcons(IconRegister register) { - pipeIcons = new PartTransmitterIcons(2, 1); + pipeIcons = new TransmitterIcons(2, 1); pipeIcons.registerCenterIcons(register, new String[] {"MechanicalPipe", "MechanicalPipeActive"}); pipeIcons.registerSideIcons(register, new String[] {"MechanicalPipeSide"}); } diff --git a/common/mekanism/common/multipart/PartPressurizedTube.java b/common/mekanism/common/multipart/PartPressurizedTube.java index b6a8dcc05..7a57c4818 100644 --- a/common/mekanism/common/multipart/PartPressurizedTube.java +++ b/common/mekanism/common/multipart/PartPressurizedTube.java @@ -8,7 +8,6 @@ import mekanism.api.gas.GasTransmission; import mekanism.api.gas.IGasHandler; import mekanism.api.transmitters.IGridTransmitter; import mekanism.api.transmitters.TransmissionType; -import mekanism.client.render.PartTransmitterIcons; import mekanism.client.render.RenderPartTransmitter; import mekanism.common.EnergyNetwork; import mekanism.common.FluidNetwork; @@ -24,7 +23,7 @@ import cpw.mods.fml.relauncher.SideOnly; public class PartPressurizedTube extends PartTransmitter { - public static PartTransmitterIcons tubeIcons; + public static TransmitterIcons tubeIcons; public float currentScale; @@ -178,7 +177,7 @@ public class PartPressurizedTube extends PartTransmitter public static void registerIcons(IconRegister register) { - tubeIcons = new PartTransmitterIcons(1, 1); + tubeIcons = new TransmitterIcons(1, 1); tubeIcons.registerCenterIcons(register, new String[] {"PressurizedTube"}); tubeIcons.registerSideIcons(register, new String[] {"TransmitterSideSmall"}); } diff --git a/common/mekanism/common/multipart/PartUniversalCable.java b/common/mekanism/common/multipart/PartUniversalCable.java index eb0274779..bda62eaaa 100644 --- a/common/mekanism/common/multipart/PartUniversalCable.java +++ b/common/mekanism/common/multipart/PartUniversalCable.java @@ -11,7 +11,6 @@ import mekanism.api.Coord4D; import mekanism.api.energy.IStrictEnergyAcceptor; import mekanism.api.transmitters.IGridTransmitter; import mekanism.api.transmitters.TransmissionType; -import mekanism.client.render.PartTransmitterIcons; import mekanism.client.render.RenderPartTransmitter; import mekanism.common.EnergyNetwork; import mekanism.common.Mekanism; @@ -29,7 +28,7 @@ import cpw.mods.fml.relauncher.SideOnly; public class PartUniversalCable extends PartTransmitter implements IStrictEnergyAcceptor, IEnergySink, IEnergyHandler { - public static PartTransmitterIcons cableIcons; + public static TransmitterIcons cableIcons; public double currentPower = 0; @@ -92,7 +91,7 @@ public class PartUniversalCable extends PartTransmitter implement public static void registerIcons(IconRegister register) { - cableIcons = new PartTransmitterIcons(1, 1); + cableIcons = new TransmitterIcons(1, 1); cableIcons.registerCenterIcons(register, new String[] {"UniversalCable"}); cableIcons.registerSideIcons(register, new String[] {"TransmitterSideSmall"}); } diff --git a/common/mekanism/client/render/PartTransmitterIcons.java b/common/mekanism/common/multipart/TransmitterIcons.java similarity index 87% rename from common/mekanism/client/render/PartTransmitterIcons.java rename to common/mekanism/common/multipart/TransmitterIcons.java index 4944c6d6b..38b742082 100644 --- a/common/mekanism/client/render/PartTransmitterIcons.java +++ b/common/mekanism/common/multipart/TransmitterIcons.java @@ -1,14 +1,14 @@ -package mekanism.client.render; +package mekanism.common.multipart; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.util.Icon; -public class PartTransmitterIcons +public class TransmitterIcons { private Icon[] sideIcons; private Icon[] centerIcons; - public PartTransmitterIcons(int numCentres, int numSides) + public TransmitterIcons(int numCentres, int numSides) { sideIcons = new Icon[numSides]; centerIcons = new Icon[numCentres]; diff --git a/common/mekanism/common/network/PacketConfigSync.java b/common/mekanism/common/network/PacketConfigSync.java new file mode 100644 index 000000000..8388b01d8 --- /dev/null +++ b/common/mekanism/common/network/PacketConfigSync.java @@ -0,0 +1,116 @@ +package mekanism.common.network; + +import java.io.DataOutputStream; + +import mekanism.common.Mekanism; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; +import net.minecraftforge.common.Configuration; + +import com.google.common.io.ByteArrayDataInput; + +public class PacketConfigSync implements IMekanismPacket +{ + @Override + public String getName() + { + return "ConfigSync"; + } + + @Override + public IMekanismPacket setParams(Object... data) + { + return this; + } + + @Override + public void read(ByteArrayDataInput dataStream, EntityPlayer player, World world) throws Exception + { + Mekanism.osmiumGenerationEnabled = dataStream.readBoolean(); + Mekanism.copperGenerationEnabled = dataStream.readBoolean(); + Mekanism.tinGenerationEnabled = dataStream.readBoolean(); + Mekanism.disableBCSteelCrafting = dataStream.readBoolean(); + Mekanism.disableBCBronzeCrafting = dataStream.readBoolean(); + Mekanism.updateNotifications = dataStream.readBoolean(); + Mekanism.controlCircuitOreDict = dataStream.readBoolean(); + Mekanism.logPackets = dataStream.readBoolean(); + Mekanism.dynamicTankEasterEgg = dataStream.readBoolean(); + Mekanism.allowBackCrafting = dataStream.readBoolean(); + Mekanism.voiceServerEnabled = dataStream.readBoolean(); + Mekanism.forceBuildcraft = dataStream.readBoolean(); + Mekanism.obsidianTNTDelay = dataStream.readInt(); + Mekanism.obsidianTNTBlastRadius = dataStream.readInt(); + Mekanism.UPDATE_DELAY = dataStream.readInt(); + Mekanism.osmiumGenerationAmount = dataStream.readInt(); + Mekanism.copperGenerationAmount = dataStream.readInt(); + Mekanism.tinGenerationAmount = dataStream.readInt(); + Mekanism.FROM_IC2 = dataStream.readDouble(); + Mekanism.TO_IC2 = dataStream.readDouble(); + Mekanism.FROM_BC = dataStream.readDouble(); + Mekanism.TO_BC = dataStream.readDouble(); + Mekanism.ENERGY_PER_REDSTONE = dataStream.readDouble(); + Mekanism.VOICE_PORT = dataStream.readInt(); + Mekanism.upgradeModifier = dataStream.readInt(); + + Mekanism.TO_TE = Mekanism.TO_BC*10; + Mekanism.FROM_TE = Mekanism.FROM_BC/10; + + Mekanism.enrichmentChamberUsage = dataStream.readDouble(); + Mekanism.osmiumCompressorUsage = dataStream.readDouble(); + Mekanism.combinerUsage = dataStream.readDouble(); + Mekanism.crusherUsage = dataStream.readDouble(); + Mekanism.factoryUsage = dataStream.readDouble(); + Mekanism.metallurgicInfuserUsage = dataStream.readDouble(); + Mekanism.purificationChamberUsage = dataStream.readDouble(); + Mekanism.energizedSmelterUsage = dataStream.readDouble(); + Mekanism.digitalMinerUsage = dataStream.readDouble(); + Mekanism.rotaryCondensentratorUsage = dataStream.readDouble(); + Mekanism.chemicalFormulatorUsage = dataStream.readDouble(); + Mekanism.chemicalInfuserUsage = dataStream.readDouble(); + + System.out.println("[Mekanism] Received config from server."); + } + + @Override + public void write(DataOutputStream dataStream) throws Exception + { + dataStream.writeBoolean(Mekanism.osmiumGenerationEnabled); + dataStream.writeBoolean(Mekanism.copperGenerationEnabled); + dataStream.writeBoolean(Mekanism.tinGenerationEnabled); + dataStream.writeBoolean(Mekanism.disableBCSteelCrafting); + dataStream.writeBoolean(Mekanism.disableBCBronzeCrafting); + dataStream.writeBoolean(Mekanism.updateNotifications); + dataStream.writeBoolean(Mekanism.controlCircuitOreDict); + dataStream.writeBoolean(Mekanism.logPackets); + dataStream.writeBoolean(Mekanism.dynamicTankEasterEgg); + dataStream.writeBoolean(Mekanism.allowBackCrafting); + dataStream.writeBoolean(Mekanism.voiceServerEnabled); + dataStream.writeBoolean(Mekanism.forceBuildcraft); + dataStream.writeInt(Mekanism.obsidianTNTDelay); + dataStream.writeInt(Mekanism.obsidianTNTBlastRadius); + dataStream.writeInt(Mekanism.UPDATE_DELAY); + dataStream.writeInt(Mekanism.osmiumGenerationAmount); + dataStream.writeInt(Mekanism.copperGenerationAmount); + dataStream.writeInt(Mekanism.tinGenerationAmount); + dataStream.writeDouble(Mekanism.FROM_IC2); + dataStream.writeDouble(Mekanism.TO_IC2); + dataStream.writeDouble(Mekanism.FROM_BC); + dataStream.writeDouble(Mekanism.TO_BC); + dataStream.writeDouble(Mekanism.ENERGY_PER_REDSTONE); + dataStream.writeInt(Mekanism.VOICE_PORT); + dataStream.writeInt(Mekanism.upgradeModifier); + + dataStream.writeDouble(Mekanism.enrichmentChamberUsage); + dataStream.writeDouble(Mekanism.osmiumCompressorUsage); + dataStream.writeDouble(Mekanism.combinerUsage); + dataStream.writeDouble(Mekanism.crusherUsage); + dataStream.writeDouble(Mekanism.factoryUsage); + dataStream.writeDouble(Mekanism.metallurgicInfuserUsage); + dataStream.writeDouble(Mekanism.purificationChamberUsage); + dataStream.writeDouble(Mekanism.energizedSmelterUsage); + dataStream.writeDouble(Mekanism.digitalMinerUsage); + dataStream.writeDouble(Mekanism.rotaryCondensentratorUsage); + dataStream.writeDouble(Mekanism.chemicalFormulatorUsage); + dataStream.writeDouble(Mekanism.chemicalInfuserUsage); + } +}