Skip to content

Commit

Permalink
Added server/client config sync for more options like ore units and t…
Browse files Browse the repository at this point in the history
…imers. Fixed synced config options from servers being applied to single player worlds if the player does not restart the game after logging out of the server.
  • Loading branch information
Kittychanley committed Dec 22, 2015
1 parent 8871075 commit c09c0d4
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/Common/com/bioxx/tfc/Core/Player/PlayerTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import com.bioxx.tfc.TerraFirmaCraft;
import com.bioxx.tfc.Core.TFC_Core;
import com.bioxx.tfc.Core.Config.TFC_ConfigFiles;
import com.bioxx.tfc.Handlers.Network.AbstractPacket;
import com.bioxx.tfc.Handlers.Network.ConfigSyncPacket;
import com.bioxx.tfc.Handlers.Network.InitClientWorldPacket;
Expand All @@ -30,6 +31,7 @@ public void onPlayerLoggedIn(PlayerLoggedInEvent event)
PlayerManagerTFC.getInstance().players.add(new PlayerInfo(
event.player.getCommandSenderName(),
event.player.getUniqueID()));
TFC_ConfigFiles.reloadAll();
AbstractPacket pkt = new InitClientWorldPacket(event.player);
TerraFirmaCraft.PACKET_PIPELINE.sendTo(pkt, (EntityPlayerMP) event.player);
TerraFirmaCraft.PACKET_PIPELINE.sendTo(new ConfigSyncPacket(), (EntityPlayerMP) event.player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ public class InitClientWorldPacket extends AbstractPacket
private float nutrProtein;
private float nutrDairy;
private boolean craftingTable;
private boolean debugMode;
private SkillStats playerSkills;
private int daysInYear, healthGainRate, healthGainCap;
private Map<String, Integer> skillMap = new HashMap<String, Integer>();
private byte chiselMode;

// Config Options
private boolean debugMode;
private int daysInYear, healthGainRate, healthGainCap, maxProtectionMonths, protectionGain, protectionBuffer,
smallOreUnits, poorOreUnits, normalOreUnits, richOreUnits, torchBurnTime, oilLampFuelMult;
private float pitKilnBurnTime, bloomeryBurnTime, charcoalPitBurnTime, saplingTimerMultiplier, animalTimeMultiplier;

public InitClientWorldPacket() {}

public InitClientWorldPacket(EntityPlayer p)
Expand All @@ -51,10 +55,27 @@ public InitClientWorldPacket(EntityPlayer p)
this.nutrGrain = fs.nutrGrain;
this.nutrProtein = fs.nutrProtein;
this.nutrDairy = fs.nutrDairy;

// Sync config options between server and client
this.debugMode = TFCOptions.enableDebugMode;
this.daysInYear = TFCOptions.yearLength;
this.healthGainRate = TFCOptions.healthGainRate;
this.healthGainCap = TFCOptions.healthGainCap;
this.debugMode = TFCOptions.enableDebugMode;
this.maxProtectionMonths = TFCOptions.maxProtectionMonths;
this.protectionGain = TFCOptions.protectionGain;
this.protectionBuffer = TFCOptions.protectionBuffer;
this.smallOreUnits = TFCOptions.smallOreUnits;
this.poorOreUnits = TFCOptions.poorOreUnits;
this.normalOreUnits = TFCOptions.normalOreUnits;
this.richOreUnits = TFCOptions.richOreUnits;
this.pitKilnBurnTime = TFCOptions.pitKilnBurnTime;
this.bloomeryBurnTime = TFCOptions.bloomeryBurnTime;
this.charcoalPitBurnTime = TFCOptions.charcoalPitBurnTime;
this.torchBurnTime = TFCOptions.torchBurnTime;
this.saplingTimerMultiplier = TFCOptions.saplingTimerMultiplier;
this.oilLampFuelMult = TFCOptions.oilLampFuelMult;
this.animalTimeMultiplier = TFCOptions.animalTimeMultiplier;


if(p.getEntityData().hasKey("craftingTable"))
this.craftingTable = true;
Expand All @@ -66,7 +87,6 @@ public InitClientWorldPacket(EntityPlayer p)
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer)
{
buffer.writeLong(this.seed);
buffer.writeInt(this.daysInYear);
buffer.writeFloat(this.stomachLevel);
buffer.writeFloat(this.waterLevel);
buffer.writeLong(this.soberTime);
Expand All @@ -75,19 +95,35 @@ public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer)
buffer.writeFloat(this.nutrGrain);
buffer.writeFloat(this.nutrProtein);
buffer.writeFloat(this.nutrDairy);
buffer.writeInt(this.healthGainRate);
buffer.writeInt(this.healthGainCap);
buffer.writeBoolean(this.craftingTable);
this.playerSkills.toOutBuffer(buffer);
buffer.writeByte(this.chiselMode);

