Skip to content

Commit

Permalink
Fix wind generators speed and direction not behaving properly in resp…
Browse files Browse the repository at this point in the history
…ect to the new world height limits #7912
  • Loading branch information
pupnewfster committed Feb 21, 2024
1 parent 75ef2aa commit 8bd636e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Expand Up @@ -59,8 +59,8 @@ private void renderTranslated(TileEntityWindGenerator tile, float partialTick, P
MekanismRenderer.rotate(matrix, tile.getDirection(), 0, 180, 90, 270);
matrix.mulPose(Axis.ZP.rotationDegrees(180));
double angle = tile.getAngle();
if (tile.getActive()) {
angle = (tile.getAngle() + ((tile.getBlockPos().getY() + 4F) / TileEntityWindGenerator.SPEED_SCALED) * partialTick) % 360;
if (tile.getActive() && partialTick > 0) {
angle = (angle + tile.getHeightSpeedRatio() * partialTick) % 360;
}
renderer.render(matrix, angle);
matrix.popPose();
Expand Down
Expand Up @@ -27,8 +27,7 @@

public class TileEntityWindGenerator extends TileEntityGenerator implements IBoundingBlock {

public static final float SPEED = 32F;
public static final float SPEED_SCALED = 256F / SPEED;
private static final float SPEED = 32F;

private double angle;
private FloatingLong currentMultiplier = FloatingLong.ZERO;
Expand Down Expand Up @@ -75,10 +74,22 @@ protected void onUpdateServer() {
protected void onUpdateClient() {
super.onUpdateClient();
if (getActive()) {
angle = (angle + (getBlockPos().getY() + 4F) / SPEED_SCALED) % 360;
angle = (angle + getHeightSpeedRatio()) % 360;
}
}

public float getHeightSpeedRatio() {
int height = getBlockPos().getY() + 4;
if (level == null) {
//Fallback to default values, but in general this is not going to happen
return SPEED * height / 384F;
}
//Shift so that a wind generator at the min build height acts as if it was at a height of zero
int minBuildHeight = level.getMinBuildHeight();
height += Math.abs(minBuildHeight);

This comment has been minimized.

Copy link
@Oct0bass

Oct0bass Feb 29, 2024

Can the min build height be positive? Because if so, I think this would shift the height the wrong way (should be height -= minBuildHeight).

return SPEED * height / (level.getMaxBuildHeight() - minBuildHeight);
}

/**
* Determines the current output multiplier, taking sky visibility and height into account.
**/
Expand Down

0 comments on commit 8bd636e

Please sign in to comment.