1
1
package org .samo_lego .healthcare .mixin ;
2
2
3
- import net .minecraft .core .Registry ;
3
+ import net .minecraft .core .registries . BuiltInRegistries ;
4
4
import net .minecraft .network .PacketSendListener ;
5
5
import net .minecraft .network .chat .Component ;
6
6
import net .minecraft .network .chat .MutableComponent ;
@@ -65,33 +65,33 @@ public abstract class ServerPlayNetworkHandlerMixin_HealthTag {
65
65
),
66
66
cancellable = true
67
67
)
68
- private void onPacketSend (Packet <?> packet , PacketSendListener listener , CallbackInfo ci ) {
69
- if (packet instanceof ClientboundSetEntityDataPacket && !this .hc_skipCheck ) {
70
- int id = (( EntityTrackerUpdateS2CPacketAccessor ) packet ). getId ();
68
+ private void onPacketSend (Packet <?> sendPacket , PacketSendListener listener , CallbackInfo ci ) {
69
+ if (sendPacket instanceof ClientboundSetEntityDataPacket packet && !this .hc_skipCheck ) {
70
+ int id = packet . id ();
71
71
Entity entity = this .player .getLevel ().getEntity (id );
72
72
final var hb = ((HealthbarPreferences ) this .player ).healthcarePrefs ();
73
73
74
74
if (entity instanceof LivingEntity living &&
75
75
hb .enabled &&
76
76
!(entity instanceof Player ) &&
77
- !config .blacklistedEntities .contains (Registry .ENTITY_TYPE .getKey (entity .getType ()).toString ()) &&
77
+ !config .blacklistedEntities .contains (BuiltInRegistries .ENTITY_TYPE .getKey (entity .getType ()).toString ()) &&
78
78
!entity .isInvisibleTo (player )) {
79
79
80
- var trackedValues = new ArrayList <>((( EntityTrackerUpdateS2CPacketAccessor ) packet ). getPackedItems ());
80
+ var trackedValues = new ArrayList <>(packet . packedItems ());
81
81
82
82
// Removing current custom name
83
- var customName = trackedValues .stream ().filter (value -> value .getAccessor (). getId () == 2 ).findFirst ();
83
+ var customName = trackedValues .stream ().filter (value -> value .id () == 2 ).findFirst ();
84
84
85
85
// Ensure name is visible only if mob is not too far away
86
86
boolean visible = (entity .distanceTo (player ) < config .activationRange || entity .isCustomNameVisible ()) && hb .alwaysVisible ;
87
- var visibleTag = new SynchedEntityData .DataItem <> (EntityAccessor .getNAME_VISIBLE (), visible );
87
+ var visibleTag = SynchedEntityData .DataValue . create (EntityAccessor .getNAME_VISIBLE (), visible );
88
88
89
89
float health = living .getHealth ();
90
90
float maxHealth = living .getMaxHealth ();
91
91
92
92
MutableComponent name = Component .empty ();
93
- if (customName .isPresent () && ((Optional <Component >) customName .get ().getValue ()).isPresent ()) {
94
- name = ((Optional <Component >) customName .get ().getValue ()).get ().copy ().append (" " );
93
+ if (customName .isPresent () && ((Optional <Component >) customName .get ().value ()).isPresent ()) {
94
+ name = ((Optional <Component >) customName .get ().value ()).get ().copy ().append (" " );
95
95
} else if (entity .hasCustomName ()) {
96
96
// @SpaceClouds42 saved me here, `.copy()` after getting custom name is essential!
97
97
name = entity .getCustomName ().copy ().append (" " );
@@ -100,17 +100,13 @@ private void onPacketSend(Packet<?> packet, PacketSendListener listener, Callbac
100
100
}
101
101
102
102
var healthbar = ((HealthbarPreferences ) this .player ).createHealthbarText (health , maxHealth );
103
- var healthTag = new SynchedEntityData .DataItem <> (EntityAccessor .getCUSTOM_NAME (), Optional .of (name .append (healthbar )));
103
+ var healthTag = SynchedEntityData .DataValue . create (EntityAccessor .getCUSTOM_NAME (), Optional .of (name .append (healthbar )));
104
104
105
105
Collections .addAll (trackedValues , visibleTag , healthTag );
106
106
107
107
// Create a new packet in order to not mess with other network handlers
108
108
// since same packet object is sent to every player
109
- var trackerUpdatePacket = new ClientboundSetEntityDataPacket (id , this .hc_dummyTracker , false );
110
- var accessor = (EntityTrackerUpdateS2CPacketAccessor ) trackerUpdatePacket ;
111
-
112
- accessor .setId (id );
113
- accessor .setPackedItems (trackedValues );
109
+ var trackerUpdatePacket = new ClientboundSetEntityDataPacket (id , trackedValues );
114
110
115
111
this .hc_skipCheck = true ;
116
112
this .send (trackerUpdatePacket , listener );
0 commit comments