Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #38 #39

Open
wants to merge 2 commits into
base: 1.21.4
Choose a base branch
from

Conversation

gisellevonbingen
Copy link

@gisellevonbingen gisellevonbingen commented Jan 7, 2025

Start

I can't understand why problem occurred too.
This code was looks greatly works.

((DisguiseUtils) original).updateTrackedData();
List<DataTracker.SerializedEntry<?>> trackedValues = disguised.getDataTracker().getChangedEntries();
((EntityTrackerUpdateS2CPacketAccessor) packet).setTrackedValues(trackedValues);

And I don't know how my solution is fixing this issue.

Debug

My debug code

System.out.println("TO: " + this.player.getName());
List<SerializedEntry<?>> trackedValuesPrev = entityTrackerUpdateS2CPacket.trackedValues();
System.out.println("prev");
for (var entry : trackedValuesPrev) {
	System.out.println(entry.id() + " = " + entry.value());
}

//
// ▲ Print original values
// ▼ Original Code
//

((DisguiseUtils) original).updateTrackedData();
List<DataTracker.SerializedEntry<?>> trackedValues = disguised.getDataTracker().getChangedEntries();
((EntityTrackerUpdateS2CPacketAccessor) packet).setTrackedValues(trackedValues);
List<SerializedEntry<?>> trackedValuesNext = entityTrackerUpdateS2CPacket.trackedValues();

//
// ▲ Original Code
// ▼ Print changed values
//

System.out.println("next");
for (var entry : trackedValuesNext) {
	System.out.println(entry.id() + " = " + entry.value());
}

var buffer = new RegistryByteBuf(Unpooled.buffer(), server.getRegistryManager());
EntityTrackerUpdateS2CPacket.CODEC.encode(buffer, entityTrackerUpdateS2CPacket);

var builder = new StringBuilder();
for (var i = 0; i < buffer.readableBytes(); i++) {
	if (i > 0) builder.append(",");
	builder.append(String.format("%02X", buffer.getByte(i)));
}
System.out.println(builder);

Printed message

Printed message looks no problem.
But the client was disconnected with below message.

