From f7d6275f3d3c8df8bdb1e932c5db0092d7395e86 Mon Sep 17 00:00:00 2001 From: Josiah Glosson Date: Mon, 22 Jul 2024 09:18:06 -0500 Subject: [PATCH] Replace fake client player with a draggable widget --- .../worldhost/GameProfileRenderer.java | 268 ------------------ .../gaming32/worldhost/WHPlayerSkin.java | 65 +++++ .../github/gaming32/worldhost/WorldHost.java | 35 +-- .../gui/screen/PlayerInfoScreen.java | 31 +- .../gui/widget/WHPlayerSkinWidget.java | 166 +++++++++++ .../mixin/MixinAbstractClientPlayer.java | 35 --- src/main/resources/world-host.mixins.json | 1 - 7 files changed, 245 insertions(+), 356 deletions(-) delete mode 100644 src/main/java/io/github/gaming32/worldhost/GameProfileRenderer.java create mode 100644 src/main/java/io/github/gaming32/worldhost/WHPlayerSkin.java create mode 100644 src/main/java/io/github/gaming32/worldhost/gui/widget/WHPlayerSkinWidget.java delete mode 100644 src/main/java/io/github/gaming32/worldhost/mixin/MixinAbstractClientPlayer.java diff --git a/src/main/java/io/github/gaming32/worldhost/GameProfileRenderer.java b/src/main/java/io/github/gaming32/worldhost/GameProfileRenderer.java deleted file mode 100644 index 9a15cb1..0000000 --- a/src/main/java/io/github/gaming32/worldhost/GameProfileRenderer.java +++ /dev/null @@ -1,268 +0,0 @@ -package io.github.gaming32.worldhost; - -import com.google.common.base.Suppliers; -import com.mojang.authlib.GameProfile; -import net.minecraft.Util; -import net.minecraft.client.Camera; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screens.inventory.InventoryScreen; -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.multiplayer.ClientPacketListener; -import net.minecraft.client.player.RemotePlayer; -import net.minecraft.client.renderer.entity.EntityRenderDispatcher; -import net.minecraft.commands.Commands; -import net.minecraft.network.Connection; -import net.minecraft.network.protocol.PacketFlow; -import net.minecraft.server.packs.repository.PackRepository; -import net.minecraft.server.packs.repository.ServerPacksSource; -import net.minecraft.world.Difficulty; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.level.Level; - -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.function.Supplier; - -//#if MC >= 1.20.0 -import net.minecraft.client.gui.GuiGraphics; -//#else -//$$ import com.mojang.blaze3d.vertex.PoseStack; -//#endif - -//#if MC >= 1.19.2 -import net.minecraft.client.gui.screens.worldselection.WorldCreationContext; -import net.minecraft.server.WorldLoader; -import net.minecraft.world.level.dimension.BuiltinDimensionTypes; -import net.minecraft.world.level.levelgen.presets.WorldPresets; -//#else -//$$ import net.minecraft.world.level.dimension.DimensionType; -//#endif - -//#if MC >= 1.19.4 -import net.minecraft.client.telemetry.TelemetryEventSender; -import net.minecraft.client.telemetry.WorldSessionTelemetryManager; -import net.minecraft.core.registries.Registries; -import net.minecraft.world.level.WorldDataConfiguration; -import net.minecraft.world.level.levelgen.WorldGenSettings; -import net.minecraft.world.level.levelgen.WorldOptions; -//#else -//$$ import com.mojang.datafixers.util.Pair; -//$$ import com.mojang.serialization.Lifecycle; -//$$ import net.minecraft.core.Registry; -//$$ import net.minecraft.core.RegistryAccess; -//$$ import net.minecraft.server.packs.PackType; -//$$ import net.minecraft.world.level.DataPackConfig; -//#endif - -//#if MC >= 1.20.4 -import net.minecraft.client.multiplayer.CommonListenerCookie; -import net.minecraft.world.flag.FeatureFlags; -//#endif - -//#if MC >= 1.20.6 -import java.util.Map; -//#endif - -//#if MC >= 1.21 -import java.util.List; -import net.minecraft.server.ServerLinks; -//#endif - -//#if NEOFORGE -//$$ import net.neoforged.neoforge.network.connection.ConnectionType; -//#endif - -public final class GameProfileRenderer { - private static final Supplier FAKE_LEVEL = Suppliers.memoize(GameProfileRenderer::createFakeLevel); - - private final Player player; - - private GameProfileRenderer(RemotePlayer player) { - this.player = player; - } - - public static GameProfileRenderer create(GameProfile profile) { - final RemotePlayer player = new RemotePlayer( - FAKE_LEVEL.get(), profile - //#if MC == 1.19.2 - //$$ , null - //#endif - ); - player.setPos(0, 80, 0); - return new GameProfileRenderer(player); - } - - public void renderFacingMouse( - //#if MC < 1.20.0 - //$$ PoseStack context, - //#else - GuiGraphics context, - //#endif - int x1, int y1, int x2, int y2, int scale, float mouseX, float mouseY - ) { - final EntityRenderDispatcher entityRenderDispatcher = Minecraft.getInstance().getEntityRenderDispatcher(); - final Camera oldCamera = entityRenderDispatcher.camera; - entityRenderDispatcher.camera = new Camera(); - //#if MC >= 1.19.4 - context.pose().pushPose(); - context.pose().translate(0f, 0f, 1000f); - InventoryScreen.renderEntityInInventoryFollowsMouse( - context, x1, y1, x2, y2, scale, 0.0625f, mouseX, mouseY, player - ); - context.pose().popPose(); - //#else - //$$ final int centerX = (x1 + x2) / 2; - //$$ final int centerY = (y1 + y2) / 2; - //$$ InventoryScreen.renderEntityInInventory( - //$$ centerX, centerY, scale, centerX - mouseX, centerY - mouseY, player - //$$ ); - //#endif - entityRenderDispatcher.camera = oldCamera; - } - - private static ClientLevel createFakeLevel() { - final Minecraft minecraft = Minecraft.getInstance(); - final GameProfile nullProfile = new GameProfile(Util.NIL_UUID, ""); - //#if MC >= 1.19.2 - final WorldCreationContext context = loadDatapacks(minecraft); - //#endif - //#if MC >= 1.19.4 - final WorldSessionTelemetryManager worldTelemetry = new WorldSessionTelemetryManager( - TelemetryEventSender.DISABLED, false, null - //#if MC >= 1.20.1 - , null - //#endif - ); - //#endif - return new ClientLevel( - new ClientPacketListener( - minecraft, - //#if MC <= 1.20.1 - //$$ null, - //#endif - new Connection(PacketFlow.CLIENTBOUND), - //#if MC >= 1.20.4 - new CommonListenerCookie( - nullProfile, worldTelemetry, - context.worldgenLoadContext(), - FeatureFlags.REGISTRY.allFlags(), - null, null, null - //#if MC >= 1.20.6 - , Map.of(), null, false - //#endif - //#if MC >= 1.21 - , Map.of(), new ServerLinks(List.of()) - //#endif - //#if NEOFORGE - //$$ , ConnectionType.OTHER - //#endif - ) - //#else - //#if MC >= 1.19.4 - //$$ null, - //#endif - //$$ nullProfile, - //#if MC >= 1.19.4 - //$$ worldTelemetry - //#else - //$$ minecraft.createTelemetryManager() - //#endif - //#endif - ), - new ClientLevel.ClientLevelData(Difficulty.NORMAL, false, false), - Level.OVERWORLD, - //#if MC >= 1.19.4 - context.worldgenLoadContext() - .registryOrThrow(Registries.DIMENSION_TYPE) - .getHolderOrThrow(BuiltinDimensionTypes.OVERWORLD), - //#elseif MC >= 1.19.2 - //$$ context.registryAccess() - //$$ .registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY) - //$$ .getHolderOrThrow(BuiltinDimensionTypes.OVERWORLD), - //#else - //$$ RegistryAccess.BUILTIN.get() - //$$ .registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY) - //$$ .getOrCreateHolder(DimensionType.OVERWORLD_LOCATION), - //#endif - //#if MC >= 1.19.2 - minecraft.options.renderDistance().get(), - minecraft.options.simulationDistance().get(), - //#else - //$$ minecraft.options.renderDistance, - //$$ minecraft.options.simulationDistance, - //#endif - minecraft::getProfiler, minecraft.levelRenderer, false, 0L - ); - } - - //#if MC >= 1.19.2 - private static WorldCreationContext loadDatapacks(Minecraft minecraft) { - //#if MC >= 1.20.4 - final ServerPacksSource packsSource = new ServerPacksSource(minecraft.directoryValidator()); - //#else - //$$ final ServerPacksSource packsSource = new ServerPacksSource(); - //#endif - final PackRepository packRepository = new PackRepository( - //#if MC < 1.19.4 - //$$ PackType.SERVER_DATA, - //#endif - packsSource - ); - final WorldLoader.InitConfig initConfig = new WorldLoader.InitConfig( - new WorldLoader.PackConfig( - packRepository, - //#if MC >= 1.19.4 - WorldDataConfiguration.DEFAULT, - //#else - //$$ DataPackConfig.DEFAULT, - //#endif - false - //#if MC >= 1.19.4 - , false - //#endif - ), - Commands.CommandSelection.INTEGRATED, 2 - ); - //#if MC >= 1.19.4 - record DataPackReloadCookie(WorldGenSettings worldGenSettings, WorldDataConfiguration dataConfiguration) { - } - //#endif - try (ExecutorService gameExecutor = Executors.newSingleThreadExecutor()) { - final CompletableFuture completableFuture = WorldLoader.load( - initConfig, - //#if MC >= 1.19.4 - dataLoadContext -> new WorldLoader.DataLoadOutput<>( - new DataPackReloadCookie( - new WorldGenSettings( - WorldOptions.defaultWithRandomSeed(), - WorldPresets.createNormalWorldDimensions(dataLoadContext.datapackWorldgen()) - ), - dataLoadContext.dataConfiguration() - ), - dataLoadContext.datapackDimensions() - ), - //#else - //$$ (resourceManager, dataPackConfig) -> { - //$$ final var frozen = RegistryAccess.builtinCopy().freeze(); - //$$ final var worldGenSettings = WorldPresets.createNormalWorldFromPreset(frozen); - //$$ return Pair.of(worldGenSettings, frozen); - //$$ }, - //#endif - (closeableResourceManager, reloadableServerResources, layeredRegistryAccess, object) -> { - closeableResourceManager.close(); - return new WorldCreationContext( - //#if MC >= 1.19.4 - object.worldGenSettings, layeredRegistryAccess, reloadableServerResources, object.dataConfiguration - //#else - //$$ object, Lifecycle.stable(), layeredRegistryAccess, reloadableServerResources - //#endif - ); - }, - Util.backgroundExecutor(), gameExecutor - ); - return completableFuture.join(); - } - } - //#endif -} diff --git a/src/main/java/io/github/gaming32/worldhost/WHPlayerSkin.java b/src/main/java/io/github/gaming32/worldhost/WHPlayerSkin.java new file mode 100644 index 0000000..90e9dad --- /dev/null +++ b/src/main/java/io/github/gaming32/worldhost/WHPlayerSkin.java @@ -0,0 +1,65 @@ +package io.github.gaming32.worldhost; + +import com.mojang.authlib.GameProfile; +import net.minecraft.client.resources.SkinManager; +import net.minecraft.resources.ResourceLocation; + + +//#if MC >= 1.20.2 +import net.minecraft.client.resources.PlayerSkin; +//#else +//$$ import com.mojang.authlib.minecraft.MinecraftProfileTexture; +//$$ import java.util.UUID; +//$$ import java.util.concurrent.CompletableFuture; +//$$ import net.minecraft.client.resources.DefaultPlayerSkin; +//$$ import net.minecraft.core.UUIDUtil; +//#endif + +// TODO: Remove in 1.20.2+ +public record WHPlayerSkin( + ResourceLocation texture, + ResourceLocation capeTexture, + Model model +) { + //#if MC >= 1.20.2 + public static WHPlayerSkin fromPlayerSkin(PlayerSkin skin) { + return new WHPlayerSkin(skin.texture(), skin.capeTexture(), Model.byName(skin.model().id())); + } + //#endif + + public static WHPlayerSkin fromSkinManager(SkinManager skinManager, GameProfile profile) { + //#if MC >= 1.20.2 + return fromPlayerSkin(skinManager.getInsecureSkin(profile)); + //#else + //$$ final var map = skinManager.getInsecureSkinInformation(profile); + //$$ final MinecraftProfileTexture skin = map.get(MinecraftProfileTexture.Type.SKIN); + //$$ final ResourceLocation skinTexture; + //$$ final String skinModel; + //$$ if (skin != null) { + //$$ skinTexture = skinManager.registerTexture(skin, MinecraftProfileTexture.Type.SKIN); + //$$ skinModel = skin.getMetadata("model"); + //$$ } else { + //$$ final UUID uuid = UUIDUtil.getOrCreatePlayerUUID(profile); + //$$ skinTexture = DefaultPlayerSkin.getDefaultSkin(uuid); + //$$ skinModel = DefaultPlayerSkin.getSkinModelName(uuid); + //$$ } + //$$ final MinecraftProfileTexture cape = map.get(MinecraftProfileTexture.Type.CAPE); + //$$ return new WHPlayerSkin( + //$$ skinTexture, + //$$ cape != null ? skinTexture.registerTexture(cape, MinecraftProfileTexture.Type.CAPE) : null, + //$$ Model.byName(skinModel) + //$$ ); + //#endif + } + + public enum Model { + SLIM, WIDE; + + public static Model byName(String name) { + return switch (name) { + case "slim" -> SLIM; + case null, default -> WIDE; + }; + } + } +} diff --git a/src/main/java/io/github/gaming32/worldhost/WorldHost.java b/src/main/java/io/github/gaming32/worldhost/WorldHost.java index a54b20f..e7aba1b 100644 --- a/src/main/java/io/github/gaming32/worldhost/WorldHost.java +++ b/src/main/java/io/github/gaming32/worldhost/WorldHost.java @@ -39,7 +39,6 @@ import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.multiplayer.ServerData; import net.minecraft.client.multiplayer.resolver.ServerAddress; -import net.minecraft.client.resources.DefaultPlayerSkin; import net.minecraft.commands.CommandSourceStack; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.ClickEvent; @@ -97,15 +96,10 @@ //#if MC >= 1.19.2 import io.github.gaming32.worldhost.mixin.MinecraftAccessor; //#else -//$$ import com.mojang.authlib.minecraft.MinecraftProfileTexture; //$$ import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService; //$$ import net.minecraft.world.entity.player.Player; //#endif -//#if MC >= 1.20.2 -import net.minecraft.client.resources.PlayerSkin; -//#endif - //#if FABRIC import dev.isxander.mainmenucredits.MainMenuCredits; import net.fabricmc.api.ClientModInitializer; @@ -579,33 +573,12 @@ public static GameProfileCache getProfileCache() { return profileCache; } - public static CompletableFuture getInsecureSkinLocation(GameProfile gameProfile) { - final var skinManager = Minecraft.getInstance().getSkinManager(); - //#if MC >= 1.20.2 - return skinManager.getOrLoad(gameProfile).thenApply(PlayerSkin::texture); - //#elseif MC >= 1.19.2 - //$$ return CompletableFuture.completedFuture(skinManager.getInsecureSkinLocation(gameProfile)); - //#else - //$$ final MinecraftProfileTexture texture = skinManager.getInsecureSkinInformation(gameProfile) - //$$ .get(MinecraftProfileTexture.Type.SKIN); - //$$ return CompletableFuture.completedFuture( - //$$ texture != null - //$$ ? skinManager.registerTexture(texture, MinecraftProfileTexture.Type.SKIN) - //$$ : DefaultPlayerSkin.getDefaultSkin(Player.createPlayerUUID(gameProfile)) - //$$ ); - //#endif + public static WHPlayerSkin getInsecureSkin(GameProfile profile) { + return WHPlayerSkin.fromSkinManager(Minecraft.getInstance().getSkinManager(), profile); } - public static ResourceLocation getSkinLocationNow(GameProfile gameProfile) { - final ResourceLocation location = getInsecureSkinLocation(gameProfile).getNow(null); - if (location == null) { - //#if MC >= 1.20.2 - return DefaultPlayerSkin.get(gameProfile).texture(); - //#else - //$$ return DefaultPlayerSkin.getDefaultSkin(gameProfile.getId()); - //#endif - } - return location; + public static ResourceLocation getSkinLocationNow(GameProfile profile) { + return getInsecureSkin(profile).texture(); } public static void getMaybeAsync(GameProfileCache cache, String name, Consumer> action) { diff --git a/src/main/java/io/github/gaming32/worldhost/gui/screen/PlayerInfoScreen.java b/src/main/java/io/github/gaming32/worldhost/gui/screen/PlayerInfoScreen.java index dd1d7c7..0d21500 100644 --- a/src/main/java/io/github/gaming32/worldhost/gui/screen/PlayerInfoScreen.java +++ b/src/main/java/io/github/gaming32/worldhost/gui/screen/PlayerInfoScreen.java @@ -1,8 +1,8 @@ package io.github.gaming32.worldhost.gui.screen; import com.mojang.authlib.GameProfile; -import io.github.gaming32.worldhost.GameProfileRenderer; import io.github.gaming32.worldhost.WorldHost; +import io.github.gaming32.worldhost.gui.widget.WHPlayerSkinWidget; import io.github.gaming32.worldhost.versions.Components; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.CommonComponents; @@ -16,39 +16,29 @@ public class PlayerInfoScreen extends WorldHostScreen { private final Screen parentScreen; private GameProfile profile; - private GameProfileRenderer renderer; public PlayerInfoScreen(Screen parentScreen, GameProfile profile) { super(Components.empty()); this.parentScreen = parentScreen; - setProfile(profile); + + this.profile = profile; WorldHost.resolveGameProfile(profile) - .thenAccept(this::setProfile) + .thenAccept(ready -> this.profile = ready) .exceptionally(t -> { WorldHost.LOGGER.error("Failed to resolve profile {}", profile, t); return null; }); } - private void setProfile(GameProfile profile) { - if (profileEquals(this.profile, profile)) return; - this.profile = profile; - renderer = GameProfileRenderer.create(profile); - } - - private static boolean profileEquals(GameProfile a, GameProfile b) { - if (a == b) { - return true; - } - if (a == null || b == null) { - return false; - } - return a.equals(b) && a.getProperties().equals(b.getProperties()); - } - @Override protected void init() { assert minecraft != null; + addRenderableWidget(new WHPlayerSkinWidget( + width / 2 - 100, height / 2 - 150, + 200, 225, + () -> WorldHost.getInsecureSkin(profile), + minecraft.getEntityModels() + )); addRenderableWidget( button(CommonComponents.GUI_BACK, b -> minecraft.setScreen(parentScreen)) .pos(width / 2 - 75, height / 2 + 100) @@ -67,7 +57,6 @@ public void render( ) { whRenderBackground(context, mouseX, mouseY, partialTick); drawCenteredString(context, font, profile.getName(), width / 2, height / 2 + 85, 0xffffff); - renderer.renderFacingMouse(context, 0, -25, width, height - 25, 100, mouseX, mouseY); super.render(context, mouseX, mouseY, partialTick); } } diff --git a/src/main/java/io/github/gaming32/worldhost/gui/widget/WHPlayerSkinWidget.java b/src/main/java/io/github/gaming32/worldhost/gui/widget/WHPlayerSkinWidget.java new file mode 100644 index 0000000..602b9d9 --- /dev/null +++ b/src/main/java/io/github/gaming32/worldhost/gui/widget/WHPlayerSkinWidget.java @@ -0,0 +1,166 @@ +package io.github.gaming32.worldhost.gui.widget; + +import com.mojang.blaze3d.platform.Lighting; +import com.mojang.math.Axis; +import io.github.gaming32.worldhost.WHPlayerSkin; +import io.github.gaming32.worldhost.versions.Components; +import net.minecraft.client.gui.components.AbstractWidget; +import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.client.model.geom.EntityModelSet; +import net.minecraft.client.model.geom.ModelLayers; + +import java.util.function.Supplier; + +import static io.github.gaming32.worldhost.gui.screen.WorldHostScreen.pose; + +//#if MC >= 1.20.0 +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.model.PlayerModel; +import net.minecraft.client.renderer.LightTexture; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.texture.OverlayTexture; +import net.minecraft.util.Mth; +//#else +//$$ import com.mojang.blaze3d.systems.RenderSystem; +//$$ import com.mojang.blaze3d.vertex.PoseStack; +//$$ import net.minecraft.client.Minecraft; +//#endif + +public class WHPlayerSkinWidget extends AbstractWidget { + private static final float MODEL_OFFSET = 0.0625f; + private static final float MODEL_HEIGHT = 2.125f; + private static final float Z_OFFSET = 100f; + private static final float ROTATION_SENSITIVITY = 2.5f; + private static final float DEFAULT_ROTATION_X = -5f; + private static final float DEFAULT_ROTATION_Y = 30f; + private static final float ROTATION_X_LIMIT = 50f; + + private final Supplier skin; + private final PlayerModel wideModel; + private final PlayerModel slimModel; + private float rotationX = DEFAULT_ROTATION_X; + private float rotationY = DEFAULT_ROTATION_Y; + + public WHPlayerSkinWidget( + int x, int y, int width, int height, + Supplier skin, + EntityModelSet models + ) { + super(x, y, width, height, Components.empty()); + this.skin = skin; + + wideModel = new PlayerModel<>(models.bakeLayer(ModelLayers.PLAYER), false); + slimModel = new PlayerModel<>(models.bakeLayer(ModelLayers.PLAYER_SLIM), true); + wideModel.young = false; + slimModel.young = false; + } + + @Override + protected void onDrag(double mouseX, double mouseY, double dragX, double dragY) { + rotationX = Mth.clamp(rotationX - (float)dragY * ROTATION_SENSITIVITY, -ROTATION_X_LIMIT, ROTATION_X_LIMIT); + rotationY += (float)dragX * ROTATION_SENSITIVITY; + } + + @Override + //#if MC >= 1.19.4 + public void renderWidget( + //#else + //$$ public void renderButton( + //#endif + //#if MC < 1.20.0 + //$$ PoseStack context, + //#else + GuiGraphics context, + //#endif + int mouseX, int mouseY, float partialTick + ) { + pose(context).pushPose(); + pose(context).translate(getX() + getWidth() / 2f, getY() + getHeight(), Z_OFFSET); + final float scale = getHeight() / MODEL_HEIGHT; + pose(context).scale(scale, scale, scale); + pose(context).translate(0f, -MODEL_OFFSET, 0f); + pose(context).rotateAround(Axis.XP.rotationDegrees(rotationX), 0f, -1f - MODEL_OFFSET, 0f); + pose(context).mulPose(Axis.YP.rotationDegrees(rotationY)); + flush(context); + Lighting.setupForEntityInInventory(Axis.XP.rotationDegrees(rotationX)); + renderModel(context, skin.get()); + flush(context); + Lighting.setupFor3DItems(); + pose(context).popPose(); + } + + private void renderModel( + //#if MC < 1.20.0 + //$$ PoseStack context, + //#else + GuiGraphics context, + //#endif + WHPlayerSkin skin + ) { + pose(context).pushPose(); + pose(context).scale(1f, 1f, -1f); + pose(context).translate(0f, -1.5f, 0f); + final PlayerModel model = skin.model() == WHPlayerSkin.Model.SLIM ? slimModel : wideModel; + final var renderType = model.renderType(skin.texture()); + model.renderToBuffer(pose(context), bufferSource(context).getBuffer(renderType), LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY); + pose(context).popPose(); + } + + private static void flush( + //#if MC < 1.20.0 + //$$ PoseStack context + //#else + GuiGraphics context + //#endif + ) { + //#if MC >= 1.20.0 + context.flush(); + //#else + //$$ RenderSystem.disableDepthTest(); + //$$ bufferSource(context).endBatch(); + //$$ RenderSystem.enableDepthTest(); + //#endif + } + + private static MultiBufferSource.BufferSource bufferSource( + //#if MC < 1.20.0 + //$$ PoseStack context + //#else + GuiGraphics context + //#endif + ) { + //#if MC >= 1.20.0 + return context.bufferSource(); + //#else + //$$ return Minecraft.getInstance().renderBuffers().bufferSource(); + //#endif + } + + //#if MC >= 1.19.4 + @Override + protected void updateWidgetNarration(NarrationElementOutput output) { + } + //#else + //$$ @Override + //$$ public void updateNarration(NarrationElementOutput output) { + //$$ } + //#endif + + //#if MC < 1.19.4 + //$$ private int getX() { + //$$ return x; + //$$ } + //$$ + //$$ private int getY() { + //$$ return y; + //$$ } + //$$ + //$$ private int getWidth() { + //$$ return width; + //$$ } + //$$ + //$$ private int getHeight() { + //$$ return height; + //$$ } + //#endif +} diff --git a/src/main/java/io/github/gaming32/worldhost/mixin/MixinAbstractClientPlayer.java b/src/main/java/io/github/gaming32/worldhost/mixin/MixinAbstractClientPlayer.java deleted file mode 100644 index fde2255..0000000 --- a/src/main/java/io/github/gaming32/worldhost/mixin/MixinAbstractClientPlayer.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.gaming32.worldhost.mixin; - -import com.mojang.authlib.GameProfile; -import io.github.gaming32.worldhost.gui.screen.PlayerInfoScreen; -import net.minecraft.client.Minecraft; -import net.minecraft.client.multiplayer.PlayerInfo; -import net.minecraft.client.player.AbstractClientPlayer; -import net.minecraft.core.BlockPos; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.level.Level; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(AbstractClientPlayer.class) -public abstract class MixinAbstractClientPlayer extends Player { - @Shadow @Nullable private PlayerInfo playerInfo; - - public MixinAbstractClientPlayer(Level level, BlockPos pos, float yRot, GameProfile gameProfile) { - super(level, pos, yRot, gameProfile); - } - - @Inject(method = "getPlayerInfo", at = @At("HEAD")) - private void fakeClientPlayerPlayerInfo(CallbackInfoReturnable cir) { - if (playerInfo == null && Minecraft.getInstance().getConnection() == null) { - final Minecraft minecraft = Minecraft.getInstance(); - if (minecraft.getConnection() == null && minecraft.screen instanceof PlayerInfoScreen) { - playerInfo = new PlayerInfo(getGameProfile(), false); - } - } - } -} diff --git a/src/main/resources/world-host.mixins.json b/src/main/resources/world-host.mixins.json index 70ddde8..a48beae 100644 --- a/src/main/resources/world-host.mixins.json +++ b/src/main/resources/world-host.mixins.json @@ -16,7 +16,6 @@ "client": [ "DisconnectedScreenAccessor", "MinecraftAccessor", - "MixinAbstractClientPlayer", "MixinConnectScreen", "MixinConnectScreen_1", "MixinGameRenderer",