From 9aa8d1eb80d285683caf0188d393176690f73229 Mon Sep 17 00:00:00 2001 From: Samuel Willows Date: Thu, 28 Nov 2024 13:53:20 -0800 Subject: [PATCH] update webAura.java - fixed crash --- .../snail/plus/modules/combat/webAura.java | 69 +++++++++++-------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/snail/plus/modules/combat/webAura.java b/src/main/java/org/snail/plus/modules/combat/webAura.java index 37f4e9f..411c72f 100644 --- a/src/main/java/org/snail/plus/modules/combat/webAura.java +++ b/src/main/java/org/snail/plus/modules/combat/webAura.java @@ -172,12 +172,13 @@ public void onTick(TickEvent.Post event) { if (entity == mc.player || entity.isDead() || entity.distanceTo(mc.player) > range.get() || Friends.get().isFriend(entity)) continue; if (onlySurround.get() && !CombatUtils.isSurrounded(entity)) continue; - for (BlockPos blockPos : positions(entity)) { + + BestTarget = entity; + for (BlockPos blockPos : positions(BestTarget)) { placed = !WorldUtils.isAir(blockPos); placeWeb(blockPos); if (doublePlace.get()) { placeWeb(blockPos.up(1)); - BestTarget = entity; } } } @@ -193,10 +194,13 @@ public void placeWeb(BlockPos pos) { long currentTime = System.currentTimeMillis(); if (currentTime - lastPlacedTime < (1000 / speed.get())) return; if (!placed) { - FindItemResult web = InvUtils.findInHotbar(Items.COBWEB); - if (web.found()) { - WorldUtils.placeBlock(web, pos, hand.get(), direction.get(), true, swapMode.get(), rotate.get()); + FindItemResult web = InvUtils.find(Items.COBWEB); + if (!web.found()) { + error("No webs in hotbar... disabling."); + toggle(); + return; } + WorldUtils.placeBlock(web, pos, hand.get(), direction.get(), true, swapMode.get(), rotate.get()); } lastPlacedTime = currentTime; } finally { @@ -208,36 +212,41 @@ public void placeWeb(BlockPos pos) { public void onRender(Render3DEvent event) { switch (mode.get()) { case smooth -> { - for (BlockPos pos : positions(BestTarget)) { - if (renderBoxTwo instanceof IBox) { - ((IBox) renderBoxTwo).set(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1, - pos.getY() + 1, pos.getZ() + 1); - } + if (BestTarget != null) { - if (renderBoxOne == null) { - renderBoxOne = new Box(pos); - } - if (renderBoxTwo == null) { - renderBoxTwo = new Box(pos); - } + for (BlockPos pos : positions(BestTarget)) { + if (renderBoxTwo instanceof IBox) { + ((IBox) renderBoxTwo).set(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1, + pos.getY() + 1, pos.getZ() + 1); + } - double offsetX = (renderBoxTwo.minX - renderBoxOne.minX) / Smoothness.get(); - double offsetY = (renderBoxTwo.minY - renderBoxOne.minY) / Smoothness.get(); - double offsetZ = (renderBoxTwo.minZ - renderBoxOne.minZ) / Smoothness.get(); - - ((IBox) renderBoxOne).set( - renderBoxOne.minX + offsetX, - renderBoxOne.minY + offsetY, - renderBoxOne.minZ + offsetZ, - renderBoxOne.maxX + offsetX, - renderBoxOne.maxY + offsetY, - renderBoxOne.maxZ + offsetZ); - event.renderer.box(renderBoxOne, sideColor.get(), lineColor.get(), shapeMode.get(), 0); + if (renderBoxOne == null) { + renderBoxOne = new Box(pos); + } + if (renderBoxTwo == null) { + renderBoxTwo = new Box(pos); + } + + double offsetX = (renderBoxTwo.minX - renderBoxOne.minX) / Smoothness.get(); + double offsetY = (renderBoxTwo.minY - renderBoxOne.minY) / Smoothness.get(); + double offsetZ = (renderBoxTwo.minZ - renderBoxOne.minZ) / Smoothness.get(); + + ((IBox) renderBoxOne).set( + renderBoxOne.minX + offsetX, + renderBoxOne.minY + offsetY, + renderBoxOne.minZ + offsetZ, + renderBoxOne.maxX + offsetX, + renderBoxOne.maxY + offsetY, + renderBoxOne.maxZ + offsetZ); + event.renderer.box(renderBoxOne, sideColor.get(), lineColor.get(), shapeMode.get(), 0); + } } } case normal -> { - for (BlockPos pos : positions(BestTarget)) { - event.renderer.box(pos, sideColor.get(), lineColor.get(), shapeMode.get(), 0); + if (BestTarget != null) { + for (BlockPos pos : positions(BestTarget)) { + event.renderer.box(pos, sideColor.get(), lineColor.get(), shapeMode.get(), 0); + } } } }