[20:01:02][Server thread/INFO](Minecraft)[STDOUT]: TO: literal{Player622}
[20:01:02][Server thread/INFO](Minecraft)[STDOUT]: prev
[20:01:02][Server thread/INFO](Minecraft)[STDOUT]: 9 = 20.0
[20:01:02][Server thread/INFO](Minecraft)[STDOUT]: 17 = 127
[20:01:02][Server thread/INFO](Minecraft)[STDOUT]: next
[20:01:02][Server thread/INFO](Minecraft)[STDOUT]: 5 = true
[20:01:02][Server thread/INFO](Minecraft)[STDOUT]: 38,05,08,01,FF
[20:01:02][Server thread/INFO][(Minecraft)Player622 lost connection: Disconnected
[20:01:02][Server thread/INFO][(Minecraft)Player622 left the game

Client disconnected with this messages

[20:01:02] [Render thread/ERROR] (Minecraft) Failed to handle packet EntityTrackerUpdateS2CPacket[id=56, packedItems=[SerializedEntry[id=9, serializer=net.minecraft.entity.data.TrackedDataHandler$$Lambda/0x00000008009b6560@7e48974f, value=20.0], SerializedEntry[id=17, serializer=net.minecraft.entity.data.TrackedDataHandler$$Lambda/0x00000008009b6560@1c2608e3, value=127]]], disconnecting
java.lang.IllegalStateException: Invalid entity data item type for field 9 on entity ChestBoatEntity['Acacia Boat with Chest'/56, l='ClientLevel', x=86.50, y=65.00, z=24.50]: old=1(class java.lang.Integer), new=20.0(class java.lang.Float)
	at knot/net.minecraft.entity.data.DataTracker.copyToFrom(DataTracker.java:124) ~[minecraft-merged-c22ab19269-1.21.4-net.fabricmc.yarn.1_21_4.1.21.4+build.1-v2.jar:?]
	at knot/net.minecraft.entity.data.DataTracker.writeUpdatedEntries(DataTracker.java:113) ~[minecraft-merged-c22ab19269-1.21.4-net.fabricmc.yarn.1_21_4.1.21.4+build.1-v2.jar:?]
	at knot/net.minecraft.client.network.ClientPlayNetworkHandler.onEntityTrackerUpdate(ClientPlayNetworkHandler.java:563) ~[minecraft-merged-c22ab19269-1.21.4-net.fabricmc.yarn.1_21_4.1.21.4+build.1-v2.jar:?]
	at knot/net.minecraft.network.packet.s2c.play.EntityTrackerUpdateS2CPacket.apply(EntityTrackerUpdateS2CPacket.java:53) ~[minecraft-merged-c22ab19269-1.21.4-net.fabricmc.yarn.1_21_4.1.21.4+build.1-v2.jar:?]
	at knot/net.minecraft.network.packet.s2c.play.EntityTrackerUpdateS2CPacket.apply(EntityTrackerUpdateS2CPacket.java:20) ~[minecraft-merged-c22ab19269-1.21.4-net.fabricmc.yarn.1_21_4.1.21.4+build.1-v2.jar:?]
	at knot/net.minecraft.network.NetworkThreadUtils.method_11072(NetworkThreadUtils.java:27) ~[minecraft-merged-c22ab19269-1.21.4-net.fabricmc.yarn.1_21_4.1.21.4+build.1-v2.jar:?]
	at knot/net.minecraft.util.thread.ThreadExecutor.executeTask(ThreadExecutor.java:144) [minecraft-merged-c22ab19269-1.21.4-net.fabricmc.yarn.1_21_4.1.21.4+build.1-v2.jar:?]
	at knot/net.minecraft.util.thread.ReentrantThreadExecutor.executeTask(ReentrantThreadExecutor.java:24) [minecraft-merged-c22ab19269-1.21.4-net.fabricmc.yarn.1_21_4.1.21.4+build.1-v2.jar:?]
	at knot/net.minecraft.util.thread.ThreadExecutor.runTask(ThreadExecutor.java:118) [minecraft-merged-c22ab19269-1.21.4-net.fabricmc.yarn.1_21_4.1.21.4+build.1-v2.jar:?]
	at knot/net.minecraft.util.thread.ThreadExecutor.runTasks(ThreadExecutor.java:107) [minecraft-merged-c22ab19269-1.21.4-net.fabricmc.yarn.1_21_4.1.21.4+build.1-v2.jar:?]
	at knot/net.minecraft.client.MinecraftClient.render(MinecraftClient.java:1295) [minecraft-merged-c22ab19269-1.21.4-net.fabricmc.yarn.1_21_4.1.21.4+build.1-v2.jar:?]
	at knot/net.minecraft.client.MinecraftClient.run(MinecraftClient.java:930) [minecraft-merged-c22ab19269-1.21.4-net.fabricmc.yarn.1_21_4.1.21.4+build.1-v2.jar:?]
	at knot/net.minecraft.client.main.Main.main(Main.java:240) [minecraft-merged-c22ab19269-1.21.4-net.fabricmc.yarn.1_21_4.1.21.4+build.1-v2.jar:?]
	at net.fabricmc.loader.impl.game.minecraft.MinecraftGameProvider.launch(MinecraftGameProvider.java:480) [fabric-loader-0.16.9.jar:?]
	at net.fabricmc.loader.impl.launch.knot.Knot.launch(Knot.java:74) [fabric-loader-0.16.9.jar:?]
	at net.fabricmc.loader.impl.launch.knot.KnotClient.main(KnotClient.java:23) [fabric-loader-0.16.9.jar:?]
	at net.fabricmc.devlaunchinjector.Main.main(Main.java:86) [dev-launch-injector-0.2.1+build.8.jar:?]
[20:01:02] [Render thread/WARN] (Minecraft) Client disconnected with reason: Network Protocol Error

Solution I found

It was fixed create a new EntityTrackerUpdateS2CPacket instance Instead of replace trackedValues.
In my test, it works for me.

Before

((DisguiseUtils) original).updateTrackedData();
List<DataTracker.SerializedEntry<?>> trackedValues = disguised.getDataTracker().getChangedEntries();
((EntityTrackerUpdateS2CPacketAccessor) packet).setTrackedValues(trackedValues);

After

((DisguiseUtils) original).updateTrackedData();
List<DataTracker.SerializedEntry<?>> trackedValues = disguised.getDataTracker().getChangedEntries();
remove.run();
add.accept(new EntityTrackerUpdateS2CPacket(entityId, trackedValues);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant