From d0c86b9fe5b672400613f60139e16a82b9431005 Mon Sep 17 00:00:00 2001 From: Dev Date: Thu, 5 Oct 2023 11:37:03 +0200 Subject: [PATCH] Release v3.1+fabric-1.20.2 --- .../gui/other/TEntityRendererElement.java | 11 +++++------ .../screen/explorer/TFileChooserScreen.java | 1 + .../api/network/packet/TCustomPayload.java | 13 ++++++++++++- .../network/TCDCommonsNetworkHandler.java | 19 ++++++++++++++----- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/tcdcommons-3-fabric-1.20.2/src/main/java/io/github/thecsdev/tcdcommons/api/client/gui/other/TEntityRendererElement.java b/tcdcommons-3-fabric-1.20.2/src/main/java/io/github/thecsdev/tcdcommons/api/client/gui/other/TEntityRendererElement.java index 6ace13c..d6b8fad 100644 --- a/tcdcommons-3-fabric-1.20.2/src/main/java/io/github/thecsdev/tcdcommons/api/client/gui/other/TEntityRendererElement.java +++ b/tcdcommons-3-fabric-1.20.2/src/main/java/io/github/thecsdev/tcdcommons/api/client/gui/other/TEntityRendererElement.java @@ -26,7 +26,7 @@ protected boolean entityErrorState; //when true, entity won't render, and its name will render instead /** The cached center XY coordinates for rendering the {@link #entity}. tY is for text. */ - protected int entityCenterX, entityCenterY, entityTextY; + protected int entityTextX, entityTextY; /** The cached calculated size at which the entity will render. */ protected int entityDisplaySize; // -------------------------------------------------- @@ -106,13 +106,12 @@ protected final void recalcCache_mobSize() } /** - * Recalculates the values of {@link #entityCenterX} and {@link #entityCenterY}. + * Recalculates the values of {@link #entityTextX} and {@link #entityTextY}. */ protected final void recalcCache_cXY() { //calculate center XY - this.entityCenterX = (this.x + (this.width / 2)); - this.entityCenterY = (getEndY() - (this.height / 4)); + this.entityTextX = (this.x + (this.width / 2)); //calculate text Y for the entity name text if(this.entityTypeName != null) { @@ -122,7 +121,7 @@ protected final void recalcCache_cXY() (fh / 2) - (this.entityTypeName.count() * fh); } - else this.entityTextY = this.entityCenterY; + else this.entityTextY = (getEndY() - (this.height / 4)); } // ================================================== public @Virtual @Override void render(TDrawContext pencil) @@ -133,7 +132,7 @@ protected final void recalcCache_cXY() if(this.entityErrorState || this.entity == null) { if(this.entityTypeName != null) - this.entityTypeName.drawCenterWithShadow(pencil, this.entityCenterX, this.entityTextY); + this.entityTypeName.drawCenterWithShadow(pencil, this.entityTextX, this.entityTextY); else pencil.drawTFill(TDrawContext.DEFAULT_ERROR_COLOR); return; } diff --git a/tcdcommons-3-fabric-1.20.2/src/main/java/io/github/thecsdev/tcdcommons/api/client/gui/screen/explorer/TFileChooserScreen.java b/tcdcommons-3-fabric-1.20.2/src/main/java/io/github/thecsdev/tcdcommons/api/client/gui/screen/explorer/TFileChooserScreen.java index 0d1295e..39e6815 100644 --- a/tcdcommons-3-fabric-1.20.2/src/main/java/io/github/thecsdev/tcdcommons/api/client/gui/screen/explorer/TFileChooserScreen.java +++ b/tcdcommons-3-fabric-1.20.2/src/main/java/io/github/thecsdev/tcdcommons/api/client/gui/screen/explorer/TFileChooserScreen.java @@ -81,6 +81,7 @@ protected TFileChooserScreen( this.parent = MC_CLIENT.currentScreen; this.contentPane = new TFillColorElement(0, 0, 100, 100, /*-1771805596*/436207615) { + public boolean isHoverable() { return true; } public boolean input(TInputContext inputContext) { //only handle hovered and mouse LMB clicks diff --git a/tcdcommons-3-fabric-1.20.2/src/main/java/io/github/thecsdev/tcdcommons/api/network/packet/TCustomPayload.java b/tcdcommons-3-fabric-1.20.2/src/main/java/io/github/thecsdev/tcdcommons/api/network/packet/TCustomPayload.java index 986ad08..e5eb0ce 100644 --- a/tcdcommons-3-fabric-1.20.2/src/main/java/io/github/thecsdev/tcdcommons/api/network/packet/TCustomPayload.java +++ b/tcdcommons-3-fabric-1.20.2/src/main/java/io/github/thecsdev/tcdcommons/api/network/packet/TCustomPayload.java @@ -38,7 +38,7 @@ public final class TCustomPayload implements CustomPayload public TCustomPayload(PacketByteBuf receivedPacketBuffer) { this(receivedPacketBuffer.readIdentifier(), - new PacketByteBuf(receivedPacketBuffer.readSlice(receivedPacketBuffer.readIntLE()))); + new PacketByteBuf(receivedPacketBuffer.readBytes(receivedPacketBuffer.readIntLE()))); } /** @@ -55,6 +55,17 @@ public TCustomPayload(Identifier packetDataID, PacketByteBuf packetData, boolean this.packetData = Objects.requireNonNull(packetData); this.closeOnWrite = closeOnWrite; } + + @SuppressWarnings("deprecation") + protected final @Override void finalize() throws Throwable + { + //call super + super.finalize(); + + //release packet data if not released, to avoid memory leaks + if(this.packetData.refCnt() > 0) + this.packetData.release(); + } // ================================================== /** * @apiNote Not to be confused with {@link #id()}, aka {@link #ID}. diff --git a/tcdcommons-3-fabric-1.20.2/src/main/java/io/github/thecsdev/tcdcommons/network/TCDCommonsNetworkHandler.java b/tcdcommons-3-fabric-1.20.2/src/main/java/io/github/thecsdev/tcdcommons/network/TCDCommonsNetworkHandler.java index a37a202..b4d89bf 100644 --- a/tcdcommons-3-fabric-1.20.2/src/main/java/io/github/thecsdev/tcdcommons/network/TCDCommonsNetworkHandler.java +++ b/tcdcommons-3-fabric-1.20.2/src/main/java/io/github/thecsdev/tcdcommons/network/TCDCommonsNetworkHandler.java @@ -4,6 +4,8 @@ import org.jetbrains.annotations.ApiStatus.Internal; +import com.google.common.collect.ImmutableMap; + import io.github.thecsdev.tcdcommons.TCDCommons; import io.github.thecsdev.tcdcommons.api.badge.PlayerBadge; import io.github.thecsdev.tcdcommons.api.badge.ServerPlayerBadgeHandler; @@ -33,9 +35,13 @@ private TCDCommonsNetworkHandler() {} /* because the vanilla game makes their maps immutable, * this here is created with the intent to override vanilla, and make the maps mutable */ - //create new maps that are mutable - final var c2s = new HashMap>(); - final var s2c = new HashMap>(); + //obtain the maps and ensure they are mutable + final var ogC2S = AccessorCustomPayloadC2SPacket.getIdToReader(); + final var ogS2C = AccessorCustomPayloadS2CPacket.getIdToReader(); + final boolean immutable = (ogC2S instanceof ImmutableMap) || (ogS2C instanceof ImmutableMap); + + final var c2s = immutable ? new HashMap>() : ogC2S; + final var s2c = immutable ? new HashMap>() : ogS2C; //put vanilla and possibly modded entries into the new maps c2s.putAll(AccessorCustomPayloadC2SPacket.getIdToReader()); @@ -46,8 +52,11 @@ private TCDCommonsNetworkHandler() {} s2c.put(TCustomPayload.ID, TCustomPayload::new); //override vanilla's immutable maps - AccessorCustomPayloadC2SPacket.setIdToReader(c2s); - AccessorCustomPayloadS2CPacket.setIdToReader(s2c); + if(immutable) + { + AccessorCustomPayloadC2SPacket.setIdToReader(c2s); + AccessorCustomPayloadS2CPacket.setIdToReader(s2c); + } } // ================================================== /**