Skip to content

Commit 5b1910f

Browse files
Fix waterwheels not updating blocked in many cases, fixes #6174
1 parent 781aff9 commit 5b1910f

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

src/main/java/blusunrize/immersiveengineering/common/blocks/wooden/WatermillBlockEntity.java

+32-23
Original file line numberDiff line numberDiff line change
@@ -153,39 +153,48 @@ public void handleUpdate(@Nullable Direction search)
153153
//Search for the waterwheel with the dynamo, or process the update if we have the connected dynamo
154154
if(dynamo.getCapability()!=null)
155155
{
156+
//Get the direction to step in
156157
Direction step = facingCap.getCapability()==null?getFacing(): getFacing().getOpposite();
157-
//Get total torque across all connected wheels up to maximum
158-
double torque = getIFScaledTorque();
159-
int wheels = 1;
160-
while(wheels < MAX_WHEELS)
158+
//Set power & speed to zero to start calculation
159+
powerOut = 0;
160+
speed = 0;
161+
//Calculate the new torque this wheel will produce
162+
if (!this.isBlocked())
161163
{
162-
BlockEntity be = SafeChunkUtils.getSafeBE(level, getBlockPos().relative(step, wheels));
163-
if(be instanceof WatermillBlockEntity watermill)
164-
if(watermill.isBlocked())
165-
break;
164+
//Number of wheels in a row, determined to be at least one
165+
int wheels = 1;
166+
//Get total torque across all connected wheels up to maximum, and check how many connected wheels there are
167+
double torque = getIFScaledTorque();
168+
for(int i = 1; i < MAX_WHEELS; i++)
169+
{
170+
BlockEntity be = SafeChunkUtils.getSafeBE(level, getBlockPos().relative(step, i));
171+
if(be instanceof WatermillBlockEntity watermill)
172+
if(watermill.isBlocked())
173+
break;
174+
else
175+
torque += watermill.getIFScaledTorque();
166176
else
167-
torque += watermill.getIFScaledTorque();
168-
else
169-
break;
170-
wheels++;
177+
break;
178+
wheels++;
179+
}
180+
//Calculate torque to use for this wheel
181+
powerOut = Math.abs(torque);
182+
speed = 0.00025*torque/wheels;
171183
}
172-
//Update connected wheels with new torque as necessary
173-
powerOut = Math.abs(torque);
174-
speed = 0.00025*torque/wheels;
175184
//Update client with the data we just set
176185
level.sendBlockUpdated(getBlockPos(), level.getBlockState(getBlockPos()), level.getBlockState(getBlockPos()), 3);
177-
for(int i=1; i < wheels; i++)
186+
//Updated connected waterwheels with torque & speed
187+
boolean blocked = false;
188+
for(int i=1; i < MAX_WHEELS; i++)
178189
{
179190
BlockPos pos = getBlockPos().relative(step, i);
180191
BlockEntity be = SafeChunkUtils.getSafeBE(level, pos);
181192
if(be instanceof WatermillBlockEntity watermill)
182-
if(watermill.isBlocked())
183-
break;
184-
else
185-
{
186-
watermill.speed = speed;
187-
watermill.rotation = rotation;
188-
}
193+
{
194+
blocked = blocked || watermill.isBlocked();
195+
watermill.speed = blocked?0: speed;
196+
watermill.rotation = blocked?0: rotation;
197+
}
189198
//Update client with the data we just set
190199
level.sendBlockUpdated(pos, level.getBlockState(pos), level.getBlockState(pos), 3);
191200
}

0 commit comments

Comments
 (0)