Added a central way of limiting the syncs.

Tiles auto sync every 30 seconds
they have a max so they can only sync 2 times a second
This commit is contained in:
modmuss50 2015-05-22 08:22:16 +01:00
parent cdf8f3e0a3
commit e930ea2a04
2 changed files with 14 additions and 7 deletions

View file

@ -97,7 +97,7 @@ public class RecipeCrafter {
}
if(canGiveInvAll){
currentRecipe = recipe;//Sets the current recipe then syncs
parentTile.syncWithAll();
parentTile.needsSync = true;
return;
}
}
@ -106,7 +106,7 @@ public class RecipeCrafter {
if(!hasAllInputs()){//If it doesn't have all the inputs reset
currentRecipe = null;
currentTickTime = 0;
parentTile.syncWithAll();
parentTile.needsSync = true;
return;
}
if (currentTickTime >= currentRecipe.tickTime()) {//If it has reached the recipe tick time
@ -127,7 +127,7 @@ public class RecipeCrafter {
useAllInputs();//this uses all the inputs
currentRecipe = null;//resets
currentTickTime = 0;
parentTile.syncWithAll();
parentTile.needsSync = true;
}
} else if (currentTickTime < currentRecipe.tickTime()) {
if (energy.canUseEnergy(currentRecipe.euPerTick())) {//This checks to see if it can use the power
@ -135,7 +135,7 @@ public class RecipeCrafter {
this.energy.setEnergyStored(this.energy.getEnergyStored() - currentRecipe.euPerTick());
}
currentTickTime++;//increase the ticktime
parentTile.syncWithAll();
parentTile.needsSync = true;
}
}
}

View file

@ -12,13 +12,20 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class TileMachineBase extends TileEntity {
private int facing;
public boolean needsSync = false;
public int ticksSinceLastSync = 0;
@Override
public void updateEntity() {
super.updateEntity();
// TODO make this happen less
// syncWithAll();
//Force a sync evey 30 seconds
if(needsSync && ticksSinceLastSync >= 10 || ticksSinceLastSync == 600){
syncWithAll();
needsSync = false;
ticksSinceLastSync = 0;
}
ticksSinceLastSync ++;
}
@SideOnly(Side.CLIENT)