From 4e3b1ef2cea077dc3c1d9f259cd872e732fd1715 Mon Sep 17 00:00:00 2001 From: Christian Knaapen Date: Mon, 23 Dec 2019 13:08:02 +0100 Subject: [PATCH] Fixed crash when placing ladders. Tweaked circle, cylinder and sphere to have the same outer radius whether they are full or hollow. --- .../buildmode/buildmodes/Circle.java | 6 +++--- .../buildmode/buildmodes/Sphere.java | 8 ++++---- .../effortlessbuilding/buildmodifier/UndoRedo.java | 1 + .../render/BlockPreviewRenderer.java | 12 +++++++----- .../effortlessbuilding/render/RenderHandler.java | 2 ++ 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main/java/nl/requios/effortlessbuilding/buildmode/buildmodes/Circle.java b/src/main/java/nl/requios/effortlessbuilding/buildmode/buildmodes/Circle.java index 5c917cd..3f7aa62 100644 --- a/src/main/java/nl/requios/effortlessbuilding/buildmode/buildmodes/Circle.java +++ b/src/main/java/nl/requios/effortlessbuilding/buildmode/buildmodes/Circle.java @@ -41,7 +41,7 @@ public class Circle extends TwoClicksBuildMode { if (ModeOptions.getFill() == ModeOptions.ActionEnum.FULL) addCircleBlocks(list, x1, y1, z1, x2, y2, z2, centerX, centerZ, radiusX, radiusZ); else - addHollowCircleBlocks(list, x1, y1, z1, x2, y2, z2, centerX, centerZ, radiusX, radiusZ, 1f); + addHollowCircleBlocks(list, x1, y1, z1, x2, y2, z2, centerX, centerZ, radiusX, radiusZ); return list; } @@ -60,7 +60,7 @@ public class Circle extends TwoClicksBuildMode { } } - public static void addHollowCircleBlocks(List list, int x1, int y1, int z1, int x2, int y2, int z2, float centerX, float centerZ, float radiusX, float radiusZ, float thickness) { + public static void addHollowCircleBlocks(List list, int x1, int y1, int z1, int x2, int y2, int z2, float centerX, float centerZ, float radiusX, float radiusZ) { for (int l = x1; x1 < x2 ? l <= x2 : l >= x2; l += x1 < x2 ? 1 : -1) { @@ -68,7 +68,7 @@ public class Circle extends TwoClicksBuildMode { float distance = distance(l, n, centerX, centerZ); float radius = calculateEllipseRadius(centerX, centerZ, radiusX, radiusZ, l, n); - if (distance < radius + (thickness / 2f) && distance > radius - (thickness / 2f)) + if (distance < radius + 0.4f && distance > radius - 0.6f) list.add(new BlockPos(l, y1, n)); } } diff --git a/src/main/java/nl/requios/effortlessbuilding/buildmode/buildmodes/Sphere.java b/src/main/java/nl/requios/effortlessbuilding/buildmode/buildmodes/Sphere.java index 8b13366..7739440 100644 --- a/src/main/java/nl/requios/effortlessbuilding/buildmode/buildmodes/Sphere.java +++ b/src/main/java/nl/requios/effortlessbuilding/buildmode/buildmodes/Sphere.java @@ -56,7 +56,7 @@ public class Sphere extends ThreeClicksBuildMode { if (ModeOptions.getFill() == ModeOptions.ActionEnum.FULL) addSphereBlocks(list, x1, y1, z1, x3, y3, z3, centerX, centerY, centerZ, radiusX, radiusY, radiusZ); else - addHollowSphereBlocks(list, x1, y1, z1, x3, y3, z3, centerX, centerY, centerZ, radiusX, radiusY, radiusZ, 1f); + addHollowSphereBlocks(list, x1, y1, z1, x3, y3, z3, centerX, centerY, centerZ, radiusX, radiusY, radiusZ); return list; } @@ -71,7 +71,7 @@ public class Sphere extends ThreeClicksBuildMode { float distance = distance(l, m, n, centerX, centerY, centerZ); float radius = calculateSpheroidRadius(centerX, centerY, centerZ, radiusX, radiusY, radiusZ, l, m, n); - if (distance < radius + 0.5f) + if (distance < radius + 0.4f) list.add(new BlockPos(l, m, n)); } } @@ -79,7 +79,7 @@ public class Sphere extends ThreeClicksBuildMode { } public static void addHollowSphereBlocks(List list, int x1, int y1, int z1, int x2, int y2, int z2, - float centerX, float centerY, float centerZ, float radiusX, float radiusY, float radiusZ, float thickness) { + float centerX, float centerY, float centerZ, float radiusX, float radiusY, float radiusZ) { for (int l = x1; x1 < x2 ? l <= x2 : l >= x2; l += x1 < x2 ? 1 : -1) { for (int n = z1; z1 < z2 ? n <= z2 : n >= z2; n += z1 < z2 ? 1 : -1) { @@ -88,7 +88,7 @@ public class Sphere extends ThreeClicksBuildMode { float distance = distance(l, m, n, centerX, centerY, centerZ); float radius = calculateSpheroidRadius(centerX, centerY, centerZ, radiusX, radiusY, radiusZ, l, m, n); - if (distance < radius + (thickness / 2f) && distance > radius - (thickness / 2f)) + if (distance < radius + 0.4f && distance > radius - 0.6f) list.add(new BlockPos(l, m, n)); } } diff --git a/src/main/java/nl/requios/effortlessbuilding/buildmodifier/UndoRedo.java b/src/main/java/nl/requios/effortlessbuilding/buildmodifier/UndoRedo.java index b91880d..fcd47aa 100644 --- a/src/main/java/nl/requios/effortlessbuilding/buildmodifier/UndoRedo.java +++ b/src/main/java/nl/requios/effortlessbuilding/buildmodifier/UndoRedo.java @@ -207,6 +207,7 @@ public class UndoRedo { private static ItemStack findItemStackInInventory(PlayerEntity player, BlockState blockState) { ItemStack itemStack = ItemStack.EMPTY; + if (blockState == null) return itemStack; //First try previousBlockStates //TODO try to find itemstack with right blockstate first diff --git a/src/main/java/nl/requios/effortlessbuilding/render/BlockPreviewRenderer.java b/src/main/java/nl/requios/effortlessbuilding/render/BlockPreviewRenderer.java index 19b0db5..28c4bfd 100644 --- a/src/main/java/nl/requios/effortlessbuilding/render/BlockPreviewRenderer.java +++ b/src/main/java/nl/requios/effortlessbuilding/render/BlockPreviewRenderer.java @@ -193,13 +193,15 @@ public class BlockPreviewRenderer { //if so, renew randomness of randomizer bag ItemRandomizerBag.renewRandomness(); //and play sound (max once every tick) - if (startCoordinates.size() > 1 && blockStates.size() > 1 && soundTime < ClientProxy.ticksInGame - 0) { + if (newCoordinates.size() > 1 && blockStates.size() > 1 && soundTime < ClientProxy.ticksInGame - 0) { soundTime = ClientProxy.ticksInGame; - SoundType soundType = blockStates.get(0).getBlock().getSoundType(blockStates.get(0), player.world, - newCoordinates.get(0), player); - player.world.playSound(player, player.getPosition(), breaking ? soundType.getBreakSound() : soundType.getPlaceSound(), - SoundCategory.BLOCKS, 0.3f, 0.8f); + if (blockStates.get(0) != null) { + SoundType soundType = blockStates.get(0).getBlock().getSoundType(blockStates.get(0), player.world, + newCoordinates.get(0), player); + player.world.playSound(player, player.getPosition(), breaking ? soundType.getBreakSound() : soundType.getPlaceSound(), + SoundCategory.BLOCKS, 0.3f, 0.8f); + } } } diff --git a/src/main/java/nl/requios/effortlessbuilding/render/RenderHandler.java b/src/main/java/nl/requios/effortlessbuilding/render/RenderHandler.java index 46a7430..12dc450 100644 --- a/src/main/java/nl/requios/effortlessbuilding/render/RenderHandler.java +++ b/src/main/java/nl/requios/effortlessbuilding/render/RenderHandler.java @@ -195,6 +195,8 @@ public class RenderHandler { } protected static void renderBlockPreview(BlockRendererDispatcher dispatcher, BlockPos blockPos, BlockState blockState) { + if (blockState == null) return; + GlStateManager.pushMatrix(); GlStateManager.translatef(blockPos.getX(), blockPos.getY(), blockPos.getZ()); GlStateManager.rotatef(-90.0F, 0.0F, 1.0F, 0.0F);