From 774722cb5a88cc38c3f24301ee054b19aae2f9ec Mon Sep 17 00:00:00 2001 From: Light_Quanta Date: Sat, 11 May 2024 13:56:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AE=9E=E4=BD=93=E6=9F=A5?= =?UTF-8?q?=E6=89=BE=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../target/client/gui/MortarGUIScreen.java | 26 ++- .../client/screens/SpyglassRangeOverlay.java | 22 +- .../network/MortarGUIButtonMessage.java | 29 +-- .../procedures/AngleAddMiniProcedure.java | 190 ++--------------- .../procedures/AngleAddPlusProcedure.java | 190 ++--------------- .../target/procedures/AngleAddProcedure.java | 190 ++--------------- .../procedures/AngleReduceMiniProcedure.java | 193 ++---------------- .../procedures/AngleReducePlusProcedure.java | 190 ++--------------- .../procedures/AngleReduceProcedure.java | 189 ++--------------- .../procedures/EntityRangeProcedure.java | 146 ------------- .../procedures/MortarAngleProcedure.java | 82 -------- ...UIGaiGUIDaKaiShiMeiKeFaShengProcedure.java | 192 ----------------- .../MortarGUIGaiGUIDaKaiShiProcedure.java | 83 -------- .../procedures/MortarPitchProcedure.java | 86 -------- .../procedures/MotarGUITickProcedure.java | 118 +++-------- .../net/mcreator/target/tools/TraceTool.java | 40 ++++ .../target/world/inventory/MortarGUIMenu.java | 16 +- 17 files changed, 191 insertions(+), 1791 deletions(-) delete mode 100644 src/main/java/net/mcreator/target/procedures/EntityRangeProcedure.java delete mode 100644 src/main/java/net/mcreator/target/procedures/MortarAngleProcedure.java delete mode 100644 src/main/java/net/mcreator/target/procedures/MortarGUIGaiGUIDaKaiShiMeiKeFaShengProcedure.java delete mode 100644 src/main/java/net/mcreator/target/procedures/MortarGUIGaiGUIDaKaiShiProcedure.java delete mode 100644 src/main/java/net/mcreator/target/procedures/MortarPitchProcedure.java create mode 100644 src/main/java/net/mcreator/target/tools/TraceTool.java diff --git a/src/main/java/net/mcreator/target/client/gui/MortarGUIScreen.java b/src/main/java/net/mcreator/target/client/gui/MortarGUIScreen.java index 52631b4de..8ebf51795 100644 --- a/src/main/java/net/mcreator/target/client/gui/MortarGUIScreen.java +++ b/src/main/java/net/mcreator/target/client/gui/MortarGUIScreen.java @@ -3,18 +3,19 @@ package net.mcreator.target.client.gui; import com.mojang.blaze3d.systems.RenderSystem; import net.mcreator.target.TargetMod; import net.mcreator.target.network.MortarGUIButtonMessage; -import net.mcreator.target.procedures.MortarAngleProcedure; -import net.mcreator.target.procedures.MortarPitchProcedure; +import net.mcreator.target.tools.TraceTool; import net.mcreator.target.world.inventory.MortarGUIMenu; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; +import java.text.DecimalFormat; import java.util.HashMap; public class MortarGUIScreen extends AbstractContainerScreen { @@ -72,12 +73,21 @@ public class MortarGUIScreen extends AbstractContainerScreen { super.containerTick(); } + private String getAngleString(Entity entity) { + if (entity == null) return ""; + Entity mortar = TraceTool.findLookingEntity(entity, 6); + if (mortar == null) return ""; + return "Angle: " + new DecimalFormat("##.#").format(-mortar.getXRot()); + } + @Override protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY) { - guiGraphics.drawString(this.font, + guiGraphics.drawString(this.font, getAngleString(entity), -18, 98, -1, false); - MortarAngleProcedure.execute(entity), -18, 98, -1, false); - guiGraphics.drawString(this.font, Component.literal("Range:" + (int) RangeHelper.getRange(MortarPitchProcedure.execute(entity))), -18, 108, -16711885, false); + Entity looking = TraceTool.findLookingEntity(entity, 6); + var range = looking == null ? 0 : -looking.getXRot(); + + guiGraphics.drawString(this.font, Component.literal("Range:" + (int) RangeHelper.getRange(range)), -18, 108, -16711885, false); } @Override @@ -97,7 +107,7 @@ public class MortarGUIScreen extends AbstractContainerScreen { button_empty = Button.builder(Component.translatable("gui.target.mortar_gui.button_empty"), e -> { TargetMod.PACKET_HANDLER.sendToServer(new MortarGUIButtonMessage(1, x, y, z)); MortarGUIButtonMessage.handleButtonAction(entity, 1, x, y, z); - }).bounds(this.leftPos + -73, this.topPos + 124, 30, 20).build(); + }).bounds(this.leftPos - 73, this.topPos + 124, 30, 20).build(); guistate.put("button:button_empty", button_empty); this.addRenderableWidget(button_empty); button_10 = Button.builder(Component.translatable("gui.target.mortar_gui.button_10"), e -> { @@ -109,13 +119,13 @@ public class MortarGUIScreen extends AbstractContainerScreen { button_101 = Button.builder(Component.translatable("gui.target.mortar_gui.button_101"), e -> { TargetMod.PACKET_HANDLER.sendToServer(new MortarGUIButtonMessage(3, x, y, z)); MortarGUIButtonMessage.handleButtonAction(entity, 3, x, y, z); - }).bounds(this.leftPos + -73, this.topPos + 151, 30, 20).build(); + }).bounds(this.leftPos - 73, this.topPos + 151, 30, 20).build(); guistate.put("button:button_101", button_101); this.addRenderableWidget(button_101); button_05 = Button.builder(Component.translatable("gui.target.mortar_gui.button_05"), e -> { TargetMod.PACKET_HANDLER.sendToServer(new MortarGUIButtonMessage(4, x, y, z)); MortarGUIButtonMessage.handleButtonAction(entity, 4, x, y, z); - }).bounds(this.leftPos + -73, this.topPos + 97, 30, 20).build(); + }).bounds(this.leftPos - 73, this.topPos + 97, 30, 20).build(); guistate.put("button:button_05", button_05); this.addRenderableWidget(button_05); button_051 = Button.builder(Component.translatable("gui.target.mortar_gui.button_051"), e -> { diff --git a/src/main/java/net/mcreator/target/client/screens/SpyglassRangeOverlay.java b/src/main/java/net/mcreator/target/client/screens/SpyglassRangeOverlay.java index f14140064..d21524b4e 100644 --- a/src/main/java/net/mcreator/target/client/screens/SpyglassRangeOverlay.java +++ b/src/main/java/net/mcreator/target/client/screens/SpyglassRangeOverlay.java @@ -1,7 +1,9 @@ package net.mcreator.target.client.screens; -import net.mcreator.target.procedures.EntityRangeProcedure; +import net.mcreator.target.tools.TraceTool; import net.minecraft.client.Minecraft; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Items; import net.minecraftforge.api.distmarker.Dist; @@ -10,6 +12,8 @@ import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; +import java.text.DecimalFormat; + @Mod.EventBusSubscriber(value = Dist.CLIENT) public class SpyglassRangeOverlay { @@ -17,16 +21,24 @@ public class SpyglassRangeOverlay { public static void eventHandler(RenderGuiEvent.Pre event) { int w = event.getWindow().getGuiScaledWidth(); int h = event.getWindow().getGuiScaledHeight(); - Player entity = Minecraft.getInstance().player; - if (entity != null && entity.getMainHandItem().getItem() == Items.SPYGLASS) { + Player player = Minecraft.getInstance().player; + if (player != null && player.getMainHandItem().getItem() == Items.SPYGLASS) { event.getGuiGraphics().drawString( Minecraft.getInstance().font, - EntityRangeProcedure.execute(entity), + getDistanceString(player), w / 2 + 19, - h / 2 + -23, + h / 2 - 23, -1, false ); } } + + private static String getDistanceString(Player entity) { + Entity looking = TraceTool.findLookingEntity(entity, 1024); + if (looking instanceof LivingEntity) { + return looking.getDisplayName().getString() + ":" + new DecimalFormat("##.#").format(entity.position().distanceTo(looking.position())) + "M"; + } + return ""; + } } diff --git a/src/main/java/net/mcreator/target/network/MortarGUIButtonMessage.java b/src/main/java/net/mcreator/target/network/MortarGUIButtonMessage.java index 3365a8771..fc29b47c6 100644 --- a/src/main/java/net/mcreator/target/network/MortarGUIButtonMessage.java +++ b/src/main/java/net/mcreator/target/network/MortarGUIButtonMessage.java @@ -59,29 +59,14 @@ public class MortarGUIButtonMessage { // security measure to prevent arbitrary chunk generation if (!world.hasChunkAt(new BlockPos(x, y, z))) return; - if (buttonID == 0) { - AngleAddProcedure.execute(entity); - } - if (buttonID == 1) { - - AngleReduceProcedure.execute(entity); - } - if (buttonID == 2) { - - AngleAddPlusProcedure.execute(entity); - } - if (buttonID == 3) { - - AngleReducePlusProcedure.execute(entity); - } - if (buttonID == 4) { - - AngleReduceMiniProcedure.execute(entity); - } - if (buttonID == 5) { - - AngleAddMiniProcedure.execute(entity); + switch (buttonID) { + case 0 -> AngleAddProcedure.execute(entity); + case 1 -> AngleReduceProcedure.execute(entity); + case 2 -> AngleAddPlusProcedure.execute(entity); + case 3 -> AngleReducePlusProcedure.execute(entity); + case 4 -> AngleReduceMiniProcedure.execute(entity); + case 5 -> AngleAddMiniProcedure.execute(entity); } } diff --git a/src/main/java/net/mcreator/target/procedures/AngleAddMiniProcedure.java b/src/main/java/net/mcreator/target/procedures/AngleAddMiniProcedure.java index 297907f22..2c6f95d37 100644 --- a/src/main/java/net/mcreator/target/procedures/AngleAddMiniProcedure.java +++ b/src/main/java/net/mcreator/target/procedures/AngleAddMiniProcedure.java @@ -1,187 +1,23 @@ package net.mcreator.target.procedures; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; +import net.mcreator.target.tools.TraceTool; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.projectile.ProjectileUtil; -import net.minecraft.world.phys.*; public class AngleAddMiniProcedure { public static void execute(Entity entity) { - if (entity == null) - return; - if (!((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)) == null)) { - if ((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)).getXRot() > -87.5) { - { - Entity _ent = (new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)); - _ent.setYRot((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)).getYRot()); - _ent.setXRot((float) ((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)).getXRot() - 0.5)); - _ent.setYBodyRot(_ent.getYRot()); - _ent.setYHeadRot(_ent.getYRot()); - _ent.yRotO = _ent.getYRot(); - _ent.xRotO = _ent.getXRot(); - if (_ent instanceof LivingEntity _entity) { - _entity.yBodyRotO = _entity.getYRot(); - _entity.yHeadRotO = _entity.getYRot(); - } - } - } + Entity looking = TraceTool.findLookingEntity(entity, 6); + if (looking == null || looking.getXRot() <= -87.5) return; + + looking.setYRot(looking.getYRot()); + looking.setXRot((float) (looking.getXRot() - 0.5)); + looking.setYBodyRot(looking.getYRot()); + looking.setYHeadRot(looking.getYRot()); + looking.yRotO = looking.getYRot(); + looking.xRotO = looking.getXRot(); + if (looking instanceof LivingEntity living) { + living.yBodyRotO = living.getYRot(); + living.yHeadRotO = living.getYRot(); } } } diff --git a/src/main/java/net/mcreator/target/procedures/AngleAddPlusProcedure.java b/src/main/java/net/mcreator/target/procedures/AngleAddPlusProcedure.java index 0c6f346bc..c0fce9558 100644 --- a/src/main/java/net/mcreator/target/procedures/AngleAddPlusProcedure.java +++ b/src/main/java/net/mcreator/target/procedures/AngleAddPlusProcedure.java @@ -1,187 +1,23 @@ package net.mcreator.target.procedures; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; +import net.mcreator.target.tools.TraceTool; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.projectile.ProjectileUtil; -import net.minecraft.world.phys.*; public class AngleAddPlusProcedure { public static void execute(Entity entity) { - if (entity == null) - return; - if (!((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult != null && hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)) == null)) { - if ((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)).getXRot() > -78) { - { - Entity _ent = (new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)); - _ent.setYRot((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)).getYRot()); - _ent.setXRot((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)).getXRot() - 10); - _ent.setYBodyRot(_ent.getYRot()); - _ent.setYHeadRot(_ent.getYRot()); - _ent.yRotO = _ent.getYRot(); - _ent.xRotO = _ent.getXRot(); - if (_ent instanceof LivingEntity _entity) { - _entity.yBodyRotO = _entity.getYRot(); - _entity.yHeadRotO = _entity.getYRot(); - } - } - } + Entity looking = TraceTool.findLookingEntity(entity, 6); + if (looking == null || looking.getXRot() <= -78) return; + + looking.setYRot(looking.getYRot()); + looking.setXRot(looking.getXRot() - 10); + looking.setYBodyRot(looking.getYRot()); + looking.setYHeadRot(looking.getYRot()); + looking.yRotO = looking.getYRot(); + looking.xRotO = looking.getXRot(); + if (looking instanceof LivingEntity living) { + living.yBodyRotO = living.getYRot(); + living.yHeadRotO = living.getYRot(); } } } diff --git a/src/main/java/net/mcreator/target/procedures/AngleAddProcedure.java b/src/main/java/net/mcreator/target/procedures/AngleAddProcedure.java index 682f8ff7f..57d8d7723 100644 --- a/src/main/java/net/mcreator/target/procedures/AngleAddProcedure.java +++ b/src/main/java/net/mcreator/target/procedures/AngleAddProcedure.java @@ -1,187 +1,23 @@ package net.mcreator.target.procedures; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; +import net.mcreator.target.tools.TraceTool; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.projectile.ProjectileUtil; -import net.minecraft.world.phys.*; public class AngleAddProcedure { public static void execute(Entity entity) { - if (entity == null) - return; - if (!((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)) == null)) { - if ((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)).getXRot() > -88) { - { - Entity _ent = (new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)); - _ent.setYRot((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)).getYRot()); - _ent.setXRot((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)).getXRot() - 1); - _ent.setYBodyRot(_ent.getYRot()); - _ent.setYHeadRot(_ent.getYRot()); - _ent.yRotO = _ent.getYRot(); - _ent.xRotO = _ent.getXRot(); - if (_ent instanceof LivingEntity _entity) { - _entity.yBodyRotO = _entity.getYRot(); - _entity.yHeadRotO = _entity.getYRot(); - } - } - } + Entity looking = TraceTool.findLookingEntity(entity, 6); + if (looking == null || looking.getXRot() <= -88) return; + + looking.setYRot(looking.getYRot()); + looking.setXRot(looking.getXRot() - 1); + looking.setYBodyRot(looking.getYRot()); + looking.setYHeadRot(looking.getYRot()); + looking.yRotO = looking.getYRot(); + looking.xRotO = looking.getXRot(); + if (looking instanceof LivingEntity living) { + living.yBodyRotO = living.getYRot(); + living.yHeadRotO = living.getYRot(); } } } diff --git a/src/main/java/net/mcreator/target/procedures/AngleReduceMiniProcedure.java b/src/main/java/net/mcreator/target/procedures/AngleReduceMiniProcedure.java index b59b70949..09e0cf7b7 100644 --- a/src/main/java/net/mcreator/target/procedures/AngleReduceMiniProcedure.java +++ b/src/main/java/net/mcreator/target/procedures/AngleReduceMiniProcedure.java @@ -1,190 +1,23 @@ package net.mcreator.target.procedures; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; +import net.mcreator.target.tools.TraceTool; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.projectile.ProjectileUtil; -import net.minecraft.world.phys.*; public class AngleReduceMiniProcedure { public static void execute(Entity entity) { - if (entity == null) - return; - if (!((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> { - return !p_234237_.isSpectator(); - }, distance); - if (entityhitresult != null) { - Entity entity1 = entityhitresult.getEntity(); - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)) == null)) { - if ((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)).getXRot() < -20.5) { - { - Entity _ent = (new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)); - _ent.setYRot((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)).getYRot()); - _ent.setXRot((float) ((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)).getXRot() + 0.5)); - _ent.setYBodyRot(_ent.getYRot()); - _ent.setYHeadRot(_ent.getYRot()); - _ent.yRotO = _ent.getYRot(); - _ent.xRotO = _ent.getXRot(); - if (_ent instanceof LivingEntity _entity) { - _entity.yBodyRotO = _entity.getYRot(); - _entity.yHeadRotO = _entity.getYRot(); - } - } - } + Entity looking = TraceTool.findLookingEntity(entity, 6); + if (looking == null || looking.getXRot() >= -20.5) return; + + looking.setYRot(looking.getYRot()); + looking.setXRot((float) (looking.getXRot() + 0.5)); + looking.setYBodyRot(looking.getYRot()); + looking.setYHeadRot(looking.getYRot()); + looking.yRotO = looking.getYRot(); + looking.xRotO = looking.getXRot(); + if (looking instanceof LivingEntity living) { + living.yBodyRotO = living.getYRot(); + living.yHeadRotO = living.getYRot(); } } } diff --git a/src/main/java/net/mcreator/target/procedures/AngleReducePlusProcedure.java b/src/main/java/net/mcreator/target/procedures/AngleReducePlusProcedure.java index 65a321b43..c2a43d943 100644 --- a/src/main/java/net/mcreator/target/procedures/AngleReducePlusProcedure.java +++ b/src/main/java/net/mcreator/target/procedures/AngleReducePlusProcedure.java @@ -1,187 +1,23 @@ package net.mcreator.target.procedures; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; +import net.mcreator.target.tools.TraceTool; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.projectile.ProjectileUtil; -import net.minecraft.world.phys.*; public class AngleReducePlusProcedure { public static void execute(Entity entity) { - if (entity == null) - return; - if (!((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)) == null)) { - if ((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)).getXRot() < -30) { - { - Entity _ent = (new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)); - _ent.setYRot((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)).getYRot()); - _ent.setXRot((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)).getXRot() + 10); - _ent.setYBodyRot(_ent.getYRot()); - _ent.setYHeadRot(_ent.getYRot()); - _ent.yRotO = _ent.getYRot(); - _ent.xRotO = _ent.getXRot(); - if (_ent instanceof LivingEntity _entity) { - _entity.yBodyRotO = _entity.getYRot(); - _entity.yHeadRotO = _entity.getYRot(); - } - } - } + Entity looking = TraceTool.findLookingEntity(entity, 6); + if (looking == null || looking.getXRot() >= -30) return; + + looking.setYRot(looking.getYRot()); + looking.setXRot(looking.getXRot() + 10); + looking.setYBodyRot(looking.getYRot()); + looking.setYHeadRot(looking.getYRot()); + looking.yRotO = looking.getYRot(); + looking.xRotO = looking.getXRot(); + if (looking instanceof LivingEntity living) { + living.yBodyRotO = living.getYRot(); + living.yHeadRotO = living.getYRot(); } } } diff --git a/src/main/java/net/mcreator/target/procedures/AngleReduceProcedure.java b/src/main/java/net/mcreator/target/procedures/AngleReduceProcedure.java index 91df8eee8..c59c1e87d 100644 --- a/src/main/java/net/mcreator/target/procedures/AngleReduceProcedure.java +++ b/src/main/java/net/mcreator/target/procedures/AngleReduceProcedure.java @@ -1,187 +1,22 @@ package net.mcreator.target.procedures; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; +import net.mcreator.target.tools.TraceTool; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.projectile.ProjectileUtil; -import net.minecraft.world.phys.*; public class AngleReduceProcedure { public static void execute(Entity entity) { - if (entity == null) - return; - if (!((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)) == null)) { - if ((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)).getXRot() < -20) { - { - Entity _ent = (new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)); - _ent.setYRot((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)).getYRot()); - _ent.setXRot((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)).getXRot() + 1); - _ent.setYBodyRot(_ent.getYRot()); - _ent.setYHeadRot(_ent.getYRot()); - _ent.yRotO = _ent.getYRot(); - _ent.xRotO = _ent.getXRot(); - if (_ent instanceof LivingEntity _entity) { - _entity.yBodyRotO = _entity.getYRot(); - _entity.yHeadRotO = _entity.getYRot(); - } - } - } + Entity looking = TraceTool.findLookingEntity(entity, 6); + if (looking == null || looking.getXRot() >= -20) return; + looking.setYRot(looking.getYRot()); + looking.setXRot(looking.getXRot() + 1); + looking.setYBodyRot(looking.getYRot()); + looking.setYHeadRot(looking.getYRot()); + looking.yRotO = looking.getYRot(); + looking.xRotO = looking.getXRot(); + if (looking instanceof LivingEntity living) { + living.yBodyRotO = living.getYRot(); + living.yHeadRotO = living.getYRot(); } } } diff --git a/src/main/java/net/mcreator/target/procedures/EntityRangeProcedure.java b/src/main/java/net/mcreator/target/procedures/EntityRangeProcedure.java deleted file mode 100644 index 11b9b87dd..000000000 --- a/src/main/java/net/mcreator/target/procedures/EntityRangeProcedure.java +++ /dev/null @@ -1,146 +0,0 @@ -package net.mcreator.target.procedures; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.projectile.ProjectileUtil; -import net.minecraft.world.phys.*; - -public class EntityRangeProcedure { - public static String execute(Entity entity) { - if (entity == null) - return ""; - if (!((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 1024)) == null) && (new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 1024)) instanceof LivingEntity) { - return (new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 1024)).getDisplayName().getString() + ":" + new java.text.DecimalFormat("##.#").format((entity.position()).distanceTo(((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> { - return !p_234237_.isSpectator(); - }, distance); - if (entityhitresult != null) { - Entity entity1 = entityhitresult.getEntity(); - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 1024)).position()))) + "M"; - } - return ""; - } -} diff --git a/src/main/java/net/mcreator/target/procedures/MortarAngleProcedure.java b/src/main/java/net/mcreator/target/procedures/MortarAngleProcedure.java deleted file mode 100644 index 4bb56c3ff..000000000 --- a/src/main/java/net/mcreator/target/procedures/MortarAngleProcedure.java +++ /dev/null @@ -1,82 +0,0 @@ -package net.mcreator.target.procedures; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.projectile.ProjectileUtil; -import net.minecraft.world.phys.*; - -public class MortarAngleProcedure { - public static String execute(Entity entity) { - if (entity == null) - return ""; - Entity mortar = null; - if (!((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)) == null)) { - mortar = new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6); - return "Angle: " + new java.text.DecimalFormat("##.#").format(-(mortar.getXRot())); - } - return ""; - } -} diff --git a/src/main/java/net/mcreator/target/procedures/MortarGUIGaiGUIDaKaiShiMeiKeFaShengProcedure.java b/src/main/java/net/mcreator/target/procedures/MortarGUIGaiGUIDaKaiShiMeiKeFaShengProcedure.java deleted file mode 100644 index a7e463020..000000000 --- a/src/main/java/net/mcreator/target/procedures/MortarGUIGaiGUIDaKaiShiMeiKeFaShengProcedure.java +++ /dev/null @@ -1,192 +0,0 @@ -package net.mcreator.target.procedures; - -import net.mcreator.target.init.TargetModAttributes; -import net.minecraft.client.gui.components.EditBox; -import net.minecraft.commands.CommandSource; -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.projectile.ProjectileUtil; -import net.minecraft.world.phys.*; - -import java.util.HashMap; - -public class MortarGUIGaiGUIDaKaiShiMeiKeFaShengProcedure { - public static void execute(Entity entity, HashMap guistate) { - if (entity == null || guistate == null) - return; - if (!((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)) == null)) { - if (20 <= new Object() { - double convert(String s) { - try { - return Double.parseDouble(s.trim()); - } catch (Exception ignored) { - } - return 0; - } - }.convert(guistate.containsKey("text:pitch") ? ((EditBox) guistate.get("text:pitch")).getValue() : "") && new Object() { - double convert(String s) { - try { - return Double.parseDouble(s.trim()); - } catch (Exception ignored) { - } - return 0; - } - }.convert(guistate.containsKey("text:pitch") ? ((EditBox) guistate.get("text:pitch")).getValue() : "") <= 90) { - { - Entity _ent = (new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)); - _ent.setYRot((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)).getYRot()); - _ent.setXRot((float) (-((LivingEntity) (new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6))).getAttribute(TargetModAttributes.MOTARPITCH.get()).getBaseValue())); - _ent.setYBodyRot(_ent.getYRot()); - _ent.setYHeadRot(_ent.getYRot()); - _ent.yRotO = _ent.getYRot(); - _ent.xRotO = _ent.getXRot(); - if (_ent instanceof LivingEntity _entity) { - _entity.yBodyRotO = _entity.getYRot(); - _entity.yHeadRotO = _entity.getYRot(); - } - } - { - if (!entity.level().isClientSide() && entity.getServer() != null) { - entity.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, entity.position(), entity.getRotationVector(), entity.level() instanceof ServerLevel ? (ServerLevel) entity.level() : null, 4, - entity.getName().getString(), entity.getDisplayName(), entity.level().getServer(), entity), "playsound minecraft:entity.arrow.hit_player player @s ~ ~ ~ 1 1"); - } - } - } else { - { - if (!entity.level().isClientSide() && entity.getServer() != null) { - entity.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, entity.position(), entity.getRotationVector(), entity.level() instanceof ServerLevel ? (ServerLevel) entity.level() : null, 4, - entity.getName().getString(), entity.getDisplayName(), entity.level().getServer(), entity), "playsound minecraft:block.note_block.bass player @s ~ ~ ~ 1 1"); - } - } - } - } - } -} diff --git a/src/main/java/net/mcreator/target/procedures/MortarGUIGaiGUIDaKaiShiProcedure.java b/src/main/java/net/mcreator/target/procedures/MortarGUIGaiGUIDaKaiShiProcedure.java deleted file mode 100644 index d5e9d605f..000000000 --- a/src/main/java/net/mcreator/target/procedures/MortarGUIGaiGUIDaKaiShiProcedure.java +++ /dev/null @@ -1,83 +0,0 @@ -package net.mcreator.target.procedures; - -import net.minecraft.client.gui.components.EditBox; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.projectile.ProjectileUtil; -import net.minecraft.world.phys.*; - -import java.util.HashMap; - -public class MortarGUIGaiGUIDaKaiShiProcedure { - public static void execute(Entity entity, HashMap guistate) { - if (entity == null || guistate == null) - return; - if (!((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)) == null)) { - if (guistate.get("text:pitch") instanceof EditBox _tf) - _tf.setValue((new java.text.DecimalFormat("##").format(-((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> !p_234237_.isSpectator(), distance); - if (entityhitresult != null) { - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)).getXRot())))); - } - } -} diff --git a/src/main/java/net/mcreator/target/procedures/MortarPitchProcedure.java b/src/main/java/net/mcreator/target/procedures/MortarPitchProcedure.java deleted file mode 100644 index 9aaec6660..000000000 --- a/src/main/java/net/mcreator/target/procedures/MortarPitchProcedure.java +++ /dev/null @@ -1,86 +0,0 @@ -package net.mcreator.target.procedures; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.projectile.ProjectileUtil; -import net.minecraft.world.phys.*; - -public class MortarPitchProcedure { - public static double execute(Entity entity) { - if (entity == null) - return 0; - if (!((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult != null && hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> { - return !p_234237_.isSpectator(); - }, distance); - if (entityhitresult != null) { - Entity entity1 = entityhitresult.getEntity(); - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)) == null)) { - return -((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult != null && hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> { - return !p_234237_.isSpectator(); - }, distance); - if (entityhitresult != null) { - Entity entity1 = entityhitresult.getEntity(); - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6)).getXRot()); - } - return 0; - } -} diff --git a/src/main/java/net/mcreator/target/procedures/MotarGUITickProcedure.java b/src/main/java/net/mcreator/target/procedures/MotarGUITickProcedure.java index d09cb1336..0e410210f 100644 --- a/src/main/java/net/mcreator/target/procedures/MotarGUITickProcedure.java +++ b/src/main/java/net/mcreator/target/procedures/MotarGUITickProcedure.java @@ -1,56 +1,38 @@ package net.mcreator.target.procedures; import net.mcreator.target.init.TargetModAttributes; +import net.mcreator.target.tools.TraceTool; import net.minecraft.client.gui.components.EditBox; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.projectile.ProjectileUtil; -import net.minecraft.world.phys.*; import java.util.HashMap; public class MotarGUITickProcedure { - public static void execute(Entity entity, HashMap guistate) { - if (entity == null || guistate == null) - return; - if (!((new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult != null && hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } + public static void execute(Entity entity, HashMap guistate) { + if (entity == null || guistate == null) return; + + Entity looking = TraceTool.findLookingEntity(entity, 6); + if (looking == null) return; + + if (20 <= new Object() { + double convert(String s) { + try { + return Double.parseDouble(s.trim()); + } catch (Exception ignored) { } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> { - return !p_234237_.isSpectator(); - }, distance); - if (entityhitresult != null) { - Entity entity1 = entityhitresult.getEntity(); - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; + return 0; } - }.func(entity, 6)) == null)) { - if (20 <= new Object() { + }.convert(guistate.containsKey("text:pitch") ? ((EditBox) guistate.get("text:pitch")).getValue() : "") && new Object() { + double convert(String s) { + try { + return Double.parseDouble(s.trim()); + } catch (Exception e) { + } + return 0; + } + }.convert(guistate.containsKey("text:pitch") ? ((EditBox) guistate.get("text:pitch")).getValue() : "") <= 90) { + ((LivingEntity) looking).getAttribute(TargetModAttributes.MOTARPITCH.get()).setBaseValue(new Object() { double convert(String s) { try { return Double.parseDouble(s.trim()); @@ -58,59 +40,7 @@ public class MotarGUITickProcedure { } return 0; } - }.convert(guistate.containsKey("text:pitch") ? ((EditBox) guistate.get("text:pitch")).getValue() : "") && new Object() { - double convert(String s) { - try { - return Double.parseDouble(s.trim()); - } catch (Exception e) { - } - return 0; - } - }.convert(guistate.containsKey("text:pitch") ? ((EditBox) guistate.get("text:pitch")).getValue() : "") <= 90) { - ((LivingEntity) (new Object() { - public Entity func(Entity player, double entityReach) { - double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = entity.pick(entityReach, 1.0f, false); - if (hitResult != null && hitResult.getType() != HitResult.Type.MISS) { - distance = hitResult.getLocation().distanceToSqr(eyePos); - double blockReach = 5; - if (distance > blockReach * blockReach) { - Vec3 pos = hitResult.getLocation(); - hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); - } - } - Vec3 viewVec = player.getViewVector(1.0F); - Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, (p_234237_) -> { - return !p_234237_.isSpectator(); - }, distance); - if (entityhitresult != null) { - Entity entity1 = entityhitresult.getEntity(); - Vec3 targetPos = entityhitresult.getLocation(); - double distanceToTarget = eyePos.distanceToSqr(targetPos); - if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { - hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); - } else if (distanceToTarget < distance) { - hitResult = entityhitresult; - } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - return ((EntityHitResult) hitResult).getEntity(); - } - return null; - } - }.func(entity, 6))).getAttribute(TargetModAttributes.MOTARPITCH.get()).setBaseValue(new Object() { - double convert(String s) { - try { - return Double.parseDouble(s.trim()); - } catch (Exception e) { - } - return 0; - } - }.convert(guistate.containsKey("text:pitch") ? ((EditBox) guistate.get("text:pitch")).getValue() : "")); - } + }.convert(guistate.containsKey("text:pitch") ? ((EditBox) guistate.get("text:pitch")).getValue() : "")); } } } diff --git a/src/main/java/net/mcreator/target/tools/TraceTool.java b/src/main/java/net/mcreator/target/tools/TraceTool.java new file mode 100644 index 000000000..0b66642ab --- /dev/null +++ b/src/main/java/net/mcreator/target/tools/TraceTool.java @@ -0,0 +1,40 @@ +package net.mcreator.target.tools; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.projectile.ProjectileUtil; +import net.minecraft.world.phys.*; + +public class TraceTool { + public static Entity findLookingEntity(Entity player, double entityReach) { + double distance = entityReach * entityReach; + Vec3 eyePos = player.getEyePosition(1.0f); + HitResult hitResult = player.pick(entityReach, 1.0f, false); + if (hitResult.getType() != HitResult.Type.MISS) { + distance = hitResult.getLocation().distanceToSqr(eyePos); + double blockReach = 5; + if (distance > blockReach * blockReach) { + Vec3 pos = hitResult.getLocation(); + hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); + } + } + Vec3 viewVec = player.getViewVector(1.0F); + Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); + AABB aabb = player.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); + EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, p -> !p.isSpectator(), distance); + if (entityhitresult != null) { + Vec3 targetPos = entityhitresult.getLocation(); + double distanceToTarget = eyePos.distanceToSqr(targetPos); + if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) { + hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); + } else if (distanceToTarget < distance) { + hitResult = entityhitresult; + } + } + if (hitResult.getType() == HitResult.Type.ENTITY) { + return ((EntityHitResult) hitResult).getEntity(); + } + return null; + } +} diff --git a/src/main/java/net/mcreator/target/world/inventory/MortarGUIMenu.java b/src/main/java/net/mcreator/target/world/inventory/MortarGUIMenu.java index 4b3b2eeeb..4c93e9bbf 100644 --- a/src/main/java/net/mcreator/target/world/inventory/MortarGUIMenu.java +++ b/src/main/java/net/mcreator/target/world/inventory/MortarGUIMenu.java @@ -1,8 +1,9 @@ package net.mcreator.target.world.inventory; import net.mcreator.target.init.TargetModMenus; -import net.mcreator.target.procedures.MortarGUIGaiGUIDaKaiShiProcedure; import net.mcreator.target.procedures.MotarGUITickProcedure; +import net.mcreator.target.tools.TraceTool; +import net.minecraft.client.gui.components.EditBox; import net.minecraft.core.BlockPos; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.entity.Entity; @@ -43,15 +44,18 @@ public class MortarGUIMenu extends AbstractContainerMenu implements Supplier