diff options
Diffstat (limited to 'src')
8 files changed, 124 insertions, 13 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)); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/FeatureMechanicBrowse.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/FeatureMechanicBrowse.java index 6436d0e0..4629e0c9 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/FeatureMechanicBrowse.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/FeatureMechanicBrowse.java @@ -156,10 +156,10 @@ public class FeatureMechanicBrowse extends GuiFeature implements GuiPostRenderLi GlStateManager.popMatrix();; if (selected != -1) { + clip(new ScaledResolution(Minecraft.getMinecraft()), feature.x + feature.width, feature.y + fr.FONT_HEIGHT + 5, feature.width , feature.height - fr.FONT_HEIGHT - 6); GlStateManager.translate(feature.width, selected * fr.FONT_HEIGHT, 0); Gui.drawRect(0, 0, feature.width, fr.FONT_HEIGHT * possibleStates.size() + 4, 0xFF444444); Gui.drawRect(-1, 1, feature.width - 1, fr.FONT_HEIGHT * possibleStates.size() + 3, 0xFF262626); - clip(new ScaledResolution(Minecraft.getMinecraft()), feature.x + feature.width, feature.y + fr.FONT_HEIGHT + 5, feature.width , feature.height - fr.FONT_HEIGHT - 6); GlStateManager.translate(2,2, 0); Point popupStart = new Point(feature.x + feature.width, (selected + 1) * fr.FONT_HEIGHT +6 + feature.y - dy + 2); @@ -200,7 +200,7 @@ public class FeatureMechanicBrowse extends GuiFeature implements GuiPostRenderLi boolean found = false; for (Map.Entry<String, DungeonMechanic> value : ((GeneralRoomProcessor) dungeonRoom.getRoomProcessor()).getDungeonRoom().getDungeonRoomInfo().getMechanics().entrySet()) { - if (value.getValue() instanceof DungeonDoor) { + if (value.getValue() instanceof DungeonFairySoul) { if (!found) { sortedMechanics.add("Fairy Souls"); sortedMechanicsName.add(""); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/pathfinding/NodeProcessorDungeonRoom.java b/src/main/java/kr/syeyoung/dungeonsguide/pathfinding/NodeProcessorDungeonRoom.java new file mode 100644 index 00000000..e31b0f84 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/pathfinding/NodeProcessorDungeonRoom.java @@ -0,0 +1,55 @@ +package kr.syeyoung.dungeonsguide.pathfinding; + +import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; +import net.minecraft.block.state.BlockState; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.Entity; +import net.minecraft.init.Blocks; +import net.minecraft.pathfinding.PathPoint; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.Vec3i; +import net.minecraft.world.pathfinder.NodeProcessor; + +public class NodeProcessorDungeonRoom extends NodeProcessor { + private DungeonRoom dungeonRoom; + private BlockPos sub; + public NodeProcessorDungeonRoom(DungeonRoom dungeonRoom) { + this.dungeonRoom = dungeonRoom; + sub = dungeonRoom.getMax().subtract(dungeonRoom.getMin()); + } + + @Override + public PathPoint getPathPointTo(Entity entityIn) { + return openPoint((int)entityIn.posX - dungeonRoom.getMin().getX(), (int)entityIn.posY - dungeonRoom.getMin().getY(), + (int)entityIn.posZ - dungeonRoom.getMin().getZ()); + } + + @Override + public PathPoint getPathPointToCoords(Entity entityIn, double x, double y, double z) { + return openPoint((int)x- dungeonRoom.getMin().getX(), (int)y - dungeonRoom.getMin().getY(), + (int)z - dungeonRoom.getMin().getZ()); + } + + @Override + public int findPathOptions(PathPoint[] pathOptions, Entity entityIn, PathPoint currentPoint, PathPoint targetPoint, float maxDistance) { + + int i = 0; + for (EnumFacing ef:EnumFacing.VALUES) { + Vec3i dir = ef.getDirectionVec(); + int newX = currentPoint.xCoord + dir.getX(); + int newY = currentPoint.yCoord + dir.getY(); + int newZ = currentPoint.zCoord + dir.getZ(); + if (newX < 0 || newZ < 0) continue; + if (newX > sub.getX()|| newZ > sub.getZ()) continue; + IBlockState state = entityIn.getEntityWorld().getBlockState(dungeonRoom.getMin().add(newX, newY, newZ)); + if (state.getBlock() == Blocks.air || state.getBlock() == Blocks.water || state.getBlock() == Blocks.lava + || state.getBlock() == Blocks.flowing_water || state.getBlock() == Blocks.flowing_lava) { + PathPoint pt = openPoint(newX, newY, newZ); + if (pt.visited) continue; + pathOptions[i++] = pt; + } + } + return i; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/utils/TextUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/utils/TextUtils.java index 01f6ebe3..6982d6d9 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/utils/TextUtils.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/utils/TextUtils.java @@ -47,7 +47,6 @@ public class TextUtils { public static String format(long value) { // return String.valueOf(value); - if (value == Long.MIN_VALUE) return format(-9223372036854775807L); if (value < 0L) |