diff options
author | syeyoung <cyong06@naver.com> | 2021-02-12 01:43:20 +0900 |
---|---|---|
committer | syeyoung <cyong06@naver.com> | 2021-02-12 01:43:20 +0900 |
commit | 92c8d9cec9fcc3a53ad95ff0212d77bf87becab7 (patch) | |
tree | 269ec202ecc2426ff0d6d73fab95af1fea57042a /src/main/java/kr/syeyoung/dungeonsguide/dungeon | |
parent | 89c82ad1fea9fd0a8e32a5e818c6c01856cdd660 (diff) | |
download | Skyblock-Dungeons-Guide-92c8d9cec9fcc3a53ad95ff0212d77bf87becab7.tar.gz Skyblock-Dungeons-Guide-92c8d9cec9fcc3a53ad95ff0212d77bf87becab7.tar.bz2 Skyblock-Dungeons-Guide-92c8d9cec9fcc3a53ad95ff0212d77bf87becab7.zip |
pathfinder go brrrr
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/dungeon')
5 files changed, 67 insertions, 10 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionChangeState.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionChangeState.java index fb1b76d7..82e87425 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionChangeState.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionChangeState.java @@ -1,5 +1,6 @@ package kr.syeyoung.dungeonsguide.dungeon.actions; +import kr.syeyoung.dungeonsguide.dungeon.mechanics.DungeonDummy; import kr.syeyoung.dungeonsguide.dungeon.mechanics.DungeonFairySoul; import kr.syeyoung.dungeonsguide.dungeon.mechanics.DungeonMechanic; import kr.syeyoung.dungeonsguide.dungeon.mechanics.DungeonSecret; @@ -46,7 +47,7 @@ public class ActionChangeState extends AbstractAction{ return false; if (mechanic instanceof DungeonSecret && ((DungeonSecret) mechanic).getSecretType() != DungeonSecret.SecretType.CHEST) return true; - if (mechanic instanceof DungeonFairySoul) + if (mechanic instanceof DungeonDummy) return true; return mechanic.getCurrentState(dungeonRoom).equalsIgnoreCase(state); } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMove.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMove.java index e80cdd84..e521a4c9 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMove.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMove.java @@ -5,12 +5,16 @@ import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; import kr.syeyoung.dungeonsguide.utils.RenderUtils; import lombok.Data; import net.minecraft.client.Minecraft; +import net.minecraft.pathfinding.PathEntity; +import net.minecraft.pathfinding.PathPoint; import net.minecraft.util.BlockPos; import net.minecraft.util.MathHelper; import java.awt.*; +import java.util.ArrayList; import java.util.HashSet; import java.util.Set; +import java.util.List; @Data public class ActionMove extends AbstractAction { @@ -36,6 +40,25 @@ public class ActionMove extends AbstractAction { BlockPos pos = target.getBlockPos(dungeonRoom); RenderUtils.drawTextAtWorld("Destination", pos.getX() + 0.5f, pos.getY() + 0.6f, pos.getZ() + 0.5f, 0xFF00FF00, 1f, true, false, partialTicks); RenderUtils.drawTextAtWorld(String.format("%.2f",MathHelper.sqrt_double(pos.distanceSq(Minecraft.getMinecraft().thePlayer.getPosition())))+"m", pos.getX() + 0.5f, pos.getY() + 0.3f, pos.getZ() + 0.5f, 0xFFFFFF00, 1f, true, false, partialTicks); + if (latest != null){ + List<BlockPos> poses = new ArrayList<BlockPos>(); + for (int i = 0; i < latest.getCurrentPathLength(); i++) { + PathPoint pathPoint = latest.getPathPointFromIndex(i); + poses.add(dungeonRoom.getMin().add(pathPoint.xCoord, pathPoint.yCoord, pathPoint.zCoord)); + } + RenderUtils.drawLines(poses, new Color(0,255,0,255), partialTicks, true); + } + } + + private int tick = -1; + private PathEntity latest; + @Override + public void onTick(DungeonRoom dungeonRoom) { + tick = (tick+1) % 10; + if (tick == 0) { + latest = dungeonRoom.getPathFinder().createEntityPathTo(dungeonRoom.getContext().getWorld(), + Minecraft.getMinecraft().thePlayer, target.getBlockPos(dungeonRoom), 100); + } } @Override diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMoveNearestAir.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMoveNearestAir.java index 92c2fe69..19a515a0 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMoveNearestAir.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMoveNearestAir.java @@ -5,11 +5,15 @@ import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; import kr.syeyoung.dungeonsguide.utils.RenderUtils; import lombok.Data; import net.minecraft.client.Minecraft; +import net.minecraft.pathfinding.PathEntity; +import net.minecraft.pathfinding.PathPoint; import net.minecraft.util.BlockPos; import net.minecraft.util.MathHelper; import java.awt.*; +import java.util.ArrayList; import java.util.HashSet; +import java.util.List; import java.util.Set; @Data @@ -30,13 +34,32 @@ public class ActionMoveNearestAir extends AbstractAction { public boolean isComplete(DungeonRoom dungeonRoom) { return target.getBlockPos(dungeonRoom).distanceSq(Minecraft.getMinecraft().thePlayer.getPosition()) < 10; } + @Override public void onRenderWorld(DungeonRoom dungeonRoom, float partialTicks) { BlockPos pos = target.getBlockPos(dungeonRoom); RenderUtils.drawTextAtWorld("Destination", pos.getX() + 0.5f, pos.getY() + 0.6f, pos.getZ() + 0.5f, 0xFF00FF00, 1f, true, false, partialTicks); - RenderUtils.drawTextAtWorld(String.format("%.2f", MathHelper.sqrt_double(pos.distanceSq(Minecraft.getMinecraft().thePlayer.getPosition())))+"m", pos.getX() + 0.5f, pos.getY() + 0.3f, pos.getZ() + 0.5f, 0xFFFFFF00, 1f, true, false, partialTicks); + RenderUtils.drawTextAtWorld(String.format("%.2f",MathHelper.sqrt_double(pos.distanceSq(Minecraft.getMinecraft().thePlayer.getPosition())))+"m", pos.getX() + 0.5f, pos.getY() + 0.3f, pos.getZ() + 0.5f, 0xFFFFFF00, 1f, true, false, partialTicks); + if (latest != null){ + List<BlockPos> poses = new ArrayList<BlockPos>(); + for (int i = 0; i < latest.getCurrentPathLength(); i++) { + PathPoint pathPoint = latest.getPathPointFromIndex(i); + poses.add(dungeonRoom.getMin().add(pathPoint.xCoord, pathPoint.yCoord, pathPoint.zCoord)); + } + RenderUtils.drawLines(poses, new Color(0,255,0,255), partialTicks, true); + } } + private int tick = -1; + private PathEntity latest; + @Override + public void onTick(DungeonRoom dungeonRoom) { + tick = (tick+1) % 10; + if (tick == 0) { + latest = dungeonRoom.getPathFinder().createEntityPathTo(dungeonRoom.getContext().getWorld(), + Minecraft.getMinecraft().thePlayer, target.getBlockPos(dungeonRoom), 100); + } + } @Override public String toString() { return "MoveNearestAir\n- target: "+target.toString(); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonDummy.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonDummy.java index 6cd7238a..41e591c1 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonDummy.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonDummy.java @@ -1,10 +1,7 @@ package kr.syeyoung.dungeonsguide.dungeon.mechanics; import com.google.common.collect.Sets; -import kr.syeyoung.dungeonsguide.dungeon.actions.Action; -import kr.syeyoung.dungeonsguide.dungeon.actions.ActionChangeState; -import kr.syeyoung.dungeonsguide.dungeon.actions.ActionInteract; -import kr.syeyoung.dungeonsguide.dungeon.actions.ActionMove; +import kr.syeyoung.dungeonsguide.dungeon.actions.*; import kr.syeyoung.dungeonsguide.dungeon.data.OffsetPoint; import kr.syeyoung.dungeonsguide.dungeon.mechanics.predicates.PredicateArmorStand; import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; @@ -26,13 +23,17 @@ public class DungeonDummy implements DungeonMechanic { @Override public Set<Action> getAction(String state, DungeonRoom dungeonRoom) { - if (!"navigate".equalsIgnoreCase(state)) throw new IllegalArgumentException(state+" is not valid state for secret"); +// if (!"navigate".equalsIgnoreCase(state)) throw new IllegalArgumentException(state+" is not valid state for secret"); Set<Action> base; Set<Action> preRequisites = base = new HashSet<Action>(); - { + if (state.equalsIgnoreCase("navigate")){ ActionMove actionMove = new ActionMove(secretPoint); preRequisites.add(actionMove); preRequisites = actionMove.getPreRequisite(); + } else if (state.equalsIgnoreCase("click")) { + ActionClick actionMove = new ActionClick(secretPoint); + preRequisites.add(actionMove); + preRequisites = actionMove.getPreRequisite(); } { for (String str : preRequisite) { @@ -68,11 +69,11 @@ public class DungeonDummy implements DungeonMechanic { @Override public Set<String> getPossibleStates(DungeonRoom dungeonRoom) { - return Sets.newHashSet("navigate"); + return Sets.newHashSet("navigate", "click"); } @Override public Set<String> getTotalPossibleStates(DungeonRoom dungeonRoom) { - return Sets.newHashSet("no-state","navigate"); + return Sets.newHashSet("no-state","navigate,click"); } @Override public OffsetPoint getRepresentingPoint() { diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoom.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoom.java index 6b0322ee..3c262856 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoom.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoom.java @@ -5,6 +5,7 @@ import kr.syeyoung.dungeonsguide.dungeon.DungeonContext; import kr.syeyoung.dungeonsguide.dungeon.MapProcessor; import kr.syeyoung.dungeonsguide.dungeon.data.DungeonRoomInfo; import kr.syeyoung.dungeonsguide.dungeon.doorfinder.DungeonDoor; +import kr.syeyoung.dungeonsguide.pathfinding.NodeProcessorDungeonRoom; import kr.syeyoung.dungeonsguide.roomprocessor.ProcessorFactory; import kr.syeyoung.dungeonsguide.roomprocessor.RoomProcessor; import kr.syeyoung.dungeonsguide.roomprocessor.RoomProcessorGenerator; @@ -12,6 +13,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; import net.minecraft.block.Block; +import net.minecraft.pathfinding.PathFinder; import net.minecraft.util.BlockPos; import javax.vecmath.Vector2d; @@ -43,6 +45,11 @@ public class DungeonRoom { @Setter private RoomState currentState = RoomState.DISCOVERED; + @Getter + private PathFinder pathFinder; + @Getter + private NodeProcessorDungeonRoom nodeProcessorDungeonRoom; + @AllArgsConstructor @Getter public static enum RoomState { @@ -71,6 +78,8 @@ public class DungeonRoom { buildDoors(); buildRoom(); updateRoomProcessor(); + nodeProcessorDungeonRoom = new NodeProcessorDungeonRoom(this); + pathFinder = new PathFinder(nodeProcessorDungeonRoom); } private static final Set<Vector2d> directions = Sets.newHashSet(new Vector2d(0,16), new Vector2d(0, -16), new Vector2d(16, 0), new Vector2d(-16 , 0)); |