// Config Options
buffer.writeBoolean(this.debugMode);
buffer.writeInt(this.daysInYear);
buffer.writeInt(this.healthGainRate);
buffer.writeInt(this.healthGainCap);
buffer.writeInt(this.maxProtectionMonths);
buffer.writeInt(this.protectionGain);
buffer.writeInt(this.protectionBuffer);
buffer.writeInt(this.smallOreUnits);
buffer.writeInt(this.poorOreUnits);
buffer.writeInt(this.normalOreUnits);
buffer.writeInt(this.richOreUnits);
buffer.writeInt(this.torchBurnTime);
buffer.writeInt(this.oilLampFuelMult);
buffer.writeFloat(this.pitKilnBurnTime);
buffer.writeFloat(this.bloomeryBurnTime);
buffer.writeFloat(this.charcoalPitBurnTime);
buffer.writeFloat(this.saplingTimerMultiplier);
buffer.writeFloat(this.animalTimeMultiplier);
}

@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer)
{
this.seed = buffer.readLong();
this.daysInYear = buffer.readInt();
this.stomachLevel = buffer.readFloat();
this.waterLevel = buffer.readFloat();
this.soberTime = buffer.readLong();
Expand All @@ -96,8 +132,6 @@ public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer)
this.nutrGrain = buffer.readFloat();
this.nutrProtein = buffer.readFloat();
this.nutrDairy = buffer.readFloat();
this.healthGainRate = buffer.readInt();
this.healthGainCap = buffer.readInt();
this.craftingTable = buffer.readBoolean();

this.skillMap.clear();
Expand All @@ -112,7 +146,26 @@ public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer)
}

this.chiselMode = buffer.readByte();

// Config Options
this.debugMode = buffer.readBoolean();
this.daysInYear = buffer.readInt();
this.healthGainRate = buffer.readInt();
this.healthGainCap = buffer.readInt();
this.maxProtectionMonths = buffer.readInt();
this.protectionGain = buffer.readInt();
this.protectionBuffer = buffer.readInt();
this.smallOreUnits = buffer.readInt();
this.poorOreUnits = buffer.readInt();
this.normalOreUnits = buffer.readInt();
this.richOreUnits = buffer.readInt();
this.torchBurnTime = buffer.readInt();
this.oilLampFuelMult = buffer.readInt();
this.pitKilnBurnTime = buffer.readFloat();
this.bloomeryBurnTime = buffer.readFloat();
this.charcoalPitBurnTime = buffer.readFloat();
this.saplingTimerMultiplier = buffer.readFloat();
this.animalTimeMultiplier = buffer.readFloat();
}

@Override
Expand All @@ -128,10 +181,6 @@ public void handleClientSide(EntityPlayer player)
fs.nutrDairy = this.nutrDairy;
TFC_Core.setPlayerFoodStats(player, fs);

TFC_Time.setYearLength(this.daysInYear);
TFCOptions.healthGainRate = this.healthGainRate;
TFCOptions.healthGainCap = this.healthGainCap;
TFCOptions.enableDebugMode = this.debugMode;
if(this.craftingTable)
{
player.getEntityData().setBoolean("craftingTable", this.craftingTable);
Expand All @@ -152,7 +201,25 @@ public void handleClientSide(EntityPlayer player)

PlayerManagerTFC.getInstance().getClientPlayer().setChiselMode(this.chiselMode);


// Sync Config Options
TFCOptions.enableDebugMode = this.debugMode;
TFC_Time.setYearLength(this.daysInYear);
TFCOptions.healthGainRate = this.healthGainRate;
TFCOptions.healthGainCap = this.healthGainCap;
TFCOptions.maxProtectionMonths = this.maxProtectionMonths;
TFCOptions.protectionGain = this.protectionGain;
TFCOptions.protectionBuffer = this.protectionBuffer;
TFCOptions.smallOreUnits = this.smallOreUnits;
TFCOptions.poorOreUnits = this.poorOreUnits;
TFCOptions.normalOreUnits = this.normalOreUnits;
TFCOptions.richOreUnits = this.richOreUnits;
TFCOptions.torchBurnTime = this.torchBurnTime;
TFCOptions.oilLampFuelMult = this.oilLampFuelMult;
TFCOptions.pitKilnBurnTime = this.pitKilnBurnTime;
TFCOptions.bloomeryBurnTime = this.bloomeryBurnTime;
TFCOptions.charcoalPitBurnTime = this.charcoalPitBurnTime;
TFCOptions.saplingTimerMultiplier = this.saplingTimerMultiplier;
TFCOptions.animalTimeMultiplier = this.animalTimeMultiplier;
}

@Override
Expand Down

0 comments on commit c09c0d4

Please sign in to comment.