Skip to content

Commit

Permalink
Fix TE update frequency glitch that caused way too many packets being…
Browse files Browse the repository at this point in the history
… sent.
  • Loading branch information
rubensworks committed Dec 18, 2014
1 parent f990767 commit 9e3b679
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/main/java/evilcraft/core/tileentity/EvilCraftTileEntity.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package evilcraft.core.tileentity;

import java.lang.reflect.Field;
import java.util.LinkedList;
import java.util.List;

import evilcraft.core.config.configurable.ConfigurableBlockContainer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import evilcraft.core.config.configurable.ConfigurableBlockContainer;

import java.lang.reflect.Field;
import java.util.LinkedList;
import java.util.List;

/**
* A base class for all the tile entities that are used inside this mod.
Expand All @@ -26,7 +26,7 @@
*/
public class EvilCraftTileEntity extends TileEntity {

private static final int UPDATE_BACKOFF_TICKS = 10;
private static final int UPDATE_BACKOFF_TICKS = 1;

private List<Field> nbtPersistedFields = null;

Expand All @@ -40,7 +40,7 @@ public class EvilCraftTileEntity extends TileEntity {
* Make a new instance.
*/
public EvilCraftTileEntity() {
sendUpdateBackoff = (int) (Math.random() * getUpdateBackoffTicks()); // Random backoff so not all TE's will be updated at once.
sendUpdateBackoff = (int) Math.round(Math.random() * getUpdateBackoffTicks()); // Random backoff so not all TE's will be updated at once.
generateNBTPersistedFields();
}

Expand Down Expand Up @@ -101,11 +101,10 @@ protected void updateTileEntity() {
private void trySendActualUpdate() {
sendUpdateBackoff--;
if(sendUpdateBackoff <= 0) {
sendUpdateBackoff = getUpdateBackoffTicks();
sendUpdateBackoff = getUpdateBackoffTicks();

if(shouldSendUpdate) {
shouldSendUpdate = false;
sendUpdateBackoff = 0;

beforeSendUpdate();
onSendUpdate();
Expand Down

0 comments on commit 9e3b679

Please sign in to comment.