2727import com .github .juliarn .npclib .api .protocol .enums .EntityPose ;
2828import com .github .juliarn .npclib .api .protocol .enums .EntityStatus ;
2929import java .util .Collection ;
30- import java .util .HashSet ;
31- import java .util .Set ;
30+ import java .util .function .Function ;
3231
3332interface DefaultEntityMetadata {
3433
35- // https://wiki.vg /Entity_metadata#Entity - see index 0
34+ // https://minecraft.wiki/w/Java_Edition_protocol /Entity_metadata#Entity - see index 0
3635 EntityMetadataFactory <Collection <EntityStatus >, Byte > ENTITY_STATUS =
3736 EntityMetadataFactory .<Collection <EntityStatus >, Byte >metaFactoryBuilder ()
3837 .baseIndex (0 )
3938 .type (Byte .class )
40- .inputConverter (rawEntries -> {
39+ .inputConverter (entries -> {
4140 // if there are no entries the mask is always 0
42- int size = rawEntries .size ();
43- if (size == 0 ) {
41+ if (entries .isEmpty ()) {
4442 return (byte ) 0 ;
4543 }
4644
47- // ensure that there are no duplicates
48- Set <EntityStatus > entries ;
49- if (rawEntries instanceof Set <?>) {
50- // already a set - nice
51- entries = (Set <EntityStatus >) rawEntries ;
52- } else {
53- // copy over the elements
54- entries = new HashSet <>(size + 1 , 1f );
55- entries .addAll (rawEntries );
56- }
57-
5845 // calculate the bitmask to send
5946 byte entryMask = 0 ;
6047 for (EntityStatus entry : entries ) {
@@ -64,7 +51,16 @@ interface DefaultEntityMetadata {
6451 return entryMask ;
6552 }).build ();
6653
67- // https://wiki.vg/Entity_metadata#Entity - see index 0 and 6
54+ // https://minecraft.wiki/w/Java_Edition_protocol/Entity_metadata#Entity - see index 6
55+ EntityMetadataFactory <EntityPose , EntityPose > ENTITY_POSE =
56+ EntityMetadataFactory .<EntityPose , EntityPose >metaFactoryBuilder ()
57+ .baseIndex (6 )
58+ .type (EntityPose .class )
59+ .inputConverter (Function .identity ())
60+ .availabilityChecker (versionAccessor -> versionAccessor .atLeast (1 , 14 , 0 ))
61+ .build ();
62+
63+ // https://minecraft.wiki/w/Java_Edition_protocol/Entity_metadata#Entity - see index 0 and 6
6864 EntityMetadataFactory <Boolean , Byte > SNEAKING = EntityMetadataFactory .<Boolean , Byte >metaFactoryBuilder ()
6965 .baseIndex (0 )
7066 .type (Byte .class )
@@ -77,7 +73,32 @@ interface DefaultEntityMetadata {
7773 .build ())
7874 .build ();
7975
80- // https://wiki.vg/Entity_metadata#Player - see index 10
76+ // https://minecraft.wiki/w/Java_Edition_protocol/Entity_metadata#Entity - see index 7
77+ EntityMetadataFactory <Boolean , Integer > SHAKING = EntityMetadataFactory .<Boolean , Integer >metaFactoryBuilder ()
78+ .baseIndex (7 )
79+ .type (Integer .class )
80+ .inputConverter (value -> value ? 250 : 0 )
81+ .availabilityChecker (versionAccessor -> versionAccessor .atLeast (1 , 17 , 0 ))
82+ .build ();
83+
84+ // https://minecraft.wiki/w/Java_Edition_protocol/Entity_metadata#Living_Entity - see index 8
85+ EntityMetadataFactory <Boolean , Byte > USING_ITEM = EntityMetadataFactory .<Boolean , Byte >metaFactoryBuilder ()
86+ .baseIndex (5 )
87+ .type (Byte .class )
88+ .indexShiftVersions (10 , 14 , 17 )
89+ .inputConverter (value -> (byte ) (value ? 0x01 : 0x00 ))
90+ .availabilityChecker (versionAccessor -> versionAccessor .atLeast (1 , 9 , 0 ))
91+ .build ();
92+
93+ // https://minecraft.wiki/w/Java_Edition_protocol/Entity_metadata#Living_Entity - see index 12
94+ EntityMetadataFactory <Integer , Integer > ARROW_COUNT = EntityMetadataFactory .<Integer , Integer >metaFactoryBuilder ()
95+ .baseIndex (9 )
96+ .type (Integer .class )
97+ .indexShiftVersions (10 , 14 , 17 )
98+ .inputConverter (value -> Math .max (0 , value ))
99+ .build ();
100+
101+ // https://minecraft.wiki/w/Java_Edition_protocol/Entity_metadata#Player - see index 17
81102 EntityMetadataFactory <Boolean , Byte > SKIN_LAYERS = EntityMetadataFactory .<Boolean , Byte >metaFactoryBuilder ()
82103 .baseIndex (10 )
83104 .type (Byte .class )
0 commit comments