Skip to content

Commit

Permalink
feat: game profiles are player references
Browse files Browse the repository at this point in the history
  • Loading branch information
andantet committed Oct 19, 2024
1 parent ef3e06c commit 2521180
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ kache_version=1.0.5
inject_version=1.2.2

# Mod Properties
mod_version=2.12.2
mod_version=2.13
maven_group=dev.andante
43 changes: 43 additions & 0 deletions src/main/java/dev/andante/audience/mixin/GameProfileMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package dev.andante.audience.mixin;

import com.mojang.authlib.GameProfile;
import dev.andante.audience.Audience;
import dev.andante.audience.player.PlayerReference;
import dev.andante.audience.player.PlayerSet;
import dev.andante.audience.player.StandalonePlayerReference;
import net.minecraft.server.network.ServerPlayerEntity;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;

import java.util.Collections;
import java.util.List;
import java.util.UUID;

@SuppressWarnings("AddedMixinMembersNamePattern")
@Mixin(GameProfile.class)
public abstract class GameProfileMixin implements Audience, PlayerReference {
@Override
public @NotNull PlayerSet getAudiencePlayers() {
StandalonePlayerReference reference = this.getHardReference();
return new PlayerSet(List.of(reference));
}

@Override
public @NotNull UUID getReferenceUuid() {
GameProfile that = (GameProfile) (Object) this;
return that.getId();
}

@Override
public boolean equals(Object other) {
if (super.equals(other)) {
return true;
}

if (other instanceof PlayerReference reference) {
return reference.getReferenceUuid() == this.getReferenceUuid();
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
import dev.andante.audience.Audience;
import dev.andante.audience.player.PlayerReference;
import dev.andante.audience.player.PlayerSet;
import dev.andante.audience.player.StandalonePlayerReference;
import net.minecraft.server.network.ServerPlayerEntity;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;

import java.util.Collections;
import java.util.List;
import java.util.UUID;

@SuppressWarnings("AddedMixinMembersNamePattern")
@Mixin(ServerPlayerEntity.class)
public abstract class ServerPlayerEntityMixin implements Audience, PlayerReference {
@Override
public @NotNull PlayerSet getAudiencePlayers() {
ServerPlayerEntity that = (ServerPlayerEntity) (Object) this;
return new PlayerSet(Collections.singletonList(that));
StandalonePlayerReference reference = this.getHardReference();
return new PlayerSet(List.of(reference));
}

@Override
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/audience.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"mixins": [
"BlockMixin",
"BlockStateMixin",
"GameProfileMixin",
"MinecraftServerMixin",
"ServerPlayerEntityMixin",
"ServerWorldMixin"
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
"dev/andante/audience/Audience",
"dev/andante/audience/player/PlayerReference"
],
"com/mojang/authlib/GameProfile": [
"dev/andante/audience/Audience",
"dev/andante/audience/player/PlayerReference"
],
"net/minecraft/server/MinecraftServer": [ "dev/andante/audience/Audience" ],
"net/minecraft/class_3218": [ "dev/andante/audience/Audience" ],
"net/minecraft/class_2248": [ "dev/andante/audience/block/BlockStateLike" ],
Expand Down
9 changes: 9 additions & 0 deletions src/test/kotlin/dev/andante/audience/test/AudienceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ package dev.andante.audience.test
import com.google.gson.JsonParser
import com.mojang.serialization.JsonOps
import dev.andante.audience.Audience
import dev.andante.audience.player.PlayerReference
import dev.andante.audience.player.PlayerSet
import dev.andante.audience.player.StandalonePlayerReference
import dev.andante.audience.resource.ByteResourcePack
import dev.andante.audience.resource.ResourcePackHandler
import net.fabricmc.api.ModInitializer
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents
import net.fabricmc.fabric.api.networking.v1.ServerConfigurationConnectionEvents
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents
import net.minecraft.command.argument.EntityArgumentType.player
import org.slf4j.LoggerFactory
import kotlin.io.path.Path
import kotlin.io.path.readBytes
Expand Down Expand Up @@ -60,5 +64,10 @@ object AudienceTest : ModInitializer {
ResourcePackHandler.add(packTwo)
println(packOne.hash)
println(packTwo.hash)

ServerConfigurationConnectionEvents.BEFORE_CONFIGURE.register { handler, server ->
val reference = handler.debugProfile as PlayerReference
println(reference.hardReference)
}
}
}

0 comments on commit 2521180

Please sign in to comment.