mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-19 03:39:09 +00:00
#19 Spread out tick updates for tile entities
This commit is contained in:
1 parent
0848cfb891
commit
786dbd82c7
26 files changed
+46
-51
No files matched your search
@@ -71,7 +71,7 @@ public abstract class TileAlveary extends TileForestry implements IAlvearyCompon
|
||||
}
|
||||
|
||||
// Periodic validation if needed
|
||||
if (worldObj.getTotalWorldTime() % 200 == 0 && (!isIntegratedIntoStructure() || isMaster())) {
|
||||
if (updateOnInterval(200) && (!isIntegratedIntoStructure() || isMaster())) {
|
||||
validateStructure();
|
||||
}
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory
|
||||
}
|
||||
}
|
||||
|
||||
if (worldObj.getTotalWorldTime() % 20 * 10 != 0) {
|
||||
if (!updateOnInterval(20)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB
|
||||
}
|
||||
|
||||
// Add swarm effects
|
||||
if (worldObj.getTotalWorldTime() % 200 == 0) {
|
||||
if (updateOnInterval(200)) {
|
||||
ISidedInventory inventory = getStructureInventory();
|
||||
if (inventory != null) {
|
||||
onQueenChange(inventory.getStackInSlot(SLOT_QUEEN));
|
||||
@@ -161,7 +161,7 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB
|
||||
queen.doFX(beekeepingLogic.getEffectData(), this);
|
||||
}
|
||||
|
||||
if (getErrorState() == EnumErrorCode.OK && worldObj.getTotalWorldTime() % 50 == 0) {
|
||||
if (getErrorState() == EnumErrorCode.OK && updateOnInterval(50)) {
|
||||
float f = xCoord + 0.5F;
|
||||
float f1 = yCoord + 0.0F + (worldObj.rand.nextFloat() * 6F) / 16F;
|
||||
float f2 = zCoord + 0.5F;
|
||||
@@ -191,7 +191,7 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB
|
||||
// / Multiplayer FX
|
||||
ItemStack queenStack = inventory.getStackInSlot(SLOT_QUEEN);
|
||||
if (PluginApiculture.beeInterface.isMated(queenStack)) {
|
||||
if (getErrorState() == EnumErrorCode.OK && worldObj.getTotalWorldTime() % 2 == 0) {
|
||||
if (getErrorState() == EnumErrorCode.OK && updateOnInterval(2)) {
|
||||
IBee displayQueen = PluginApiculture.beeInterface.getMember(queenStack);
|
||||
displayQueen.doFX(beekeepingLogic.getEffectData(), this);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class TileAlvearySieve extends TileAlveary implements ICrafter, IBeeListe
|
||||
@Override
|
||||
protected void updateServerSide() {
|
||||
super.updateServerSide();
|
||||
if (worldObj.getTotalWorldTime() % 200 != 0) {
|
||||
if (!updateOnInterval(200)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public class TileAlvearyStabiliser extends TileAlveary implements IBeeModifier {
|
||||
@Override
|
||||
protected void updateServerSide() {
|
||||
super.updateServerSide();
|
||||
if (worldObj.getTotalWorldTime() % 200 != 0) {
|
||||
if (!updateOnInterval(200)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,14 +66,14 @@ public class TileAlvearySwarmer extends TileAlveary implements ISidedInventory {
|
||||
|
||||
if (pendingSpawns.size() > 0) {
|
||||
setIsActive(true);
|
||||
if (worldObj.getTotalWorldTime() % 1000 == 0) {
|
||||
if (updateOnInterval(1000)) {
|
||||
trySpawnSwarm();
|
||||
}
|
||||
} else {
|
||||
setIsActive(false);
|
||||
}
|
||||
|
||||
if (worldObj.getTotalWorldTime() % 500 != 0) {
|
||||
if (!updateOnInterval(500)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -161,7 +161,7 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised {
|
||||
|
||||
// / Multiplayer FX
|
||||
if (PluginApiculture.beeInterface.isMated(getInternalInventory().getStackInSlot(SLOT_QUEEN))) {
|
||||
if (getErrorState() == EnumErrorCode.OK && worldObj.getTotalWorldTime() % 2 % 2 == 0) {
|
||||
if (getErrorState() == EnumErrorCode.OK && updateOnInterval(2)) {
|
||||
IBee displayQueen = PluginApiculture.beeInterface.getMember(getInternalInventory().getStackInSlot(SLOT_QUEEN));
|
||||
displayQueen.doFX(logic.getEffectData(), this);
|
||||
}
|
||||
@@ -180,26 +180,9 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised {
|
||||
}
|
||||
|
||||
// Add swarm effects
|
||||
if (worldObj.getTotalWorldTime() % 200 * 10 == 0) {
|
||||
if (updateOnInterval(200)) {
|
||||
onQueenChange(getInternalInventory().getStackInSlot(SLOT_QUEEN));
|
||||
}
|
||||
/* These should get already done on the client / doesn't work server-side anyway
|
||||
if (getErrorState() == EnumErrorCode.OK && worldObj.getTotalWorldTime() % 2 % 2 == 0)
|
||||
queen.doFX(logic.getEffectData(), this);
|
||||
|
||||
if (getErrorState() == EnumErrorCode.OK && worldObj.getTotalWorldTime() % 50 == 0) {
|
||||
float f = xCoord + 0.5F;
|
||||
float f1 = yCoord + 0.0F + (worldObj.rand.nextFloat() * 6F) / 16F;
|
||||
float f2 = zCoord + 0.5F;
|
||||
float f3 = 0.52F;
|
||||
float f4 = worldObj.rand.nextFloat() * 0.6F - 0.3F;
|
||||
|
||||
Proxies.common.addEntitySwarmFX(worldObj, (f - f3), f1, (f2 + f4), 0F, 0F, 0F);
|
||||
Proxies.common.addEntitySwarmFX(worldObj, (f + f3), f1, (f2 + f4), 0F, 0F, 0F);
|
||||
Proxies.common.addEntitySwarmFX(worldObj, (f + f4), f1, (f2 - f3), 0F, 0F, 0F);
|
||||
Proxies.common.addEntitySwarmFX(worldObj, (f + f4), f1, (f2 + f3), 0F, 0F, 0F);
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
// @Override
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.core.gadgets;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
@@ -58,9 +59,12 @@ import buildcraft.api.statements.ITriggerProvider;
|
||||
@Optional.Interface(iface = "buildcraft.api.statements.ITriggerProvider", modid = "BuildCraftAPI|statements")
|
||||
public abstract class TileForestry extends TileEntity implements INetworkedEntity, IRestrictedAccess, IErrorSource, ITriggerProvider, ISidedInventory, IFilterSlotDelegate {
|
||||
|
||||
private static Random rand = new Random();
|
||||
|
||||
protected final AdjacentTileCache tileCache = new AdjacentTileCache(this);
|
||||
protected boolean isInited = false;
|
||||
private IInventoryAdapter inventory = FakeInventoryAdapter.instance();
|
||||
private final int tickUpdateOffset = rand.nextInt();
|
||||
|
||||
public AdjacentTileCache getTileCache() {
|
||||
return tileCache;
|
||||
@@ -116,6 +120,10 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit
|
||||
}
|
||||
}
|
||||
|
||||
public final boolean updateOnInterval(int tickInterval) {
|
||||
return (worldObj.getTotalWorldTime() + tickUpdateOffset) % tickInterval == 0;
|
||||
}
|
||||
|
||||
public abstract void initialize();
|
||||
|
||||
// / SAVING & LOADING
|
||||
|
||||
@@ -62,7 +62,7 @@ public abstract class TilePowered extends TileBase implements IRenderableMachine
|
||||
workCounter++;
|
||||
}
|
||||
|
||||
if (workCounter >= WORK_CYCLES && worldObj.getTotalWorldTime() % 5 == 0) {
|
||||
if (workCounter >= WORK_CYCLES && updateOnInterval(5)) {
|
||||
if (workCycle()) {
|
||||
workCounter = 0;
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank
|
||||
@Override
|
||||
public void updateServerSide() {
|
||||
super.updateServerSide();
|
||||
if (worldObj.getTotalWorldTime() % 20 * 10 != 0) {
|
||||
if (!updateOnInterval(20)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ public class EngineCopper extends Engine implements ISidedInventory {
|
||||
public void updateServerSide() {
|
||||
super.updateServerSide();
|
||||
|
||||
if (worldObj.getTotalWorldTime() % 40 != 0) {
|
||||
if (!updateOnInterval(40)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ public class MachineGenerator extends TileBase implements ISidedInventory, ILiqu
|
||||
|
||||
@Override
|
||||
public void updateServerSide() {
|
||||
if (worldObj.getTotalWorldTime() % 20 == 0) {
|
||||
if (updateOnInterval(20)) {
|
||||
// Check inventory slots for fuel
|
||||
// Check if we have suitable items waiting in the item slot
|
||||
IInventoryAdapter inventory = getInternalInventory();
|
||||
|
||||
@@ -229,7 +229,7 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq
|
||||
|
||||
@Override
|
||||
public void updateServerSide() {
|
||||
if (worldObj.getTotalWorldTime() % 20 != 0) {
|
||||
if (!updateOnInterval(20)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -339,7 +339,7 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL
|
||||
@Override
|
||||
public void updateServerSide() {
|
||||
|
||||
if (worldObj.getTotalWorldTime() % 20 != 0) {
|
||||
if (!updateOnInterval(20)) {
|
||||
return;
|
||||
}
|
||||
IInventoryAdapter accessibleInventory = getInternalInventory();
|
||||
@@ -348,7 +348,7 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL
|
||||
FluidHelper.drainContainers(tankManager, accessibleInventory, SLOT_CAN_INPUT);
|
||||
}
|
||||
|
||||
if (worldObj.getTotalWorldTime() % 40 != 0) {
|
||||
if (!updateOnInterval(40)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -213,7 +213,7 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory {
|
||||
@Override
|
||||
public void updateServerSide() {
|
||||
|
||||
if (worldObj.getTotalWorldTime() % 20 * 10 != 0) {
|
||||
if (!updateOnInterval(20)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -278,7 +278,7 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
@Override
|
||||
public void updateServerSide() {
|
||||
|
||||
if (worldObj.getTotalWorldTime() % 20 != 0) {
|
||||
if (!updateOnInterval(20)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -115,6 +115,11 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui
|
||||
|
||||
@Override
|
||||
public void updateServerSide() {
|
||||
|
||||
if (!updateOnInterval(20)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isValidBiome) {
|
||||
setErrorState(EnumErrorCode.INVALIDBIOME);
|
||||
} else if (!worldObj.canBlockSeeTheSky(xCoord, yCoord + 1, zCoord)) {
|
||||
@@ -125,11 +130,7 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui
|
||||
resourceTank.fill(STACK_WATER, true);
|
||||
setErrorState(EnumErrorCode.OK);
|
||||
}
|
||||
|
||||
if (worldObj.getTotalWorldTime() % 16 != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
IInventoryAdapter inventory = getInternalInventory();
|
||||
if (!StackUtils.isIdenticalItem(usedEmpty, inventory.getStackInSlot(SLOT_RESOURCE))) {
|
||||
fillingTime = 0;
|
||||
|
||||
@@ -210,7 +210,7 @@ public class MachineSqueezer extends TilePowered implements ISidedInventory, ILi
|
||||
@Override
|
||||
public void updateServerSide() {
|
||||
|
||||
if (worldObj.getTotalWorldTime() % 20 != 0) {
|
||||
if (!updateOnInterval(20)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -188,7 +188,7 @@ public class MachineStill extends TilePowered implements ISidedInventory, ILiqui
|
||||
@Override
|
||||
public void updateServerSide() {
|
||||
|
||||
if (worldObj.getTotalWorldTime() % 20 * 10 != 0) {
|
||||
if (!updateOnInterval(20)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ public abstract class TileFarm extends TileForestry implements IFarmComponent {
|
||||
}
|
||||
|
||||
// Periodic validation if needed
|
||||
if (worldObj.getTotalWorldTime() % 200 == 0 && (!isIntegratedIntoStructure() || isMaster())) {
|
||||
if (updateOnInterval(200) && (!isIntegratedIntoStructure() || isMaster())) {
|
||||
validateStructure();
|
||||
}
|
||||
|
||||
|
||||
@@ -204,7 +204,7 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
}
|
||||
}
|
||||
|
||||
if (worldObj.getTotalWorldTime() % 20 != 0) {
|
||||
if (!updateOnInterval(20)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ public class TileGearbox extends TileFarm implements IPowerHandler {
|
||||
workCounter++;
|
||||
}
|
||||
|
||||
if (workCounter >= WORK_CYCLES && worldObj.getTotalWorldTime() % 5 == 0) {
|
||||
if (workCounter >= WORK_CYCLES && updateOnInterval(5)) {
|
||||
ITileStructure central = getCentralTE();
|
||||
if (!(central instanceof IFarmHousing)) {
|
||||
return;
|
||||
|
||||
@@ -54,7 +54,7 @@ public class TileHatch extends TileFarm implements ISidedInventory {
|
||||
|
||||
@Override
|
||||
protected void updateServerSide() {
|
||||
if (worldObj.getTotalWorldTime() % 40 == 0) {
|
||||
if (updateOnInterval(40)) {
|
||||
dumpStash();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.lepidopterology.items;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
@@ -44,6 +45,8 @@ import forestry.plugins.PluginLepidopterology;
|
||||
|
||||
public class ItemButterflyGE extends ItemGE {
|
||||
|
||||
private static Random rand = new Random();
|
||||
|
||||
private final EnumFlutterType type;
|
||||
|
||||
public ItemButterflyGE(EnumFlutterType type) {
|
||||
@@ -113,7 +116,7 @@ public class ItemButterflyGE extends ItemGE {
|
||||
if (!Proxies.common.isSimulating(entityItem.worldObj) || entityItem.ticksExisted < 80) {
|
||||
return false;
|
||||
}
|
||||
if (entityItem.worldObj.getTotalWorldTime() % 24 != 0) {
|
||||
if (rand.nextInt(24) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public class MachinePhilatelist extends TileBase implements IInventory {
|
||||
// / UPDATING
|
||||
@Override
|
||||
public void updateServerSide() {
|
||||
if (worldObj.getTotalWorldTime() % 20 * 10 != 0) {
|
||||
if (!updateOnInterval(20)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ public class MachineTrader extends TileBase {
|
||||
@Override
|
||||
public void updateServerSide() {
|
||||
|
||||
if (!isLinked() || worldObj.getTotalWorldTime() % 4 != 0) {
|
||||
if (!isLinked() || !updateOnInterval(10)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user