From 1bcae16a8333486cb2d5b04c2b94fcb4ceb1684b Mon Sep 17 00:00:00 2001 From: ISNing <1208733578@qq.com> Date: Fri, 21 Jul 2023 19:36:51 +0800 Subject: [PATCH] Avoid causing exception when getDestroySpeed needs real block pos This fix https://github.com/DynamicTreesTeam/DynamicTrees/issues/792 --- src/main/java/weather2/util/WeatherUtil.java | 14 +++++--------- .../weathersystem/storm/TornadoHelper.java | 2 +- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main/java/weather2/util/WeatherUtil.java b/src/main/java/weather2/util/WeatherUtil.java index cbf6d037..f84a01eb 100644 --- a/src/main/java/weather2/util/WeatherUtil.java +++ b/src/main/java/weather2/util/WeatherUtil.java @@ -159,25 +159,21 @@ public static boolean isOceanBlock(Block blockID) return false; } - public static boolean isSolidBlock(Block id) - { + public static boolean isSolidBlock(Block id) { return (id == Blocks.STONE || id == Blocks.COBBLESTONE || id == Blocks.SANDSTONE); } - public static boolean shouldGrabBlock(Level parWorld, BlockState state) - { - try - { + public static boolean shouldGrabBlock(Level parWorld, BlockState state, BlockPos pos) { + try { ItemStack itemStr = new ItemStack(Items.DIAMOND_AXE); Block block = state.getBlock(); boolean result = true; - if (ConfigTornado.Storm_Tornado_GrabCond_List) - { + if (ConfigTornado.Storm_Tornado_GrabCond_List) { try { result = canGrabViaLists(state); } catch (Exception e) { @@ -198,7 +194,7 @@ public static boolean shouldGrabBlock(Level parWorld, BlockState state) } else { //float strVsBlock = block.getBlockHardness(block.defaultBlockState(), parWorld, new BlockPos(0, 0, 0)) - (((itemStr.getStrVsBlock(block.defaultBlockState()) - 1) / 4F)); - float strVsBlock = state.getDestroySpeed(parWorld, new BlockPos(0, 0, 0)) - (((itemStr.getDestroySpeed(block.defaultBlockState()) - 1) / 4F)); + float strVsBlock = state.getDestroySpeed(parWorld, pos) - (((itemStr.getDestroySpeed(block.defaultBlockState()) - 1) / 4F)); //System.out.println(strVsBlock); if (/*block.getHardness() <= 10000.6*/ (strVsBlock <= strMax && strVsBlock >= strMin) || diff --git a/src/main/java/weather2/weathersystem/storm/TornadoHelper.java b/src/main/java/weather2/weathersystem/storm/TornadoHelper.java index a8ce0b48..86c0eca3 100644 --- a/src/main/java/weather2/weathersystem/storm/TornadoHelper.java +++ b/src/main/java/weather2/weathersystem/storm/TornadoHelper.java @@ -529,7 +529,7 @@ public boolean canGrab(Level parWorld, BlockState state, BlockPos pos) state.getBlock() != Blocks.FIRE && //TODO: 1.14 uncomment /*state.getBlock() != CommonProxy.blockRepairingBlock &&*/ - WeatherUtil.shouldGrabBlock(parWorld, state) && + WeatherUtil.shouldGrabBlock(parWorld, state, pos) && !isBlockGrabbingBlocked(parWorld, state, pos)) { return canGrabEventCheck(parWorld, state, pos);