Skip to content

Commit a2992f0

Browse files
committed
Fix water mill short circuit
1 parent a993d1b commit a2992f0

File tree

5 files changed

+46
-23
lines changed

5 files changed

+46
-23
lines changed

src/main/java/ml/sakii/factoryisland/Game.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import ml.sakii.factoryisland.blocks.components.PowerPropagatorComponent;
5151
import ml.sakii.factoryisland.blocks.components.SignalConsumerComponent;
5252
import ml.sakii.factoryisland.blocks.components.SignalPropagatorComponent;
53-
import ml.sakii.factoryisland.blocks.components.TickUpdateComponent;
5453
import ml.sakii.factoryisland.blocks.components.WorldLoadComponent;
5554
import ml.sakii.factoryisland.entities.Entity;
5655
import ml.sakii.factoryisland.entities.PlayerMP;
@@ -595,7 +594,7 @@ public void run() {
595594
float timePercent = (realTime*1f/Globals.TICKS_PER_DAY);
596595
double light = Math.sin(2*Math.PI*timePercent);
597596
debugInfo.add("Tick: " + Engine.Tick + "(" + Engine.TickableBlocks.size() + "), day:"+Engine.isDay((int)PE.ViewFrom.z)+",light:"+light);
598-
debugInfo.add("needUpdate:" + !SelectedBlock.getComponents(TickUpdateComponent.class).isEmpty() +", blockLightPass:"+Engine.world.lightCalcRuns);
597+
debugInfo.add("needUpdate:" + Engine.TickableBlocks.contains(SelectedBlock.pos) +", blockLightPass:"+Engine.world.lightCalcRuns);
599598
debugInfo.add("Blocks: " + Engine.world.getSize() + ", hotbarIndex:"+PE.inventory.getHotbarIndex()+", selected:"+((PE.inventory.getHotbarIndex()>-1 ) ? PE.inventory.getSelectedKind() : ""));
600599
if (Engine.client != null)
601600
{

src/main/java/ml/sakii/factoryisland/GameEngine.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class GameEngine{
3333

3434

3535
public World world;
36-
public final HashSet<TickUpdateComponent> TickableBlocks = new HashSet<>();
36+
public final ArrayList<Point3D> TickableBlocks = new ArrayList<>();
3737
final ArrayList<DayNightComponent> DayNightBlocks = new ArrayList<>();
3838
public long Tick=0;
3939

@@ -96,11 +96,33 @@ public void performTick() {
9696
if(server != null || client==null) {
9797

9898

99-
for(TickUpdateComponent tuc : new ArrayList<>(TickableBlocks)) {
99+
ArrayList<Point3D> current = new ArrayList<>(TickableBlocks);
100+
TickableBlocks.clear();
101+
for(Point3D p : current) {
102+
103+
Block bl = world.getBlockAtP(p);
104+
if(bl != Block.NOTHING) {
105+
boolean keep=false;
106+
for(TickUpdateComponent tuc : bl.getComponents(TickUpdateComponent.class)) {
107+
if(Tick % tuc.refreshRate != 0 || tuc.onTick(Tick)) {
108+
keep=true;
109+
}
110+
}
111+
if(keep) {
112+
TickableBlocks.add(p);
113+
}
114+
}else if(Main.verbose){
115+
// Air block ticked
116+
Main.err("Attempted to tick air block:"+p);
117+
}
118+
119+
}
120+
121+
/*for(TickUpdateComponent tuc : new ArrayList<>(TickableBlocks)) {
100122
if(Tick % tuc.refreshRate == 0 && !tuc.onTick(Tick)) {
101123
TickableBlocks.remove(tuc);
102124
}
103-
}
125+
}*/
104126

105127

106128

src/main/java/ml/sakii/factoryisland/World.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -445,13 +445,13 @@ private void ReplaceBlock(Block b) {
445445

446446
for (Entry<BlockFace, Block> entry : get6Blocks(b, false).entrySet()) {
447447
Block block = entry.getValue();
448-
for(TickUpdateComponent tuc : block.getComponents(TickUpdateComponent.class)) {
449-
Engine.TickableBlocks.add(tuc);
448+
if(block.getComponents(TickUpdateComponent.class).size() > 0) {
449+
Engine.TickableBlocks.add(block.pos);
450450
}
451451
}
452452

453-
for(TickUpdateComponent tuc : b.getComponents(TickUpdateComponent.class)) {
454-
Engine.TickableBlocks.add(tuc);
453+
if(b.getComponents(TickUpdateComponent.class).size() > 0) {
454+
Engine.TickableBlocks.add(b.pos);
455455
}
456456

457457
for(DayNightComponent dnc : b.getComponents(DayNightComponent.class)) {
@@ -504,7 +504,8 @@ public void destroyBlock(Block b, boolean resend) {
504504
}else {
505505

506506
if (getBlockAtP(b.pos) == Block.NOTHING) {
507-
Main.err("Attempted to destroy air block: "+b.pos);
507+
Thread.dumpStack();
508+
//Main.err("Attempted to destroy air block: "+b.pos);
508509
return;
509510
}
510511

@@ -520,13 +521,16 @@ public void destroyBlock(Block b, boolean resend) {
520521

521522
for (Entry<BlockFace, Block> entry : get6Blocks(b, false).entrySet()) {
522523
Block bu = entry.getValue();
523-
for(TickUpdateComponent tuc : bu.getComponents(TickUpdateComponent.class)) {
524-
Engine.TickableBlocks.add(tuc);
524+
if (bu.getComponents(TickUpdateComponent.class).size() > 0) {
525+
Engine.TickableBlocks.add(bu.pos);
525526
}
527+
526528
}
527529

528-
for(TickUpdateComponent tuc : b.getComponents(TickUpdateComponent.class)) {
529-
Engine.TickableBlocks.remove(tuc);
530+
531+
532+
if (b.getComponents(TickUpdateComponent.class).size() > 0) {
533+
Engine.TickableBlocks.remove(b.pos);
530534
}
531535

532536
for(DayNightComponent dnc : b.getComponents(DayNightComponent.class)) {

src/main/java/ml/sakii/factoryisland/api/Block.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package ml.sakii.factoryisland.api;
22

3-
import java.util.List;
4-
53
import ml.sakii.factoryisland.GameEngine;
6-
import ml.sakii.factoryisland.blocks.components.TickUpdateComponent;
74

85
public class Block{
96

@@ -46,8 +43,7 @@ public void setMetadata(String key, String value) {
4643
}
4744

4845
public void update() {
49-
List<TickUpdateComponent> tuc = b.getComponents(TickUpdateComponent.class);
50-
Engine.TickableBlocks.addAll(tuc);
46+
Engine.TickableBlocks.add(b.pos);
5147
}
5248

5349

src/main/java/ml/sakii/factoryisland/blocks/Block.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,16 @@ public final void setMetadata(String key, String value, boolean resend)
197197
if(!alreadyput) {
198198
BlockMeta.put(key, value);
199199
}
200-
for(TickUpdateComponent tuc : this.getComponents(TickUpdateComponent.class)) {
201-
Engine.TickableBlocks.add(tuc);
200+
201+
if(this.getComponents(TickUpdateComponent.class).size() > 0) {
202+
Engine.TickableBlocks.add(pos);
202203
}
204+
203205
for (Block b2 : Engine.world.get6Blocks(this, false).values())
204206
{
205207
if(Engine.client == null || (Engine.client != null && Engine.client != null)) {
206-
for(TickUpdateComponent tuc2 : b2.getComponents(TickUpdateComponent.class)) {
207-
Engine.TickableBlocks.add(tuc2);
208+
if(b2.getComponents(TickUpdateComponent.class).size() > 0) {
209+
Engine.TickableBlocks.add(b2.pos);
208210
}
209211
}
210212
}

0 commit comments

Comments
 (0)