diff --git a/build.gradle b/build.gradle index 5abcdbb..9c59ec0 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ import com.modrinth.minotaur.TaskModrinthUpload plugins { - id 'fabric-loom' version '0.10-SNAPSHOT' + id 'fabric-loom' version '0.12-SNAPSHOT' id 'maven-publish' id "com.matthewprenger.cursegradle" version "1.4.0" id "com.modrinth.minotaur" version "1.1.0" @@ -27,7 +27,7 @@ repositories { dependencies { // To change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" + mappings loom.officialMojangMappings() modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" // Fabric API. This is technically optional, but you probably want it anyway. @@ -108,6 +108,7 @@ curseforge { releaseType = "release" addGameVersion "${project.minecraft_version}" addGameVersion "Fabric" + addGameVersion "Quilt" mainArtifact(file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar")) { displayName = "[${project.minecraft_version}] Healthcare ${version}" @@ -138,4 +139,5 @@ task modrinth(type: TaskModrinthUpload, dependsOn: remapJar) { addGameVersion("${project.minecraft_version}") addLoader('fabric') + addLoader('quilt') } diff --git a/gradle.properties b/gradle.properties index b53bdfd..f12052c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,18 +1,14 @@ # Done to increase the memory available to gradle. org.gradle.jvmargs=-Xmx1G - # Fabric Properties -minecraft_version=1.18.2 -yarn_mappings=1.18.2+build.1 -loader_version=0.13.3 - +minecraft_version=1.19 +yarn_mappings=1.19+build.1 +loader_version=0.14.6 #Fabric api -fabric_version=0.47.8+1.18.2 - +fabric_version=0.55.2+1.19 # Mod Properties -mod_version = 1.0.11 -maven_group = org.samo_lego -archives_base_name = healthcare - +mod_version=1.1.0 +maven_group=org.samo_lego +archives_base_name=healthcare # Config editing lib -c2b_version = 1.0.2 +c2b_version=4c3b0be618 diff --git a/src/main/java/org/samo_lego/healthcare/HealthCare.java b/src/main/java/org/samo_lego/healthcare/HealthCare.java index 1ce0ec8..2063a05 100644 --- a/src/main/java/org/samo_lego/healthcare/HealthCare.java +++ b/src/main/java/org/samo_lego/healthcare/HealthCare.java @@ -1,7 +1,7 @@ package org.samo_lego.healthcare; import net.fabricmc.api.ModInitializer; -import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; +import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents; import net.fabricmc.loader.api.FabricLoader; import org.samo_lego.healthcare.command.HealthbarCommand; diff --git a/src/main/java/org/samo_lego/healthcare/command/HealthbarCommand.java b/src/main/java/org/samo_lego/healthcare/command/HealthbarCommand.java index 124df22..df12b9d 100644 --- a/src/main/java/org/samo_lego/healthcare/command/HealthbarCommand.java +++ b/src/main/java/org/samo_lego/healthcare/command/HealthbarCommand.java @@ -7,14 +7,15 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.suggestion.SuggestionProvider; -import net.minecraft.command.CommandSource; -import net.minecraft.command.argument.MessageArgumentType; -import net.minecraft.command.suggestion.SuggestionProviders; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.LiteralText; -import net.minecraft.text.TranslatableText; -import net.minecraft.util.Formatting; -import net.minecraft.util.Identifier; +import net.minecraft.ChatFormatting; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.commands.SharedSuggestionProvider; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.commands.synchronization.SuggestionProviders; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; import org.samo_lego.healthcare.healthbar.HealthbarPreferences; import org.samo_lego.healthcare.permission.PermissionHelper; @@ -23,15 +24,17 @@ import static com.mojang.brigadier.arguments.IntegerArgumentType.integer; import static com.mojang.brigadier.arguments.StringArgumentType.word; -import static net.minecraft.command.argument.MessageArgumentType.message; -import static net.minecraft.server.command.CommandManager.argument; -import static net.minecraft.server.command.CommandManager.literal; -import static org.samo_lego.healthcare.HealthCare.*; +import static net.minecraft.commands.Commands.argument; +import static net.minecraft.commands.Commands.literal; +import static net.minecraft.commands.arguments.MessageArgument.message; +import static org.samo_lego.healthcare.HealthCare.LUCKPERMS_LOADED; +import static org.samo_lego.healthcare.HealthCare.MODID; +import static org.samo_lego.healthcare.HealthCare.config; public class HealthbarCommand { - private static final SuggestionProvider HEALTHBAR_STYLES; + private static final SuggestionProvider HEALTHBAR_STYLES; - public static void register(CommandDispatcher dispatcher, boolean dedicated) { + public static void register(CommandDispatcher dispatcher, CommandBuildContext context, Commands.CommandSelection selection) { dispatcher.register(literal("healthbar") .then(literal("toggle").executes(HealthbarCommand::toggleHealthBar)) .then(literal("preferences") @@ -72,47 +75,47 @@ public static void register(CommandDispatcher dispatcher, b ); } - private static int toggleEntityType(CommandContext context) throws CommandSyntaxException { - if(LUCKPERMS_LOADED && !PermissionHelper.checkPermission(context.getSource(), config.perms.healthbar_edit_showEntityType, 0)) { - context.getSource().sendError(new TranslatableText("commands.help.failed").formatted(Formatting.RED)); + private static int toggleEntityType(CommandContext context) throws CommandSyntaxException { + if (LUCKPERMS_LOADED && !PermissionHelper.checkPermission(context.getSource(), config.perms.healthbar_edit_showEntityType, 0)) { + context.getSource().sendFailure(Component.translatable("commands.help.failed").withStyle(ChatFormatting.RED)); return -1; } - HealthbarPreferences preferences = (HealthbarPreferences) context.getSource().getPlayer(); + HealthbarPreferences preferences = (HealthbarPreferences) context.getSource().getPlayerOrException(); boolean allowEntityType = BoolArgumentType.getBool(context, "allow entity type"); preferences.setShowEntityType(allowEntityType); - context.getSource().sendFeedback( - new LiteralText(String.format(config.lang.toggledType, allowEntityType)) - .formatted(Formatting.GREEN) + context.getSource().sendSuccess( + Component.literal(String.format(config.lang.toggledType, allowEntityType)) + .withStyle(ChatFormatting.GREEN) .append("\n") - .append(new LiteralText(config.lang.reloadRequired).formatted(Formatting.GOLD)), + .append(Component.literal(config.lang.reloadRequired).withStyle(ChatFormatting.GOLD)), false ); return 0; } - private static int editHealthbarLength(CommandContext context) throws CommandSyntaxException { - if(LUCKPERMS_LOADED && !PermissionHelper.checkPermission(context.getSource(), config.perms.healthbar_edit_custom_length, 0)) { - context.getSource().sendError(new TranslatableText("commands.help.failed").formatted(Formatting.RED)); + private static int editHealthbarLength(CommandContext context) throws CommandSyntaxException { + if (LUCKPERMS_LOADED && !PermissionHelper.checkPermission(context.getSource(), config.perms.healthbar_edit_custom_length, 0)) { + context.getSource().sendFailure(Component.translatable("commands.help.failed").withStyle(ChatFormatting.RED)); return -1; } - HealthbarPreferences preferences = (HealthbarPreferences) context.getSource().getPlayer(); + HealthbarPreferences preferences = (HealthbarPreferences) context.getSource().getPlayerOrException(); int length = IntegerArgumentType.getInteger(context, "length"); preferences.setCustomLength(length); - context.getSource().sendFeedback( - new LiteralText(String.format(config.lang.customLengthSet, length)) - .formatted(Formatting.GREEN) - .append("\n") - .append(new LiteralText(config.lang.reloadRequired).formatted(Formatting.GOLD)), + context.getSource().sendSuccess( + Component.literal(String.format(config.lang.customLengthSet, length)) + .withStyle(ChatFormatting.GREEN) + .append("\n") + .append(Component.literal(config.lang.reloadRequired).withStyle(ChatFormatting.GOLD)), false ); - if(!preferences.getHealthbarStyle().equals(HealthbarPreferences.HealthbarStyle.CUSTOM)) { - context.getSource().sendFeedback( - new LiteralText(config.lang.useCustomStyle).formatted(Formatting.GOLD), + if (!preferences.getHealthbarStyle().equals(HealthbarPreferences.HealthbarStyle.CUSTOM)) { + context.getSource().sendSuccess( + Component.literal(config.lang.useCustomStyle).withStyle(ChatFormatting.GOLD), false ); } @@ -120,30 +123,30 @@ private static int editHealthbarLength(CommandContext conte return 0; } - private static int setSymbol(CommandContext context, boolean full) throws CommandSyntaxException { - if(LUCKPERMS_LOADED && !PermissionHelper.checkPermission(context.getSource(), full ? config.perms.healthbar_edit_custom_symbols_full : config.perms.healthbar_edit_custom_symbols_empty, 0)) { - context.getSource().sendError(new TranslatableText("commands.help.failed").formatted(Formatting.RED)); + private static int setSymbol(CommandContext context, boolean full) throws CommandSyntaxException { + if (LUCKPERMS_LOADED && !PermissionHelper.checkPermission(context.getSource(), full ? config.perms.healthbar_edit_custom_symbols_full : config.perms.healthbar_edit_custom_symbols_empty, 0)) { + context.getSource().sendFailure(Component.translatable("commands.help.failed").withStyle(ChatFormatting.RED)); return -1; } - HealthbarPreferences preferences = (HealthbarPreferences) context.getSource().getPlayer(); - char symbol = MessageArgumentType.getMessage(context, "symbol").getString().toCharArray()[0]; + HealthbarPreferences preferences = (HealthbarPreferences) context.getSource().getPlayerOrException(); + char symbol = MessageArgument.getMessage(context, "symbol").getString().toCharArray()[0]; - if(full) + if (full) preferences.setCustomFullChar(symbol); else preferences.setCustomEmptyChar(symbol); - context.getSource().sendFeedback( - new LiteralText(String.format(config.lang.customSymbolSet, full ? "Full" : "Empty", symbol)) - .formatted(Formatting.GREEN) - .append("\n") - .append(new LiteralText(config.lang.reloadRequired).formatted(Formatting.GOLD)), + context.getSource().sendSuccess( + Component.literal(String.format(config.lang.customSymbolSet, full ? "Full" : "Empty", symbol)) + .withStyle(ChatFormatting.GREEN) + .append("\n") + .append(Component.literal(config.lang.reloadRequired).withStyle(ChatFormatting.GOLD)), false ); - if(!preferences.getHealthbarStyle().equals(HealthbarPreferences.HealthbarStyle.CUSTOM)) { - context.getSource().sendFeedback( - new LiteralText(config.lang.useCustomStyle).formatted(Formatting.GOLD), + if (!preferences.getHealthbarStyle().equals(HealthbarPreferences.HealthbarStyle.CUSTOM)) { + context.getSource().sendSuccess( + Component.literal(config.lang.useCustomStyle).withStyle(ChatFormatting.GOLD), false ); } @@ -151,62 +154,62 @@ private static int setSymbol(CommandContext context, boolea return 0; } - private static int changeVisibility(CommandContext context) throws CommandSyntaxException { - if(LUCKPERMS_LOADED && !PermissionHelper.checkPermission(context.getSource(), config.perms.healthbar_edit_visibility, 0)) { - context.getSource().sendError(new TranslatableText("commands.help.failed").formatted(Formatting.RED)); + private static int changeVisibility(CommandContext context) throws CommandSyntaxException { + if (LUCKPERMS_LOADED && !PermissionHelper.checkPermission(context.getSource(), config.perms.healthbar_edit_visibility, 0)) { + context.getSource().sendFailure(Component.translatable("commands.help.failed").withStyle(ChatFormatting.RED)); return -1; } - HealthbarPreferences preferences = (HealthbarPreferences) context.getSource().getPlayer(); + HealthbarPreferences preferences = (HealthbarPreferences) context.getSource().getPlayerOrException(); boolean alwaysVisible = BoolArgumentType.getBool(context, "visibility"); preferences.setAlwaysVisible(alwaysVisible); - context.getSource().sendFeedback( - new LiteralText(String.format(config.lang.visibilitySet, alwaysVisible)) - .formatted(Formatting.GREEN) - .append("\n") - .append(new LiteralText(config.lang.reloadRequired).formatted(Formatting.GOLD)), + context.getSource().sendSuccess( + Component.literal(String.format(config.lang.visibilitySet, alwaysVisible)) + .withStyle(ChatFormatting.GREEN) + .append("\n") + .append(Component.literal(config.lang.reloadRequired).withStyle(ChatFormatting.GOLD)), false ); return 0; } - private static int editHealthbarStyle(CommandContext context) throws CommandSyntaxException { - if(LUCKPERMS_LOADED && !PermissionHelper.checkPermission(context.getSource(), config.perms.healthbar_edit_style, 0)) { - context.getSource().sendError(new TranslatableText("commands.help.failed").formatted(Formatting.RED)); + private static int editHealthbarStyle(CommandContext context) throws CommandSyntaxException { + if (LUCKPERMS_LOADED && !PermissionHelper.checkPermission(context.getSource(), config.perms.healthbar_edit_style, 0)) { + context.getSource().sendFailure(Component.translatable("commands.help.failed").withStyle(ChatFormatting.RED)); return -1; } - HealthbarPreferences preferences = (HealthbarPreferences) context.getSource().getPlayer(); + HealthbarPreferences preferences = (HealthbarPreferences) context.getSource().getPlayerOrException(); HealthbarPreferences.HealthbarStyle style = HealthbarPreferences.HealthbarStyle.valueOf(StringArgumentType.getString(context, "style")); preferences.setHealthbarStyle(style); - context.getSource().sendFeedback( - new LiteralText(String.format(config.lang.styleSet, style)) - .formatted(Formatting.GREEN) - .append("\n") - .append(new LiteralText(config.lang.reloadRequired).formatted(Formatting.GOLD)), + context.getSource().sendSuccess( + Component.literal(String.format(config.lang.styleSet, style)) + .withStyle(ChatFormatting.GREEN) + .append("\n") + .append(Component.literal(config.lang.reloadRequired).withStyle(ChatFormatting.GOLD)), false ); return 0; } - private static int toggleHealthBar(CommandContext context) throws CommandSyntaxException { - if(LUCKPERMS_LOADED && !PermissionHelper.checkPermission(context.getSource(), config.perms.healthbar_toggle, 0)) { - context.getSource().sendError(new TranslatableText("commands.help.failed").formatted(Formatting.RED)); + private static int toggleHealthBar(CommandContext context) throws CommandSyntaxException { + if (LUCKPERMS_LOADED && !PermissionHelper.checkPermission(context.getSource(), config.perms.healthbar_toggle, 0)) { + context.getSource().sendFailure(Component.translatable("commands.help.failed").withStyle(ChatFormatting.RED)); return -1; } - HealthbarPreferences preferences = (HealthbarPreferences) context.getSource().getPlayer(); + HealthbarPreferences preferences = (HealthbarPreferences) context.getSource().getPlayerOrException(); preferences.setEnabled(!preferences.isEnabled()); - context.getSource().sendFeedback( - new LiteralText(preferences.isEnabled() ? config.lang.healthbarEnabled : config.lang.healthbarDisabled) - .formatted(Formatting.GREEN) - .append("\n") - .append(new LiteralText(config.lang.reloadRequired).formatted(Formatting.GOLD)), + context.getSource().sendSuccess( + Component.literal(preferences.isEnabled() ? config.lang.healthbarEnabled : config.lang.healthbarDisabled) + .withStyle(ChatFormatting.GREEN) + .append("\n") + .append(Component.literal(config.lang.reloadRequired).withStyle(ChatFormatting.GOLD)), false ); @@ -215,9 +218,9 @@ private static int toggleHealthBar(CommandContext context) static { HEALTHBAR_STYLES = SuggestionProviders.register( - new Identifier(MODID, "healthbar_styles"), + new ResourceLocation(MODID, "healthbar_styles"), (context, builder) -> - CommandSource.suggestMatching(Stream.of(HealthbarPreferences.HealthbarStyle.values()).map(Enum::name).collect(Collectors.toList()), builder) + SharedSuggestionProvider.suggest(Stream.of(HealthbarPreferences.HealthbarStyle.values()).map(Enum::name).collect(Collectors.toList()), builder) ); } } diff --git a/src/main/java/org/samo_lego/healthcare/command/HealthcareCommand.java b/src/main/java/org/samo_lego/healthcare/command/HealthcareCommand.java index fa67cf7..b42e363 100644 --- a/src/main/java/org/samo_lego/healthcare/command/HealthcareCommand.java +++ b/src/main/java/org/samo_lego/healthcare/command/HealthcareCommand.java @@ -3,30 +3,34 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.tree.LiteralCommandNode; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Formatting; +import net.minecraft.ChatFormatting; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.network.chat.Component; import org.samo_lego.healthcare.config.HealthConfig; import org.samo_lego.healthcare.permission.PermissionHelper; -import static net.minecraft.server.command.CommandManager.literal; -import static org.samo_lego.healthcare.HealthCare.*; +import static net.minecraft.commands.Commands.literal; +import static org.samo_lego.healthcare.HealthCare.CONFIG_FILE; +import static org.samo_lego.healthcare.HealthCare.LUCKPERMS_LOADED; +import static org.samo_lego.healthcare.HealthCare.config; public class HealthcareCommand { - public static void register(CommandDispatcher dispatcher, boolean dedicated) { - LiteralCommandNode healthcareNode = dispatcher.register(literal("healthcare") - .requires(src -> LUCKPERMS_LOADED ? PermissionHelper.checkPermission(src, config.perms.healthcare_config, 4) : src.hasPermissionLevel(4))); + public static void register(CommandDispatcher dispatcher, CommandBuildContext context, Commands.CommandSelection selection) { + LiteralCommandNode healthcareNode = dispatcher.register(literal("healthcare") + .requires(src -> LUCKPERMS_LOADED ? PermissionHelper.checkPermission(src, config.perms.healthcare_config, 4) : src.hasPermission(4))); - LiteralCommandNode configNode = literal("config") + LiteralCommandNode configNode = literal("config") .then(literal("reload") - .requires(src -> LUCKPERMS_LOADED ? PermissionHelper.checkPermission(src, config.perms.healthcare_config_reload, 4) : src.hasPermissionLevel(4)) + .requires(src -> LUCKPERMS_LOADED ? PermissionHelper.checkPermission(src, config.perms.healthcare_config_reload, 4) : src.hasPermission(4)) .executes(HealthcareCommand::reloadConfig) ) .build(); - LiteralCommandNode editNode = literal("edit") - .requires(src -> LUCKPERMS_LOADED ? PermissionHelper.checkPermission(src, config.perms.healthcare_config_edit, 4) : src.hasPermissionLevel(4)) + LiteralCommandNode editNode = literal("edit") + .requires(src -> LUCKPERMS_LOADED ? PermissionHelper.checkPermission(src, config.perms.healthcare_config_edit, 4) : src.hasPermission(4)) .build(); config.generateCommand(editNode); @@ -35,12 +39,12 @@ public static void register(CommandDispatcher dispatcher, b healthcareNode.addChild(configNode); } - private static int reloadConfig(CommandContext ctx) { + private static int reloadConfig(CommandContext ctx) { HealthConfig newConfig = HealthConfig.loadConfigFile(CONFIG_FILE); config.reload(newConfig); - ctx.getSource().sendFeedback( - new LiteralText(config.lang.configReloaded).formatted(Formatting.GREEN), + ctx.getSource().sendSuccess( + Component.literal(config.lang.configReloaded).withStyle(ChatFormatting.GREEN), false ); return 0; diff --git a/src/main/java/org/samo_lego/healthcare/event/EventHandler.java b/src/main/java/org/samo_lego/healthcare/event/EventHandler.java index 2921d0d..3de4d68 100644 --- a/src/main/java/org/samo_lego/healthcare/event/EventHandler.java +++ b/src/main/java/org/samo_lego/healthcare/event/EventHandler.java @@ -1,7 +1,7 @@ package org.samo_lego.healthcare.event; import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents; -import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.level.ServerPlayer; import org.samo_lego.healthcare.healthbar.HealthbarPreferences; public class EventHandler implements ServerPlayerEvents.CopyFrom { @@ -14,7 +14,7 @@ public class EventHandler implements ServerPlayerEvents.CopyFrom { * @param alive whether the old player is still alive */ @Override - public void copyFromPlayer(ServerPlayerEntity oldPlayer, ServerPlayerEntity newPlayer, boolean alive) { + public void copyFromPlayer(ServerPlayer oldPlayer, ServerPlayer newPlayer, boolean alive) { ((HealthbarPreferences) newPlayer).setHealthbarStyle(((HealthbarPreferences) oldPlayer).getHealthbarStyle()); ((HealthbarPreferences) newPlayer).setEnabled(((HealthbarPreferences) oldPlayer).isEnabled()); ((HealthbarPreferences) newPlayer).setAlwaysVisible(((HealthbarPreferences) oldPlayer).isAlwaysVisible()); diff --git a/src/main/java/org/samo_lego/healthcare/healthbar/HealthbarPreferences.java b/src/main/java/org/samo_lego/healthcare/healthbar/HealthbarPreferences.java index c389307..dcb3c14 100644 --- a/src/main/java/org/samo_lego/healthcare/healthbar/HealthbarPreferences.java +++ b/src/main/java/org/samo_lego/healthcare/healthbar/HealthbarPreferences.java @@ -1,6 +1,6 @@ package org.samo_lego.healthcare.healthbar; -import net.minecraft.text.MutableText; +import net.minecraft.network.chat.MutableComponent; public interface HealthbarPreferences { /** @@ -12,11 +12,12 @@ public interface HealthbarPreferences { /** * Gets the health text from current health and max health depending on HealthbarStyle. - * @param health current health + * + * @param health current health * @param maxHealth max health * @return formatted mutable text with health info */ - MutableText getHealthbarText(float health, float maxHealth); + MutableComponent getHealthbarText(float health, float maxHealth); void setEnabled(boolean enabled); boolean isEnabled(); diff --git a/src/main/java/org/samo_lego/healthcare/mixin/EntityAccessor.java b/src/main/java/org/samo_lego/healthcare/mixin/EntityAccessor.java index 48c2869..e1119ec 100644 --- a/src/main/java/org/samo_lego/healthcare/mixin/EntityAccessor.java +++ b/src/main/java/org/samo_lego/healthcare/mixin/EntityAccessor.java @@ -1,8 +1,8 @@ package org.samo_lego.healthcare.mixin; -import net.minecraft.entity.Entity; -import net.minecraft.entity.data.TrackedData; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.world.entity.Entity; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; @@ -10,12 +10,13 @@ @Mixin(Entity.class) public interface EntityAccessor { - @Accessor("NAME_VISIBLE") - static TrackedData getNAME_VISIBLE() { + @Accessor("DATA_CUSTOM_NAME_VISIBLE") + static EntityDataAccessor getNAME_VISIBLE() { throw new AssertionError(); } - @Accessor("CUSTOM_NAME") - static TrackedData> getCUSTOM_NAME() { + + @Accessor("DATA_CUSTOM_NAME") + static EntityDataAccessor> getCUSTOM_NAME() { throw new AssertionError(); } } diff --git a/src/main/java/org/samo_lego/healthcare/mixin/EntityTrackerUpdateS2CPacketAccessor.java b/src/main/java/org/samo_lego/healthcare/mixin/EntityTrackerUpdateS2CPacketAccessor.java index 2704613..4542b5c 100644 --- a/src/main/java/org/samo_lego/healthcare/mixin/EntityTrackerUpdateS2CPacketAccessor.java +++ b/src/main/java/org/samo_lego/healthcare/mixin/EntityTrackerUpdateS2CPacketAccessor.java @@ -1,22 +1,22 @@ package org.samo_lego.healthcare.mixin; -import net.minecraft.entity.data.DataTracker; -import net.minecraft.network.packet.s2c.play.EntityTrackerUpdateS2CPacket; +import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; +import net.minecraft.network.syncher.SynchedEntityData; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; import org.spongepowered.asm.mixin.gen.Accessor; import java.util.List; -@Mixin(EntityTrackerUpdateS2CPacket.class) +@Mixin(ClientboundSetEntityDataPacket.class) public interface EntityTrackerUpdateS2CPacketAccessor { - @Accessor("trackedValues") - List> getTrackedValues(); + @Accessor("packedItems") + List> getPackedItems(); @Mutable - @Accessor("trackedValues") - void setTrackedValues(List> trackedValues); + @Accessor("packedItems") + void setPackedItems(List> packedItems); @Accessor("id") int getId(); diff --git a/src/main/java/org/samo_lego/healthcare/mixin/PlayerEntityMixinCast_Preferences.java b/src/main/java/org/samo_lego/healthcare/mixin/PlayerEntityMixinCast_Preferences.java index 5a519c5..349637e 100644 --- a/src/main/java/org/samo_lego/healthcare/mixin/PlayerEntityMixinCast_Preferences.java +++ b/src/main/java/org/samo_lego/healthcare/mixin/PlayerEntityMixinCast_Preferences.java @@ -1,10 +1,10 @@ package org.samo_lego.healthcare.mixin; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.text.LiteralText; -import net.minecraft.text.MutableText; -import net.minecraft.util.Formatting; +import net.minecraft.ChatFormatting; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.world.entity.player.Player; import org.samo_lego.healthcare.healthbar.HealthbarPreferences; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -13,7 +13,7 @@ import static org.samo_lego.healthcare.HealthCare.config; -@Mixin(PlayerEntity.class) +@Mixin(Player.class) public class PlayerEntityMixinCast_Preferences implements HealthbarPreferences { private HealthbarStyle healthbarStyle = config.defaultStyle; @@ -36,14 +36,14 @@ public void setHealthbarStyle(HealthbarStyle healthbarStyle) { } @Override - public MutableText getHealthbarText(float health, float maxHealth) { - if(health < 0.0F) { + public MutableComponent getHealthbarText(float health, float maxHealth) { + if (health < 0.0F) { health = 0.0F; } - if(maxHealth <= 0.0F) { + if (maxHealth <= 0.0F) { maxHealth = 1.0F; } - if(health > maxHealth) { + if (health > maxHealth) { maxHealth = health; } @@ -55,14 +55,14 @@ public MutableText getHealthbarText(float health, float maxHealth) { second = String.valueOf((int) Math.ceil(maxHealth)); // We return it here because of custom formatting - return new LiteralText(first) - .formatted(health > maxHealth / 2 ? Formatting.GREEN : Formatting.YELLOW) - .append(new LiteralText("/") - .formatted(Formatting.WHITE)) - .append(new LiteralText(second) - .formatted(Formatting.GREEN)) - .append(new LiteralText(String.valueOf((char) 10084)) // ❤ - .formatted(Formatting.RED)); + return Component.literal(first) + .withStyle(health > maxHealth / 2 ? ChatFormatting.GREEN : ChatFormatting.YELLOW) + .append(Component.literal("/") + .withStyle(ChatFormatting.WHITE)) + .append(Component.literal(second) + .withStyle(ChatFormatting.GREEN)) + .append(Component.literal(String.valueOf((char) 10084)) // ❤ + .withStyle(ChatFormatting.RED)); } case NUMBER -> { // Number @@ -98,9 +98,9 @@ public MutableText getHealthbarText(float health, float maxHealth) { second = new String(new char[heartCount - fullHearts]).replace('\0', empty); } } - return new LiteralText(first) - .formatted(Formatting.RED) /*health > maxHealth / 3 ? (health > maxHealth * 1.5F ? Formatting.YELLOW : Formatting.GOLD) : */ - .append(new LiteralText(second).formatted(Formatting.GRAY)); + return Component.literal(first) + .withStyle(ChatFormatting.RED) /*health > maxHealth / 3 ? (health > maxHealth * 1.5F ? Formatting.YELLOW : Formatting.GOLD) : */ + .append(Component.literal(second).withStyle(ChatFormatting.GRAY)); } @Override @@ -155,7 +155,7 @@ public int getCustomFullChar() { @Override public void setCustomLength(int length) { - if(length >= 0) // Don't allow negative length + if (length >= 0) // Don't allow negative length this.customLength = length; } @@ -164,14 +164,14 @@ public int getCustomLength() { return this.customLength; } - @Inject(method = "writeCustomDataToNbt", at = @At("TAIL")) - private void writeCustomDataToTag(NbtCompound tag, CallbackInfo ci) { - NbtCompound healthbar = new NbtCompound(); + @Inject(method = "addAdditionalSaveData", at = @At("TAIL")) + private void writeCustomDataToTag(CompoundTag tag, CallbackInfo ci) { + CompoundTag healthbar = new CompoundTag(); healthbar.putString("Style", this.healthbarStyle.toString()); healthbar.putBoolean("Enabled", this.enabled); healthbar.putBoolean("ShowType", this.showType); healthbar.putBoolean("AlwaysVisible", this.alwaysVisible); - if(this.healthbarStyle.equals(HealthbarStyle.CUSTOM)) { + if (this.healthbarStyle.equals(HealthbarStyle.CUSTOM)) { healthbar.putInt("CustomFullChar", this.customFullChar); healthbar.putInt("CustomEmptyChar", this.customEmptyChar); healthbar.putInt("Length", this.customLength); @@ -179,16 +179,16 @@ private void writeCustomDataToTag(NbtCompound tag, CallbackInfo ci) { tag.put("Healthbar", healthbar); } - @Inject(method = "readCustomDataFromNbt", at = @At("TAIL")) - private void readCustomDataFromTag(NbtCompound tag, CallbackInfo ci) { - if(tag.contains("Healthbar")) { - NbtCompound healthbar = tag.getCompound("Healthbar"); + @Inject(method = "readAdditionalSaveData", at = @At("TAIL")) + private void readCustomDataFromTag(CompoundTag tag, CallbackInfo ci) { + if (tag.contains("Healthbar")) { + CompoundTag healthbar = tag.getCompound("Healthbar"); this.healthbarStyle = HealthbarStyle.valueOf(healthbar.getString("Style")); this.enabled = healthbar.getBoolean("Enabled"); this.alwaysVisible = healthbar.getBoolean("AlwaysVisible"); this.showType = healthbar.getBoolean("ShowType"); - if(this.healthbarStyle.equals(HealthbarStyle.CUSTOM)) { + if (this.healthbarStyle.equals(HealthbarStyle.CUSTOM)) { this.customFullChar = healthbar.getInt("CustomFullChar"); this.customEmptyChar = healthbar.getInt("CustomEmptyChar"); this.customLength = healthbar.getInt("Length"); diff --git a/src/main/java/org/samo_lego/healthcare/mixin/ServerPlayNetworkHandlerMixin_HealthTag.java b/src/main/java/org/samo_lego/healthcare/mixin/ServerPlayNetworkHandlerMixin_HealthTag.java index 2ede4a9..7125a23 100644 --- a/src/main/java/org/samo_lego/healthcare/mixin/ServerPlayNetworkHandlerMixin_HealthTag.java +++ b/src/main/java/org/samo_lego/healthcare/mixin/ServerPlayNetworkHandlerMixin_HealthTag.java @@ -2,20 +2,18 @@ import io.netty.util.concurrent.Future; import io.netty.util.concurrent.GenericFutureListener; -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.data.DataTracker; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.network.ClientConnection; -import net.minecraft.network.Packet; -import net.minecraft.network.packet.s2c.play.EntityTrackerUpdateS2CPacket; -import net.minecraft.server.network.ServerPlayNetworkHandler; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.LiteralText; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import net.minecraft.text.TranslatableText; -import net.minecraft.util.registry.Registry; +import net.minecraft.core.Registry; +import net.minecraft.network.Connection; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerGamePacketListenerImpl; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; import org.samo_lego.healthcare.healthbar.HealthbarPreferences; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -32,11 +30,14 @@ import static org.samo_lego.healthcare.HealthCare.config; -@Mixin(ServerPlayNetworkHandler.class) +@Mixin(ServerGamePacketListenerImpl.class) public class ServerPlayNetworkHandlerMixin_HealthTag { - @Shadow public ServerPlayerEntity player; + @Shadow + public ServerPlayer player; - @Shadow @Final public ClientConnection connection; + @Shadow + @Final + public Connection connection; /** * Dummy handler used for creating modified @@ -46,70 +47,70 @@ public class ServerPlayNetworkHandlerMixin_HealthTag { * as non-dirty upon sending the fake packet. */ @Unique - private final DataTracker healthcare$dummyTracker = new DataTracker(null); + private final SynchedEntityData healthcare$dummyTracker = new SynchedEntityData(null); /** * Gets the current packet being sent and modifies * it accordingly to player's preferences if it is - * an {@link EntityTrackerUpdateS2CPacket}. + * an {@link ClientboundSetEntityDataPacket}. * - * @param packet packet being sent + * @param packet packet being sent * @param listener * @param ci */ @Inject( - method = "sendPacket(Lnet/minecraft/network/Packet;Lio/netty/util/concurrent/GenericFutureListener;)V", + method = "send(Lnet/minecraft/network/protocol/Packet;Lio/netty/util/concurrent/GenericFutureListener;)V", at = @At( value = "INVOKE", - target = "Lnet/minecraft/network/ClientConnection;send(Lnet/minecraft/network/Packet;Lio/netty/util/concurrent/GenericFutureListener;)V" + target = "Lnet/minecraft/network/Connection;send(Lnet/minecraft/network/protocol/Packet;Lio/netty/util/concurrent/GenericFutureListener;)V" ), cancellable = true ) private void onPacketSend(Packet packet, GenericFutureListener> listener, CallbackInfo ci) { - if(packet instanceof EntityTrackerUpdateS2CPacket) { + if (packet instanceof ClientboundSetEntityDataPacket) { int id = ((EntityTrackerUpdateS2CPacketAccessor) packet).getId(); - Entity entity = this.player.getWorld().getEntityById(id); + Entity entity = this.player.getLevel().getEntity(id); - if( + if ( entity instanceof LivingEntity living && - ((HealthbarPreferences) this.player).isEnabled() && - !(entity instanceof PlayerEntity) && - !config.blacklistedEntities.contains(Registry.ENTITY_TYPE.getId(entity.getType()).toString()) && - !entity.isInvisibleTo(player) + ((HealthbarPreferences) this.player).isEnabled() && + !(entity instanceof Player) && + !config.blacklistedEntities.contains(Registry.ENTITY_TYPE.getKey(entity.getType()).toString()) && + !entity.isInvisibleTo(player) ) { - List> trackedValues = new ArrayList<>(((EntityTrackerUpdateS2CPacketAccessor) packet).getTrackedValues()); + List> trackedValues = new ArrayList<>(((EntityTrackerUpdateS2CPacketAccessor) packet).getPackedItems()); // Removing current custom name - trackedValues.removeIf(value -> value.getData().getId() == 2); + trackedValues.removeIf(value -> value.getAccessor().getId() == 2); // Ensure name is visible only if mob is not too far away boolean visible = (entity.distanceTo(player) < config.activationRange || entity.isCustomNameVisible()) && ((HealthbarPreferences) player).isAlwaysVisible(); - DataTracker.Entry visibleTag = new DataTracker.Entry<>(EntityAccessor.getNAME_VISIBLE(), visible); + SynchedEntityData.DataItem visibleTag = new SynchedEntityData.DataItem<>(EntityAccessor.getNAME_VISIBLE(), visible); float health = living.getHealth(); float maxHealth = living.getMaxHealth(); // @SpaceClouds42 saved me here, `.copy()` after getting custom name is essential! - MutableText name; - if(entity.hasCustomName()) - name = entity.getCustomName().shallowCopy().append(" "); - else if(((HealthbarPreferences) player).showEntityType()) - name = new TranslatableText(entity.getType().getTranslationKey()).append(" "); + MutableComponent name; + if (entity.hasCustomName()) + name = entity.getCustomName().copy().append(" "); + else if (((HealthbarPreferences) player).showEntityType()) + name = Component.translatable(entity.getType().getDescriptionId()).append(" "); else - name = new LiteralText(""); + name = Component.literal(""); - MutableText healthbar = ((HealthbarPreferences) this.player).getHealthbarText(health, maxHealth); - DataTracker.Entry> healthTag = new DataTracker.Entry<>(EntityAccessor.getCUSTOM_NAME(), Optional.of(name.append(healthbar))); + MutableComponent healthbar = ((HealthbarPreferences) this.player).getHealthbarText(health, maxHealth); + SynchedEntityData.DataItem> healthTag = new SynchedEntityData.DataItem<>(EntityAccessor.getCUSTOM_NAME(), Optional.of(name.append(healthbar))); Collections.addAll(trackedValues, visibleTag, healthTag); // Create a new packet in order to not mess with other network handlers // since same packet object is sent to every player - EntityTrackerUpdateS2CPacket trackerUpdatePacket = new EntityTrackerUpdateS2CPacket(id, this.healthcare$dummyTracker, false); + ClientboundSetEntityDataPacket trackerUpdatePacket = new ClientboundSetEntityDataPacket(id, this.healthcare$dummyTracker, false); EntityTrackerUpdateS2CPacketAccessor accessor = (EntityTrackerUpdateS2CPacketAccessor) trackerUpdatePacket; accessor.setId(id); - accessor.setTrackedValues(trackedValues); + accessor.setPackedItems(trackedValues); this.connection.send(trackerUpdatePacket, listener); ci.cancel(); // cancel the original packet going out diff --git a/src/main/java/org/samo_lego/healthcare/permission/PermissionHelper.java b/src/main/java/org/samo_lego/healthcare/permission/PermissionHelper.java index d041ed0..2c02f31 100644 --- a/src/main/java/org/samo_lego/healthcare/permission/PermissionHelper.java +++ b/src/main/java/org/samo_lego/healthcare/permission/PermissionHelper.java @@ -1,10 +1,10 @@ package org.samo_lego.healthcare.permission; import me.lucko.fabric.api.permissions.v0.Permissions; -import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.commands.CommandSourceStack; public class PermissionHelper { - public static boolean checkPermission(ServerCommandSource commandSource, String permission, int defaultLevel) { + public static boolean checkPermission(CommandSourceStack commandSource, String permission, int defaultLevel) { return Permissions.check(commandSource, permission, defaultLevel); } }