Skip to content

Commit b0f3e04

Browse files
authored
Merge pull request #15 from GalvinPython/chore/26.1-update
update to 26.1 (well snapshots at least)
2 parents 4a776e8 + e3078ec commit b0f3e04

File tree

7 files changed

+115
-103
lines changed

7 files changed

+115
-103
lines changed

.github/workflows/build.yml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,36 @@
44
# against bad commits.
55

66
name: build
7-
on: [pull_request, push]
7+
8+
on:
9+
pull_request:
10+
paths: &build_paths
11+
- '.github/workflows/build.yml'
12+
- 'build.gradle'
13+
- 'gradle.properties'
14+
- 'gradle/**'
15+
- 'gradlew'
16+
- 'gradlew.bat'
17+
- 'settings.gradle'
18+
- 'src/**'
19+
20+
push:
21+
branches: [main]
22+
paths: *build_paths
23+
24+
concurrency:
25+
group: "java-build-${{ github.ref }}"
26+
cancel-in-progress: true
827

928
jobs:
1029
build:
1130
strategy:
1231
matrix:
1332
# Use these Java versions
1433
java: [
15-
21, # Current Java LTS
34+
25, # Current Java LTS
1635
]
17-
runs-on: ubuntu-22.04
36+
runs-on: ubuntu-latest
1837
steps:
1938
- name: checkout repository
2039
uses: actions/checkout@v4
@@ -30,8 +49,8 @@ jobs:
3049
- name: build
3150
run: ./gradlew build
3251
- name: capture build artifacts
33-
if: ${{ matrix.java == '21' }} # Only upload artifacts built from latest java
52+
if: ${{ matrix.java == '25' }} # Only upload artefacts built from latest java
3453
uses: actions/upload-artifact@v4
3554
with:
3655
name: Artifacts
37-
path: build/libs/
56+
path: build/libs/

build.gradle

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id 'fabric-loom' version "${loom_version}"
2+
id 'net.fabricmc.fabric-loom' version "${loom_version}"
33
id 'maven-publish'
44
}
55

