From 6e7aab673faf209f822b93a8e945d5d72eedaf12 Mon Sep 17 00:00:00 2001 From: Christian Knaapen Date: Sat, 19 Mar 2022 21:49:37 +0100 Subject: [PATCH] Fixed crash when previewing lanterns using mirror or radial mirror (blockstate nullpointer). --- build.gradle | 2 +- .../buildmodifier/BuildModifiers.java | 5 +++++ .../buildmodifier/RadialMirror.java | 22 +++++++++---------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/build.gradle b/build.gradle index 987bab1..6cbf376 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ apply plugin: 'net.minecraftforge.gradle' apply plugin: 'eclipse' apply plugin: 'maven-publish' -version = '1.18.1-2.32' +version = '1.18.1-2.33' group = 'nl.requios.effortlessbuilding' // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = 'effortlessbuilding' diff --git a/src/main/java/nl/requios/effortlessbuilding/buildmodifier/BuildModifiers.java b/src/main/java/nl/requios/effortlessbuilding/buildmodifier/BuildModifiers.java index 2564f42..db2363a 100644 --- a/src/main/java/nl/requios/effortlessbuilding/buildmodifier/BuildModifiers.java +++ b/src/main/java/nl/requios/effortlessbuilding/buildmodifier/BuildModifiers.java @@ -198,12 +198,15 @@ public class BuildModifiers { for (BlockPos blockPos : posList) { if (!(itemStack.getItem() instanceof BlockItem)) itemBlock = CompatHelper.getItemBlockFromStack(itemStack); BlockState blockState = getBlockStateFromItem(itemBlock, player, blockPos, facing, hitVec, InteractionHand.MAIN_HAND); + if (blockState == null) continue; + blockStates.add(blockState); itemStacks.add(itemBlock); } for (BlockPos blockPos : posList) { BlockState blockState = getBlockStateFromItem(itemBlock, player, blockPos, facing, hitVec, InteractionHand.MAIN_HAND); + if (blockState == null) continue; List arrayBlockStates = Array.findBlockStates(player, blockPos, blockState, itemStack, itemStacks); blockStates.addAll(arrayBlockStates); @@ -214,6 +217,8 @@ public class BuildModifiers { for (int i = 0; i < arrayCoordinates.size(); i++) { BlockPos coordinate = arrayCoordinates.get(i); BlockState blockState1 = arrayBlockStates.get(i); + if (blockState1 == null) continue; + blockStates.addAll(Mirror.findBlockStates(player, coordinate, blockState1, itemStack, itemStacks)); blockStates.addAll(RadialMirror.findBlockStates(player, coordinate, blockState1, itemStack, itemStacks)); } diff --git a/src/main/java/nl/requios/effortlessbuilding/buildmodifier/RadialMirror.java b/src/main/java/nl/requios/effortlessbuilding/buildmodifier/RadialMirror.java index eabe117..347dc2b 100644 --- a/src/main/java/nl/requios/effortlessbuilding/buildmodifier/RadialMirror.java +++ b/src/main/java/nl/requios/effortlessbuilding/buildmodifier/RadialMirror.java @@ -71,7 +71,7 @@ public class RadialMirror { double startAngleInSlice = startAngleToCenterMod % sliceAngle; //Rotate the original blockstate - blockState = rotateOriginalBlockState(startAngleToCenter, blockState); + blockState = rotateOriginalBlockState(player, startPos, startAngleToCenter, blockState); //Randomizer bag synergy AbstractRandomizerBagItem randomizerBagItem = null; @@ -102,11 +102,11 @@ public class RadialMirror { newBlockState = BuildModifiers .getBlockStateFromItem(itemStack, player, startPos, Direction.UP, new Vec3(0, 0, 0), InteractionHand.MAIN_HAND); - newBlockState = rotateOriginalBlockState(startAngleToCenter, newBlockState); + newBlockState = rotateOriginalBlockState(player, startPos, startAngleToCenter, newBlockState); } //rotate - newBlockState = rotateBlockState(relNewVec, newBlockState, r.alternate && i % 2 == 1); + newBlockState = rotateBlockState(player, startPos, relNewVec, newBlockState, r.alternate && i % 2 == 1); blockStates.add(newBlockState); itemStacks.add(itemStack); @@ -115,36 +115,36 @@ public class RadialMirror { return blockStates; } - private static BlockState rotateOriginalBlockState(double startAngleToCenter, BlockState blockState) { + private static BlockState rotateOriginalBlockState(Player player, BlockPos startPos, double startAngleToCenter, BlockState blockState) { BlockState newBlockState = blockState; if (startAngleToCenter < -0.751 * Math.PI || startAngleToCenter > 0.749 * Math.PI) { - newBlockState = blockState.rotate(Rotation.CLOCKWISE_180); + newBlockState = blockState.rotate(player.level, startPos, Rotation.CLOCKWISE_180); } else if (startAngleToCenter < -0.251 * Math.PI) { - newBlockState = blockState.rotate(Rotation.COUNTERCLOCKWISE_90); + newBlockState = blockState.rotate(player.level, startPos, Rotation.COUNTERCLOCKWISE_90); } else if (startAngleToCenter > 0.249 * Math.PI) { - newBlockState = blockState.rotate(Rotation.CLOCKWISE_90); + newBlockState = blockState.rotate(player.level, startPos, Rotation.CLOCKWISE_90); } return newBlockState; } - private static BlockState rotateBlockState(Vec3 relVec, BlockState blockState, boolean alternate) { + private static BlockState rotateBlockState(Player player, BlockPos startPos, Vec3 relVec, BlockState blockState, boolean alternate) { BlockState newBlockState; double angleToCenter = Mth.atan2(relVec.x, relVec.z); //between -PI and PI if (angleToCenter < -0.751 * Math.PI || angleToCenter > 0.749 * Math.PI) { - newBlockState = blockState.rotate(Rotation.CLOCKWISE_180); + newBlockState = blockState.rotate(player.level, startPos, Rotation.CLOCKWISE_180); if (alternate) { newBlockState = newBlockState.mirror(Mirror.FRONT_BACK); } } else if (angleToCenter < -0.251 * Math.PI) { - newBlockState = blockState.rotate(Rotation.CLOCKWISE_90); + newBlockState = blockState.rotate(player.level, startPos, Rotation.CLOCKWISE_90); if (alternate) { newBlockState = newBlockState.mirror(Mirror.LEFT_RIGHT); } } else if (angleToCenter > 0.249 * Math.PI) { - newBlockState = blockState.rotate(Rotation.COUNTERCLOCKWISE_90); + newBlockState = blockState.rotate(player.level, startPos, Rotation.COUNTERCLOCKWISE_90); if (alternate) { newBlockState = newBlockState.mirror(Mirror.LEFT_RIGHT); }