From 5d4a2a4a0d8ee9a39563717c804374e583e5e1e6 Mon Sep 17 00:00:00 2001 From: JOO200 Date: Wed, 29 Dec 2021 05:58:56 +0100 Subject: [PATCH] Use Math.floor instead of int cast 757bef1f7d2b16317ab3d18427ad22183344e28d --- .../math/convolution/HeightMapFilter.java | 2 +- .../math/convolution/SnowHeightMap.java | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMapFilter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMapFilter.java index 9015a17ac..7d6d7cedd 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMapFilter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMapFilter.java @@ -105,7 +105,7 @@ public class HeightMapFilter { for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { - outData[index++] = (int) calculateHeight(inDataFloat, width, height, offset, matrix, x, y); + outData[index++] = (int) Math.floor(calculateHeight(inDataFloat, width, height, offset, matrix, x, y)); } } return outData; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/SnowHeightMap.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/SnowHeightMap.java index df030639e..7de599f39 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/SnowHeightMap.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/SnowHeightMap.java @@ -178,13 +178,13 @@ public class SnowHeightMap { ++blocksChanged; // Grow -- start from 1 below top replacing airblocks - for (int y = (int) newHeight - 1 - originY; y >= 0; --y) { - if (y >= newHeight - 1 - originY - layerBlocks) { + for (int y = (int) Math.floor(newHeight - 1 - originY); y >= 0; --y) { + if (y >= Math.floor(newHeight - 1 - originY - layerBlocks)) { //FAWE start - avoid BlockVector3 creation for no reason session.setBlock(xr, originY + y, zr, fillerSnow); //FAWE end } else { - int copyFrom = (int) (y * scale); + int copyFrom = (int) Math.floor(y * scale); //FAWE start - avoid BlockVector3 creation for no reason BlockState block = session.getBlock(xr, originY + copyFrom, zr); session.setBlock(xr, originY + y, zr, block); @@ -195,13 +195,13 @@ public class SnowHeightMap { } } else { // Shrink -- start from bottom - for (int y = 0; y < (int) newHeight - originY; ++y) { - if (y >= (int) newHeight - originY - layerBlocks) { + for (int y = 0; y < (int) Math.floor(newHeight - originY); ++y) { + if (y >= (int) Math.floor(newHeight - originY - layerBlocks)) { //FAWE start - avoid BlockVector3 creation for no reason session.setBlock(xr, originY + y, zr, fillerSnow); //FAWE end } else { - int copyFrom = (int) (y * scale); + int copyFrom = (int) Math.floor(y * scale); //FAWE start - avoid BlockVector3 creation for no reason BlockState block = session.getBlock(xr, originY + copyFrom, zr); session.setBlock(xr, originY + y, zr, block); @@ -214,7 +214,7 @@ public class SnowHeightMap { ++blocksChanged; // Fill rest with air - for (int y = (int) newHeight + 1; y <= curHeight; ++y) { + for (int y = (int) Math.floor(newHeight + 1); y <= Math.floor(curHeight); ++y) { //FAWE start - avoid BlockVector3 creation for no reason session.setBlock(xr, y, zr, fillerAir); //FAWE end @@ -229,7 +229,8 @@ public class SnowHeightMap { } private void setSnowLayer(int x, int z, float newHeight) throws MaxChangedBlocksException { - int numOfLayers = (int) ((newHeight % 1) * 8) + 1; + int y = (int) Math.floor(newHeight); + int numOfLayers = (int) ((newHeight - y) * 8) + 1; //FAWE start - avoid BlockVector3 creation for no reason session.setBlock(x, (int) newHeight, z, BlockTypes.SNOW.getDefaultState().with(LAYERS, numOfLayers)); //FAWE end