@@ -153,39 +153,48 @@ public void handleUpdate(@Nullable Direction search)
153
153
//Search for the waterwheel with the dynamo, or process the update if we have the connected dynamo
154
154
if (dynamo .getCapability ()!=null )
155
155
{
156
+ //Get the direction to step in
156
157
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 ())
161
163
{
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 ();
166
176
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 ;
171
183
}
172
- //Update connected wheels with new torque as necessary
173
- powerOut = Math .abs (torque );
174
- speed = 0.00025 *torque /wheels ;
175
184
//Update client with the data we just set
176
185
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 ++)
178
189
{
179
190
BlockPos pos = getBlockPos ().relative (step , i );
180
191
BlockEntity be = SafeChunkUtils .getSafeBE (level , pos );
181
192
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
+ }
189
198
//Update client with the data we just set
190
199
level .sendBlockUpdated (pos , level .getBlockState (pos ), level .getBlockState (pos ), 3 );
191
200
}
0 commit comments