Fixed crash when previewing lanterns using mirror or radial mirror (blockstate nullpointer).

This commit is contained in:
Christian Knaapen
2022-03-19 21:49:37 +01:00
parent ad2e81c54e
commit 6e7aab673f
3 changed files with 17 additions and 12 deletions

View File

@@ -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<BlockState> 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));
}

View File

@@ -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);
}