Skip to content

Commit

Permalink
Release v3.1+fabric-1.20.2
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCSDev committed Oct 5, 2023
1 parent febedd4 commit d0c86b9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}. <b>tY</b> 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;
// --------------------------------------------------
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())));
}

/**
Expand All @@ -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}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Identifier, PacketByteBuf.PacketReader<? extends CustomPayload>>();
final var s2c = new HashMap<Identifier, PacketByteBuf.PacketReader<? extends CustomPayload>>();
//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<Identifier, PacketByteBuf.PacketReader<? extends CustomPayload>>() : ogC2S;
final var s2c = immutable ? new HashMap<Identifier, PacketByteBuf.PacketReader<? extends CustomPayload>>() : ogS2C;

//put vanilla and possibly modded entries into the new maps
c2s.putAll(AccessorCustomPayloadC2SPacket.getIdToReader());
Expand All @@ -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);
}
}
// ==================================================
/**
Expand Down

0 comments on commit d0c86b9

Please sign in to comment.