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

@@ -12,7 +12,7 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse' apply plugin: 'eclipse'
apply plugin: 'maven-publish' 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 group = 'nl.requios.effortlessbuilding' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'effortlessbuilding' archivesBaseName = 'effortlessbuilding'

View File

@@ -198,12 +198,15 @@ public class BuildModifiers {
for (BlockPos blockPos : posList) { for (BlockPos blockPos : posList) {
if (!(itemStack.getItem() instanceof BlockItem)) itemBlock = CompatHelper.getItemBlockFromStack(itemStack); if (!(itemStack.getItem() instanceof BlockItem)) itemBlock = CompatHelper.getItemBlockFromStack(itemStack);
BlockState blockState = getBlockStateFromItem(itemBlock, player, blockPos, facing, hitVec, InteractionHand.MAIN_HAND); BlockState blockState = getBlockStateFromItem(itemBlock, player, blockPos, facing, hitVec, InteractionHand.MAIN_HAND);
if (blockState == null) continue;
blockStates.add(blockState); blockStates.add(blockState);
itemStacks.add(itemBlock); itemStacks.add(itemBlock);
} }
for (BlockPos blockPos : posList) { for (BlockPos blockPos : posList) {
BlockState blockState = getBlockStateFromItem(itemBlock, player, blockPos, facing, hitVec, InteractionHand.MAIN_HAND); 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); List<BlockState> arrayBlockStates = Array.findBlockStates(player, blockPos, blockState, itemStack, itemStacks);
blockStates.addAll(arrayBlockStates); blockStates.addAll(arrayBlockStates);
@@ -214,6 +217,8 @@ public class BuildModifiers {
for (int i = 0; i < arrayCoordinates.size(); i++) { for (int i = 0; i < arrayCoordinates.size(); i++) {
BlockPos coordinate = arrayCoordinates.get(i); BlockPos coordinate = arrayCoordinates.get(i);
BlockState blockState1 = arrayBlockStates.get(i); BlockState blockState1 = arrayBlockStates.get(i);
if (blockState1 == null) continue;
blockStates.addAll(Mirror.findBlockStates(player, coordinate, blockState1, itemStack, itemStacks)); blockStates.addAll(Mirror.findBlockStates(player, coordinate, blockState1, itemStack, itemStacks));
blockStates.addAll(RadialMirror.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; double startAngleInSlice = startAngleToCenterMod % sliceAngle;
//Rotate the original blockstate //Rotate the original blockstate
blockState = rotateOriginalBlockState(startAngleToCenter, blockState); blockState = rotateOriginalBlockState(player, startPos, startAngleToCenter, blockState);
//Randomizer bag synergy //Randomizer bag synergy
AbstractRandomizerBagItem randomizerBagItem = null; AbstractRandomizerBagItem randomizerBagItem = null;
@@ -102,11 +102,11 @@ public class RadialMirror {
newBlockState = BuildModifiers newBlockState = BuildModifiers
.getBlockStateFromItem(itemStack, player, startPos, Direction.UP, new Vec3(0, 0, 0), InteractionHand.MAIN_HAND); .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 //rotate
newBlockState = rotateBlockState(relNewVec, newBlockState, r.alternate && i % 2 == 1); newBlockState = rotateBlockState(player, startPos, relNewVec, newBlockState, r.alternate && i % 2 == 1);
blockStates.add(newBlockState); blockStates.add(newBlockState);
itemStacks.add(itemStack); itemStacks.add(itemStack);
@@ -115,36 +115,36 @@ public class RadialMirror {
return blockStates; 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; BlockState newBlockState = blockState;
if (startAngleToCenter < -0.751 * Math.PI || startAngleToCenter > 0.749 * Math.PI) { 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) { } 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) { } else if (startAngleToCenter > 0.249 * Math.PI) {
newBlockState = blockState.rotate(Rotation.CLOCKWISE_90); newBlockState = blockState.rotate(player.level, startPos, Rotation.CLOCKWISE_90);
} }
return newBlockState; 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; BlockState newBlockState;
double angleToCenter = Mth.atan2(relVec.x, relVec.z); //between -PI and PI double angleToCenter = Mth.atan2(relVec.x, relVec.z); //between -PI and PI
if (angleToCenter < -0.751 * Math.PI || angleToCenter > 0.749 * Math.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) { if (alternate) {
newBlockState = newBlockState.mirror(Mirror.FRONT_BACK); newBlockState = newBlockState.mirror(Mirror.FRONT_BACK);
} }
} else if (angleToCenter < -0.251 * Math.PI) { } else if (angleToCenter < -0.251 * Math.PI) {
newBlockState = blockState.rotate(Rotation.CLOCKWISE_90); newBlockState = blockState.rotate(player.level, startPos, Rotation.CLOCKWISE_90);
if (alternate) { if (alternate) {
newBlockState = newBlockState.mirror(Mirror.LEFT_RIGHT); newBlockState = newBlockState.mirror(Mirror.LEFT_RIGHT);
} }
} else if (angleToCenter > 0.249 * Math.PI) { } else if (angleToCenter > 0.249 * Math.PI) {
newBlockState = blockState.rotate(Rotation.COUNTERCLOCKWISE_90); newBlockState = blockState.rotate(player.level, startPos, Rotation.COUNTERCLOCKWISE_90);
if (alternate) { if (alternate) {
newBlockState = newBlockState.mirror(Mirror.LEFT_RIGHT); newBlockState = newBlockState.mirror(Mirror.LEFT_RIGHT);
} }