@@ -21,11 +21,10 @@ repositories {
2121
dependencies {
2222
// To change the versions see the gradle.properties file
2323
minecraft "com.mojang:minecraft:${project.minecraft_version}"
24-
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
25-
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
24+
implementation "net.fabricmc:fabric-loader:${project.loader_version}"
2625

2726
// Fabric API. This is technically optional, but you probably want it anyway.
28-
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
27+
implementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"
2928

3029
}
3130

@@ -38,7 +37,7 @@ processResources {
3837
}
3938

4039
tasks.withType(JavaCompile).configureEach {
41-
it.options.release = 21
40+
it.options.release = 25
4241
}
4342

4443
java {
@@ -47,8 +46,8 @@ java {
4746
// If you remove this line, sources will not be generated.
4847
withSourcesJar()
4948

50-
sourceCompatibility = JavaVersion.VERSION_21
51-
targetCompatibility = JavaVersion.VERSION_21
49+
sourceCompatibility = JavaVersion.VERSION_25
50+
targetCompatibility = JavaVersion.VERSION_25
5251
}
5352

5453
jar {
@@ -75,4 +74,4 @@ publishing {
7574
// The repositories here will be used for publishing your artifact, not for
7675
// retrieving dependencies.
7776
}
78-
}
77+
}

gradle.properties

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ org.gradle.parallel=true
44

55
# Fabric Properties
66
# check these on https://fabricmc.net/develop
7-
minecraft_version=1.21.11
8-
yarn_mappings=1.21.11+build.3
7+
minecraft_version=26.1-snapshot-3
98
loader_version=0.18.4
109
loom_version=1.14-SNAPSHOT
1110

1211
# Mod Properties
13-
mod_version=1.0.4+1.21.11
12+
mod_version=1.0.5-beta+26.1-snapshots
1413
maven_group=me.imgalvin.playerfinder
1514
archives_base_name=player-finder
1615

1716
# Dependencies
18-
fabric_version=0.140.2+1.21.11
17+
fabric_api_version=0.142.0+26.1
Lines changed: 66 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,78 @@
11
package me.imgalvin.playerfinder;
22

3-
import com.mojang.brigadier.arguments.StringArgumentType;
43
import net.fabricmc.api.ModInitializer;
54
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;
5+
import net.minecraft.ChatFormatting;
6+
import net.minecraft.commands.Commands;
7+
import net.minecraft.commands.arguments.EntityArgument;
8+
import net.minecraft.core.BlockPos;
9+
import net.minecraft.network.chat.Component;
10+
import net.minecraft.resources.ResourceKey;
11+
import net.minecraft.server.level.ServerPlayer;
12+
import net.minecraft.world.level.Level;
13+
import org.slf4j.Logger;
14+
import org.slf4j.LoggerFactory;
1315

1416
public class PlayerFinder implements ModInitializer {
1517
PlayerFinderUtils utils = new PlayerFinderUtils();
1618

19+
public static final Logger LOGGER = LoggerFactory.getLogger("PlayerFinder");
20+
1721
@Override
1822
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.getEntityWorld().getRegistryKey();
34-
RegistryKey<World> sourceDimension = sourcePlayer.getEntityWorld().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-
});
23+
LOGGER.info("PlayerFinder initialized!");
24+
// _ previously registryAccess, environment
25+
CommandRegistrationCallback.EVENT.register((dispatcher, _, _) -> dispatcher.register(Commands.literal("findplayer")
26+
.then(Commands.argument("player", EntityArgument.player())
27+
.executes(context -> {
28+
LOGGER.info("Executing /findplayer command");
29+
30+
ServerPlayer targetPlayerName = EntityArgument.getPlayer(context, "player");
31+
String playerName = targetPlayerName.getGameProfile().name();
32+
33+
ServerPlayer targetPlayer = context.getSource().getServer().getPlayerList().getPlayer(playerName);
34+
ServerPlayer sourcePlayer = context.getSource().getServer().getPlayerList().getPlayer(context.getSource().getTextName());
35+
36+
if (targetPlayer == null) {
37+
context.getSource().sendSystemMessage(Component.literal("[PlayerFinder ERROR] Player " + playerName + " not found").withStyle(ChatFormatting.RED));
38+
return 0;
39+
}
40+
if (sourcePlayer == null) {
41+
context.getSource().sendSystemMessage(Component.literal("[PlayerFinder ERROR] Could not determine command source player").withStyle(ChatFormatting.RED));
42+
return 0;
43+
}
44+
45+
BlockPos targetBlockPos = targetPlayer.blockPosition();
46+
BlockPos sourceBlockPos = sourcePlayer.blockPosition();
47+
48+
LOGGER.info("Target player position: {}", targetBlockPos);
49+
LOGGER.info("Source player position: {}", sourceBlockPos);
50+
51+
ResourceKey<Level> playerDimension = targetPlayer.level().getLevel().dimension();
52+
ResourceKey<Level> sourceDimension = sourcePlayer.level().getLevel().dimension();
53+
54+
LOGGER.info("Target player dimension: {}", playerDimension);
55+
LOGGER.info("Source player dimension: {}", sourceDimension);
56+
57+
boolean isSameDimension = sourceDimension == playerDimension;
58+
59+
Component message = Component.literal(playerName + " is at ")
60+
.append(Component.literal(targetBlockPos.getX() + ", " + targetBlockPos.getY() + ", " + targetBlockPos.getZ())
61+
.withStyle(utils.getDimensionColor(playerDimension)))
62+
.append(Component.literal(" in the ").withStyle(ChatFormatting.WHITE))
63+
.append(Component.literal(utils.getDimensionText(playerDimension))
64+
.withStyle(utils.getDimensionColor(playerDimension)))
65+
.append(Component.literal(isSameDimension
66+
? " (" + utils.getDistance(sourceBlockPos, targetBlockPos) + " blocks away)"
67+
: " (Player is in a different dimension)")
68+
.withStyle(isSameDimension ? ChatFormatting.GREEN : ChatFormatting.RED));
69+
70+
// Send it as a system message to the source
71+
context.getSource().sendSystemMessage(message);
72+
73+
return 1;
74+
})
75+
)
76+
));
5477
}
5578
}
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
package me.imgalvin.playerfinder;
22

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;
3+
import net.minecraft.ChatFormatting;
4+
import net.minecraft.core.BlockPos;
5+
import net.minecraft.resources.ResourceKey;
6+
import net.minecraft.server.level.ServerLevel;
7+
import net.minecraft.world.level.Level;
78
import org.jetbrains.annotations.NotNull;
89

910
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
11+
public ChatFormatting getDimensionColor(@NotNull ResourceKey<Level> playerDimension) {
12+
return playerDimension.equals(ServerLevel.OVERWORLD) ? ChatFormatting.GREEN :
13+
playerDimension.equals(ServerLevel.NETHER) ? ChatFormatting.RED :
14+
playerDimension.equals(ServerLevel.END) ? ChatFormatting.LIGHT_PURPLE :
15+
ChatFormatting.GRAY; // Fallback colour for custom or unknown dimensions
1516
}
1617

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_", "");
18+
public String getDimensionText(@NotNull ResourceKey<Level> playerDimension) {
19+
return playerDimension.identifier().getPath().replace("the_", "");
2020
}
2121

2222
public int getDistance(@NotNull BlockPos playerPos, @NotNull BlockPos targetPos) {
23+
System.out.println("Calculating distance between " + playerPos + " and " + targetPos);
2324
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));
2425
}
2526
}

src/main/java/me/imgalvin/playerfinder/PlayerSuggestionProvider.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/main/resources/fabric.mod.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
},
2222
"depends": {
2323
"fabricloader": ">=0.17.3",
24-
"minecraft": "1.21.11",
25-
"java": ">=21",
24+
"minecraft": "26.1-alpha.3",
25+
"java": ">=25",
2626
"fabric-api": ">=0.139.5"
2727
}
2828
}

0 commit comments

Comments
 (0)