Skip to content

Commit cf0856a

Browse files
committed
1.0.1: improved command response
1 parent fcd8f93 commit cf0856a

File tree

9 files changed

+99
-57
lines changed

9 files changed

+99
-57
lines changed

.github/assets/java_ptTODXNtAi.png

46.4 KB
Loading

.github/assets/java_uYBQHtklFT.png

-40.2 KB
Binary file not shown.

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# Player Finder
2+
[Download from Modrinth](https://modrinth.com/mod/playerfinder)
3+
24
Player Finder is a Minecraft Mod for Fabric 1.21 that allows users to find the co-ordinates of other players on your server
35

4-
![Demonstration](https://raw.githubusercontent.com/GalvinPython/minecraft-playerfinder/main/.github/assets/java_uYBQHtklFT.png)
6+
![Demonstration](https://raw.githubusercontent.com/GalvinPython/minecraft-playerfinder/main/.github/assets/java_ptTODXNtAi.png)
7+
8+
*Note: The "the" in the dimensions have been removed since this screenshot was taken*
59

610
# Usage
711
Use the `/findplayer` command and enter the player's name. There is also a dropdown of players, so you don't have to type it in full and can use autocomplete!
@@ -11,6 +15,7 @@ Use the `/findplayer` command and enter the player's name. There is also a dropd
1115
# Compatible Versions
1216
| Mod Version | Game Version(s) | Mod Version Title |
1317
|-------------|-----------------|-------------------|
18+
| 1.0.1 | 1.21 - 1.21.1 | 1.0.1+1.21 |
1419
| 1.0.0 | 1.21 - 1.21.1 | 1.0.0+1.21 |
1520

1621
# Important Note
@@ -19,3 +24,10 @@ This mod is a **server-side** mod! You are **not** required to install this mod
1924
Also: This mod requires the **Fabric API** and Fabric Loader **0.16.0 or higher to be installed**.
2025

2126
PS: *You cannot use this mod on servers that don't use this mod. The commands are created server-side*
27+
28+
# Changelog
29+
## 1.0.1
30+
* Added colours to the co-ordinates depending on the dimension
31+
* Updated dimensions to remove "the" in the name
32+
* Added the distance in blocks to the player
33+
* Updated links in the mod metadata

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ yarn_mappings=1.21+build.9
99
loader_version=0.16.0
1010

1111
# Mod Properties
12-
mod_version=1.0.0
13-
maven_group=galvin.playerfinder
12+
mod_version=1.0.1+1.21
13+
maven_group=me.imgalvin.playerfinder
1414
archives_base_name=player-finder
1515

1616
# Dependencies

src/main/java/galvin/playerfinder/PlayerFinder.java

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package me.imgalvin.playerfinder;
2+
3+
import com.mojang.brigadier.arguments.StringArgumentType;
4+
import net.fabricmc.api.ModInitializer;
5+
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
6+
import net.minecraft.entity.player.PlayerEntity;
7+
import net.minecraft.registry.RegistryKey;
8+
import net.minecraft.server.command.CommandManager;
9+
import net.minecraft.text.Text;
10+
import net.minecraft.util.Formatting;
11+
import net.minecraft.util.math.BlockPos;
12+
import net.minecraft.world.World;
13+
14+
public class PlayerFinder implements ModInitializer {
15+
PlayerFinderUtils utils = new PlayerFinderUtils();
16+
17+
@Override
18+
public void onInitialize() {
19+
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
20+
dispatcher.register(CommandManager.literal("findplayer")
21+
.then(CommandManager.argument("player", StringArgumentType.string())
22+
.suggests(new PlayerSuggestionProvider())
23+
.executes(context -> {
24+
String playerName = StringArgumentType.getString(context, "player");
25+
PlayerEntity targetPlayer = context.getSource().getServer().getPlayerManager().getPlayer(playerName);
26+
PlayerEntity sourcePlayer = context.getSource().getPlayer();
27+
28+
assert targetPlayer != null;
29+
assert sourcePlayer != null;
30+
31+
BlockPos targetBlockPos = targetPlayer.getBlockPos();
32+
BlockPos sourceBlockPos = sourcePlayer.getBlockPos();
33+
RegistryKey<World> playerDimension = targetPlayer.getWorld().getRegistryKey();
34+
RegistryKey<World> sourceDimension = sourcePlayer.getWorld().getRegistryKey();
35+
36+
boolean isSameDimension = sourceDimension == playerDimension;
37+
38+
context.getSource().sendFeedback(() -> (Text) Text.literal(playerName + " is at ")
39+
.append(Text.literal(targetBlockPos.getX() + ", " + targetBlockPos.getY() + ", " + targetBlockPos.getZ())
40+
.formatted(utils.getDimensionColor(playerDimension)))
41+
.append(Text.literal(" in the ")
42+
.formatted(Formatting.WHITE))
43+
.append(Text.literal(utils.getDimensionText(playerDimension))
44+
.formatted(utils.getDimensionColor(playerDimension)))
45+
.append(Text.literal(isSameDimension
46+
? " (" + utils.getDistance(sourceBlockPos, targetBlockPos) + " blocks away)"
47+
: " (Player is in a different dimension)")
48+
.formatted(isSameDimension ? Formatting.GREEN : Formatting.RED)), false);
49+
return 1;
50+
})
51+
)
52+
);
53+
});
54+
}
55+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package me.imgalvin.playerfinder;
2+
3+
import net.minecraft.registry.RegistryKey;
4+
import net.minecraft.util.Formatting;
5+
import net.minecraft.util.math.BlockPos;
6+
import net.minecraft.world.World;
7+
import org.jetbrains.annotations.NotNull;
8+
9+
public class PlayerFinderUtils {
10+
public Formatting getDimensionColor(@NotNull RegistryKey<World> playerDimension) {
11+
return playerDimension.equals(World.OVERWORLD) ? Formatting.GREEN :
12+
playerDimension.equals(World.NETHER) ? Formatting.RED :
13+
playerDimension.equals(World.END) ? Formatting.LIGHT_PURPLE :
14+
Formatting.GRAY; // Fallback color for custom or unknown dimensions
15+
}
16+
17+
public String getDimensionText(@NotNull RegistryKey<World> playerDimension) {
18+
// note: this function only works for vanilla dimensions. custom dimensions will have a slight issue
19+
return playerDimension.getValue().toString().split(":")[1].replace("the_", "");
20+
}
21+
22+
public int getDistance(@NotNull BlockPos playerPos, @NotNull BlockPos targetPos) {
23+
return (int) Math.sqrt(Math.pow(playerPos.getX() - targetPos.getX(), 2) + Math.pow(playerPos.getY() - targetPos.getY(), 2) + Math.pow(playerPos.getZ() - targetPos.getZ(), 2));
24+
}
25+
}

src/main/java/galvin/playerfinder/PlayerSuggestionProvider.java renamed to src/main/java/me/imgalvin/playerfinder/PlayerSuggestionProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package galvin.playerfinder;
1+
package me.imgalvin.playerfinder;
22

33
import com.mojang.brigadier.context.CommandContext;
44
import com.mojang.brigadier.exceptions.CommandSyntaxException;

src/main/resources/fabric.mod.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
"GalvinPython"
99
],
1010
"contact": {
11-
"homepage": "https://fabricmc.net/",
12-
"sources": "https://github.com/FabricMC/fabric-example-mod"
11+
"homepage": "https://modrinth.com/mod/playerfinder",
12+
"sources": "https://github.com/GalvinPython/minecraft-playerfinder"
1313
},
1414
"license": "MIT",
1515
"icon": "assets/player-finder/icon.png",
1616
"environment": "*",
1717
"entrypoints": {
1818
"main": [
19-
"galvin.playerfinder.PlayerFinder"
19+
"me.imgalvin.playerfinder.PlayerFinder"
2020
]
2121
},
2222
"depends": {

0 commit comments

Comments
 (0)