From 9e3b679553e49d452d6fafec88303de2740b26ef Mon Sep 17 00:00:00 2001 From: Ruben Taelman Date: Thu, 18 Dec 2014 18:47:37 +0100 Subject: [PATCH] Fix TE update frequency glitch that caused way too many packets being sent. --- .../core/tileentity/EvilCraftTileEntity.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/evilcraft/core/tileentity/EvilCraftTileEntity.java b/src/main/java/evilcraft/core/tileentity/EvilCraftTileEntity.java index 0740971230..ffae087ece 100644 --- a/src/main/java/evilcraft/core/tileentity/EvilCraftTileEntity.java +++ b/src/main/java/evilcraft/core/tileentity/EvilCraftTileEntity.java @@ -1,9 +1,6 @@ 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; @@ -11,7 +8,10 @@ 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. @@ -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 nbtPersistedFields = null; @@ -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(); } @@ -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();