From 882790d133000518ed1a761c18b0ccffb06e82db Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 19 Jul 2018 18:10:29 -0400 Subject: [PATCH] Sleeping system changes --- core/src/io/anuke/mindustry/entities/TileEntity.java | 11 +++++++++++ core/src/io/anuke/mindustry/world/BaseBlock.java | 2 +- .../mindustry/world/blocks/distribution/Conduit.java | 2 +- .../mindustry/world/blocks/distribution/Conveyor.java | 4 +++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/core/src/io/anuke/mindustry/entities/TileEntity.java b/core/src/io/anuke/mindustry/entities/TileEntity.java index 64cda916fd..59b05c68df 100644 --- a/core/src/io/anuke/mindustry/entities/TileEntity.java +++ b/core/src/io/anuke/mindustry/entities/TileEntity.java @@ -103,6 +103,17 @@ public class TileEntity extends BaseEntity implements TargetTrait{ * If the entity was sleeping, this enables it. This also resets the sleep timer. */ public void wakeUp(){ + noSleep(); + + for(Tile tile : proximity){ + if(tile.entity.isSleeping()){ + tile.entity.wakeUp(); + } + } + } + + /**Call when this entity is updating. This wakes it up.*/ + public void noSleep(){ sleepTime = 0f; if(sleeping){ add(); diff --git a/core/src/io/anuke/mindustry/world/BaseBlock.java b/core/src/io/anuke/mindustry/world/BaseBlock.java index 4893c9f0a8..9b97c1940e 100644 --- a/core/src/io/anuke/mindustry/world/BaseBlock.java +++ b/core/src/io/anuke/mindustry/world/BaseBlock.java @@ -72,7 +72,7 @@ public abstract class BaseBlock{ } public void onProximityUpdate(Tile tile){ - if(tile.entity != null) tile.entity.wakeUp(); + if(tile.entity != null) tile.entity.noSleep(); } public void handleItem(Item item, Tile tile, Tile source){ diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/Conduit.java b/core/src/io/anuke/mindustry/world/blocks/distribution/Conduit.java index 5deb50a848..01513da6b8 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/Conduit.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/Conduit.java @@ -105,7 +105,7 @@ public class Conduit extends LiquidBlock{ if(tile.entity.liquids.total() > 0.001f && tile.entity.timer.get(timerFlow, 1)){ tryMoveLiquid(tile, tile.getNearby(tile.getRotation()), true, tile.entity.liquids.current()); - entity.wakeUp(); + entity.noSleep(); }else{ entity.sleep(); } diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/Conveyor.java b/core/src/io/anuke/mindustry/world/blocks/distribution/Conveyor.java index f117acf923..33ce205151 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/Conveyor.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/Conveyor.java @@ -176,7 +176,7 @@ public class Conveyor extends Block{ public void unitOn(Tile tile, Unit unit){ ConveyorEntity entity = tile.entity(); - entity.wakeUp(); + entity.noSleep(); float speed = this.speed * tilesize / 2.3f; float centerSpeed = 0.1f; @@ -267,6 +267,8 @@ public class Conveyor extends Block{ if(totalMoved/Timers.delta() <= 0.0001f){ entity.sleep(); + }else{ + entity.noSleep(); } if(minremove != Integer.MAX_VALUE) entity.convey.truncate(minremove);