From 3a46ad125fbf07a493f2175c15d9ac4973cbf9c3 Mon Sep 17 00:00:00 2001 From: Morpheus Date: Sun, 12 Nov 2023 23:18:57 +0000 Subject: [PATCH] Remove invalid accessor and fix broken client (#3919) * Remove invalid accessor and fix broken client * run spotlessApply --- .../AbstractSelectionListAccessor.java | 35 ---------- .../resources/mixins.sponge.accessors.json | 1 - .../gui/widget/list/FilterableList.java | 70 ++++++------------- 3 files changed, 23 insertions(+), 83 deletions(-) delete mode 100644 src/accessors/java/org/spongepowered/common/accessor/client/gui/components/AbstractSelectionListAccessor.java diff --git a/src/accessors/java/org/spongepowered/common/accessor/client/gui/components/AbstractSelectionListAccessor.java b/src/accessors/java/org/spongepowered/common/accessor/client/gui/components/AbstractSelectionListAccessor.java deleted file mode 100644 index 33209edf20b..00000000000 --- a/src/accessors/java/org/spongepowered/common/accessor/client/gui/components/AbstractSelectionListAccessor.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This file is part of Sponge, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package org.spongepowered.common.accessor.client.gui.components; - -import net.minecraft.client.gui.components.AbstractSelectionList; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(AbstractSelectionList.class) -public interface AbstractSelectionListAccessor { - - @Accessor("renderSelection") boolean accessor$renderSelection(); -} diff --git a/src/accessors/resources/mixins.sponge.accessors.json b/src/accessors/resources/mixins.sponge.accessors.json index 96a26714538..f5a50601004 100644 --- a/src/accessors/resources/mixins.sponge.accessors.json +++ b/src/accessors/resources/mixins.sponge.accessors.json @@ -4,7 +4,6 @@ "package": "org.spongepowered.common.accessor", "client": [ "client.KeyMappingAccessor", - "client.gui.components.AbstractSelectionListAccessor", "client.multiplayer.ClientLevelAccessor", "world.level.entity.TransientEntitySectionManagerAccessor" ], diff --git a/vanilla/src/main/java/org/spongepowered/vanilla/client/gui/widget/list/FilterableList.java b/vanilla/src/main/java/org/spongepowered/vanilla/client/gui/widget/list/FilterableList.java index 05cd1da4597..8a1f6ed2360 100644 --- a/vanilla/src/main/java/org/spongepowered/vanilla/client/gui/widget/list/FilterableList.java +++ b/vanilla/src/main/java/org/spongepowered/vanilla/client/gui/widget/list/FilterableList.java @@ -24,12 +24,6 @@ */ package org.spongepowered.vanilla.client.gui.widget.list; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.BufferBuilder; -import com.mojang.blaze3d.vertex.DefaultVertexFormat; -import com.mojang.blaze3d.vertex.Tesselator; -import com.mojang.blaze3d.vertex.VertexFormat; -import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; @@ -39,11 +33,9 @@ import net.minecraft.client.gui.narration.NarrationElementOutput; import net.minecraft.client.gui.narration.NarrationSupplier; import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.renderer.GameRenderer; import net.minecraft.network.chat.Component; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; -import org.spongepowered.common.accessor.client.gui.components.AbstractSelectionListAccessor; import org.spongepowered.vanilla.util.Bounds; import java.util.Arrays; @@ -234,61 +226,45 @@ public boolean mouseClicked(final double p_mouseClicked_1_, final double p_mouse } @Override - protected void renderList(final GuiGraphics stack, final int renderX, final int renderY, final float p_renderList_3_) { + protected void renderList(final GuiGraphics $$0, final int $$1, final int $$2, final float $$3) { // Most of this is based on AbstractList::renderList logic - final List filteredList = this.filterSupplier == null ? new ObjectArrayList<>(this.children()) : this.filterSupplier.get(); - final int itemCount = filteredList.size(); - final Tesselator tessellator = Tesselator.getInstance(); - final BufferBuilder bufferbuilder = tessellator.getBuilder(); + final List filteredList = this.filterSupplier == null ? this.children() : this.filterSupplier.get(); if (filteredList.isEmpty()) { final Font font = this.minecraft.font; final String noResults = "No results..."; final int noResultsWidth = font.width(noResults); - stack.drawString(font, noResults, (this.width / 2) + this.x0 - (noResultsWidth / 2), this.y0 + 10, ChatFormatting.GRAY.getColor()); + $$0.drawString(font, noResults, (this.width / 2) + this.x0 - (noResultsWidth / 2), this.y0 + 10, ChatFormatting.GRAY.getColor()); return; } - for (int i = 0; i < itemCount; ++i) { - final int rowTop = this.getRowTop(i); - final int rowBottom = this.getRowBottom(i); - if (rowBottom >= this.y0 && rowTop <= this.y1) { - final int yStart = renderY + i * this.itemHeight + this.headerHeight; - final int yEnd = this.itemHeight - 4; - - final int rowWidth = this.getRowWidth(); - - if (((AbstractSelectionListAccessor) this).accessor$renderSelection() && Objects.equals(this.getSelected(), filteredList.get(i))) { - final int xSelectStart = this.x0 + this.width / 2 - rowWidth / 2 - 2; - final int xSelectEnd = this.x0 + this.width / 2 + rowWidth / 2 - 4; -// RenderSystem.disableTexture(); - RenderSystem.setShader(GameRenderer::getPositionShader); - final float f = this.isFocused() ? 1.0F : 0.5F; - RenderSystem.setShaderColor(f, f, f, 1.0F); - bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION); - bufferbuilder.vertex(xSelectStart, yStart + yEnd + 2, 0.0D).endVertex(); - bufferbuilder.vertex(xSelectEnd, yStart + yEnd + 2, 0.0D).endVertex(); - bufferbuilder.vertex(xSelectEnd, yStart - 2, 0.0D).endVertex(); - bufferbuilder.vertex(xSelectStart, yStart - 2, 0.0D).endVertex(); - tessellator.end(); - RenderSystem.setShaderColor(0.0F, 0.0F, 0.0F, 1.0F); - bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION); - bufferbuilder.vertex(xSelectStart + 1, yStart + yEnd + 1, 0.0D).endVertex(); - bufferbuilder.vertex(xSelectEnd - 1, yStart + yEnd + 1, 0.0D).endVertex(); - bufferbuilder.vertex(xSelectEnd - 1, yStart - 1, 0.0D).endVertex(); - bufferbuilder.vertex(xSelectStart + 1, yStart - 1, 0.0D).endVertex(); - tessellator.end(); -// RenderSystem.enableTexture(); - } + final int $$4 = this.getRowLeft(); + final int $$5 = this.getRowWidth(); + final int $$6 = this.itemHeight - 4; + final int $$7 = filteredList.size(); - final E entry = filteredList.get(i); - entry.render(stack, i, rowTop, this.getRowLeft(), rowWidth, yEnd, renderX, renderY, false, p_renderList_3_); + for (int $$8 = 0; $$8 < $$7; ++$$8) { + final int $$9 = this.getRowTop($$8); + final int $$10 = this.getRowBottom($$8); + if ($$10 >= this.y0 && $$9 <= this.y1) { + this.renderItemFromList(filteredList, $$0, $$1, $$2, $$3, $$8, $$4, $$9, $$5, $$6); } } } + private void renderItemFromList(final List list, final GuiGraphics $$0, final int $$1, final int $$2, final float $$3, final int $$4, final int $$5, final int $$6, final int $$7, final int $$8) { + final E $$9 = list.get($$4); + $$9.renderBack($$0, $$4, $$6, $$5, $$7, $$8, $$1, $$2, Objects.equals(this.getHovered(), $$9), $$3); + if (this.isSelectedItem($$4)) { + final int $$10 = this.isFocused() ? -1 : -8355712; + this.renderSelection($$0, $$6, $$7, $$8, $$10, -16777216); + } + + $$9.render($$0, $$4, $$6, $$5, $$7, $$8, $$1, $$2, Objects.equals(this.getHovered(), $$9), $$3); + } + @Override public void updateNarration(final @NonNull NarrationElementOutput narrationConsumer) { final @org.checkerframework.checker.nullness.qual.Nullable E hovered = this.getCurrentHoveredEntry();