Skip to content

Commit

Permalink
fix: Cast issue
Browse files Browse the repository at this point in the history
  • Loading branch information
null2264 committed Jan 8, 2024
1 parent ee3d95d commit 616f12e
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public ByteBufCompat(ByteBuf byteBuf) {
super(byteBuf);
}

public static ByteBufCompat fromMC(FriendlyByteBuf buf) {
return new ByteBufCompat(buf.copy());
}

//#if MC<=1.16.5
//$$ public <T> void writeOptional(Optional<T> optional, @NotNull BiConsumer<FriendlyByteBuf, T> predicate) {
//$$ if (optional.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void toPacket(ByteBufCompat buf) {
final Map<String, List<WeightedBlock>> outMap = getOutput();
buf.writeMap(
outMap,
FriendlyByteBuf::writeUtf, (o, blocks) -> ((ByteBufCompat) o).writeCollection(blocks, (p, block) -> block.toPacket(p))
FriendlyByteBuf::writeUtf, (o, blocks) -> ((ByteBufCompat) o).writeCollection(blocks, (p, block) -> block.toPacket((ByteBufCompat) p))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ public void toPacket(ByteBufCompat buf) {

buf.writeMap(
getOutput(),
FriendlyByteBuf::writeUtf, (o, blocks) -> ((ByteBufCompat) o).writeCollection(blocks, (p, block) -> block.toPacket(p))
FriendlyByteBuf::writeUtf, (o, blocks) -> ((ByteBufCompat) o).writeCollection(blocks, (p, block) -> block.toPacket((ByteBufCompat) p))
);
buf.writeMap(
getObsidianOutput(),
FriendlyByteBuf::writeUtf, (o, blocks) -> ((ByteBufCompat) o).writeCollection(blocks, (p, block) -> block.toPacket(p))
FriendlyByteBuf::writeUtf, (o, blocks) -> ((ByteBufCompat) o).writeCollection(blocks, (p, block) -> block.toPacket((ByteBufCompat) p))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void toPacket(ByteBufCompat buf) {
final Map<String, List<WeightedBlock>> outMap = getOutput();
buf.writeMap(
outMap,
FriendlyByteBuf::writeUtf, (o, blocks) -> ((ByteBufCompat) o).writeCollection(blocks, (p, block) -> block.toPacket(p))
FriendlyByteBuf::writeUtf, (o, blocks) -> ((ByteBufCompat) o).writeCollection(blocks, (p, block) -> block.toPacket((ByteBufCompat) p))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ static Generator fromPacket(FriendlyByteBuf buf) {
try {
Method method = Class.forName(className).getMethod("fromPacket", FriendlyByteBuf.class);
return (Generator) method.invoke(null, buf);
} catch (ClassNotFoundException t) {
// Do nothing
} catch (Throwable t) {
CGLog.error("Failed to get generator packet: " + className + " ", t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,5 @@

public interface PacketSerializable<T>
{
default void toPacket(ByteBufCompat buf) {
toPacket((FriendlyByteBuf) buf);
}

default void toPacket(FriendlyByteBuf buf) {
throw new UnsupportedOperationException();
}
void toPacket(ByteBufCompat buf);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@ public static boolean handlePacket(ClientPacketListener listener, ClientboundCus
//#endif

if (id.equals(SYNC_CHANNEL)) {
final FriendlyByteBuf packetData =
final FriendlyByteBuf mcPacket =
//#if MC<1.20.2
packet.getData();
//#else
//$$ ((PacketByteBufPayload) packet).data();
//#endif

final ByteBufCompat packetData = ByteBufCompat.fromMC(mcPacket);

boolean isReload = packetData.readBoolean();
FLUID_INTERACTION.readGeneratorsFromPacket((ByteBufCompat) packetData);
FLUID_INTERACTION.readGeneratorsFromPacket(packetData);

boolean isSync = FLUID_INTERACTION.isSync();
if (isSync)
Expand Down

0 comments on commit 616f12e

Please sign in to comment.