Skip to content

Commit 26b7909

Browse files
feat: mission direction arrow
Took 22 minutes
1 parent e60ee68 commit 26b7909

6 files changed

Lines changed: 94 additions & 9 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package net.swofty.types.generic.mission;
2+
3+
import net.minestom.server.coordinate.Pos;
4+
5+
public interface LocationAssociatedMission {
6+
Pos getLocation();
7+
}

type.generic/src/main/java/net/swofty/types/generic/mission/missions/blacksmith/MissionTalkToBlacksmith.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package net.swofty.types.generic.mission.missions.blacksmith;
22

3+
import net.minestom.server.coordinate.Pos;
34
import net.swofty.types.generic.event.EventNodes;
45
import net.swofty.types.generic.event.SkyBlockEvent;
56
import net.swofty.types.generic.event.custom.PlayerRegionChangeEvent;
7+
import net.swofty.types.generic.mission.LocationAssociatedMission;
68
import net.swofty.types.generic.mission.MissionData;
79
import net.swofty.types.generic.mission.SkyBlockMission;
810
import net.swofty.types.generic.region.RegionType;
@@ -12,12 +14,11 @@
1214
import java.util.Map;
1315
import java.util.Set;
1416

15-
public class MissionTalkToBlacksmith extends SkyBlockMission {
16-
17+
public class MissionTalkToBlacksmith extends SkyBlockMission implements LocationAssociatedMission {
1718

1819
@SkyBlockEvent(node = EventNodes.CUSTOM , requireDataLoaded = true)
1920
public void run(PlayerRegionChangeEvent event) {
20-
MissionData data = ((PlayerRegionChangeEvent) event).getPlayer().getMissionData();
21+
MissionData data = event.getPlayer().getMissionData();
2122

2223
if (event.getTo() == null || !event.getTo().equals(RegionType.BLACKSMITH)) {
2324
return;
@@ -54,4 +55,9 @@ public void onEnd(SkyBlockPlayer player, Map<String, Object> customData, Mission
5455
public Set<RegionType> getValidRegions() {
5556
return Set.of(RegionType.BLACKSMITH, RegionType.COAL_MINE);
5657
}
58+
59+
@Override
60+
public Pos getLocation() {
61+
return new Pos(-28.5, 69, -125.45);
62+
}
5763
}

type.generic/src/main/java/net/swofty/types/generic/mission/missions/blacksmith/MissionTalkToBlacksmithAgain.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package net.swofty.types.generic.mission.missions.blacksmith;
22

3+
import net.minestom.server.coordinate.Pos;
4+
import net.swofty.types.generic.mission.LocationAssociatedMission;
35
import net.swofty.types.generic.mission.MissionData;
46
import net.swofty.types.generic.mission.SkyBlockMission;
57
import net.swofty.types.generic.region.RegionType;
@@ -9,7 +11,7 @@
911
import java.util.Map;
1012
import java.util.Set;
1113

12-
public class MissionTalkToBlacksmithAgain extends SkyBlockMission {
14+
public class MissionTalkToBlacksmithAgain extends SkyBlockMission implements LocationAssociatedMission {
1315
@Override
1416
public String getID() {
1517
return "talk_to_blacksmith_again";
@@ -37,4 +39,8 @@ public Set<RegionType> getValidRegions() {
3739
return Set.of(RegionType.BLACKSMITH, RegionType.COAL_MINE);
3840
}
3941

42+
@Override
43+
public Pos getLocation() {
44+
return new Pos(-28.5, 69, -125.45);
45+
}
4046
}

type.generic/src/main/java/net/swofty/types/generic/user/SkyBlockScoreboard.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313
import net.swofty.types.generic.data.DataHandler;
1414
import net.swofty.types.generic.data.datapoints.DatapointDouble;
1515
import net.swofty.types.generic.data.datapoints.DatapointInteger;
16+
import net.swofty.types.generic.mission.LocationAssociatedMission;
1617
import net.swofty.types.generic.mission.MissionData;
18+
import net.swofty.types.generic.mission.SkyBlockMission;
1719
import net.swofty.types.generic.mission.SkyBlockProgressMission;
1820
import net.swofty.types.generic.region.SkyBlockRegion;
21+
import net.swofty.types.generic.utility.BlockUtility;
1922

2023
import java.text.SimpleDateFormat;
2124
import java.util.Date;
@@ -69,9 +72,18 @@ public static void start() {
6972
if (region != null &&
7073
!missionData.getActiveMissions(region.getType()).isEmpty()) {
7174
MissionData.ActiveMission mission = missionData.getActiveMissions(region.getType()).getFirst();
72-
73-
addLine("§fObjective", sidebar);
74-
addLine("§e" + mission, sidebar);
75+
SkyBlockMission skyBlockMission = MissionData.getMissionClass(mission.getMissionID());
76+
77+
if (skyBlockMission instanceof LocationAssociatedMission locationAssociatedMission) {
78+
addLine("§fObjective §e" + BlockUtility.getArrow(
79+
player.getPosition(),
80+
locationAssociatedMission.getLocation()
81+
), sidebar);
82+
addLine("§e" + mission, sidebar);
83+
} else {
84+
addLine("§fObjective", sidebar);
85+
addLine("§e" + mission, sidebar);
86+
}
7587

7688
SkyBlockProgressMission progressMission = missionData.getAsProgressMission(mission.getMissionID());
7789
if (progressMission != null)
Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package net.swofty.types.generic.utility;
22

3+
import net.minestom.server.coordinate.Pos;
34
import net.minestom.server.instance.block.Block;
45
import org.json.JSONObject;
56

67
public class BlockUtility {
78

8-
99
public static Block applyTexture(Block block , String texture){
1010
JSONObject json = new JSONObject();
1111
json.put("isPublic", true);
@@ -14,10 +14,59 @@ public static Block applyTexture(Block block , String texture){
1414
new JSONObject().put("url", "http://textures.minecraft.net/texture/" + texture).put("metadata", new JSONObject().put("model", "slim"))));
1515

1616
/*
17+
1718
String texturesEncoded = Base64.getEncoder().encodeToString(json.toString().getBytes());
1819
block = block.withTag(ExtraItemTags.SKULL_OWNER , new ExtraItemTags.SkullOwner(null , "25" ,
1920
new PlayerSkin(texturesEncoded , null)));*/
2021
return block;
2122
}
2223

24+
/**
25+
* Returns an ASCII arrow showing the direction relative to where the player is currently looking.
26+
* The arrow shows which way to turn/move from the current view direction to reach the target.
27+
*
28+
* @param from the starting position (with current yaw/pitch)
29+
* @param to the target position
30+
* @return ASCII arrow character showing relative direction from current view
31+
*/
32+
public static String getArrow(Pos from, Pos to) {
33+
if (from.samePoint(to)) {
34+
return "•";
35+
}
36+
37+
// Get the yaw needed to look toward the target
38+
Pos lookingAt = from.withLookAt(to);
39+
float targetYaw = lookingAt.yaw();
40+
41+
float currentYaw = from.yaw();
42+
float yawDifference = targetYaw - currentYaw;
43+
44+
// Normalize the difference to -180 to 180 range
45+
while (yawDifference > 180) yawDifference -= 360;
46+
while (yawDifference < -180) yawDifference += 360;
47+
48+
// Convert to 0-360 range for easier mapping
49+
float relativeAngle = yawDifference < 0 ? yawDifference + 360 : yawDifference;
50+
51+
// Map to 8 directions based on relative angle
52+
// Add 22.5° offset so ranges are centered on cardinal directions
53+
relativeAngle += 22.5f;
54+
if (relativeAngle >= 360) {
55+
relativeAngle -= 360;
56+
}
57+
58+
int direction = (int) (relativeAngle / 45.0f);
59+
60+
return switch (direction) {
61+
case 0 -> "↑"; // Straight ahead
62+
case 1 -> "↗"; // Forward-right
63+
case 2 -> "→"; // Right
64+
case 3 -> "↘"; // Back-right
65+
case 4 -> "↓"; // Behind
66+
case 5 -> "↙"; // Back-left
67+
case 6 -> "←"; // Left
68+
case 7 -> "↖"; // Forward-left
69+
default -> throw new IllegalArgumentException("Invalid direction: " + direction);
70+
};
71+
}
2372
}

velocity.extension/src/main/java/net/swofty/velocity/SkyBlockVelocity.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,12 @@ public void onServerCrash(KickedFromServerEvent event) {
238238
}
239239

240240
try {
241-
GameManager.GameServer server = BalanceConfigurations.getServerFor(event.getPlayer(), serverType);
241+
ServerType serverTypeToTry = serverType;
242+
if (!GameManager.hasType(serverTypeToTry) || !GameManager.isAnyEmpty(serverTypeToTry)) {
243+
serverTypeToTry = ServerType.ISLAND;
244+
}
245+
246+
GameManager.GameServer server = BalanceConfigurations.getServerFor(event.getPlayer(), serverTypeToTry);
242247
if (server == null) {
243248
transferHandler.forceRemoveFromLimbo();
244249
event.getPlayer().disconnect(reason);

0 commit comments

Comments
 (0)