Compare commits

...

296 Commits

Author SHA1 Message Date
Nassim Jahnke 2d41eb52a6
Remove invalid chunk entities for 1.20.5 clients
Fixes #3804
2024-05-14 18:47:57 +02:00
Nassim Jahnke 7e268a6f87
Bump version to 4.10.3-SNAPSHOT 2024-05-14 16:33:39 +02:00
Nassim Jahnke 113bf1e275
4.10.2 Release 2024-05-10 13:24:23 +02:00
EnZaXD 2aec3ce6d1
Expose StructuredDataConverter#removeBackupTag (#3838) 2024-05-09 20:50:45 +02:00
EnZaXD f60e31ac78
Add block entity ids in 1.20.3->.5 conversion (#3837) 2024-05-09 20:37:20 +02:00
EnZaXD 8c4ff7ebfc
Remove fix which got merged into MCStructs (#3836) 2024-05-09 20:04:36 +02:00
Nassim Jahnke 4c7729e602
Fixup banner handling, some other fixes 2024-05-09 19:33:26 +02:00
Nassim Jahnke 3dfc3bb15b
Actually add properties tag in 1.20.5->1.20.4 item handler 2024-05-09 17:21:53 +02:00
EnZaXD 69b33dc2d2
Handle invalid disconnect message in 1.8->1.9 (#3834) 2024-05-09 09:26:28 +02:00
EnZaXD c24169c410
[ci skip] Use login/status packet enums in older protocols (#3835) 2024-05-09 09:25:54 +02:00
Nassim Jahnke 31211c2214
Fix tipped arrow and area effect cloud color 2024-05-08 20:28:55 +02:00
Nassim Jahnke cb5fc9fb08
Fix empty effect handling
Fixes #3832
2024-05-08 11:55:35 +02:00
EnZaXD a8d7ab62e3
Add alpha to particle colors in 1.20.3->.5 (#3827) 2024-05-06 09:51:41 +02:00
Nassim Jahnke 71313b4753
Simplify raider check in 1.13->1.14 entity data handler 2024-05-06 09:42:49 +02:00
Nassim Jahnke 994bc8eefc
Move down super onMappingDataLoaded calls 2024-05-05 23:15:20 +02:00
Nassim Jahnke 7d35826637
Bump version to 4.10.2-SNAPSHOT 2024-05-05 23:12:43 +02:00
Nassim Jahnke 4f40372392
4.10.1 Release 2024-05-05 16:38:28 +02:00
Nassim Jahnke e993be751c
Filter items in entity data with amount < 1 2024-05-05 16:36:46 +02:00
Nassim Jahnke f1b92fea8d
Move loadFullMappings to MappingDataBase, use loadMiMappings 2024-05-05 14:41:30 +02:00
Nassim Jahnke fc9d5b6d9d
Clean up entriesLength usage 2024-05-05 13:33:21 +02:00
EnZaXD 9549a18cec
Handle duplicated registry ids in 1.20.3->.5 (#3825)
Minecraft 1.20.4 and earlier silently overrides the previous values if multiple registry elements have the same id (Tested using a Fabric 1.20.4 mod by parsing a registry sent by a server and then printing the parsed objects).
2024-05-05 13:08:09 +02:00
Nassim Jahnke d691096ce1
Move around types, apply to other enums
This doesn't include ALL abstract types, mostly if they are single-use or not at all relevant to our handling and most likely never will
2024-05-05 12:10:57 +02:00
Nassim Jahnke 73ed425bf7
Fixup entity type hierarchy 2024-05-04 18:11:50 +02:00
EnZaXD cdc9c3ae95
Update mappings (#3823)
48167fe5b6
2024-05-03 19:12:24 +02:00
EnZaXD c113e19d41
Convert plain to json instead of doing component conversion in DeathListener (#3821)
Closes https://github.com/ViaVersion/ViaVersion/issues/3817
2024-05-02 17:09:27 +02:00
EnZaXD d3af70d76c
Add optional registry utils to TagUtil (#3819) 2024-05-02 15:45:19 +02:00
Nassim Jahnke c00bc6b667
Check both namespaced and implicit key when replacing registry 2024-05-01 10:28:53 +02:00
Nassim Jahnke fa3c933b2f
Fix banner pattern backup
Fixes #3816
2024-05-01 00:06:22 +02:00
Nassim Jahnke 07bb0269c3
Auto: Update copyright headers 2024-04-30 22:23:11 +02:00
Nassim Jahnke 57c0d83608
Clean up component rewriter 2024-04-30 16:09:11 +02:00
Nassim Jahnke 4854b131b8
Some cleanup 2024-04-30 09:02:24 +02:00
Nassim Jahnke 1864b66e42
Handle new banner patterns in backwards translation 2024-04-29 23:58:57 +02:00
Nassim Jahnke 8aa6769193
Handle empty items in item lists 2024-04-29 23:11:10 +02:00
Nassim Jahnke 5f90bcbbaf
Fix item cost type reading 2024-04-28 15:15:17 +02:00
Nassim Jahnke d068822143
Add paperweight-mappings-namespace manifest attribute 2024-04-28 03:51:56 +02:00
Nassim Jahnke a77e328dfe
Put components in entity data through component rewriter
Cursed, but possibly needed
2024-04-27 21:39:20 +02:00
Gero 9c84e0dbe9 Fix remapping of 1.20.5 CLICK_WINDOW_BUTTON 2024-04-27 21:26:28 +02:00
Nassim Jahnke 66e0453398
Fix block protocols disconnect packet 2024-04-27 12:13:09 +02:00
Nassim Jahnke 7ec6888a30
Handle invalid command argument types
The client ignores these presumably for modded servers
Fixes #3806
2024-04-27 11:26:18 +02:00
Nassim Jahnke c9733948b3
Use raw data filler in 1.12->1.13 2024-04-27 10:23:04 +02:00
Nassim Jahnke 798b70cbe6
Be even more defensive about half valid items in hover events
While they aren't particularly useful or intended, they were valid
2024-04-26 19:00:37 +02:00
Nassim Jahnke 1f43ff571d
Bump to 4.10.1-SNAPSHOT 2024-04-26 18:26:37 +02:00
Nassim Jahnke d28e7cd652
4.10.0 Release 2024-04-26 15:03:17 +02:00
Nassim Jahnke f20d99fcef
Add 1.20.6 to .5 version
We technically don't know whether that will stay true, but might as well now to prevent confusion, as it wouldn't have any consequences if it did change
2024-04-26 15:02:57 +02:00
Nassim Jahnke a1c182f291
Ignore invalid names in the data component for hover events as well 2024-04-26 10:01:29 +02:00
Nassim Jahnke 8e63fd635b
Ignore invalid names in player heads 2024-04-26 09:29:19 +02:00
FlorianMichael 676e62c71f
Fix via dump throwing an error on sponge 2024-04-25 22:44:42 +02:00
FlorianMichael f422e03348
Rename ranged protocol version names 2024-04-25 20:31:22 +02:00
Nassim Jahnke fdf735420f
Add enforce-secure-chat setting to determine what is sent to the client by default 2024-04-25 20:21:36 +02:00
Nassim Jahnke b13fbbe175
Fix various issues in hover events serialization 2024-04-25 10:34:24 +02:00
Nassim Jahnke 9dd3348510
Move appendClientbound/Serverbound methods to Protocol interface 2024-04-24 20:11:05 +02:00
Nassim Jahnke 0e97af29b4
Add warning on Bungee startup
Without more specific injection points as with Velocity, Via has started failing more and more on Bungee and maintaining the required hackfixes coming from that has shown time intensive
2024-04-24 19:56:09 +02:00
Nassim Jahnke 3dfcd6b9b9
Fix written book hover serialization 2024-04-24 15:47:56 +02:00
Nassim Jahnke 8df0c0ae2e
Catch component parsing exceptions separately instead of failing the entire item 2024-04-24 15:47:47 +02:00
Nassim Jahnke d2ca6a82be
Assume enforce secure chat as false by default
Setting it to true will result in chat validation errors on the client for other players without chat sessions or valid signatures
2024-04-24 10:26:35 +02:00
Nassim Jahnke 9654a613cd
Put combat kill through component rewriter 2024-04-24 10:15:53 +02:00
Nassim Jahnke c5e6fa7d0c
Fix trim material ids at tail 2024-04-24 10:11:22 +02:00
Nassim Jahnke b78f9d350b
Check for lore length, not component length 2024-04-23 23:53:24 +02:00
Nassim Jahnke ebbe1b6da2
Make backwards enchantment code more readable 2024-04-23 23:44:12 +02:00
Nassim Jahnke 3aed7cb949
Fix mending translation from getting the id from the wrong class 2024-04-23 19:56:17 +02:00
Nassim Jahnke e2f3dc7572
Limit enchantments to 0-255 2024-04-23 19:32:32 +02:00
Nassim Jahnke f2b9c42590
Remove snapshot version support 2024-04-23 17:01:46 +02:00
Nassim Jahnke 9894671274
Add back default method 2024-04-23 13:47:05 +02:00
Nassim Jahnke 71ab15b331
Serialize to 1.20.3 components in conversion
Aside from hover events, only reading of components changed and we need the 1.20.3 hover input. Hover events are already handled by us.
2024-04-23 13:39:15 +02:00
Nassim Jahnke 34bc5b9d36
Put item name and lore through component rewriter
An absolute classic moment where servers are putting hover events into not hoverable item names and lore
2024-04-23 13:07:05 +02:00
Nassim Jahnke d80fd46c2f
Update version references 2024-04-23 11:26:17 +02:00
Nassim Jahnke b47446d9f7
Merge branch 'refs/heads/dev' into preview 2024-04-23 10:59:45 +02:00
EnZaXD dcf741a2ba
Fix sound mapping lookup in 1.8->1.9 (#3801) 2024-04-23 10:46:40 +02:00
Nassim Jahnke a4adef3cec
Fix attribute slot handling 2024-04-22 23:57:55 +02:00
Nassim Jahnke f525ad98e7
Fix handling of sweeping 2024-04-22 16:24:13 +02:00
Nassim Jahnke bc0b4470f6
1.20.5-rc3 2024-04-22 16:20:09 +02:00
Nassim Jahnke d3d6d4f1cd
Fixes to hover event handling, some cleanup 2024-04-22 16:05:44 +02:00
Nassim Jahnke 5069b26c2f
Reuse previously sent enforces-secure-chat value 2024-04-22 16:05:40 +02:00
FlorianMichael 079671060c
Remove items from extra-identifiers-1.20.3 file 2024-04-22 07:13:03 +02:00
Nassim Jahnke 89cd8aec1d
Merge branch 'refs/heads/dev' into preview 2024-04-21 23:47:01 +02:00
Nassim Jahnke 7ac7ea485f
Add UserConnection to component rewriters as well 2024-04-21 23:01:58 +02:00
Nassim Jahnke 5e4f25efeb
Merge branch 'refs/heads/dev' into preview
# Conflicts:
#	common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java
#	common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java
#	common/src/main/java/com/viaversion/viaversion/rewriter/ItemRewriter.java
2024-04-21 22:51:45 +02:00
Nassim Jahnke a152993ffd
Add UserConnection to item rewriters
Already required for ViaBackwards, later required for ViaVersion as well due to synchronized registry entries in items
2024-04-21 22:39:13 +02:00
Nassim Jahnke 73daac471c
Split up version data in dump 2024-04-21 21:55:59 +02:00
Nassim Jahnke f4e9225f85
Store item identifiers, make identifier files more compact via global table 2024-04-21 20:47:38 +02:00
EnZaXD 1ed22327f6
Replace string->component conversion in 1.8->1.9 (#3794) 2024-04-21 16:00:30 +02:00
EnZaXD ce2ad7d5eb
Change default value for new ocelot setting (#3797) 2024-04-21 15:15:17 +02:00
FlorianMichael d7e66260de
Add 1.20.5 nbt->component conversion base
Has to be implemented into ViaBackwards yet and handlers are still missing
2024-04-21 14:53:25 +02:00
FlorianMichael dc6d581123
Update mcstructs and use new component serializer 2024-04-21 12:13:59 +02:00
FlorianMichael bd3f1206e6
[ci skip] document 1.9 metadata in MetaIndex 2024-04-21 11:35:10 +02:00
FlorianMichael b9e92e5c1f
Fix zombie metadata in 1.10->1.11 2024-04-21 11:24:20 +02:00
Gero 0acaed7c7a Use correct item type for 1.20.5 particle reading 2024-04-20 23:50:24 +02:00
FlorianMichael 3055a4277d
Use toString() method in ComponentUtil 2024-04-20 22:52:40 +02:00
Gero bcbe69d24c Fix ITEM_NAME component to tag conversion 2024-04-20 22:44:22 +02:00
EnZaXD 33cc21d6e6
Add setting for ocelot->cat translation in 1.13.2->1.14 (#3796) 2024-04-20 15:17:26 +02:00
Nassim Jahnke 949b3d712e
Fix illager metadata in 1.13->1.14 2024-04-20 13:36:00 +02:00
Nassim Jahnke 216dcb2931
Remove invalid zombified piglin data 2024-04-20 12:43:08 +02:00
Nassim Jahnke bff1536529
Fall back to keys without namespace in registry data 2024-04-20 12:06:39 +02:00
Nassim Jahnke b221e47eb7
Add creative mode range attributes if needed
Add the range argument either with or without modifiers depending on the gamemode to otherwise reset them
2024-04-19 21:35:41 +02:00
EnZaXD fb434a79bd
Use correct deserialization method in SerializerVersion#toComponent (#3795)
MCStructs has multiple methods for parsing jsons depending on the version, we should use them correctly in our wrapper to support all possible cases of components.
2024-04-19 17:05:07 +02:00
Nassim Jahnke 1be0605f51
Eat remaining particle data in spawn particle 2024-04-19 17:02:08 +02:00
Nassim Jahnke c75b4d8ef5
1.20.5-rc2 2024-04-19 15:38:35 +02:00
Gero e08c263ced Add missing dust_color_transition data remapping (changed in 24w03a) 2024-04-19 11:02:11 +02:00
Nassim Jahnke 1bb85b11e9
Merge branch 'refs/heads/dev' into preview 2024-04-19 10:11:05 +02:00
AJ Ferguson 128e191132
Fix 1.15->1.16 item attribute uuid (#3793) 2024-04-19 10:09:17 +02:00
Nassim Jahnke 3520f99d5a
Remove empty items from various block entities 2024-04-19 09:56:24 +02:00
RaphiMC 7825a1e460
Handle show_entity type field 2024-04-18 23:11:19 +02:00
RK_01 bfde4b953c
Fix 1.11->1.12 show_achievement rewriter (#3792) 2024-04-18 20:45:19 +02:00
Nassim Jahnke 57b37457d6
Add spit damage type
The client depends on it
2024-04-18 20:12:38 +02:00
Nassim Jahnke f7aa1a516e
Fill wolf_food item tag 2024-04-18 18:58:29 +02:00
Nassim Jahnke b1468ac6d0
Update particle codec format
Was changed in 1.20.5-pre1
2024-04-18 18:36:22 +02:00
Nassim Jahnke 27b5fdb4ff
Merge branch 'refs/heads/dev' into preview
# Conflicts:
#	common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13_1to1_13/metadata/MetadataRewriter1_13_1To1_13.java
#	common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/metadata/MetadataRewriter1_14To1_13_2.java
#	common/src/main/java/com/viaversion/viaversion/protocols/protocol1_15to1_14_4/metadata/MetadataRewriter1_15To1_14_4.java
#	common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/metadata/MetadataRewriter1_16_2To1_16_1.java
#	common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/metadata/MetadataRewriter1_16To1_15_2.java
#	common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/EntityPackets.java
#	common/src/main/java/com/viaversion/viaversion/protocols/protocol1_18to1_17_1/packets/EntityPackets.java
#	common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_3to1_19_1/packets/EntityPackets.java
#	common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java
2024-04-18 16:17:05 +02:00
Nassim Jahnke a99273db2e
Always call onMappingDataLoaded in TagRewriter
In case they are needed in the future, so that we don't also have to check whether the different methods are actually called
2024-04-18 16:12:57 +02:00
Nassim Jahnke 64f911ed4a
1.20.5-rc1 2024-04-18 15:47:44 +02:00
EnZaXD 4302dd61aa
Remove Protocol1_9To1_8#FIX_JSON usage in 1.11->1.12 (#3791) 2024-04-18 15:26:13 +02:00
EnZaXD 98c5d38d0c
Push book contents through component conversion in 1.8->1.9 (#3790) 2024-04-18 15:25:48 +02:00
FlorianMichael 033d5ae49a
Handle removed item conversion in component rewriter 2024-04-17 22:39:08 +02:00
Nassim Jahnke 8cf9114403
1.20.5-pre4 2024-04-17 15:01:16 +02:00
EnZaXD bd8e469216
Fix IdAndData constructor without data field (#3789) 2024-04-17 08:46:56 +02:00
EnZaXD 57d7fd59cc
Change IdAndData#setData parameter to int (#3788) 2024-04-16 21:00:04 +02:00
EnZaXD 8fe0681778
Replace incoming/outgoing usages with client/server bound (#3787) 2024-04-16 20:59:48 +02:00
EnZaXD ea5cf3e594
Add IdAndData util and replace conversions (#3786) 2024-04-16 15:55:55 +02:00
Nassim Jahnke 13eec3c2ea
1.20.5-pre3 2024-04-16 15:36:02 +02:00
Nassim Jahnke 31ccd2ab9b
1.20.5-pre2 2024-04-15 17:14:23 +02:00
FlorianMichael 2be190d152
Some consistency cleanup 2024-04-13 22:32:56 +02:00
FlorianMichael 4e25549682
Handle legacy item hover events
Co-authored-by: RaphiMC <50594595+raphimc@users.noreply.github.com>
2024-04-13 21:01:34 +02:00
FlorianMichael 287678c12a
[ci skip] Add comments for conversion direction to classes 2024-04-13 20:58:38 +02:00
FlorianMichael 4343aa17fc
Add missing annotations to StatePropertyMatcher 2024-04-13 20:57:32 +02:00
FlorianMichael 970986bc59
Add component rewriter for 1.20.3->1.20.5 2024-04-13 20:56:54 +02:00
RK_01 2586788bf6
Fix config read/write error when parent file is null (#3783) 2024-04-10 17:35:25 +02:00
EnZaXD 0c2c8400ae
Make handling of optional block metadata more explicit in <1.19.4 (#3782) 2024-04-10 17:34:56 +02:00
Nassim Jahnke ba4404fad6
1.20.5-pre1 2024-04-10 17:33:10 +02:00
RK_01 6f53c069ea
Fix 1.12 -> 1.13 held enderman block translation (#3781) 2024-04-10 10:43:48 +02:00
Nassim Jahnke 99f29e2597
Prepare proper banner id tracking, small other fixes 2024-04-09 12:40:16 +02:00
EnZaXD 7932b79080
Explain backup tags (#1) 2024-04-08 16:59:33 +02:00
FlorianMichael 4b780b92ee
Fix armor trim conversion 2024-04-08 15:05:01 +02:00
Nassim Jahnke d04aaeb926
Handle color in area effect cloud 2024-04-08 14:21:11 +02:00
FlorianMichael 9f1ee27afc
Add missing checks in item id conversions 2024-04-08 13:36:58 +02:00
Nassim Jahnke 5f685884ff
Handle entity effect particle in spawn particle 2024-04-08 13:33:59 +02:00
FlorianMichael ba2e50cc88
Fix StructuredDataConverter#removeItemBackupTag 2024-04-08 13:31:13 +02:00
FlorianMichael 7b28683b6a
Add remaining data backup handling 2024-04-08 13:18:49 +02:00
Nassim Jahnke 510747a7cd
Replace empty items in recipes 2024-04-08 10:53:39 +02:00
Nassim Jahnke 8c5752bb4c
Update unsupported java version warning 2024-04-07 22:34:20 +02:00
Nassim Jahnke 33e2a1fc13
Send unsigned messages if possible
The server cannot guarantee that the last seen values are correct, so in order to avoid kicks from invalid signatures, we will just strip them if possible.
2024-04-07 22:05:14 +02:00
Nassim Jahnke dbe8a389ce
Update authors 2024-04-07 20:41:44 +02:00
Nassim Jahnke 83223c1520
Also handle ack in serverbound chat message 2024-04-07 20:35:07 +02:00
FlorianMichael 935077222e
Simplify code 2024-04-07 20:08:16 +02:00
FlorianMichael 8961660846
Fix chat command handling 2024-04-07 19:43:29 +02:00
Nassim Jahnke 1fe23e4aeb
Fix trade list handling 2024-04-07 13:36:02 +02:00
Nassim Jahnke 06394c1f74
Apply network limits 2024-04-07 11:41:57 +02:00
Nassim Jahnke 68c2af2795
Replace unknown sounds with direct value in registry data 2024-04-06 23:47:27 +02:00
Nassim Jahnke 35a00d0b95
Check for new outbound_config pipeline handler 2024-04-06 23:10:58 +02:00
Nassim Jahnke c2489c7a4c
Back up 1.20.5 data components in VB for creative clients 2024-04-06 21:26:44 +02:00
Nassim Jahnke c743c20334
Update wolf textures again, add utility methods 2024-04-06 21:26:44 +02:00
FlorianMichael 228689f181
Remove temporary goat horn fix 2024-04-06 21:26:44 +02:00
Nassim Jahnke 67e6e1a2e3
24w14a 2024-04-06 21:26:44 +02:00
Nassim Jahnke a2c1c52f51
24w13a 2024-04-06 21:26:44 +02:00
Nassim Jahnke fd4db24d44
Fix intangible projectile data reading 2024-04-06 21:26:43 +02:00
Nassim Jahnke 0b7fdd4c69
Update wild wolf texture field name 2024-04-06 21:26:43 +02:00
Nassim Jahnke 4849ca0745
Start working on 24w12a 2024-04-06 21:26:43 +02:00
Nassim Jahnke 60b782455d
Fix display tag setting and doubled item id rewriting 2024-04-06 21:26:43 +02:00
FlorianMichael 3fef71db2e
Added missing null checks for CONTAINER_LOOT handler 2024-04-06 21:26:43 +02:00
Nassim Jahnke 9ca02680c8
Fix enchantment level 2024-04-06 21:26:43 +02:00
FlorianMichael 5899886b42
Fixes 2024-04-06 21:26:42 +02:00
Nassim Jahnke c2567115d8
Fix various issues 2024-04-06 21:26:42 +02:00
Nassim Jahnke 4255876c22
Fix up block state handling, add PotDecorations wrapper 2024-04-06 21:26:42 +02:00
FlorianMichael 57a589924d
More structured data handling 2024-04-06 21:26:42 +02:00
Nassim Jahnke 936dcafc11
Make HolderSet an interface 2024-04-06 21:26:42 +02:00
Nassim Jahnke b6489b8343
Fix block predicate parsing 2024-04-06 21:26:41 +02:00
Nassim Jahnke bf11a0a7de
Start working on 24w11a 2024-04-06 21:26:41 +02:00
Nassim Jahnke 7d41706026
Rewrite block predicates the other way around as well 2024-04-06 21:26:41 +02:00
FlorianMichael 93f081dd84
Add even more backwards rewriters 2024-04-06 21:26:41 +02:00
Nassim Jahnke 3f82b150d2
Handle CanPlaceOn and CanDestroy tags 2024-04-06 21:26:39 +02:00
Nassim Jahnke 7a96498f6d
Some sanity checks, get item id by name fast 2024-04-06 21:26:17 +02:00
FlorianMichael 817febe605
Even more work! 2024-04-06 21:26:16 +02:00
Nassim Jahnke bb4a8b73e0
Small cleanup 2024-04-06 21:26:16 +02:00
Nassim Jahnke 8d3492ba30
Add more structured data -> nbt converters 2024-04-06 21:26:16 +02:00
Nassim Jahnke 658364b643
Add a few structured data -> nbt converters 2024-04-06 21:26:16 +02:00
Nassim Jahnke 666b204ebb
Prepare class for structured data->tag rewriting 2024-04-06 21:26:16 +02:00
Nassim Jahnke bfab9b0c11
Banner patterns and wolves 2024-04-06 21:26:15 +02:00
Nassim Jahnke 121f107ff3
More handled structures 2024-04-06 21:26:15 +02:00
Nassim Jahnke 426bd9aa99
More handled structures 2024-04-06 21:26:13 +02:00
Nassim Jahnke 7a66bb8e1c
More handled structures 2024-04-06 21:25:39 +02:00
Nassim Jahnke 329abcac7d
More handled structures 2024-04-06 21:25:08 +02:00
Nassim Jahnke 0961de898d
Handle books, among other things 2024-04-06 21:25:05 +02:00
Nassim Jahnke b4ee564aa2
24w10a, more item component work 2024-04-06 21:23:57 +02:00
EnZaXD 73178b504e
Inline player on-ground movement handler (#3777) 2024-04-06 09:29:57 +02:00
EnZaXD d0cc531386
Cleanup MetaIndex style and field names (#3775) 2024-04-05 20:15:41 +02:00
EnZaXD 617ef10667
Remove MetaType1_8#NonExistent (#3774) 2024-04-05 19:48:59 +02:00
EnZaXD 5569caf610
Improve horse armor patch in 1.8->1.9 (#3773) 2024-04-05 15:46:20 +02:00
EnZaXD 868a5bd24e
Remove non existing metadata from MetaIndex (#3772) 2024-04-05 15:45:13 +02:00
EnZaXD b113a82710
Catch errors in <= 1.20 custom payload reading (#3770) 2024-04-04 22:25:02 +02:00
EnZaXD 3ee4c8ed63
Make ViaVersion fake nbt format consistent (#3771)
Adding ItemRewriter#nbtTagName utils to prefix nbt tags with a consistent format:
<Platform>|<Protocol name>|<original nbt name>
2024-04-04 09:31:58 +02:00
EnZaXD cd65925d6b
Add conversion methods to SerializerVersion and replace missing MCStructs usages (#3769) 2024-04-01 15:52:57 +02:00
Nassim Jahnke 307414eb51
Move simple mcstructs usage into utils 2024-04-01 14:13:43 +02:00
EnZaXD 51745cb2ef
Rewrite 1.12.2->1.13 ComponentRewriter (#3765) 2024-04-01 13:38:43 +02:00
EnZaXD f44782d21d
Fix minor inconsistencies in protocol packages (#3768) 2024-04-01 12:55:50 +02:00
EnZaXD 7556f7b8fa
Move chat registry dumps into nbt files (#3763) 2024-03-31 15:07:46 +02:00
EnZaXD abd58399cd
Remove entity metadata buffering in 1.8->1.9 (#3766) 2024-03-30 22:27:40 +01:00
EnZaXD 0a2fd8f296
Add MappingDataLoader#getLogger and MappingDataLoader#getDataFolder (#3757) 2024-03-24 22:04:41 +01:00
EnZaXD f2c816df72
Add mapped and unmapped identifier read method (#3756) 2024-03-24 12:14:42 +01:00
EnZaXD 098f7ff3c2
Allow platforms to use the mapping system (#3754) 2024-03-24 11:10:20 +01:00
RK_01 18f04bf8ea
Add more functionality to ChunkUtil (#3755) 2024-03-24 11:05:30 +01:00
Nassim Jahnke feefe6f278
Merge branch 'master' into dev
# Conflicts:
#	bukkit-legacy/src/main/java/com/viaversion/viaversion/bukkit/util/ProtocolSupportUtil.java
#	bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaInjector.java
#	bungee/src/main/java/com/viaversion/viaversion/bungee/handlers/BungeeServerHandler.java
#	bungee/src/main/java/com/viaversion/viaversion/bungee/providers/BungeeVersionProvider.java
#	common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/storage/EntityTracker1_9.java
#	common/src/main/java/com/viaversion/viaversion/update/UpdateUtil.java
#	velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaInjector.java
#	velocity/src/main/java/com/viaversion/viaversion/velocity/service/ProtocolDetectorService.java
2024-03-22 20:54:44 +01:00
Nassim Jahnke 4074231a57
Update Hangar publish plugin 2024-03-22 20:49:57 +01:00
Kichura 13efe47a5c
Update build dependencies (#3742) 2024-03-22 20:38:03 +01:00
Nassim Jahnke b07cf03dc1
Check for jsonnull in component conversion
Closes #3745
2024-03-17 16:23:27 +01:00
Nassim Jahnke 0a921d9bdc
Use the correct entity sound rewriter method 2024-03-14 14:43:37 +01:00
EnZaXD 7b0c2fb51a
Replace printStackTrace usages with proper logging (#3741) 2024-03-09 13:57:41 +01:00
Nassim Jahnke b426302e76
Merge branch 'master' into dev
# Conflicts:
#	common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java
#	common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java
#	gradle/libs.versions.toml
2024-03-09 12:59:36 +01:00
Nassim Jahnke 3442cda8ce
Update ViaNBT 2024-03-09 12:57:55 +01:00
Nassim Jahnke 55a0a70264
Merge branch 'master' into dev 2024-03-09 11:36:41 +01:00
EnZaXD a9bfda4568
Rewrite 1.11->1.12 ChatItemRewriter (#3740) 2024-03-09 10:58:42 +01:00
Nassim Jahnke 93990c8baa
Merge branch 'master' into dev
# Conflicts:
#	common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java
#	common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java
#	gradle.properties
#	gradle/libs.versions.toml
2024-03-07 13:45:10 +01:00
Nassim Jahnke f868dfa125
Update ViaNBT 2024-03-07 13:30:33 +01:00
Nassim Jahnke 386495e168
Handle map related data and skull owners
Co-authored-by: Drex <nicknamedrex@gmail.com>
2024-03-06 13:26:06 +01:00
Nassim Jahnke cad78ea68f
Trim string tags in component conversion
Somewhat dirty but inconsequential, as the given protocol does not use this method in item conversion and it should only ever be triggered in hover events
Closes #3650
2024-03-06 12:31:31 +01:00
EnZaXD 908823c612
Make ItemRewriter type getters nullable and optional (#3737) 2024-03-05 23:23:57 +01:00
Nassim Jahnke 2d03110f08
Small refactor 2024-03-01 14:10:44 +01:00
Nassim Jahnke 92878a39ef
We continue to fall 2024-03-01 13:46:26 +01:00
Nassim Jahnke aa0423c6e2
Merge branch 'master' into dev 2024-03-01 12:39:25 +01:00
Nassim Jahnke 39180e22b8
The endless pit continues to be endless 2024-03-01 12:13:43 +01:00
Nassim Jahnke f68aed464d
Once again refactor structured data storage
Optionals are no more
2024-02-29 19:59:18 +01:00
Nassim Jahnke 6ffa24b50b
Add todos 2024-02-29 18:23:46 +01:00
Nassim Jahnke e51d7b3fdb
Fix initial item sending, add some data translation and more rigid data structures 2024-02-29 17:03:50 +01:00
Nassim Jahnke 01bb8dedda
More renames 2024-02-29 12:08:29 +01:00
EnZaXD 6cdca97d35
Add classic version range to VersionType#CLASSIC javadoc (#3729) 2024-02-29 11:11:23 +01:00
RK_01 4cf271af81
Use equals in legacy custom payload channel comparisons (#3721) 2024-02-29 11:11:00 +01:00
Nassim Jahnke aa262bb0a5
Rename itemdata to be more generic 2024-02-28 22:46:33 +01:00
Nassim Jahnke 2480eb6a7f
Start working on 24w09a 2024-02-28 22:15:31 +01:00
Nassim Jahnke 56b82b049a
Move a few methods out of AbstractProtocol 2024-02-27 17:21:27 +01:00
EnZaXD 3c0930c62f
Use existing ProtocolVersion#getProtocol when possible (#3720) 2024-02-27 14:02:16 +01:00
EnZaXD 26a8e5fef1
Fix enabled version sorting in DumpUtil (#3719) 2024-02-27 14:01:47 +01:00
caramel caa6519780
Fix leather armor rendering (#3713) 2024-02-25 20:36:48 +01:00
caramel 1e35c2713f
Fix particle doesn't use new mapping id (#3712) 2024-02-25 20:36:27 +01:00
caramel cd5d88c34f
Fix wrong join game packet handling (#3710) 2024-02-24 20:54:38 +01:00
EnZaXD 7640342165
Don't require a base protocol for current version in BaseProtocol (#3709) 2024-02-23 15:13:33 +01:00
Nassim Jahnke 4e1d4a75b2
Small refactors around ProtocolPipeline and concurrent collections
Make concurrency handling in ProtocolPipelineImpl more defensive, as generally the pipeline is expected to never be called from multiple threads. The only case to look out for is pipeline additions during protocol transformation in a base protocol
2024-02-21 12:18:19 +01:00
EnZaXD 343b403cf1
Ensure ProtocolManagerImpl#registerBaseProtocol doesn't support VersionType#SPECIAL protocols (#3705) 2024-02-19 10:09:44 +01:00
RK_01 78aecbddf8
Don't add base protocols when using special versions (#3704) 2024-02-18 21:55:14 +01:00
Nassim Jahnke 48241ba841
Fix Bungee server change 2024-02-18 19:32:55 +01:00
Nassim Jahnke a8fbb000eb
Add ProtocolManager#hasLoadedMappings 2024-02-15 18:27:52 +01:00
EnZaXD ff25cbd6eb
Add RedirectProtocolVersion API to common module (#3701) 2024-02-15 18:21:38 +01:00
Nassim Jahnke e2a7e10312
Add back default getProtocolPath with int versions 2024-02-15 15:45:23 +01:00
EnZaXD c7baa27fd0
Some code cleanup (#3698) 2024-02-14 22:53:50 +01:00
Nassim Jahnke 35578372a1
Fix isWorkingPipe and cursed ProtocolVersion comparator 2024-02-14 22:45:34 +01:00
EnZaXD 293427c172
Only pass ProtocolVersion#toString into via dumps (#3699) 2024-02-14 21:49:40 +01:00
EnZaXD 08d8ccf6ca
Don't add ProtocolVersion#unknown into ProtocolVersion#VERSION_LIST (#3697) 2024-02-14 21:07:36 +01:00
EnZaXD 35ceee1a47
Rename ProtocolVersion#v1_7_1 to v1_7_2 (#3696) 2024-02-14 20:14:17 +01:00
Nassim Jahnke dccda57fc0
Consistent equalTo names 2024-02-14 19:14:41 +01:00
Nassim Jahnke 5c21f60ef7
Fix Bungee ping default 2024-02-14 19:12:05 +01:00
Nassim Jahnke c124c1c809
Sort ProtocolVersions version list, fix base protocol registration 2024-02-14 17:57:00 +01:00
EnZaXD 302716054d
Port of internals and API to ProtocolVersion (#3694) 2024-02-14 17:56:28 +01:00
Nassim Jahnke 46a5bb16d7
24w07a 2024-02-14 17:32:13 +01:00
EnZaXD f3f7ea7987
Fix version ranges in VersionType (#3692) 2024-02-14 09:57:41 +01:00
EnZaXD e62c4a3f9e
Rename comparing methods in ProtocolVersion (#3693) 2024-02-14 09:54:15 +01:00
EnZaXD d58c80cd2f
Add ProtocolVersionRange API (#3691) 2024-02-14 09:51:56 +01:00
Nassim Jahnke 7a6c51331b
Move config load after platform creation 2024-02-13 23:37:00 +01:00
Nassim Jahnke 564286d742
Remove version check from config
The platform might now always be available
2024-02-13 23:18:39 +01:00
Nassim Jahnke dcc0642af9
Replace more raw versions with ProtocolVersion 2024-02-13 22:48:08 +01:00
EnZaXD e449599ae7
Add ProtocolVersion#betweenInclusive and ProtocolVersion#betweenExclusive (#3690) 2024-02-13 21:50:19 +01:00
Nassim Jahnke 621c02f974
Move some data out of extending MappingData classes 2024-02-13 18:41:05 +01:00
Nassim Jahnke 22bd350e35
Add proper ProtocolVersion comparison 2024-02-13 18:40:21 +01:00
Nassim Jahnke a8dc5f0f07
Merge branch 'master' into dev
# Conflicts:
#	common/src/main/java/com/viaversion/viaversion/data/entity/DimensionDataImpl.java
#	common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java
#	common/src/main/java/com/viaversion/viaversion/update/UpdateUtil.java
2024-02-12 10:44:03 +01:00
Nassim Jahnke d76edced04
Update template protocol 2024-02-12 10:40:17 +01:00
Nassim Jahnke e0f32d9f2f
Merge remote-tracking branch 'origin/master' into dev 2024-02-08 22:02:25 +01:00
Nassim Jahnke 4a8bd2cca2
24w06a 2024-02-07 18:29:19 +01:00
Nassim Jahnke 0fcb764652
24w05b 2024-02-01 17:49:58 +01:00
Nassim Jahnke 46e322b2f3
Merge branch 'master' into dev 2024-01-31 22:28:22 +01:00
Nassim Jahnke e020c616c9
24w05a 2024-01-31 17:36:12 +01:00
Nassim Jahnke da87241549
Merge branch 'master' into dev
# Conflicts:
#	common/src/main/java/com/viaversion/viaversion/rewriter/ItemRewriter.java
2024-01-29 17:26:49 +01:00
Nassim Jahnke 6473b608f6
Merge branch 'master' into dev
# Conflicts:
#	.github/workflows/gradle.yml
2024-01-27 13:49:48 +01:00
Nassim Jahnke a5bd8abe93
Resize registry data array to actual size once collected 2024-01-27 13:49:27 +01:00
Nassim Jahnke c8d339ab30
Add generic types on base protocols 2024-01-27 13:45:40 +01:00
Nassim Jahnke 8000561ae9
Handle registry data with skipped ids 2024-01-26 16:05:58 +01:00
Nassim Jahnke 1dafa7d273
Cleanup config packet registration in newer protocols 2024-01-26 15:48:10 +01:00
Nassim Jahnke ce8fab7c44
Cleanup config packet registering in AbstractProtocol 2024-01-26 14:35:19 +01:00
Nassim Jahnke 37561705ed
24w04a 2024-01-24 20:23:33 +01:00
Nassim Jahnke 00176c4a0c
Merge branch 'master' into dev 2024-01-24 17:27:04 +01:00
Nassim Jahnke 7b8a33cc78
Small refactor to UpdateUtil 2024-01-20 16:34:18 +01:00
Nassim Jahnke ceae2c2094
Rewrite transfer intention on older servers 2024-01-18 21:44:26 +01:00
Nassim Jahnke 52b9db5029
Handle new client intent 2024-01-18 21:22:44 +01:00
Nassim Jahnke 27af372f79
Block entity tags are no longer nullable 2024-01-18 20:46:25 +01:00
Nassim Jahnke c4e50efa90
24w03b 2024-01-18 16:10:09 +01:00
Nassim Jahnke fa1ae5b9c9
Entity sound did not change 2024-01-18 12:00:19 +01:00
Nassim Jahnke 8f6784e0e2
Respect previous buffer types in particle rewriting 2024-01-18 10:25:58 +01:00
Nassim Jahnke 5d5c98acc6
24w03a (maybe, and it's a bit ugly) 2024-01-17 22:55:16 +01:00
Nassim Jahnke 0946c72bdc
Update missing filterFamily method name change 2024-01-12 16:01:30 +01:00
Nassim Jahnke 05470c5f1b
Merge branch 'master' into dev 2024-01-12 15:59:42 +01:00
Nassim Jahnke 34bd15dec7
Merge branch 'master' into dev
# Conflicts:
#	template/src/main/java/com/viaversion/viaversion/template/protocols/rewriter/EntityPacketRewriter1_99.java
2024-01-12 10:30:24 +01:00
Nassim Jahnke abb05ce902
Merge remote-tracking branch 'origin/master' into dev 2024-01-04 17:50:24 +01:00
Nassim Jahnke fe0fbc7081
Merge branch 'master' into dev
# Conflicts:
#	common/src/main/java/com/viaversion/viaversion/util/NBTConverter.java
2023-12-29 16:50:47 +01:00
RK_01 00b8d22cf6
Fix 1.19 -> 1.18.2 ENTITY_EFFECT translation (#3605) 2023-12-27 22:11:34 +01:00
Nassim Jahnke d62284e9cd
Make NBTConverter public 2023-12-27 20:20:09 +01:00
Nassim Jahnke 3904ed4fd7
Merge branch 'master' into dev 2023-12-27 19:44:46 +01:00
RK_01 64c436c2e1
Handle invalid config data types (#3595) 2023-12-26 13:18:55 +01:00
Kichura 84b093a997
[ci skip] Update setup-java to v4 (#3589) 2023-12-21 09:27:06 +01:00
Nassim Jahnke 794f401bd0
Add armadildo state meta type 2023-12-18 19:34:53 +01:00
Nassim Jahnke dc732fac6f
23w51b 2023-12-18 18:52:18 +01:00
Nassim Jahnke 2f8114abb1
Finish 23w51a, maybe 2023-12-18 17:14:24 +01:00
Nassim Jahnke 90781c9d27
Start working on 23w51a 2023-12-18 15:58:49 +01:00
423 changed files with 17462 additions and 4387 deletions

View File

@ -10,4 +10,7 @@ ij_java_class_count_to_use_import_on_demand = 999999
ij_java_names_count_to_use_import_on_demand = 999999
ij_java_imports_layout = *,|,$*
ij_java_generate_final_locals = true
ij_java_generate_final_parameters = true
ij_java_generate_final_parameters = true
[{*.json,*.yml}]
indent_size = 2

View File

@ -13,7 +13,7 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
uses: gradle/wrapper-validation-action@v2
- name: Set up JDK 17
uses: actions/setup-java@v4
with:

View File

@ -13,7 +13,7 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
uses: gradle/wrapper-validation-action@v2
- name: Set up JDK 17
uses: actions/setup-java@v4
with:

View File

@ -23,7 +23,7 @@
package us.myles.ViaVersion.api.protocol;
import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.protocol.version.VersionRange;
import com.viaversion.viaversion.api.protocol.version.SubVersionRange;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.util.ArrayList;
@ -42,23 +42,23 @@ public class ProtocolVersion {
private static final Int2ObjectMap<ProtocolVersion> versions = new Int2ObjectOpenHashMap<>();
private static final List<ProtocolVersion> versionList = new ArrayList<>();
public static final ProtocolVersion v1_4_6 = register(51, "1.4.6/7", new VersionRange("1.4", 6, 7));
public static final ProtocolVersion v1_4_6 = register(51, "1.4.6/7", new SubVersionRange("1.4", 6, 7));
public static final ProtocolVersion v1_5_1 = register(60, "1.5.1");
public static final ProtocolVersion v1_5_2 = register(61, "1.5.2");
public static final ProtocolVersion v_1_6_1 = register(73, "1.6.1");
public static final ProtocolVersion v_1_6_2 = register(74, "1.6.2");
public static final ProtocolVersion v_1_6_3 = register(77, "1.6.3");
public static final ProtocolVersion v_1_6_4 = register(78, "1.6.4");
public static final ProtocolVersion v1_7_1 = register(4, "1.7-1.7.5", new VersionRange("1.7", 0, 5));
public static final ProtocolVersion v1_7_6 = register(5, "1.7.6-1.7.10", new VersionRange("1.7", 6, 10));
public static final ProtocolVersion v1_7_1 = register(4, "1.7-1.7.5", new SubVersionRange("1.7", 0, 5));
public static final ProtocolVersion v1_7_6 = register(5, "1.7.6-1.7.10", new SubVersionRange("1.7", 6, 10));
public static final ProtocolVersion v1_8 = register(47, "1.8.x");
public static final ProtocolVersion v1_9 = register(107, "1.9");
public static final ProtocolVersion v1_9_1 = register(108, "1.9.1");
public static final ProtocolVersion v1_9_2 = register(109, "1.9.2");
public static final ProtocolVersion v1_9_3 = register(110, "1.9.3/4", new VersionRange("1.9", 3, 4));
public static final ProtocolVersion v1_9_3 = register(110, "1.9.3/1.9.4", new SubVersionRange("1.9", 3, 4));
public static final ProtocolVersion v1_10 = register(210, "1.10.x");
public static final ProtocolVersion v1_11 = register(315, "1.11");
public static final ProtocolVersion v1_11_1 = register(316, "1.11.1/2", new VersionRange("1.11", 1, 2));
public static final ProtocolVersion v1_11_1 = register(316, "1.11.1/1.11.2", new SubVersionRange("1.11", 1, 2));
public static final ProtocolVersion v1_12 = register(335, "1.12");
public static final ProtocolVersion v1_12_1 = register(338, "1.12.1");
public static final ProtocolVersion v1_12_2 = register(340, "1.12.2");
@ -77,18 +77,19 @@ public class ProtocolVersion {
public static final ProtocolVersion v1_16_1 = register(736, "1.16.1");
public static final ProtocolVersion v1_16_2 = register(751, "1.16.2");
public static final ProtocolVersion v1_16_3 = register(753, "1.16.3");
public static final ProtocolVersion v1_16_4 = register(754, "1.16.4/5", new VersionRange("1.16", 4, 5));
public static final ProtocolVersion v1_16_4 = register(754, "1.16.4/1.16.5", new SubVersionRange("1.16", 4, 5));
public static final ProtocolVersion v1_17 = register(755, "1.17");
public static final ProtocolVersion v1_17_1 = register(756, "1.17.1");
public static final ProtocolVersion v1_18 = register(757, "1.18/1.18.1", new VersionRange("1.18", 0, 1));
public static final ProtocolVersion v1_18 = register(757, "1.18/1.18.1", new SubVersionRange("1.18", 0, 1));
public static final ProtocolVersion v1_18_2 = register(758, "1.18.2");
public static final ProtocolVersion v1_19 = register(759, "1.19");
public static final ProtocolVersion v1_19_1 = register(760, "1.19.1/2", new VersionRange("1.19", 1, 2));
public static final ProtocolVersion v1_19_1 = register(760, "1.19.1/1.19.2", new SubVersionRange("1.19", 1, 2));
public static final ProtocolVersion v1_19_3 = register(761, "1.19.3");
public static final ProtocolVersion v1_19_4 = register(762, "1.19.4");
public static final ProtocolVersion v1_20 = register(763, "1.20/1.20.1", new VersionRange("1.20", 0, 1));
public static final ProtocolVersion v1_20 = register(763, "1.20/1.20.1", new SubVersionRange("1.20", 0, 1));
public static final ProtocolVersion v1_20_2 = register(764, "1.20.2");
public static final ProtocolVersion v1_20_3 = register(765, "1.20.3");
public static final ProtocolVersion v1_20_3 = register(765, "1.20.3/1.20.4", new SubVersionRange("1.20", 3, 4));
public static final ProtocolVersion v1_20_5 = register(766, "1.20.5");
public static final ProtocolVersion unknown = register(-1, "UNKNOWN");
public static ProtocolVersion register(int version, String name) {
@ -99,11 +100,11 @@ public class ProtocolVersion {
return register(version, snapshotVersion, name, null);
}
public static ProtocolVersion register(int version, String name, @Nullable VersionRange versionRange) {
public static ProtocolVersion register(int version, String name, @Nullable SubVersionRange versionRange) {
return register(version, -1, name, versionRange);
}
public static ProtocolVersion register(int version, int snapshotVersion, String name, @Nullable VersionRange versionRange) {
public static ProtocolVersion register(int version, int snapshotVersion, String name, @Nullable SubVersionRange versionRange) {
ProtocolVersion protocol = new ProtocolVersion(version, snapshotVersion, name, versionRange);
versionList.add(protocol);
versions.put(protocol.getVersion(), protocol);
@ -166,7 +167,7 @@ public class ProtocolVersion {
this(version, -1, name, null);
}
public ProtocolVersion(int version, int snapshotVersion, String name, @Nullable VersionRange versionRange) {
public ProtocolVersion(int version, int snapshotVersion, String name, @Nullable SubVersionRange versionRange) {
this.version = version;
this.snapshotVersion = snapshotVersion;
this.name = name;

View File

@ -16,8 +16,6 @@ sourceSets {
dependencies {
api(libs.fastutil)
api(libs.flare)
api(libs.flareFastutil)
api(libs.vianbt)
api(libs.gson)
implementation(rootProject.libs.text) {

View File

@ -27,10 +27,13 @@ import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.legacy.LegacyViaAPI;
import com.viaversion.viaversion.api.platform.ViaPlatform;
import com.viaversion.viaversion.api.protocol.ProtocolManager;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.protocol.version.ServerProtocolVersion;
import io.netty.buffer.ByteBuf;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.UUID;
import java.util.stream.Collectors;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
@ -63,7 +66,7 @@ public interface ViaAPI<T> {
* @return API version incremented with meaningful API changes
*/
default int apiVersion() {
return 23;
return 26;
}
/**
@ -80,7 +83,18 @@ public interface ViaAPI<T> {
* @param player the platform's player object, e.g. Bukkit this is Player
* @return protocol version, for example (47=1.8-1.8.8, 107=1.9, 108=1.9.1), or -1 if no longer connected
*/
int getPlayerVersion(T player);
default int getPlayerVersion(T player) {
return getPlayerProtocolVersion(player).getVersion();
}
/**
* Returns the protocol version of a player.
* This will also retrieve the version from ProtocolSupport if it's being used.
*
* @param player the platform's player object, e.g. Bukkit this is Player
* @return the protocol version object (see {@link ProtocolVersion}), or ProtocolVersion.unknown if not connected
*/
ProtocolVersion getPlayerProtocolVersion(T player);
/**
* Returns the protocol version of a player.
@ -88,7 +102,19 @@ public interface ViaAPI<T> {
* @param uuid UUID of a player
* @return protocol version, for example (47=1.8-1.8.8, 107=1.9, 108=1.9.1), or -1 if not connected
*/
int getPlayerVersion(UUID uuid);
default int getPlayerVersion(UUID uuid) {
return getPlayerProtocolVersion(uuid).getVersion();
}
/**
* Returns the protocol version of a player.
* This will also retrieve the version from ProtocolSupport if it's being used.
*
* @param uuid UUID of a player
* @return the protocol version object (see {@link ProtocolVersion}), or ProtocolVersion.unknown if not connected
*/
ProtocolVersion getPlayerProtocolVersion(UUID uuid);
/**
* Returns whether Via injected into this player connection.
@ -131,6 +157,16 @@ public interface ViaAPI<T> {
*/
void sendRawPacket(UUID uuid, ByteBuf packet);
@Deprecated
default SortedSet<Integer> getSupportedVersions() {
return getSupportedProtocolVersions().stream().map(ProtocolVersion::getVersion).collect(Collectors.toCollection(TreeSet::new));
}
@Deprecated
default SortedSet<Integer> getFullSupportedVersions() {
return getFullSupportedProtocolVersions().stream().map(ProtocolVersion::getVersion).collect(Collectors.toCollection(TreeSet::new));
}
/**
* Returns the supported protocol versions.
* This method removes any blocked protocol versions.
@ -138,14 +174,15 @@ public interface ViaAPI<T> {
* @return a sorted set of protocol versions
* @see #getFullSupportedVersions() for a full list
*/
SortedSet<Integer> getSupportedVersions();
SortedSet<ProtocolVersion> getSupportedProtocolVersions();
/**
* Returns the supported protocol versions, including blocked protocols.
*
* @return a sorted set of protocol versions
*/
SortedSet<Integer> getFullSupportedVersions();
SortedSet<ProtocolVersion> getFullSupportedProtocolVersions();
/**
* Returns legacy api only applicable on/to legacy versions.

View File

@ -27,8 +27,6 @@ import com.viaversion.viaversion.api.connection.StorableObject;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.WorldIdentifiers;
import com.viaversion.viaversion.api.protocol.version.BlockedProtocolVersions;
import it.unimi.dsi.fastutil.ints.IntSet;
import org.checkerframework.checker.nullness.qual.Nullable;
public interface ViaVersionConfig extends Config {
@ -235,13 +233,6 @@ public interface ViaVersionConfig extends Config {
*/
boolean isChunkBorderFix();
/**
* Force json transform
*
* @return true if enabled
*/
boolean isForceJsonTransform();
/**
* Should we fix nbt array's in json chat messages for 1.12 clients
*
@ -272,17 +263,6 @@ public interface ViaVersionConfig extends Config {
*/
BlockedProtocolVersions blockedProtocolVersions();
/**
* Get the blocked protocols
*
* @return An Integer list
* @deprecated use {@link #blockedProtocolVersions()}
*/
@Deprecated/*(forRemoval = true)*/
default IntSet getBlockedProtocols() {
return blockedProtocolVersions().singleBlockedVersions();
}
/**
* Get the custom disconnect message
*
@ -463,4 +443,18 @@ public interface ViaVersionConfig extends Config {
* @return true if enabled
*/
boolean isArmorToggleFix();
/**
* If disabled, tamed cats will be displayed as ocelots to 1.14+ clients on 1.13 servers. Otherwise, ocelots (tamed and untamed) will be displayed as cats.
*
* @return true if enabled
*/
boolean translateOcelotToCat();
/**
* Returns the value of the "enforce secure chat" setting sent to 1.19+ clients on join.
*
* @return the value sent to 1.19+ clients on join
*/
boolean enforceSecureChat();
}

View File

@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.connection;
import com.viaversion.viaversion.api.protocol.ProtocolPipeline;
import com.viaversion.viaversion.api.protocol.packet.Direction;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import java.util.UUID;
import org.checkerframework.checker.nullness.qual.Nullable;
@ -93,24 +94,36 @@ public interface ProtocolInfo {
void setServerState(State serverState);
/**
* Returns the user's protocol version, or -1 if not set.
* Returns the user's protocol version, or null if not set.
* This is set during the {@link State#HANDSHAKE} state.
*
* @return protocol version, or -1 if not set
* @return protocol version, may be unknown
* @see ProtocolVersion#isKnown()
*/
int getProtocolVersion();
ProtocolVersion protocolVersion();
void setProtocolVersion(int protocolVersion);
void setProtocolVersion(ProtocolVersion protocolVersion);
/**
* Returns the server protocol version the user is connected to, or -1 if not set.
* Returns the server protocol version the user is connected to.
* This is set during the {@link State#HANDSHAKE} state.
*
* @return server protocol version, or -1 if not set
* @return the server protocol version the user is connected to, may be unknown
* @see ProtocolVersion#isKnown()
*/
int getServerProtocolVersion();
ProtocolVersion serverProtocolVersion();
void setServerProtocolVersion(int serverProtocolVersion);
void setServerProtocolVersion(ProtocolVersion protocolVersion);
@Deprecated
default int getProtocolVersion() {
return protocolVersion() != null ? protocolVersion().getVersion() : -1;
}
@Deprecated
default int getServerProtocolVersion() {
return serverProtocolVersion() != null ? serverProtocolVersion().getVersion() : -1;
}
/**
* Returns the username associated with this connection.

View File

@ -27,7 +27,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Mappings containing the full string identifier mappings.
*/
public interface FullMappings extends Mappings {
public interface FullMappings extends BiMappings {
/**
* Returns the unmapped integer id for the given identifier, or -1 if not found.
@ -49,17 +49,17 @@ public interface FullMappings extends Mappings {
* Returns the unmapped string identifier for the given mapped id.
*
* @param id unmapped id
* @return unmapped string identifier
* @return unmapped string identifier, or null if out of bounds
*/
String identifier(int id);
@Nullable String identifier(int id);
/**
* Returns the mapped string identifier for the given mapped id.
*
* @param mappedId mapped id
* @return mapped string identifier
* @return mapped string identifier, or null if out of bounds
*/
String mappedIdentifier(int mappedId);
@Nullable String mappedIdentifier(int mappedId);
/**
* Returns the mapped string identifier for the given unmapped identifier.

View File

@ -22,6 +22,7 @@
*/
package com.viaversion.viaversion.api.data;
import com.google.common.base.Preconditions;
import com.viaversion.viaversion.util.Key;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
@ -37,6 +38,7 @@ public class FullMappingsBase implements FullMappings {
private final Mappings mappings;
public FullMappingsBase(final List<String> unmappedIdentifiers, final List<String> mappedIdentifiers, final Mappings mappings) {
Preconditions.checkNotNull(mappings, "Mappings cannot be null");
this.mappings = mappings;
this.stringToId = toInverseMap(unmappedIdentifiers);
this.mappedStringToId = toInverseMap(mappedIdentifiers);
@ -64,12 +66,20 @@ public class FullMappingsBase implements FullMappings {
@Override
public String identifier(final int id) {
if (id < 0 || id >= idToString.length) {
return null;
}
final String identifier = idToString[id];
return Key.namespaced(identifier);
}
@Override
public String mappedIdentifier(final int mappedId) {
if (mappedId < 0 || mappedId >= mappedIdToString.length) {
return null;
}
final String identifier = mappedIdToString[mappedId];
return Key.namespaced(identifier);
}

View File

@ -79,6 +79,8 @@ public interface MappingData {
*/
int getNewParticleId(int id);
int getNewAttributeId(int id);
/**
* Returns a list of tags to send if present.
*
@ -87,8 +89,21 @@ public interface MappingData {
*/
@Nullable List<TagData> getTags(RegistryType type);
/**
* Returns item mappings.
*
* @return item mappings
*/
@Nullable BiMappings getItemMappings();
/**
* Returns item mappings if they also have identifier data present.
*
* @return item mappings if they also have identifier data present
* @see #getItemMappings()
*/
@Nullable FullMappings getFullItemMappings();
@Nullable ParticleMappings getParticleMappings();
@Nullable Mappings getBlockMappings();
@ -105,9 +120,15 @@ public interface MappingData {
@Nullable Mappings getEnchantmentMappings();
@Nullable Mappings getAttributeMappings();
@Nullable Mappings getPaintingMappings();
@Nullable FullMappings getEntityMappings();
@Nullable FullMappings getArgumentTypeMappings();
@Nullable Mappings getPaintingMappings();
@Nullable FullMappings getRecipeSerializerMappings();
@Nullable FullMappings getDataComponentSerializerMappings();
}

View File

@ -24,7 +24,6 @@ package com.viaversion.viaversion.api.data;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.RegistryType;
@ -34,7 +33,6 @@ import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.checkerframework.checker.nullness.qual.Nullable;
public class MappingDataBase implements MappingData {
@ -44,6 +42,8 @@ public class MappingDataBase implements MappingData {
protected BiMappings itemMappings;
protected FullMappings argumentTypeMappings;
protected FullMappings entityMappings;
protected FullMappings recipeSerializerMappings;
protected FullMappings itemDataSerializerMappings;
protected ParticleMappings particleMappings;
protected Mappings blockMappings;
protected Mappings blockStateMappings;
@ -53,6 +53,7 @@ public class MappingDataBase implements MappingData {
protected Mappings enchantmentMappings;
protected Mappings paintingMappings;
protected Mappings menuMappings;
protected Mappings attributeMappings;
protected Map<RegistryType, List<TagData>> tags;
public MappingDataBase(final String unmappedVersion, final String mappedVersion) {
@ -66,7 +67,7 @@ public class MappingDataBase implements MappingData {
getLogger().info("Loading " + unmappedVersion + " -> " + mappedVersion + " mappings...");
}
final CompoundTag data = readNBTFile("mappings-" + unmappedVersion + "to" + mappedVersion + ".nbt");
final CompoundTag data = readMappingsFile("mappings-" + unmappedVersion + "to" + mappedVersion + ".nbt");
blockMappings = loadMappings(data, "blocks");
blockStateMappings = loadMappings(data, "blockstates");
blockEntityMappings = loadMappings(data, "blockentities");
@ -75,29 +76,33 @@ public class MappingDataBase implements MappingData {
menuMappings = loadMappings(data, "menus");
enchantmentMappings = loadMappings(data, "enchantments");
paintingMappings = loadMappings(data, "paintings");
itemMappings = loadBiMappings(data, "items");
attributeMappings = loadMappings(data, "attributes");
final CompoundTag unmappedIdentifierData = MappingDataLoader.loadNBT("identifiers-" + unmappedVersion + ".nbt", true);
final CompoundTag mappedIdentifierData = MappingDataLoader.loadNBT("identifiers-" + mappedVersion + ".nbt", true);
final CompoundTag unmappedIdentifierData = readUnmappedIdentifiersFile("identifiers-" + unmappedVersion + ".nbt");
final CompoundTag mappedIdentifierData = readMappedIdentifiersFile("identifiers-" + mappedVersion + ".nbt");
if (unmappedIdentifierData != null && mappedIdentifierData != null) {
itemMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "items");
entityMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "entities");
argumentTypeMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "argumenttypes");
recipeSerializerMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "recipe_serializers");
itemDataSerializerMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "data_component_type");
final ListTag unmappedParticles = unmappedIdentifierData.get("particles");
final ListTag mappedParticles = mappedIdentifierData.get("particles");
final List<String> unmappedParticles = identifiersFromGlobalIds(unmappedIdentifierData, "particles");
final List<String> mappedParticles = identifiersFromGlobalIds(mappedIdentifierData, "particles");
if (unmappedParticles != null && mappedParticles != null) {
Mappings particleMappings = loadMappings(data, "particles");
if (particleMappings == null) {
particleMappings = new IdentityMappings(unmappedParticles.size(), mappedParticles.size());
}
final List<String> identifiers = unmappedParticles.getValue().stream().map(t -> (String) t.getValue()).collect(Collectors.toList());
final List<String> mappedIdentifiers = mappedParticles.getValue().stream().map(t -> (String) t.getValue()).collect(Collectors.toList());
this.particleMappings = new ParticleMappings(identifiers, mappedIdentifiers, particleMappings);
this.particleMappings = new ParticleMappings(unmappedParticles, mappedParticles, particleMappings);
}
} else {
// Might not have identifiers in older versions
itemMappings = loadBiMappings(data, "items");
}
final CompoundTag tagsTag = data.get("tags");
final CompoundTag tagsTag = data.getCompoundTag("tags");
if (tagsTag != null) {
this.tags = new EnumMap<>(RegistryType.class);
loadTags(RegistryType.ITEM, tagsTag);
@ -107,16 +112,39 @@ public class MappingDataBase implements MappingData {
loadExtras(data);
}
protected @Nullable CompoundTag readNBTFile(final String name) {
return MappingDataLoader.loadNBT(name);
protected @Nullable List<String> identifiersFromGlobalIds(final CompoundTag mappingsTag, final String key) {
return MappingDataLoader.INSTANCE.identifiersFromGlobalIds(mappingsTag, key);
}
protected @Nullable CompoundTag readMappingsFile(final String name) {
return MappingDataLoader.INSTANCE.loadNBT(name);
}
protected @Nullable CompoundTag readUnmappedIdentifiersFile(final String name) {
return MappingDataLoader.INSTANCE.loadNBT(name, true);
}
protected @Nullable CompoundTag readMappedIdentifiersFile(final String name) {
return MappingDataLoader.INSTANCE.loadNBT(name, true);
}
protected @Nullable Mappings loadMappings(final CompoundTag data, final String key) {
return MappingDataLoader.loadMappings(data, key);
return MappingDataLoader.INSTANCE.loadMappings(data, key);
}
protected @Nullable FullMappings loadFullMappings(final CompoundTag data, final CompoundTag unmappedIdentifiers, final CompoundTag mappedIdentifiers, final String key) {
return MappingDataLoader.loadFullMappings(data, unmappedIdentifiers, mappedIdentifiers, key);
protected @Nullable FullMappings loadFullMappings(final CompoundTag data, final CompoundTag unmappedIdentifiersTag, final CompoundTag mappedIdentifiersTag, final String key) {
if (!unmappedIdentifiersTag.contains(key) || !mappedIdentifiersTag.contains(key)) {
return null;
}
final List<String> unmappedIdentifiers = identifiersFromGlobalIds(unmappedIdentifiersTag, key);
final List<String> mappedIdentifiers = identifiersFromGlobalIds(mappedIdentifiersTag, key);
Mappings mappings = loadBiMappings(data, key); // Load as bi-mappings to keep the inverse cached
if (mappings == null) {
mappings = new IdentityMappings(unmappedIdentifiers.size(), mappedIdentifiers.size());
}
return new FullMappingsBase(unmappedIdentifiers, mappedIdentifiers, mappings);
}
protected @Nullable BiMappings loadBiMappings(final CompoundTag data, final String key) {
@ -125,7 +153,7 @@ public class MappingDataBase implements MappingData {
}
private void loadTags(final RegistryType type, final CompoundTag data) {
final CompoundTag tag = data.get(type.resourceLocation());
final CompoundTag tag = data.getCompoundTag(type.resourceLocation());
if (tag == null) {
return;
}
@ -164,6 +192,11 @@ public class MappingDataBase implements MappingData {
return checkValidity(id, particleMappings.getNewId(id), "particles");
}
@Override
public int getNewAttributeId(final int id) {
return checkValidity(id, attributeMappings.getNewId(id), "attributes");
}
@Override
public @Nullable List<TagData> getTags(final RegistryType type) {
return tags != null ? tags.get(type) : null;
@ -174,6 +207,14 @@ public class MappingDataBase implements MappingData {
return itemMappings;
}
@Override
public @Nullable FullMappings getFullItemMappings() {
if (itemMappings instanceof FullMappings) {
return (FullMappings) itemMappings;
}
return null;
}
@Override
public @Nullable ParticleMappings getParticleMappings() {
return particleMappings;
@ -214,6 +255,11 @@ public class MappingDataBase implements MappingData {
return enchantmentMappings;
}
@Override
public @Nullable Mappings getAttributeMappings() {
return attributeMappings;
}
@Override
public @Nullable FullMappings getEntityMappings() {
return entityMappings;
@ -224,11 +270,21 @@ public class MappingDataBase implements MappingData {
return argumentTypeMappings;
}
@Override
public @Nullable FullMappings getDataComponentSerializerMappings() {
return itemDataSerializerMappings;
}
@Override
public @Nullable Mappings getPaintingMappings() {
return paintingMappings;
}
@Override
public @Nullable FullMappings getRecipeSerializerMappings() {
return recipeSerializerMappings;
}
protected Logger getLogger() {
return Via.getPlatform().getLogger();
}

View File

@ -27,6 +27,8 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.github.steveice10.opennbt.tag.io.NBTIO;
import com.github.steveice10.opennbt.tag.io.TagReader;
import com.google.common.annotations.Beta;
@ -39,29 +41,76 @@ import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.util.GsonUtil;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.logging.Logger;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class MappingDataLoader {
public class MappingDataLoader {
private static final Map<String, CompoundTag> MAPPINGS_CACHE = new HashMap<>();
private static final TagReader<CompoundTag> MAPPINGS_READER = NBTIO.reader(CompoundTag.class).named();
public static final MappingDataLoader INSTANCE = new MappingDataLoader(MappingDataLoader.class, "assets/viaversion/data/");
public static final TagReader<CompoundTag> MAPPINGS_READER = NBTIO.reader(CompoundTag.class).named();
private static final Map<String, String[]> GLOBAL_IDENTIFIER_INDEXES = new HashMap<>();
private static final byte DIRECT_ID = 0;
private static final byte SHIFTS_ID = 1;
private static final byte CHANGES_ID = 2;
private static final byte IDENTITY_ID = 3;
private static boolean cacheValid = true;
public static void clearCache() {
MAPPINGS_CACHE.clear();
private final Map<String, CompoundTag> mappingsCache = new HashMap<>();
private final Class<?> dataLoaderClass;
private final String dataPath;
private boolean cacheValid = true;
public MappingDataLoader(final Class<?> dataLoaderClass, final String dataPath) {
this.dataLoaderClass = dataLoaderClass;
this.dataPath = dataPath;
}
public static void loadGlobalIdentifiers() {
// Load in a file with all the identifiers we need, so that we don't need to duplicate them
// for every single new version with only a couple of changes in them.
final CompoundTag globalIdentifiers = INSTANCE.loadNBT("identifier-table.nbt");
for (final Map.Entry<String, Tag> entry : globalIdentifiers.entrySet()) {
//noinspection unchecked
final ListTag<StringTag> value = (ListTag<StringTag>) entry.getValue();
final String[] array = new String[value.size()];
for (int i = 0, size = value.size(); i < size; i++) {
array[i] = value.get(i).getValue();
}
GLOBAL_IDENTIFIER_INDEXES.put(entry.getKey(), array);
}
}
/**
* Returns the global id of the identifier in the registry.
*
* @param registry registry key
* @param globalId global id
* @return identifier
* @throws IllegalArgumentException if the registry key is invalid
*/
public @Nullable String identifierFromGlobalId(final String registry, final int globalId) {
final String[] array = GLOBAL_IDENTIFIER_INDEXES.get(registry);
if (array == null) {
throw new IllegalArgumentException("Unknown global identifier key: " + registry);
}
if (globalId < 0 || globalId >= array.length) {
throw new IllegalArgumentException("Unknown global identifier index: " + globalId);
}
return array[globalId];
}
public void clearCache() {
mappingsCache.clear();
cacheValid = false;
}
@ -70,8 +119,8 @@ public final class MappingDataLoader {
*
* @return loaded json object, or null if not found or invalid
*/
public static @Nullable JsonObject loadFromDataDir(final String name) {
final File file = new File(Via.getPlatform().getDataFolder(), name);
public @Nullable JsonObject loadFromDataDir(final String name) {
final File file = new File(getDataFolder(), name);
if (!file.exists()) {
return loadData(name);
}
@ -81,7 +130,7 @@ public final class MappingDataLoader {
return GsonUtil.getGson().fromJson(reader, JsonObject.class);
} catch (final JsonSyntaxException e) {
// Users might mess up the format, so let's catch the syntax error
Via.getPlatform().getLogger().warning(name + " is badly formatted!");
getLogger().warning(name + " is badly formatted!");
throw new RuntimeException(e);
} catch (final IOException | JsonIOException e) {
throw new RuntimeException(e);
@ -93,7 +142,7 @@ public final class MappingDataLoader {
*
* @return loaded json object from bundled resources if present
*/
public static @Nullable JsonObject loadData(final String name) {
public @Nullable JsonObject loadData(final String name) {
final InputStream stream = getResource(name);
if (stream == null) {
return null;
@ -106,12 +155,12 @@ public final class MappingDataLoader {
}
}
public static @Nullable CompoundTag loadNBT(final String name, final boolean cache) {
public @Nullable CompoundTag loadNBT(final String name, final boolean cache) {
if (!cacheValid) {
return loadNBTFromFile(name);
}
CompoundTag data = MAPPINGS_CACHE.get(name);
CompoundTag data = mappingsCache.get(name);
if (data != null) {
return data;
}
@ -119,29 +168,29 @@ public final class MappingDataLoader {
data = loadNBTFromFile(name);
if (cache && data != null) {
MAPPINGS_CACHE.put(name, data);
mappingsCache.put(name, data);
}
return data;
}
public static @Nullable CompoundTag loadNBT(final String name) {
public @Nullable CompoundTag loadNBT(final String name) {
return loadNBT(name, false);
}
public static @Nullable CompoundTag loadNBTFromFile(final String name) {
public @Nullable CompoundTag loadNBTFromFile(final String name) {
final InputStream resource = getResource(name);
if (resource == null) {
return null;
}
try (final InputStream stream = resource) {
try (final InputStream stream = new BufferedInputStream(resource)) {
return MAPPINGS_READER.read(stream);
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
public static @Nullable Mappings loadMappings(final CompoundTag mappingsTag, final String key) {
public @Nullable Mappings loadMappings(final CompoundTag mappingsTag, final String key) {
return loadMappings(mappingsTag, key, size -> {
final int[] array = new int[size];
Arrays.fill(array, -1);
@ -150,29 +199,29 @@ public final class MappingDataLoader {
}
@Beta
public static <M extends Mappings, V> @Nullable Mappings loadMappings(
final CompoundTag mappingsTag,
final String key,
final MappingHolderSupplier<V> holderSupplier,
final AddConsumer<V> addConsumer,
final MappingsSupplier<M, V> mappingsSupplier
public <M extends Mappings, V> @Nullable Mappings loadMappings(
final CompoundTag mappingsTag,
final String key,
final MappingHolderSupplier<V> holderSupplier,
final AddConsumer<V> addConsumer,
final MappingsSupplier<M, V> mappingsSupplier
) {
final CompoundTag tag = mappingsTag.get(key);
final CompoundTag tag = mappingsTag.getCompoundTag(key);
if (tag == null) {
return null;
}
final ByteTag serializationStragetyTag = tag.get("id");
final IntTag mappedSizeTag = tag.get("mappedSize");
final ByteTag serializationStragetyTag = tag.getUnchecked("id");
final IntTag mappedSizeTag = tag.getUnchecked("mappedSize");
final byte strategy = serializationStragetyTag.asByte();
final V mappings;
if (strategy == DIRECT_ID) {
final IntArrayTag valuesTag = tag.get("val");
final IntArrayTag valuesTag = tag.getIntArrayTag("val");
return IntArrayMappings.of(valuesTag.getValue(), mappedSizeTag.asInt());
} else if (strategy == SHIFTS_ID) {
final IntArrayTag shiftsAtTag = tag.get("at");
final IntArrayTag shiftsTag = tag.get("to");
final IntTag sizeTag = tag.get("size");
final IntArrayTag shiftsAtTag = tag.getIntArrayTag("at");
final IntArrayTag shiftsTag = tag.getIntArrayTag("to");
final IntTag sizeTag = tag.getUnchecked("size");
final int[] shiftsAt = shiftsAtTag.getValue();
final int[] shiftsTo = shiftsTag.getValue();
final int size = sizeTag.asInt();
@ -196,9 +245,9 @@ public final class MappingDataLoader {
}
}
} else if (strategy == CHANGES_ID) {
final IntArrayTag changesAtTag = tag.get("at");
final IntArrayTag valuesTag = tag.get("val");
final IntTag sizeTag = tag.get("size");
final IntArrayTag changesAtTag = tag.getIntArrayTag("at");
final IntArrayTag valuesTag = tag.getIntArrayTag("val");
final IntTag sizeTag = tag.getUnchecked("size");
final boolean fillBetween = tag.get("nofill") == null;
final int[] changesAt = changesAtTag.getValue();
final int[] values = valuesTag.getValue();
@ -218,7 +267,7 @@ public final class MappingDataLoader {
addConsumer.addTo(mappings, id, values[i]);
}
} else if (strategy == IDENTITY_ID) {
final IntTag sizeTag = tag.get("size");
final IntTag sizeTag = tag.getUnchecked("size");
return new IdentityMappings(sizeTag.asInt(), mappedSizeTag.asInt());
} else {
throw new IllegalArgumentException("Unknown serialization strategy: " + strategy);
@ -226,23 +275,17 @@ public final class MappingDataLoader {
return mappingsSupplier.create(mappings, mappedSizeTag.asInt());
}
public static FullMappings loadFullMappings(final CompoundTag mappingsTag, final CompoundTag unmappedIdentifiers, final CompoundTag mappedIdentifiers, final String key) {
final ListTag unmappedElements = unmappedIdentifiers.get(key);
final ListTag mappedElements = mappedIdentifiers.get(key);
if (unmappedElements == null || mappedElements == null) {
public @Nullable List<String> identifiersFromGlobalIds(final CompoundTag mappingsTag, final String key) {
final Mappings mappings = loadMappings(mappingsTag, key);
if (mappings == null) {
return null;
}
Mappings mappings = loadMappings(mappingsTag, key);
if (mappings == null) {
mappings = new IdentityMappings(unmappedElements.size(), mappedElements.size());
final List<String> identifiers = new ArrayList<>(mappings.size());
for (int i = 0; i < mappings.size(); i++) {
identifiers.add(identifierFromGlobalId(key, mappings.getNewId(i)));
}
return new FullMappingsBase(
unmappedElements.getValue().stream().map(t -> (String) t.getValue()).collect(Collectors.toList()),
mappedElements.getValue().stream().map(t -> (String) t.getValue()).collect(Collectors.toList()),
mappings
);
return identifiers;
}
/**
@ -251,7 +294,7 @@ public final class MappingDataLoader {
* @param object json object
* @return map with indexes hashed by their id value
*/
public static Object2IntMap<String> indexedObjectToMap(final JsonObject object) {
public Object2IntMap<String> indexedObjectToMap(final JsonObject object) {
final Object2IntMap<String> map = new Object2IntOpenHashMap<>(object.size(), .99F);
map.defaultReturnValue(-1);
for (final Map.Entry<String, JsonElement> entry : object.entrySet()) {
@ -266,7 +309,7 @@ public final class MappingDataLoader {
* @param array json array
* @return map with indexes hashed by their id value
*/
public static Object2IntMap<String> arrayToMap(final JsonArray array) {
public Object2IntMap<String> arrayToMap(final JsonArray array) {
final Object2IntMap<String> map = new Object2IntOpenHashMap<>(array.size(), .99F);
map.defaultReturnValue(-1);
for (int i = 0; i < array.size(); i++) {
@ -275,8 +318,16 @@ public final class MappingDataLoader {
return map;
}
public static @Nullable InputStream getResource(final String name) {
return MappingDataLoader.class.getClassLoader().getResourceAsStream("assets/viaversion/data/" + name);
public Logger getLogger() {
return Via.getPlatform().getLogger();
}
public File getDataFolder() {
return Via.getPlatform().getDataFolder();
}
public @Nullable InputStream getResource(final String name) {
return dataLoaderClass.getClassLoader().getResourceAsStream(dataPath + name);
}
@FunctionalInterface

View File

@ -84,10 +84,4 @@ public interface Mappings {
* @return mappings with keys and values swapped
*/
Mappings inverse();
@FunctionalInterface
interface MappingsSupplier<T extends Mappings> {
T supply(int[] mappings, int mappedIds);
}
}

View File

@ -35,6 +35,7 @@ public class ParticleMappings extends FullMappingsBase {
addBlockParticle("block");
addBlockParticle("falling_dust");
addBlockParticle("block_marker");
addBlockParticle("dust_pillar");
addItemParticle("item");
}

View File

@ -24,6 +24,8 @@ package com.viaversion.viaversion.api.data.entity;
public interface DimensionData {
int id();
int minY();
int height();

View File

@ -34,6 +34,7 @@ public interface EntityTracker {
*
* @return user connection
*/
@Deprecated
UserConnection user();
/**
@ -165,6 +166,8 @@ public interface EntityTracker {
@Nullable DimensionData dimensionData(String dimension);
@Nullable DimensionData dimensionData(int dimensionId);
void setDimensions(Map<String, DimensionData> dimensions);
/**

View File

@ -0,0 +1,75 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft;
import java.util.UUID;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class GameProfile {
private final String name;
private final UUID id;
private final Property[] properties;
public GameProfile(@Nullable final String name, @Nullable final UUID id, final Property[] properties) {
this.name = name;
this.id = id;
this.properties = properties;
}
public @Nullable String name() {
return name;
}
public @Nullable UUID id() {
return id;
}
public Property[] properties() {
return properties;
}
public static final class Property {
private final String name;
private final String value;
private final String signature;
public Property(final String name, final String value, @Nullable final String signature) {
this.name = name;
this.value = value;
this.signature = signature;
}
public String name() {
return name;
}
public String value() {
return value;
}
public @Nullable String signature() {
return signature;
}
}
}

View File

@ -0,0 +1,82 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft;
public interface Holder<T> {
/**
* Returns an indirect id holder.
*
* @param id the id
* @param <T> the type of the value
* @return a new holder with the given id
* @throws IllegalArgumentException if the id is negative
*/
static <T> Holder<T> of(final int id) {
return new HolderImpl<>(id);
}
/**
* Returns a direct value holder.
*
* @param value the value
* @param <T> the type of the value
* @return a new direct holder
*/
static <T> Holder<T> of(final T value) {
return new HolderImpl<>(value);
}
/**
* Returns true if this holder is backed by a direct value.
*
* @return true if the holder is direct
* @see #hasId()
*/
boolean isDirect();
/**
* Returns true if this holder has an id.
*
* @return true if this holder has an id
* @see #isDirect()
*/
boolean hasId();
/**
* Returns the value of this holder.
*
* @return the value of this holder
* @throws IllegalArgumentException if this holder is not direct
* @see #isDirect()
*/
T value();
/**
* Returns the id of this holder, or -1 if this holder is direct.
*
* @return the id of this holder, or -1 if this holder is direct
* @see #hasId()
*/
int id();
}

View File

@ -0,0 +1,63 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft;
import com.google.common.base.Preconditions;
final class HolderImpl<T> implements Holder<T> {
private final T value;
private final int id;
HolderImpl(final int id) {
Preconditions.checkArgument(id >= 0, "id cannot be negative");
this.value = null;
this.id = id;
}
HolderImpl(final T value) {
this.value = value;
this.id = -1;
}
@Override
public boolean isDirect() {
return id == -1;
}
@Override
public boolean hasId() {
return id != -1;
}
@Override
public T value() {
Preconditions.checkArgument(isDirect(), "Holder is not direct");
return value;
}
@Override
public int id() {
return id;
}
}

View File

@ -0,0 +1,79 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft;
/**
* Set of ids that either holds a string tag key or an array of ids.
*/
public interface HolderSet {
/**
* Creates a new holder set for the given tag.
*
* @param tagKey the tag key
* @return a new holder set
*/
static HolderSet of(final String tagKey) {
return new HolderSetImpl(tagKey);
}
/**
* Creates a new holder set for the given ids.
*
* @param ids the direct ids
* @return a new holder set
*/
static HolderSet of(final int[] ids) {
return new HolderSetImpl(ids);
}
/**
* Gets the tag key.
*
* @return the tag key
* @see #hasTagKey()
*/
String tagKey();
/**
* Returns whether this holder set has a tag key.
*
* @return true if this holder set has a tag key, false if it has direct ids
*/
boolean hasTagKey();
/**
* Gets the direct ids.
*
* @return direct ids
* @see #hasIds()
*/
int[] ids();
/**
* Returns whether this holder set has direct ids.
*
* @return true if this holder set has direct ids, false if it has a tag key
*/
boolean hasIds();
}

View File

@ -0,0 +1,56 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft;
import com.viaversion.viaversion.util.EitherImpl;
final class HolderSetImpl extends EitherImpl<String, int[]> implements HolderSet {
HolderSetImpl(final String tagKey) {
super(tagKey, null);
}
HolderSetImpl(final int[] ids) {
super(null, ids);
}
@Override
public String tagKey() {
return left();
}
@Override
public boolean hasTagKey() {
return isLeft();
}
@Override
public int[] ids() {
return right();
}
@Override
public boolean hasIds() {
return isRight();
}
}

View File

@ -24,11 +24,12 @@ package com.viaversion.viaversion.api.minecraft;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.util.IdHolder;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import java.util.List;
public final class Particle {
public final class Particle implements IdHolder {
private final List<ParticleData<?>> arguments = new ArrayList<>(4);
private int id;
@ -36,10 +37,16 @@ public final class Particle {
this.id = id;
}
@Deprecated
public int getId() {
return id;
}
@Override
public int id() {
return id;
}
public void setId(final int id) {
this.id = id;
}
@ -66,6 +73,18 @@ public final class Particle {
arguments.add(index, new ParticleData<>(type, value));
}
public <T> void set(final int index, final Type<T> type, final T value) {
arguments.set(index, new ParticleData<>(type, value));
}
@Override
public String toString() {
return "Particle{" +
"arguments=" + arguments +
", id=" + id +
'}';
}
public static final class ParticleData<T> {
private final Type<T> type;
private T value;

View File

@ -0,0 +1,48 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class RegistryEntry {
private final String key;
private final Tag tag;
public RegistryEntry(String key, @Nullable Tag tag) {
this.key = key;
this.tag = tag;
}
public String key() {
return key;
}
public @Nullable Tag tag() {
return tag;
}
public RegistryEntry withKey(final String key) {
return new RegistryEntry(key, tag != null ? tag.copy() : null);
}
}

View File

@ -0,0 +1,48 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class SoundEvent {
private final String identifier;
private final Float fixedRange;
public SoundEvent(final String identifier, @Nullable final Float fixedRange) {
this.identifier = identifier;
this.fixedRange = fixedRange;
}
public String identifier() {
return identifier;
}
public @Nullable Float fixedRange() {
return fixedRange;
}
public SoundEvent withIdentifier(final String identifier) {
return new SoundEvent(identifier, this.fixedRange);
}
}

View File

@ -22,6 +22,8 @@
*/
package com.viaversion.viaversion.api.minecraft;
import java.util.Arrays;
public final class TagData {
private final String identifier;
private final int[] entries;
@ -38,4 +40,12 @@ public final class TagData {
public int[] entries() {
return entries;
}
@Override
public String toString() {
return "TagData{" +
"identifier='" + identifier + '\'' +
", entries=" + Arrays.toString(entries) +
'}';
}
}

View File

@ -0,0 +1,94 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.data;
import io.netty.buffer.ByteBuf;
final class EmptyStructuredData<T> implements StructuredData<T> {
private final StructuredDataKey<T> key;
private int id;
EmptyStructuredData(final StructuredDataKey<T> key, final int id) {
this.key = key;
this.id = id;
}
@Override
public void setValue(final T value) {
throw new UnsupportedOperationException();
}
@Override
public void write(final ByteBuf buffer) {
}
@Override
public void setId(final int id) {
this.id = id;
}
@Override
public StructuredDataKey<T> key() {
return this.key;
}
@Override
public T value() {
return null;
}
@Override
public boolean isEmpty() {
return true;
}
@Override
public int id() {
return this.id;
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final EmptyStructuredData<?> that = (EmptyStructuredData<?>) o;
if (id != that.id) return false;
return key.equals(that.key);
}
@Override
public int hashCode() {
int result = key.hashCode();
result = 31 * result + id;
return result;
}
@Override
public String toString() {
return "EmptyStructuredData{" +
"key=" + key +
", id=" + id +
'}';
}
}

View File

@ -0,0 +1,103 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.data;
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import java.util.Objects;
final class FilledStructuredData<T> implements StructuredData<T> {
private final StructuredDataKey<T> key;
private T value;
private int id;
FilledStructuredData(final StructuredDataKey<T> key, final T value, final int id) {
Preconditions.checkNotNull(key);
this.key = key;
this.value = value;
this.id = id;
}
@Override
public void setValue(final T value) {
this.value = value;
}
@Override
public void write(final ByteBuf buffer) throws Exception {
key.type().write(buffer, value);
}
@Override
public void setId(final int id) {
this.id = id;
}
@Override
public StructuredDataKey<T> key() {
return key;
}
@Override
public T value() {
return value;
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public int id() {
return id;
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final FilledStructuredData<?> that = (FilledStructuredData<?>) o;
if (id != that.id) return false;
if (!key.equals(that.key)) return false;
return Objects.equals(value, that.value);
}
@Override
public int hashCode() {
int result = key.hashCode();
result = 31 * result + (value != null ? value.hashCode() : 0);
result = 31 * result + id;
return result;
}
@Override
public String toString() {
return "FilledStructuredData{" +
"key=" + key +
", value=" + value +
", id=" + id +
'}';
}
}

View File

@ -0,0 +1,80 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.data;
import com.viaversion.viaversion.util.IdHolder;
import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable;
public interface StructuredData<T> extends IdHolder {
/**
* Returns filled structured data, equivalent to an Optional with a value in vanilla.
*
* @param key serializer key
* @param value value
* @param id serializer id
* @param <T> serializer type
* @return filled structured data
*/
static <T> StructuredData<T> of(final StructuredDataKey<T> key, final T value, final int id) {
return new FilledStructuredData<>(key, value, id);
}
/**
* Returns empty structured data, equivalent to an empty Optional in vanilla.
*
* @param key serializer key
* @param id serializer id
* @return empty structured data
*/
static <T> StructuredData<T> empty(final StructuredDataKey<T> key, final int id) {
return new EmptyStructuredData<>(key, id);
}
void setValue(final T value);
void write(final ByteBuf buffer) throws Exception;
void setId(final int id);
StructuredDataKey<T> key();
@Nullable T value();
/**
* Returns whether the structured data is present. Even if true, the value may be null.
*
* @return true if the structured data is present
*/
default boolean isPresent() {
return !isEmpty();
}
/**
* Returns whether the structured data is empty. Not to be confused with a null value.
*
* @return true if the structured data is empty
*/
boolean isEmpty();
}

View File

@ -0,0 +1,170 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.data;
import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.data.FullMappings;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.util.Unit;
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
import java.util.Map;
import java.util.function.Function;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class StructuredDataContainer {
private final Map<StructuredDataKey<?>, StructuredData<?>> data;
private FullMappings lookup;
private boolean mappedNames;
public StructuredDataContainer(final Map<StructuredDataKey<?>, StructuredData<?>> data) {
this.data = data;
}
public StructuredDataContainer(final StructuredData<?>[] dataArray) {
this(new Reference2ObjectOpenHashMap<>(dataArray.length));
for (final StructuredData<?> data : dataArray) {
this.data.put(data.key(), data);
}
}
public StructuredDataContainer() {
this(new Reference2ObjectOpenHashMap<>());
}
/**
* Returns structured data by id if present.
*
* @param key serializer id
* @param <T> data type
* @return structured data
*/
public @Nullable <T> StructuredData<T> get(final StructuredDataKey<T> key) {
//noinspection unchecked
return (StructuredData<T>) this.data.get(key);
}
/**
* Returns structured data by id if not empty.
*
* @param key serializer id
* @param <T> data type
* @return structured data if not empty
*/
public @Nullable <T> StructuredData<T> getNonEmpty(final StructuredDataKey<T> key) {
//noinspection unchecked
final StructuredData<T> data = (StructuredData<T>) this.data.get(key);
return data != null && data.isPresent() ? data : null;
}
/**
* Returns structured data by id if not empty, or creates it.
*
* @param key serializer id
* @param mappingFunction function to create structured data if not present
* @param <T> data type
* @return structured data if not empty
*/
public <T> StructuredData<T> computeIfAbsent(final StructuredDataKey<T> key, final Function<StructuredDataKey<T>, T> mappingFunction) {
final StructuredData<T> data = this.getNonEmpty(key);
if (data != null) {
return data;
}
final int id = serializerId(key);
final StructuredData<T> empty = StructuredData.of(key, mappingFunction.apply(key), id);
this.data.put(key, empty);
return empty;
}
public <T> void set(final StructuredDataKey<T> key, final T value) {
final int id = serializerId(key);
if (id != -1) {
this.data.put(key, StructuredData.of(key, value, id));
}
}
public void set(final StructuredDataKey<Unit> key) {
this.set(key, Unit.INSTANCE);
}
public void addEmpty(final StructuredDataKey<?> key) {
// Empty optional to override the Minecraft default
this.data.put(key, StructuredData.empty(key, serializerId(key)));
}
/**
* Removes and returns structured data by the given key.
*
* @param key serializer key
* @param <T> data type
* @return removed structured data
*/
public @Nullable <T> StructuredData<T> remove(final StructuredDataKey<T> key) {
final StructuredData<?> data = this.data.remove(key);
//noinspection unchecked
return data != null ? (StructuredData<T>) data : null;
}
public boolean contains(final StructuredDataKey<?> key) {
return this.data.containsKey(key);
}
/**
* Sets the lookup for serializer ids. Required to call most of the other methods.
*
* @param protocol protocol to retreive the id of the serializer from
* @param mappedNames if the names are mapped (true if structures from the mapped version are added, false for the unmapped version)
*/
public void setIdLookup(final Protocol<?, ?, ?, ?> protocol, final boolean mappedNames) {
this.lookup = protocol.getMappingData().getDataComponentSerializerMappings();
Preconditions.checkNotNull(this.lookup, "Data component serializer mappings are null");
this.mappedNames = mappedNames;
}
public StructuredDataContainer copy() {
final StructuredDataContainer copy = new StructuredDataContainer(new Reference2ObjectOpenHashMap<>(data));
copy.lookup = this.lookup;
return copy;
}
private int serializerId(final StructuredDataKey<?> key) {
final int id = mappedNames ? lookup.mappedId(key.identifier()) : lookup.id(key.identifier());
if (id == -1) {
Via.getPlatform().getLogger().severe("Could not find item data serializer for type " + key);
}
return id;
}
public Map<StructuredDataKey<?>, StructuredData<?>> data() {
return data;
}
@Override
public String toString() {
return "StructuredDataContainer{" +
"data=" + data +
'}';
}
}

View File

@ -0,0 +1,136 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.data;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.api.minecraft.GameProfile;
import com.viaversion.viaversion.api.minecraft.Holder;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.item.data.AdventureModePredicate;
import com.viaversion.viaversion.api.minecraft.item.data.ArmorTrim;
import com.viaversion.viaversion.api.minecraft.item.data.AttributeModifiers;
import com.viaversion.viaversion.api.minecraft.item.data.BannerPatternLayer;
import com.viaversion.viaversion.api.minecraft.item.data.Bee;
import com.viaversion.viaversion.api.minecraft.item.data.BlockStateProperties;
import com.viaversion.viaversion.api.minecraft.item.data.DyedColor;
import com.viaversion.viaversion.api.minecraft.item.data.Enchantments;
import com.viaversion.viaversion.api.minecraft.item.data.FilterableString;
import com.viaversion.viaversion.api.minecraft.item.data.FireworkExplosion;
import com.viaversion.viaversion.api.minecraft.item.data.Fireworks;
import com.viaversion.viaversion.api.minecraft.item.data.FoodProperties;
import com.viaversion.viaversion.api.minecraft.item.data.Instrument;
import com.viaversion.viaversion.api.minecraft.item.data.LodestoneTracker;
import com.viaversion.viaversion.api.minecraft.item.data.PotDecorations;
import com.viaversion.viaversion.api.minecraft.item.data.PotionContents;
import com.viaversion.viaversion.api.minecraft.item.data.SuspiciousStewEffect;
import com.viaversion.viaversion.api.minecraft.item.data.ToolProperties;
import com.viaversion.viaversion.api.minecraft.item.data.Unbreakable;
import com.viaversion.viaversion.api.minecraft.item.data.WrittenBook;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_20_5;
import com.viaversion.viaversion.util.Unit;
public final class StructuredDataKey<T> {
public static final StructuredDataKey<CompoundTag> CUSTOM_DATA = new StructuredDataKey<>("custom_data", Type.COMPOUND_TAG);
public static final StructuredDataKey<Integer> MAX_STACK_SIZE = new StructuredDataKey<>("max_stack_size", Type.VAR_INT);
public static final StructuredDataKey<Integer> MAX_DAMAGE = new StructuredDataKey<>("max_damage", Type.VAR_INT);
public static final StructuredDataKey<Integer> DAMAGE = new StructuredDataKey<>("damage", Type.VAR_INT);
public static final StructuredDataKey<Unbreakable> UNBREAKABLE = new StructuredDataKey<>("unbreakable", Unbreakable.TYPE);
public static final StructuredDataKey<Tag> CUSTOM_NAME = new StructuredDataKey<>("custom_name", Type.TAG);
public static final StructuredDataKey<Tag> ITEM_NAME = new StructuredDataKey<>("item_name", Type.TAG);
public static final StructuredDataKey<Tag[]> LORE = new StructuredDataKey<>("lore", Type.TAG_ARRAY);
public static final StructuredDataKey<Integer> RARITY = new StructuredDataKey<>("rarity", Type.VAR_INT);
public static final StructuredDataKey<Enchantments> ENCHANTMENTS = new StructuredDataKey<>("enchantments", Enchantments.TYPE);
public static final StructuredDataKey<AdventureModePredicate> CAN_PLACE_ON = new StructuredDataKey<>("can_place_on", AdventureModePredicate.TYPE);
public static final StructuredDataKey<AdventureModePredicate> CAN_BREAK = new StructuredDataKey<>("can_break", AdventureModePredicate.TYPE);
public static final StructuredDataKey<AttributeModifiers> ATTRIBUTE_MODIFIERS = new StructuredDataKey<>("attribute_modifiers", AttributeModifiers.TYPE);
public static final StructuredDataKey<Integer> CUSTOM_MODEL_DATA = new StructuredDataKey<>("custom_model_data", Type.VAR_INT);
public static final StructuredDataKey<Unit> HIDE_ADDITIONAL_TOOLTIP = new StructuredDataKey<>("hide_additional_tooltip", Type.EMPTY);
public static final StructuredDataKey<Unit> HIDE_TOOLTIP = new StructuredDataKey<>("hide_tooltip", Type.EMPTY);
public static final StructuredDataKey<Integer> REPAIR_COST = new StructuredDataKey<>("repair_cost", Type.VAR_INT);
public static final StructuredDataKey<Unit> CREATIVE_SLOT_LOCK = new StructuredDataKey<>("creative_slot_lock", Type.EMPTY);
public static final StructuredDataKey<Boolean> ENCHANTMENT_GLINT_OVERRIDE = new StructuredDataKey<>("enchantment_glint_override", Type.BOOLEAN);
public static final StructuredDataKey<Tag> INTANGIBLE_PROJECTILE = new StructuredDataKey<>("intangible_projectile", Type.TAG); // Doesn't actually hold data
public static final StructuredDataKey<FoodProperties> FOOD = new StructuredDataKey<>("food", FoodProperties.TYPE);
public static final StructuredDataKey<Unit> FIRE_RESISTANT = new StructuredDataKey<>("fire_resistant", Type.EMPTY);
public static final StructuredDataKey<ToolProperties> TOOL = new StructuredDataKey<>("tool", ToolProperties.TYPE);
public static final StructuredDataKey<Enchantments> STORED_ENCHANTMENTS = new StructuredDataKey<>("stored_enchantments", Enchantments.TYPE);
public static final StructuredDataKey<DyedColor> DYED_COLOR = new StructuredDataKey<>("dyed_color", DyedColor.TYPE);
public static final StructuredDataKey<Integer> MAP_COLOR = new StructuredDataKey<>("map_color", Type.INT);
public static final StructuredDataKey<Integer> MAP_ID = new StructuredDataKey<>("map_id", Type.VAR_INT);
public static final StructuredDataKey<CompoundTag> MAP_DECORATIONS = new StructuredDataKey<>("map_decorations", Type.COMPOUND_TAG);
public static final StructuredDataKey<Integer> MAP_POST_PROCESSING = new StructuredDataKey<>("map_post_processing", Type.VAR_INT);
public static final StructuredDataKey<Item[]> CHARGED_PROJECTILES = new StructuredDataKey<>("charged_projectiles", Types1_20_5.ITEM_ARRAY);
public static final StructuredDataKey<Item[]> BUNDLE_CONTENTS = new StructuredDataKey<>("bundle_contents", Types1_20_5.ITEM_ARRAY);
public static final StructuredDataKey<PotionContents> POTION_CONTENTS = new StructuredDataKey<>("potion_contents", PotionContents.TYPE);
public static final StructuredDataKey<SuspiciousStewEffect[]> SUSPICIOUS_STEW_EFFECTS = new StructuredDataKey<>("suspicious_stew_effects", SuspiciousStewEffect.ARRAY_TYPE);
public static final StructuredDataKey<FilterableString[]> WRITABLE_BOOK_CONTENT = new StructuredDataKey<>("writable_book_content", FilterableString.ARRAY_TYPE);
public static final StructuredDataKey<WrittenBook> WRITTEN_BOOK_CONTENT = new StructuredDataKey<>("written_book_content", WrittenBook.TYPE);
public static final StructuredDataKey<ArmorTrim> TRIM = new StructuredDataKey<>("trim", ArmorTrim.TYPE);
public static final StructuredDataKey<CompoundTag> DEBUG_STICK_STATE = new StructuredDataKey<>("debug_stick_state", Type.COMPOUND_TAG);
public static final StructuredDataKey<CompoundTag> ENTITY_DATA = new StructuredDataKey<>("entity_data", Type.COMPOUND_TAG);
public static final StructuredDataKey<CompoundTag> BUCKET_ENTITY_DATA = new StructuredDataKey<>("bucket_entity_data", Type.COMPOUND_TAG);
public static final StructuredDataKey<CompoundTag> BLOCK_ENTITY_DATA = new StructuredDataKey<>("block_entity_data", Type.COMPOUND_TAG);
public static final StructuredDataKey<Holder<Instrument>> INSTRUMENT = new StructuredDataKey<>("instrument", Instrument.TYPE);
public static final StructuredDataKey<Integer> OMINOUS_BOTTLE_AMPLIFIER = new StructuredDataKey<>("ominous_bottle_amplifier", Type.VAR_INT);
public static final StructuredDataKey<Tag> RECIPES = new StructuredDataKey<>("recipes", Type.TAG);
public static final StructuredDataKey<LodestoneTracker> LODESTONE_TRACKER = new StructuredDataKey<>("lodestone_tracker", LodestoneTracker.TYPE);
public static final StructuredDataKey<FireworkExplosion> FIREWORK_EXPLOSION = new StructuredDataKey<>("firework_explosion", FireworkExplosion.TYPE);
public static final StructuredDataKey<Fireworks> FIREWORKS = new StructuredDataKey<>("fireworks", Fireworks.TYPE);
public static final StructuredDataKey<GameProfile> PROFILE = new StructuredDataKey<>("profile", Type.GAME_PROFILE);
public static final StructuredDataKey<String> NOTE_BLOCK_SOUND = new StructuredDataKey<>("note_block_sound", Type.STRING);
public static final StructuredDataKey<BannerPatternLayer[]> BANNER_PATTERNS = new StructuredDataKey<>("banner_patterns", BannerPatternLayer.ARRAY_TYPE);
public static final StructuredDataKey<Integer> BASE_COLOR = new StructuredDataKey<>("base_color", Type.VAR_INT);
public static final StructuredDataKey<PotDecorations> POT_DECORATIONS = new StructuredDataKey<>("pot_decorations", PotDecorations.TYPE);
public static final StructuredDataKey<Item[]> CONTAINER = new StructuredDataKey<>("container", Types1_20_5.ITEM_ARRAY);
public static final StructuredDataKey<BlockStateProperties> BLOCK_STATE = new StructuredDataKey<>("block_state", BlockStateProperties.TYPE);
public static final StructuredDataKey<Bee[]> BEES = new StructuredDataKey<>("bees", Bee.ARRAY_TYPE);
public static final StructuredDataKey<Tag> LOCK = new StructuredDataKey<>("lock", Type.TAG);
public static final StructuredDataKey<CompoundTag> CONTAINER_LOOT = new StructuredDataKey<>("container_loot", Type.COMPOUND_TAG);
private final String identifier;
private final Type<T> type;
public StructuredDataKey(final String identifier, final Type<T> type) {
this.identifier = identifier;
this.type = type;
}
public Type<T> type() {
return type;
}
public String identifier() {
return identifier;
}
@Override
public String toString() {
return "StructuredDataKey{" +
"identifier='" + identifier + '\'' +
", type=" + type +
'}';
}
}

View File

@ -22,223 +22,232 @@
*/
package com.viaversion.viaversion.api.minecraft.entities;
import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.util.EntityTypeUtil;
import java.util.Locale;
import org.checkerframework.checker.nullness.qual.Nullable;
public enum EntityTypes1_14 implements EntityType {
ENTITY(-1),
ENTITY(null, null),
AREA_EFFECT_CLOUD(0, ENTITY),
END_CRYSTAL(17, ENTITY),
EVOKER_FANGS(21, ENTITY),
EXPERIENCE_ORB(23, ENTITY),
EYE_OF_ENDER(24, ENTITY),
FALLING_BLOCK(25, ENTITY),
FIREWORK_ROCKET(26, ENTITY),
ITEM(34, ENTITY),
LLAMA_SPIT(39, ENTITY),
TNT(58, ENTITY),
SHULKER_BULLET(63, ENTITY),
FISHING_BOBBER(101, ENTITY),
AREA_EFFECT_CLOUD(ENTITY),
END_CRYSTAL(ENTITY),
EVOKER_FANGS(ENTITY),
EXPERIENCE_ORB(ENTITY),
EYE_OF_ENDER(ENTITY),
FALLING_BLOCK(ENTITY),
ITEM(ENTITY),
TNT(ENTITY),
LIGHTNING_BOLT(ENTITY),
LIVINGENTITY(-1, ENTITY),
ARMOR_STAND(1, LIVINGENTITY),
PLAYER(100, LIVINGENTITY),
ABSTRACT_INSENTIENT(-1, LIVINGENTITY),
ENDER_DRAGON(18, ABSTRACT_INSENTIENT),
ABSTRACT_CREATURE(-1, ABSTRACT_INSENTIENT),
ABSTRACT_AGEABLE(-1, ABSTRACT_CREATURE),
VILLAGER(84, ABSTRACT_AGEABLE),
WANDERING_TRADER(88, ABSTRACT_AGEABLE),
// Animals
ABSTRACT_ANIMAL(-1, ABSTRACT_AGEABLE),
DOLPHIN(13, ABSTRACT_INSENTIENT),
CHICKEN(8, ABSTRACT_ANIMAL),
COW(10, ABSTRACT_ANIMAL),
MOOSHROOM(49, COW),
PANDA(52, ABSTRACT_INSENTIENT),
PIG(54, ABSTRACT_ANIMAL),
POLAR_BEAR(57, ABSTRACT_ANIMAL),
RABBIT(59, ABSTRACT_ANIMAL),
SHEEP(61, ABSTRACT_ANIMAL),
TURTLE(77, ABSTRACT_ANIMAL),
FOX(27, ABSTRACT_ANIMAL),
ABSTRACT_TAMEABLE_ANIMAL(-1, ABSTRACT_ANIMAL),
CAT(6, ABSTRACT_TAMEABLE_ANIMAL),
OCELOT(50, ABSTRACT_TAMEABLE_ANIMAL),
WOLF(93, ABSTRACT_TAMEABLE_ANIMAL),
ABSTRACT_PARROT(-1, ABSTRACT_TAMEABLE_ANIMAL),
PARROT(53, ABSTRACT_PARROT),
// Horses
ABSTRACT_HORSE(-1, ABSTRACT_ANIMAL),
CHESTED_HORSE(-1, ABSTRACT_HORSE),
DONKEY(12, CHESTED_HORSE),
MULE(48, CHESTED_HORSE),
LLAMA(38, CHESTED_HORSE),
TRADER_LLAMA(75, CHESTED_HORSE),
HORSE(31, ABSTRACT_HORSE),
SKELETON_HORSE(66, ABSTRACT_HORSE),
ZOMBIE_HORSE(95, ABSTRACT_HORSE),
// Golem
ABSTRACT_GOLEM(-1, ABSTRACT_CREATURE),
SNOW_GOLEM(69, ABSTRACT_GOLEM),
IRON_GOLEM(85, ABSTRACT_GOLEM),
SHULKER(62, ABSTRACT_GOLEM),
// Fish
ABSTRACT_FISHES(-1, ABSTRACT_CREATURE),
COD(9, ABSTRACT_FISHES),
PUFFERFISH(55, ABSTRACT_FISHES),
SALMON(60, ABSTRACT_FISHES),
TROPICAL_FISH(76, ABSTRACT_FISHES),
// Monsters
ABSTRACT_MONSTER(-1, ABSTRACT_CREATURE),
BLAZE(4, ABSTRACT_MONSTER),
CREEPER(11, ABSTRACT_MONSTER),
ENDERMITE(20, ABSTRACT_MONSTER),
ENDERMAN(19, ABSTRACT_MONSTER),
GIANT(29, ABSTRACT_MONSTER),
SILVERFISH(64, ABSTRACT_MONSTER),
VEX(83, ABSTRACT_MONSTER),
WITCH(89, ABSTRACT_MONSTER),
WITHER(90, ABSTRACT_MONSTER),
RAVAGER(98, ABSTRACT_MONSTER),
// Illagers
ABSTRACT_ILLAGER_BASE(-1, ABSTRACT_MONSTER),
ABSTRACT_EVO_ILLU_ILLAGER(-1, ABSTRACT_ILLAGER_BASE),
EVOKER(22, ABSTRACT_EVO_ILLU_ILLAGER),
ILLUSIONER(33, ABSTRACT_EVO_ILLU_ILLAGER),
VINDICATOR(86, ABSTRACT_ILLAGER_BASE),
PILLAGER(87, ABSTRACT_ILLAGER_BASE),
// Skeletons
ABSTRACT_SKELETON(-1, ABSTRACT_MONSTER),
SKELETON(65, ABSTRACT_SKELETON),
STRAY(74, ABSTRACT_SKELETON),
WITHER_SKELETON(91, ABSTRACT_SKELETON),
// Guardians
GUARDIAN(30, ABSTRACT_MONSTER),
ELDER_GUARDIAN(16, GUARDIAN),
// Spiders
SPIDER(72, ABSTRACT_MONSTER),
CAVE_SPIDER(7, SPIDER),
// Zombies - META CHECKED
ZOMBIE(94, ABSTRACT_MONSTER),
DROWNED(15, ZOMBIE),
HUSK(32, ZOMBIE),
ZOMBIE_PIGMAN(56, ZOMBIE),
ZOMBIE_VILLAGER(96, ZOMBIE),
// Flying entities
ABSTRACT_FLYING(-1, ABSTRACT_INSENTIENT),
GHAST(28, ABSTRACT_FLYING),
PHANTOM(97, ABSTRACT_FLYING),
ABSTRACT_AMBIENT(-1, ABSTRACT_INSENTIENT),
BAT(3, ABSTRACT_AMBIENT),
ABSTRACT_WATERMOB(-1, ABSTRACT_INSENTIENT),
SQUID(73, ABSTRACT_WATERMOB),
// Slimes
SLIME(67, ABSTRACT_INSENTIENT),
MAGMA_CUBE(40, SLIME),
// Hangable objects
ABSTRACT_HANGING(-1, ENTITY),
LEASH_KNOT(37, ABSTRACT_HANGING),
ITEM_FRAME(35, ABSTRACT_HANGING),
PAINTING(51, ABSTRACT_HANGING),
ABSTRACT_LIGHTNING(-1, ENTITY),
LIGHTNING_BOLT(99, ABSTRACT_LIGHTNING),
// Arrows
ABSTRACT_ARROW(-1, ENTITY),
ARROW(2, ABSTRACT_ARROW),
SPECTRAL_ARROW(71, ABSTRACT_ARROW),
TRIDENT(82, ABSTRACT_ARROW),
// Fireballs
ABSTRACT_FIREBALL(-1, ENTITY),
DRAGON_FIREBALL(14, ABSTRACT_FIREBALL),
FIREBALL(36, ABSTRACT_FIREBALL),
SMALL_FIREBALL(68, ABSTRACT_FIREBALL),
WITHER_SKULL(92, ABSTRACT_FIREBALL),
// Hanging entities
ABSTRACT_HANGING(ENTITY, null),
LEASH_KNOT(ABSTRACT_HANGING),
PAINTING(ABSTRACT_HANGING),
ITEM_FRAME(ABSTRACT_HANGING),
// Projectiles
PROJECTILE_ABSTRACT(-1, ENTITY),
SNOWBALL(70, PROJECTILE_ABSTRACT),
ENDER_PEARL(79, PROJECTILE_ABSTRACT),
EGG(78, PROJECTILE_ABSTRACT),
POTION(81, PROJECTILE_ABSTRACT),
EXPERIENCE_BOTTLE(80, PROJECTILE_ABSTRACT),
PROJECTILE_ABSTRACT(ENTITY, null), // Not actually its own abstract type, but useful for categorizing
SNOWBALL(PROJECTILE_ABSTRACT),
ENDER_PEARL(PROJECTILE_ABSTRACT),
EGG(PROJECTILE_ABSTRACT),
POTION(PROJECTILE_ABSTRACT),
EXPERIENCE_BOTTLE(PROJECTILE_ABSTRACT),
FIREWORK_ROCKET(PROJECTILE_ABSTRACT),
LLAMA_SPIT(PROJECTILE_ABSTRACT),
SHULKER_BULLET(PROJECTILE_ABSTRACT),
FISHING_BOBBER(PROJECTILE_ABSTRACT),
WITHER_SKULL(PROJECTILE_ABSTRACT),
DRAGON_FIREBALL(PROJECTILE_ABSTRACT), // Doesn't actually inherit fireball
ABSTRACT_ARROW(PROJECTILE_ABSTRACT, null),
ARROW(ABSTRACT_ARROW),
SPECTRAL_ARROW(ABSTRACT_ARROW),
TRIDENT(ABSTRACT_ARROW),
ABSTRACT_FIREBALL(ENTITY, null),
FIREBALL(ABSTRACT_FIREBALL),
SMALL_FIREBALL(ABSTRACT_FIREBALL),
// Vehicles
MINECART_ABSTRACT(-1, ENTITY),
CHESTED_MINECART_ABSTRACT(-1, MINECART_ABSTRACT),
CHEST_MINECART(42, CHESTED_MINECART_ABSTRACT),
HOPPER_MINECART(45, CHESTED_MINECART_ABSTRACT),
MINECART(41, MINECART_ABSTRACT),
FURNACE_MINECART(44, MINECART_ABSTRACT),
COMMAND_BLOCK_MINECART(43, MINECART_ABSTRACT),
TNT_MINECART(47, MINECART_ABSTRACT),
SPAWNER_MINECART(46, MINECART_ABSTRACT),
BOAT(5, ENTITY);
VEHICLE(ENTITY, null),
BOAT(VEHICLE),
private static final EntityType[] TYPES;
MINECART_ABSTRACT(VEHICLE, null),
MINECART(MINECART_ABSTRACT),
FURNACE_MINECART(MINECART_ABSTRACT),
COMMAND_BLOCK_MINECART(MINECART_ABSTRACT),
TNT_MINECART(MINECART_ABSTRACT),
SPAWNER_MINECART(MINECART_ABSTRACT),
private final int id;
CHESTED_MINECART_ABSTRACT(MINECART_ABSTRACT, null),
CHEST_MINECART(CHESTED_MINECART_ABSTRACT),
HOPPER_MINECART(CHESTED_MINECART_ABSTRACT),
// Living entities as a larger subclass
LIVINGENTITY(ENTITY, null),
ARMOR_STAND(LIVINGENTITY),
PLAYER(LIVINGENTITY),
// Mobs as a larger subclass
ABSTRACT_INSENTIENT(LIVINGENTITY, null),
ENDER_DRAGON(ABSTRACT_INSENTIENT),
SLIME(ABSTRACT_INSENTIENT),
MAGMA_CUBE(SLIME),
// Ambient mobs
ABSTRACT_AMBIENT(ABSTRACT_INSENTIENT, null),
BAT(ABSTRACT_AMBIENT),
// Flying mobs
ABSTRACT_FLYING(ABSTRACT_INSENTIENT, null),
GHAST(ABSTRACT_FLYING),
PHANTOM(ABSTRACT_FLYING),
// Pathfinder mobs and its subclasses
ABSTRACT_CREATURE(ABSTRACT_INSENTIENT, null),
ABSTRACT_GOLEM(ABSTRACT_CREATURE, null),
SNOW_GOLEM(ABSTRACT_GOLEM),
IRON_GOLEM(ABSTRACT_GOLEM),
SHULKER(ABSTRACT_GOLEM),
// Water mobs
ABSTRACT_WATERMOB(ABSTRACT_CREATURE, null),
DOLPHIN(ABSTRACT_WATERMOB),
SQUID(ABSTRACT_WATERMOB),
ABSTRACT_FISHES(ABSTRACT_WATERMOB, null),
PUFFERFISH(ABSTRACT_FISHES),
ABSTRACT_SCHOOLING_FISH(ABSTRACT_FISHES, null),
COD(ABSTRACT_SCHOOLING_FISH),
SALMON(ABSTRACT_SCHOOLING_FISH),
TROPICAL_FISH(ABSTRACT_SCHOOLING_FISH),
// Ageable mobs and (tamable) animals
ABSTRACT_AGEABLE(ABSTRACT_CREATURE, null),
ABSTRACT_VILLAGER(ABSTRACT_AGEABLE, null),
VILLAGER(ABSTRACT_VILLAGER),
WANDERING_TRADER(ABSTRACT_VILLAGER),
ABSTRACT_ANIMAL(ABSTRACT_AGEABLE, null),
CHICKEN(ABSTRACT_ANIMAL),
PANDA(ABSTRACT_ANIMAL),
PIG(ABSTRACT_ANIMAL),
POLAR_BEAR(ABSTRACT_ANIMAL),
RABBIT(ABSTRACT_ANIMAL),
SHEEP(ABSTRACT_ANIMAL),
TURTLE(ABSTRACT_ANIMAL),
FOX(ABSTRACT_ANIMAL),
COW(ABSTRACT_ANIMAL),
MOOSHROOM(COW),
ABSTRACT_TAMEABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(ABSTRACT_TAMEABLE_ANIMAL),
OCELOT(ABSTRACT_TAMEABLE_ANIMAL),
WOLF(ABSTRACT_TAMEABLE_ANIMAL),
PARROT(ABSTRACT_TAMEABLE_ANIMAL),
ABSTRACT_HORSE(ABSTRACT_ANIMAL, null),
HORSE(ABSTRACT_HORSE),
SKELETON_HORSE(ABSTRACT_HORSE),
ZOMBIE_HORSE(ABSTRACT_HORSE),
CHESTED_HORSE(ABSTRACT_HORSE, null),
DONKEY(CHESTED_HORSE),
MULE(CHESTED_HORSE),
LLAMA(CHESTED_HORSE),
TRADER_LLAMA(LLAMA),
// Monsters
ABSTRACT_MONSTER(ABSTRACT_CREATURE, null),
BLAZE(ABSTRACT_MONSTER),
CREEPER(ABSTRACT_MONSTER),
ENDERMITE(ABSTRACT_MONSTER),
ENDERMAN(ABSTRACT_MONSTER),
GIANT(ABSTRACT_MONSTER),
SILVERFISH(ABSTRACT_MONSTER),
VEX(ABSTRACT_MONSTER),
WITHER(ABSTRACT_MONSTER),
ABSTRACT_SKELETON(ABSTRACT_MONSTER, null),
SKELETON(ABSTRACT_SKELETON),
STRAY(ABSTRACT_SKELETON),
WITHER_SKELETON(ABSTRACT_SKELETON),
ZOMBIE(ABSTRACT_MONSTER),
DROWNED(ZOMBIE),
HUSK(ZOMBIE),
ZOMBIE_PIGMAN(ZOMBIE),
ZOMBIE_VILLAGER(ZOMBIE),
GUARDIAN(ABSTRACT_MONSTER),
ELDER_GUARDIAN(GUARDIAN),
SPIDER(ABSTRACT_MONSTER),
CAVE_SPIDER(SPIDER),
// Raiders
ABSTRACT_RAIDER(ABSTRACT_MONSTER, null),
WITCH(ABSTRACT_RAIDER),
RAVAGER(ABSTRACT_RAIDER),
ABSTRACT_ILLAGER_BASE(ABSTRACT_RAIDER, null),
ABSTRACT_EVO_ILLU_ILLAGER(ABSTRACT_ILLAGER_BASE, null),
VINDICATOR(ABSTRACT_ILLAGER_BASE),
PILLAGER(ABSTRACT_ILLAGER_BASE),
EVOKER(ABSTRACT_EVO_ILLU_ILLAGER),
ILLUSIONER(ABSTRACT_EVO_ILLU_ILLAGER);
private static final EntityType[] TYPES = EntityTypeUtil.createSizedArray(values());
private final EntityType parent;
private final String identifier;
private int id = -1;
EntityTypes1_14(int id) {
this.id = id;
this.parent = null;
EntityTypes1_14(final EntityType parent) {
this.parent = parent;
this.identifier = "minecraft:" + name().toLowerCase(Locale.ROOT);
}
EntityTypes1_14(int id, EntityType parent) {
this.id = id;
EntityTypes1_14(final EntityType parent, @Nullable final String identifier) {
this.parent = parent;
this.identifier = identifier;
}
@Override
public int getId() {
if (id == -1) {
throw new IllegalStateException("Ids have not been initialized yet (type " + name() + ")");
}
return id;
}
@Override
public EntityType getParent() {
public String identifier() {
Preconditions.checkArgument(identifier != null, "Called identifier method on abstract type");
return identifier;
}
@Override
public @Nullable EntityType getParent() {
return parent;
}
@Override
public String identifier() {
throw new UnsupportedOperationException();
}
@Override
public boolean isAbstractType() {
return id != -1;
return identifier == null;
}
static {
TYPES = EntityTypeUtil.toOrderedArray(values());
}
public static EntityType getTypeFromId(int typeId) {
public static EntityType getTypeFromId(final int typeId) {
return EntityTypeUtil.getTypeFromId(TYPES, typeId, ENTITY);
}
public static void initialize(final Protocol<?, ?, ?, ?> protocol) {
EntityTypeUtil.initialize(values(), TYPES, protocol, (type, id) -> type.id = id);
}
}

View File

@ -22,225 +22,233 @@
*/
package com.viaversion.viaversion.api.minecraft.entities;
import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.util.EntityTypeUtil;
import java.util.Locale;
import org.checkerframework.checker.nullness.qual.Nullable;
public enum EntityTypes1_15 implements EntityType {
ENTITY(-1),
ENTITY(null, null),
AREA_EFFECT_CLOUD(0, ENTITY),
END_CRYSTAL(18, ENTITY),
EVOKER_FANGS(22, ENTITY),
EXPERIENCE_ORB(24, ENTITY),
EYE_OF_ENDER(25, ENTITY),
FALLING_BLOCK(26, ENTITY),
FIREWORK_ROCKET(27, ENTITY),
ITEM(35, ENTITY),
LLAMA_SPIT(40, ENTITY),
TNT(59, ENTITY),
SHULKER_BULLET(64, ENTITY),
FISHING_BOBBER(102, ENTITY),
AREA_EFFECT_CLOUD(ENTITY),
END_CRYSTAL(ENTITY),
EVOKER_FANGS(ENTITY),
EXPERIENCE_ORB(ENTITY),
EYE_OF_ENDER(ENTITY),
FALLING_BLOCK(ENTITY),
ITEM(ENTITY),
TNT(ENTITY),
LIGHTNING_BOLT(ENTITY),
LIVINGENTITY(-1, ENTITY),
ARMOR_STAND(1, LIVINGENTITY),
PLAYER(101, LIVINGENTITY),
ABSTRACT_INSENTIENT(-1, LIVINGENTITY),
ENDER_DRAGON(19, ABSTRACT_INSENTIENT),
BEE(4, ABSTRACT_INSENTIENT),
ABSTRACT_CREATURE(-1, ABSTRACT_INSENTIENT),
ABSTRACT_AGEABLE(-1, ABSTRACT_CREATURE),
VILLAGER(85, ABSTRACT_AGEABLE),
WANDERING_TRADER(89, ABSTRACT_AGEABLE),
// Animals
ABSTRACT_ANIMAL(-1, ABSTRACT_AGEABLE),
DOLPHIN(14, ABSTRACT_INSENTIENT),
CHICKEN(9, ABSTRACT_ANIMAL),
COW(11, ABSTRACT_ANIMAL),
MOOSHROOM(50, COW),
PANDA(53, ABSTRACT_INSENTIENT),
PIG(55, ABSTRACT_ANIMAL),
POLAR_BEAR(58, ABSTRACT_ANIMAL),
RABBIT(60, ABSTRACT_ANIMAL),
SHEEP(62, ABSTRACT_ANIMAL),
TURTLE(78, ABSTRACT_ANIMAL),
FOX(28, ABSTRACT_ANIMAL),
ABSTRACT_TAMEABLE_ANIMAL(-1, ABSTRACT_ANIMAL),
CAT(7, ABSTRACT_TAMEABLE_ANIMAL),
OCELOT(51, ABSTRACT_TAMEABLE_ANIMAL),
WOLF(94, ABSTRACT_TAMEABLE_ANIMAL),
ABSTRACT_PARROT(-1, ABSTRACT_TAMEABLE_ANIMAL),
PARROT(54, ABSTRACT_PARROT),
// Horses
ABSTRACT_HORSE(-1, ABSTRACT_ANIMAL),
CHESTED_HORSE(-1, ABSTRACT_HORSE),
DONKEY(13, CHESTED_HORSE),
MULE(49, CHESTED_HORSE),
LLAMA(39, CHESTED_HORSE),
TRADER_LLAMA(76, CHESTED_HORSE),
HORSE(32, ABSTRACT_HORSE),
SKELETON_HORSE(67, ABSTRACT_HORSE),
ZOMBIE_HORSE(96, ABSTRACT_HORSE),
// Golem
ABSTRACT_GOLEM(-1, ABSTRACT_CREATURE),
SNOW_GOLEM(70, ABSTRACT_GOLEM),
IRON_GOLEM(86, ABSTRACT_GOLEM),
SHULKER(63, ABSTRACT_GOLEM),
// Fish
ABSTRACT_FISHES(-1, ABSTRACT_CREATURE),
COD(10, ABSTRACT_FISHES),
PUFFERFISH(56, ABSTRACT_FISHES),
SALMON(61, ABSTRACT_FISHES),
TROPICAL_FISH(77, ABSTRACT_FISHES),
// Monsters
ABSTRACT_MONSTER(-1, ABSTRACT_CREATURE),
BLAZE(5, ABSTRACT_MONSTER),
CREEPER(12, ABSTRACT_MONSTER),
ENDERMITE(21, ABSTRACT_MONSTER),
ENDERMAN(20, ABSTRACT_MONSTER),
GIANT(30, ABSTRACT_MONSTER),
SILVERFISH(65, ABSTRACT_MONSTER),
VEX(84, ABSTRACT_MONSTER),
WITCH(90, ABSTRACT_MONSTER),
WITHER(91, ABSTRACT_MONSTER),
RAVAGER(99, ABSTRACT_MONSTER),
// Illagers
ABSTRACT_ILLAGER_BASE(-1, ABSTRACT_MONSTER),
ABSTRACT_EVO_ILLU_ILLAGER(-1, ABSTRACT_ILLAGER_BASE),
EVOKER(23, ABSTRACT_EVO_ILLU_ILLAGER),
ILLUSIONER(34, ABSTRACT_EVO_ILLU_ILLAGER),
VINDICATOR(87, ABSTRACT_ILLAGER_BASE),
PILLAGER(88, ABSTRACT_ILLAGER_BASE),
// Skeletons
ABSTRACT_SKELETON(-1, ABSTRACT_MONSTER),
SKELETON(66, ABSTRACT_SKELETON),
STRAY(75, ABSTRACT_SKELETON),
WITHER_SKELETON(92, ABSTRACT_SKELETON),
// Guardians
GUARDIAN(31, ABSTRACT_MONSTER),
ELDER_GUARDIAN(17, GUARDIAN),
// Spiders
SPIDER(73, ABSTRACT_MONSTER),
CAVE_SPIDER(8, SPIDER),
// Zombies
ZOMBIE(95, ABSTRACT_MONSTER),
DROWNED(16, ZOMBIE),
HUSK(33, ZOMBIE),
ZOMBIE_PIGMAN(57, ZOMBIE),
ZOMBIE_VILLAGER(97, ZOMBIE),
// Flying entities
ABSTRACT_FLYING(-1, ABSTRACT_INSENTIENT),
GHAST(29, ABSTRACT_FLYING),
PHANTOM(98, ABSTRACT_FLYING),
ABSTRACT_AMBIENT(-1, ABSTRACT_INSENTIENT),
BAT(3, ABSTRACT_AMBIENT),
ABSTRACT_WATERMOB(-1, ABSTRACT_INSENTIENT),
SQUID(74, ABSTRACT_WATERMOB),
// Slimes
SLIME(68, ABSTRACT_INSENTIENT),
MAGMA_CUBE(41, SLIME),
// Hangable objects
ABSTRACT_HANGING(-1, ENTITY),
LEASH_KNOT(38, ABSTRACT_HANGING),
ITEM_FRAME(36, ABSTRACT_HANGING),
PAINTING(52, ABSTRACT_HANGING),
ABSTRACT_LIGHTNING(-1, ENTITY),
LIGHTNING_BOLT(100, ABSTRACT_LIGHTNING),
// Arrows
ABSTRACT_ARROW(-1, ENTITY),
ARROW(2, ABSTRACT_ARROW),
SPECTRAL_ARROW(72, ABSTRACT_ARROW),
TRIDENT(83, ABSTRACT_ARROW),
// Fireballs
ABSTRACT_FIREBALL(-1, ENTITY),
DRAGON_FIREBALL(15, ABSTRACT_FIREBALL),
FIREBALL(37, ABSTRACT_FIREBALL),
SMALL_FIREBALL(69, ABSTRACT_FIREBALL),
WITHER_SKULL(93, ABSTRACT_FIREBALL),
// Hanging entities
ABSTRACT_HANGING(ENTITY, null),
LEASH_KNOT(ABSTRACT_HANGING),
PAINTING(ABSTRACT_HANGING),
ITEM_FRAME(ABSTRACT_HANGING),
// Projectiles
PROJECTILE_ABSTRACT(-1, ENTITY),
SNOWBALL(71, PROJECTILE_ABSTRACT),
ENDER_PEARL(80, PROJECTILE_ABSTRACT),
EGG(79, PROJECTILE_ABSTRACT),
POTION(82, PROJECTILE_ABSTRACT),
EXPERIENCE_BOTTLE(81, PROJECTILE_ABSTRACT),
PROJECTILE_ABSTRACT(ENTITY, null), // Not actually its own abstract type, but useful for categorizing
SNOWBALL(PROJECTILE_ABSTRACT),
ENDER_PEARL(PROJECTILE_ABSTRACT),
EGG(PROJECTILE_ABSTRACT),
POTION(PROJECTILE_ABSTRACT),
EXPERIENCE_BOTTLE(PROJECTILE_ABSTRACT),
FIREWORK_ROCKET(PROJECTILE_ABSTRACT),
LLAMA_SPIT(PROJECTILE_ABSTRACT),
SHULKER_BULLET(PROJECTILE_ABSTRACT),
FISHING_BOBBER(PROJECTILE_ABSTRACT),
WITHER_SKULL(PROJECTILE_ABSTRACT),
DRAGON_FIREBALL(PROJECTILE_ABSTRACT), // Doesn't actually inherit fireball
ABSTRACT_ARROW(PROJECTILE_ABSTRACT, null),
ARROW(ABSTRACT_ARROW),
SPECTRAL_ARROW(ABSTRACT_ARROW),
TRIDENT(ABSTRACT_ARROW),
ABSTRACT_FIREBALL(ENTITY, null),
FIREBALL(ABSTRACT_FIREBALL),
SMALL_FIREBALL(ABSTRACT_FIREBALL),
// Vehicles
MINECART_ABSTRACT(-1, ENTITY),
CHESTED_MINECART_ABSTRACT(-1, MINECART_ABSTRACT),
CHEST_MINECART(43, CHESTED_MINECART_ABSTRACT),
HOPPER_MINECART(46, CHESTED_MINECART_ABSTRACT),
MINECART(42, MINECART_ABSTRACT),
FURNACE_MINECART(45, MINECART_ABSTRACT),
COMMAND_BLOCK_MINECART(44, MINECART_ABSTRACT),
TNT_MINECART(48, MINECART_ABSTRACT),
SPAWNER_MINECART(47, MINECART_ABSTRACT),
BOAT(6, ENTITY);
VEHICLE(ENTITY, null),
BOAT(VEHICLE),
private static final EntityType[] TYPES;
MINECART_ABSTRACT(VEHICLE, null),
MINECART(MINECART_ABSTRACT),
FURNACE_MINECART(MINECART_ABSTRACT),
COMMAND_BLOCK_MINECART(MINECART_ABSTRACT),
TNT_MINECART(MINECART_ABSTRACT),
SPAWNER_MINECART(MINECART_ABSTRACT),
private final int id;
CHESTED_MINECART_ABSTRACT(MINECART_ABSTRACT, null),
CHEST_MINECART(CHESTED_MINECART_ABSTRACT),
HOPPER_MINECART(CHESTED_MINECART_ABSTRACT),
// Living entities as a larger subclass
LIVINGENTITY(ENTITY, null),
ARMOR_STAND(LIVINGENTITY),
PLAYER(LIVINGENTITY),
// Mobs as a larger subclass
ABSTRACT_INSENTIENT(LIVINGENTITY, null),
ENDER_DRAGON(ABSTRACT_INSENTIENT),
SLIME(ABSTRACT_INSENTIENT),
MAGMA_CUBE(SLIME),
// Ambient mobs
ABSTRACT_AMBIENT(ABSTRACT_INSENTIENT, null),
BAT(ABSTRACT_AMBIENT),
// Flying mobs
ABSTRACT_FLYING(ABSTRACT_INSENTIENT, null),
GHAST(ABSTRACT_FLYING),
PHANTOM(ABSTRACT_FLYING),
// Pathfinder mobs and its subclasses
ABSTRACT_CREATURE(ABSTRACT_INSENTIENT, null),
ABSTRACT_GOLEM(ABSTRACT_CREATURE, null),
SNOW_GOLEM(ABSTRACT_GOLEM),
IRON_GOLEM(ABSTRACT_GOLEM),
SHULKER(ABSTRACT_GOLEM),
// Water mobs
ABSTRACT_WATERMOB(ABSTRACT_CREATURE, null),
DOLPHIN(ABSTRACT_WATERMOB),
SQUID(ABSTRACT_WATERMOB),
ABSTRACT_FISHES(ABSTRACT_WATERMOB, null),
PUFFERFISH(ABSTRACT_FISHES),
ABSTRACT_SCHOOLING_FISH(ABSTRACT_FISHES, null),
COD(ABSTRACT_SCHOOLING_FISH),
SALMON(ABSTRACT_SCHOOLING_FISH),
TROPICAL_FISH(ABSTRACT_SCHOOLING_FISH),
// Ageable mobs and (tamable) animals
ABSTRACT_AGEABLE(ABSTRACT_CREATURE, null),
ABSTRACT_VILLAGER(ABSTRACT_AGEABLE, null),
VILLAGER(ABSTRACT_VILLAGER),
WANDERING_TRADER(ABSTRACT_VILLAGER),
ABSTRACT_ANIMAL(ABSTRACT_AGEABLE, null),
CHICKEN(ABSTRACT_ANIMAL),
PANDA(ABSTRACT_ANIMAL),
PIG(ABSTRACT_ANIMAL),
POLAR_BEAR(ABSTRACT_ANIMAL),
RABBIT(ABSTRACT_ANIMAL),
SHEEP(ABSTRACT_ANIMAL),
BEE(ABSTRACT_ANIMAL),
TURTLE(ABSTRACT_ANIMAL),
FOX(ABSTRACT_ANIMAL),
COW(ABSTRACT_ANIMAL),
MOOSHROOM(COW),
ABSTRACT_TAMEABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(ABSTRACT_TAMEABLE_ANIMAL),
OCELOT(ABSTRACT_TAMEABLE_ANIMAL),
WOLF(ABSTRACT_TAMEABLE_ANIMAL),
PARROT(ABSTRACT_TAMEABLE_ANIMAL),
ABSTRACT_HORSE(ABSTRACT_ANIMAL, null),
HORSE(ABSTRACT_HORSE),
SKELETON_HORSE(ABSTRACT_HORSE),
ZOMBIE_HORSE(ABSTRACT_HORSE),
CHESTED_HORSE(ABSTRACT_HORSE, null),
DONKEY(CHESTED_HORSE),
MULE(CHESTED_HORSE),
LLAMA(CHESTED_HORSE),
TRADER_LLAMA(LLAMA),
// Monsters
ABSTRACT_MONSTER(ABSTRACT_CREATURE, null),
BLAZE(ABSTRACT_MONSTER),
CREEPER(ABSTRACT_MONSTER),
ENDERMITE(ABSTRACT_MONSTER),
ENDERMAN(ABSTRACT_MONSTER),
GIANT(ABSTRACT_MONSTER),
SILVERFISH(ABSTRACT_MONSTER),
VEX(ABSTRACT_MONSTER),
WITHER(ABSTRACT_MONSTER),
ABSTRACT_SKELETON(ABSTRACT_MONSTER, null),
SKELETON(ABSTRACT_SKELETON),
STRAY(ABSTRACT_SKELETON),
WITHER_SKELETON(ABSTRACT_SKELETON),
ZOMBIE(ABSTRACT_MONSTER),
DROWNED(ZOMBIE),
HUSK(ZOMBIE),
ZOMBIE_PIGMAN(ZOMBIE),
ZOMBIE_VILLAGER(ZOMBIE),
GUARDIAN(ABSTRACT_MONSTER),
ELDER_GUARDIAN(GUARDIAN),
SPIDER(ABSTRACT_MONSTER),
CAVE_SPIDER(SPIDER),
// Raiders
ABSTRACT_RAIDER(ABSTRACT_MONSTER, null),
WITCH(ABSTRACT_RAIDER),
RAVAGER(ABSTRACT_RAIDER),
ABSTRACT_ILLAGER_BASE(ABSTRACT_RAIDER, null),
ABSTRACT_EVO_ILLU_ILLAGER(ABSTRACT_ILLAGER_BASE, null),
VINDICATOR(ABSTRACT_ILLAGER_BASE),
PILLAGER(ABSTRACT_ILLAGER_BASE),
EVOKER(ABSTRACT_EVO_ILLU_ILLAGER),
ILLUSIONER(ABSTRACT_EVO_ILLU_ILLAGER);
private static final EntityType[] TYPES = EntityTypeUtil.createSizedArray(values());
private final EntityType parent;
private final String identifier;
private int id = -1;
EntityTypes1_15(int id) {
this.id = id;
this.parent = null;
EntityTypes1_15(final EntityType parent) {
this.parent = parent;
this.identifier = "minecraft:" + name().toLowerCase(Locale.ROOT);
}
EntityTypes1_15(int id, EntityType parent) {
this.id = id;
EntityTypes1_15(final EntityType parent, @Nullable final String identifier) {
this.parent = parent;
this.identifier = identifier;
}
@Override
public int getId() {
if (id == -1) {
throw new IllegalStateException("Ids have not been initialized yet (type " + name() + ")");
}
return id;
}
@Override
public EntityType getParent() {
public String identifier() {
Preconditions.checkArgument(identifier != null, "Called identifier method on abstract type");
return identifier;
}
@Override
public @Nullable EntityType getParent() {
return parent;
}
@Override
public String identifier() {
throw new UnsupportedOperationException();
}
@Override
public boolean isAbstractType() {
return id != -1;
return identifier == null;
}
static {
TYPES = EntityTypeUtil.toOrderedArray(values());
}
public static EntityType getTypeFromId(int typeId) {
public static EntityType getTypeFromId(final int typeId) {
return EntityTypeUtil.getTypeFromId(TYPES, typeId, ENTITY);
}
public static void initialize(final Protocol<?, ?, ?, ?> protocol) {
EntityTypeUtil.initialize(values(), TYPES, protocol, (type, id) -> type.id = id);
}
}

View File

@ -22,230 +22,237 @@
*/
package com.viaversion.viaversion.api.minecraft.entities;
import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.util.EntityTypeUtil;
import java.util.Locale;
import org.checkerframework.checker.nullness.qual.Nullable;
public enum EntityTypes1_16 implements EntityType {
ENTITY(-1),
ENTITY(null, null),
AREA_EFFECT_CLOUD(0, ENTITY),
END_CRYSTAL(18, ENTITY),
EVOKER_FANGS(23, ENTITY),
EXPERIENCE_ORB(24, ENTITY),
EYE_OF_ENDER(25, ENTITY),
FALLING_BLOCK(26, ENTITY),
FIREWORK_ROCKET(27, ENTITY),
ITEM(37, ENTITY),
LLAMA_SPIT(43, ENTITY),
TNT(63, ENTITY),
SHULKER_BULLET(70, ENTITY),
FISHING_BOBBER(106, ENTITY),
AREA_EFFECT_CLOUD(ENTITY),
END_CRYSTAL(ENTITY),
EVOKER_FANGS(ENTITY),
EXPERIENCE_ORB(ENTITY),
EYE_OF_ENDER(ENTITY),
FALLING_BLOCK(ENTITY),
ITEM(ENTITY),
TNT(ENTITY),
LIGHTNING_BOLT(ENTITY),
LIVINGENTITY(-1, ENTITY),
ARMOR_STAND(1, LIVINGENTITY),
PLAYER(105, LIVINGENTITY),
ABSTRACT_INSENTIENT(-1, LIVINGENTITY),
ENDER_DRAGON(19, ABSTRACT_INSENTIENT),
BEE(4, ABSTRACT_INSENTIENT),
ABSTRACT_CREATURE(-1, ABSTRACT_INSENTIENT),
ABSTRACT_AGEABLE(-1, ABSTRACT_CREATURE),
VILLAGER(92, ABSTRACT_AGEABLE),
WANDERING_TRADER(94, ABSTRACT_AGEABLE),
// Animals
ABSTRACT_ANIMAL(-1, ABSTRACT_AGEABLE),
DOLPHIN(13, ABSTRACT_INSENTIENT),
CHICKEN(9, ABSTRACT_ANIMAL),
COW(11, ABSTRACT_ANIMAL),
MOOSHROOM(53, COW),
PANDA(56, ABSTRACT_INSENTIENT),
PIG(59, ABSTRACT_ANIMAL),
POLAR_BEAR(62, ABSTRACT_ANIMAL),
RABBIT(65, ABSTRACT_ANIMAL),
SHEEP(68, ABSTRACT_ANIMAL),
TURTLE(90, ABSTRACT_ANIMAL),
FOX(28, ABSTRACT_ANIMAL),
ABSTRACT_TAMEABLE_ANIMAL(-1, ABSTRACT_ANIMAL),
CAT(7, ABSTRACT_TAMEABLE_ANIMAL),
OCELOT(54, ABSTRACT_TAMEABLE_ANIMAL),
WOLF(99, ABSTRACT_TAMEABLE_ANIMAL),
ABSTRACT_PARROT(-1, ABSTRACT_TAMEABLE_ANIMAL),
PARROT(57, ABSTRACT_PARROT),
// Horses
ABSTRACT_HORSE(-1, ABSTRACT_ANIMAL),
CHESTED_HORSE(-1, ABSTRACT_HORSE),
DONKEY(14, CHESTED_HORSE),
MULE(52, CHESTED_HORSE),
LLAMA(42, CHESTED_HORSE),
TRADER_LLAMA(88, CHESTED_HORSE),
HORSE(33, ABSTRACT_HORSE),
SKELETON_HORSE(73, ABSTRACT_HORSE),
ZOMBIE_HORSE(102, ABSTRACT_HORSE),
// Golem
ABSTRACT_GOLEM(-1, ABSTRACT_CREATURE),
SNOW_GOLEM(76, ABSTRACT_GOLEM),
IRON_GOLEM(36, ABSTRACT_GOLEM),
SHULKER(69, ABSTRACT_GOLEM),
// Fish
ABSTRACT_FISHES(-1, ABSTRACT_CREATURE),
COD(10, ABSTRACT_FISHES),
PUFFERFISH(64, ABSTRACT_FISHES),
SALMON(67, ABSTRACT_FISHES),
TROPICAL_FISH(89, ABSTRACT_FISHES),
// Monsters
ABSTRACT_MONSTER(-1, ABSTRACT_CREATURE),
BLAZE(5, ABSTRACT_MONSTER),
CREEPER(12, ABSTRACT_MONSTER),
ENDERMITE(21, ABSTRACT_MONSTER),
ENDERMAN(20, ABSTRACT_MONSTER),
GIANT(30, ABSTRACT_MONSTER),
SILVERFISH(71, ABSTRACT_MONSTER),
VEX(91, ABSTRACT_MONSTER),
WITCH(95, ABSTRACT_MONSTER),
WITHER(96, ABSTRACT_MONSTER),
RAVAGER(66, ABSTRACT_MONSTER),
PIGLIN(60, ABSTRACT_MONSTER),
HOGLIN(32, ABSTRACT_ANIMAL),
STRIDER(82, ABSTRACT_ANIMAL),
ZOGLIN(100, ABSTRACT_MONSTER),
// Illagers
ABSTRACT_ILLAGER_BASE(-1, ABSTRACT_MONSTER),
ABSTRACT_EVO_ILLU_ILLAGER(-1, ABSTRACT_ILLAGER_BASE),
EVOKER(22, ABSTRACT_EVO_ILLU_ILLAGER),
ILLUSIONER(35, ABSTRACT_EVO_ILLU_ILLAGER),
VINDICATOR(93, ABSTRACT_ILLAGER_BASE),
PILLAGER(61, ABSTRACT_ILLAGER_BASE),
// Skeletons
ABSTRACT_SKELETON(-1, ABSTRACT_MONSTER),
SKELETON(72, ABSTRACT_SKELETON),
STRAY(81, ABSTRACT_SKELETON),
WITHER_SKELETON(97, ABSTRACT_SKELETON),
// Guardians
GUARDIAN(31, ABSTRACT_MONSTER),
ELDER_GUARDIAN(17, GUARDIAN),
// Spiders
SPIDER(79, ABSTRACT_MONSTER),
CAVE_SPIDER(8, SPIDER),
// Zombies
ZOMBIE(101, ABSTRACT_MONSTER),
DROWNED(16, ZOMBIE),
HUSK(34, ZOMBIE),
ZOMBIFIED_PIGLIN(104, ZOMBIE),
ZOMBIE_VILLAGER(103, ZOMBIE),
// Flying entities
ABSTRACT_FLYING(-1, ABSTRACT_INSENTIENT),
GHAST(29, ABSTRACT_FLYING),
PHANTOM(58, ABSTRACT_FLYING),
ABSTRACT_AMBIENT(-1, ABSTRACT_INSENTIENT),
BAT(3, ABSTRACT_AMBIENT),
ABSTRACT_WATERMOB(-1, ABSTRACT_INSENTIENT),
SQUID(80, ABSTRACT_WATERMOB),
// Slimes
SLIME(74, ABSTRACT_INSENTIENT),
MAGMA_CUBE(44, SLIME),
// Hangable objects
ABSTRACT_HANGING(-1, ENTITY),
LEASH_KNOT(40, ABSTRACT_HANGING),
ITEM_FRAME(38, ABSTRACT_HANGING),
PAINTING(55, ABSTRACT_HANGING),
ABSTRACT_LIGHTNING(-1, ENTITY),
LIGHTNING_BOLT(41, ABSTRACT_LIGHTNING),
// Arrows
ABSTRACT_ARROW(-1, ENTITY),
ARROW(2, ABSTRACT_ARROW),
SPECTRAL_ARROW(78, ABSTRACT_ARROW),
TRIDENT(87, ABSTRACT_ARROW),
// Fireballs
ABSTRACT_FIREBALL(-1, ENTITY),
DRAGON_FIREBALL(15, ABSTRACT_FIREBALL),
FIREBALL(39, ABSTRACT_FIREBALL),
SMALL_FIREBALL(75, ABSTRACT_FIREBALL),
WITHER_SKULL(98, ABSTRACT_FIREBALL),
// Hanging entities
ABSTRACT_HANGING(ENTITY, null),
LEASH_KNOT(ABSTRACT_HANGING),
PAINTING(ABSTRACT_HANGING),
ITEM_FRAME(ABSTRACT_HANGING),
// Projectiles
PROJECTILE_ABSTRACT(-1, ENTITY),
SNOWBALL(77, PROJECTILE_ABSTRACT),
ENDER_PEARL(84, PROJECTILE_ABSTRACT),
EGG(83, PROJECTILE_ABSTRACT),
POTION(86, PROJECTILE_ABSTRACT),
EXPERIENCE_BOTTLE(85, PROJECTILE_ABSTRACT),
PROJECTILE_ABSTRACT(ENTITY, null), // Not actually its own abstract type, but useful for categorizing
SNOWBALL(PROJECTILE_ABSTRACT),
ENDER_PEARL(PROJECTILE_ABSTRACT),
EGG(PROJECTILE_ABSTRACT),
POTION(PROJECTILE_ABSTRACT),
EXPERIENCE_BOTTLE(PROJECTILE_ABSTRACT),
FIREWORK_ROCKET(PROJECTILE_ABSTRACT),
LLAMA_SPIT(PROJECTILE_ABSTRACT),
SHULKER_BULLET(PROJECTILE_ABSTRACT),
FISHING_BOBBER(PROJECTILE_ABSTRACT),
WITHER_SKULL(PROJECTILE_ABSTRACT),
DRAGON_FIREBALL(PROJECTILE_ABSTRACT), // Doesn't actually inherit fireball
ABSTRACT_ARROW(PROJECTILE_ABSTRACT, null),
ARROW(ABSTRACT_ARROW),
SPECTRAL_ARROW(ABSTRACT_ARROW),
TRIDENT(ABSTRACT_ARROW),
ABSTRACT_FIREBALL(ENTITY, null),
FIREBALL(ABSTRACT_FIREBALL),
SMALL_FIREBALL(ABSTRACT_FIREBALL),
// Vehicles
MINECART_ABSTRACT(-1, ENTITY),
CHESTED_MINECART_ABSTRACT(-1, MINECART_ABSTRACT),
CHEST_MINECART(46, CHESTED_MINECART_ABSTRACT),
HOPPER_MINECART(49, CHESTED_MINECART_ABSTRACT),
MINECART(45, MINECART_ABSTRACT),
FURNACE_MINECART(48, MINECART_ABSTRACT),
COMMAND_BLOCK_MINECART(47, MINECART_ABSTRACT),
TNT_MINECART(51, MINECART_ABSTRACT),
SPAWNER_MINECART(50, MINECART_ABSTRACT),
BOAT(6, ENTITY);
VEHICLE(ENTITY, null),
BOAT(VEHICLE),
private static final EntityType[] TYPES;
MINECART_ABSTRACT(VEHICLE, null),
MINECART(MINECART_ABSTRACT),
FURNACE_MINECART(MINECART_ABSTRACT),
COMMAND_BLOCK_MINECART(MINECART_ABSTRACT),
TNT_MINECART(MINECART_ABSTRACT),
SPAWNER_MINECART(MINECART_ABSTRACT),
private final int id;
CHESTED_MINECART_ABSTRACT(MINECART_ABSTRACT, null),
CHEST_MINECART(CHESTED_MINECART_ABSTRACT),
HOPPER_MINECART(CHESTED_MINECART_ABSTRACT),
// Living entities as a larger subclass
LIVINGENTITY(ENTITY, null),
ARMOR_STAND(LIVINGENTITY),
PLAYER(LIVINGENTITY),
// Mobs as a larger subclass
ABSTRACT_INSENTIENT(LIVINGENTITY, null),
ENDER_DRAGON(ABSTRACT_INSENTIENT),
SLIME(ABSTRACT_INSENTIENT),
MAGMA_CUBE(SLIME),
// Ambient mobs
ABSTRACT_AMBIENT(ABSTRACT_INSENTIENT, null),
BAT(ABSTRACT_AMBIENT),
// Flying mobs
ABSTRACT_FLYING(ABSTRACT_INSENTIENT, null),
GHAST(ABSTRACT_FLYING),
PHANTOM(ABSTRACT_FLYING),
// Pathfinder mobs and its subclasses
ABSTRACT_CREATURE(ABSTRACT_INSENTIENT, null),
ABSTRACT_GOLEM(ABSTRACT_CREATURE, null),
SNOW_GOLEM(ABSTRACT_GOLEM),
IRON_GOLEM(ABSTRACT_GOLEM),
SHULKER(ABSTRACT_GOLEM),
// Water mobs
ABSTRACT_WATERMOB(ABSTRACT_CREATURE, null),
DOLPHIN(ABSTRACT_WATERMOB),
SQUID(ABSTRACT_WATERMOB),
ABSTRACT_FISHES(ABSTRACT_WATERMOB, null),
PUFFERFISH(ABSTRACT_FISHES),
ABSTRACT_SCHOOLING_FISH(ABSTRACT_FISHES, null),
COD(ABSTRACT_SCHOOLING_FISH),
SALMON(ABSTRACT_SCHOOLING_FISH),
TROPICAL_FISH(ABSTRACT_SCHOOLING_FISH),
// Ageable mobs and (tamable) animals
ABSTRACT_AGEABLE(ABSTRACT_CREATURE, null),
ABSTRACT_VILLAGER(ABSTRACT_AGEABLE, null),
VILLAGER(ABSTRACT_VILLAGER),
WANDERING_TRADER(ABSTRACT_VILLAGER),
ABSTRACT_ANIMAL(ABSTRACT_AGEABLE, null),
CHICKEN(ABSTRACT_ANIMAL),
PANDA(ABSTRACT_ANIMAL),
PIG(ABSTRACT_ANIMAL),
POLAR_BEAR(ABSTRACT_ANIMAL),
RABBIT(ABSTRACT_ANIMAL),
SHEEP(ABSTRACT_ANIMAL),
BEE(ABSTRACT_ANIMAL),
TURTLE(ABSTRACT_ANIMAL),
FOX(ABSTRACT_ANIMAL),
HOGLIN(ABSTRACT_ANIMAL),
STRIDER(ABSTRACT_ANIMAL),
COW(ABSTRACT_ANIMAL),
MOOSHROOM(COW),
ABSTRACT_TAMEABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(ABSTRACT_TAMEABLE_ANIMAL),
OCELOT(ABSTRACT_TAMEABLE_ANIMAL),
WOLF(ABSTRACT_TAMEABLE_ANIMAL),
PARROT(ABSTRACT_TAMEABLE_ANIMAL),
ABSTRACT_HORSE(ABSTRACT_ANIMAL, null),
HORSE(ABSTRACT_HORSE),
SKELETON_HORSE(ABSTRACT_HORSE),
ZOMBIE_HORSE(ABSTRACT_HORSE),
CHESTED_HORSE(ABSTRACT_HORSE, null),
DONKEY(CHESTED_HORSE),
MULE(CHESTED_HORSE),
LLAMA(CHESTED_HORSE),
TRADER_LLAMA(LLAMA),
// Monsters
ABSTRACT_MONSTER(ABSTRACT_CREATURE, null),
BLAZE(ABSTRACT_MONSTER),
CREEPER(ABSTRACT_MONSTER),
ENDERMITE(ABSTRACT_MONSTER),
ENDERMAN(ABSTRACT_MONSTER),
GIANT(ABSTRACT_MONSTER),
SILVERFISH(ABSTRACT_MONSTER),
VEX(ABSTRACT_MONSTER),
WITHER(ABSTRACT_MONSTER),
ZOGLIN(ABSTRACT_MONSTER),
PIGLIN(ABSTRACT_MONSTER),
ABSTRACT_SKELETON(ABSTRACT_MONSTER, null),
SKELETON(ABSTRACT_SKELETON),
STRAY(ABSTRACT_SKELETON),
WITHER_SKELETON(ABSTRACT_SKELETON),
ZOMBIE(ABSTRACT_MONSTER),
DROWNED(ZOMBIE),
HUSK(ZOMBIE),
ZOMBIFIED_PIGLIN(ZOMBIE),
ZOMBIE_VILLAGER(ZOMBIE),
GUARDIAN(ABSTRACT_MONSTER),
ELDER_GUARDIAN(GUARDIAN),
SPIDER(ABSTRACT_MONSTER),
CAVE_SPIDER(SPIDER),
// Raiders
ABSTRACT_RAIDER(ABSTRACT_MONSTER, null),
WITCH(ABSTRACT_RAIDER),
RAVAGER(ABSTRACT_RAIDER),
ABSTRACT_ILLAGER_BASE(ABSTRACT_RAIDER, null),
ABSTRACT_EVO_ILLU_ILLAGER(ABSTRACT_ILLAGER_BASE, null),
VINDICATOR(ABSTRACT_ILLAGER_BASE),
PILLAGER(ABSTRACT_ILLAGER_BASE),
EVOKER(ABSTRACT_EVO_ILLU_ILLAGER),
ILLUSIONER(ABSTRACT_EVO_ILLU_ILLAGER);
private static final EntityType[] TYPES = EntityTypeUtil.createSizedArray(values());
private final EntityType parent;
private final String identifier;
private int id = -1;
EntityTypes1_16(int id) {
this.id = id;
this.parent = null;
EntityTypes1_16(final EntityType parent) {
this.parent = parent;
this.identifier = "minecraft:" + name().toLowerCase(Locale.ROOT);
}
EntityTypes1_16(int id, EntityType parent) {
this.id = id;
EntityTypes1_16(final EntityType parent, @Nullable final String identifier) {
this.parent = parent;
this.identifier = identifier;
}
@Override
public int getId() {
if (id == -1) {
throw new IllegalStateException("Ids have not been initialized yet (type " + name() + ")");
}
return id;
}
@Override
public EntityType getParent() {
public String identifier() {
Preconditions.checkArgument(identifier != null, "Called identifier method on abstract type");
return identifier;
}
@Override
public @Nullable EntityType getParent() {
return parent;
}
@Override
public String identifier() {
throw new UnsupportedOperationException();
}
@Override
public boolean isAbstractType() {
return id != -1;
return identifier == null;
}
static {
TYPES = EntityTypeUtil.toOrderedArray(values());
}
public static EntityType getTypeFromId(int typeId) {
public static EntityType getTypeFromId(final int typeId) {
return EntityTypeUtil.getTypeFromId(TYPES, typeId, ENTITY);
}
public static void initialize(final Protocol<?, ?, ?, ?> protocol) {
EntityTypeUtil.initialize(values(), TYPES, protocol, (type, id) -> type.id = id);
}
}

View File

@ -22,234 +22,240 @@
*/
package com.viaversion.viaversion.api.minecraft.entities;
import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.util.EntityTypeUtil;
import java.util.Locale;
import org.checkerframework.checker.nullness.qual.Nullable;
public enum EntityTypes1_16_2 implements EntityType {
ENTITY(-1),
ENTITY(null, null),
AREA_EFFECT_CLOUD(0, ENTITY),
END_CRYSTAL(18, ENTITY),
EVOKER_FANGS(23, ENTITY),
EXPERIENCE_ORB(24, ENTITY),
EYE_OF_ENDER(25, ENTITY),
FALLING_BLOCK(26, ENTITY),
FIREWORK_ROCKET(27, ENTITY),
ITEM(37, ENTITY),
LLAMA_SPIT(43, ENTITY),
TNT(64, ENTITY),
SHULKER_BULLET(71, ENTITY),
FISHING_BOBBER(107, ENTITY),
AREA_EFFECT_CLOUD(ENTITY),
END_CRYSTAL(ENTITY),
EVOKER_FANGS(ENTITY),
EXPERIENCE_ORB(ENTITY),
EYE_OF_ENDER(ENTITY),
FALLING_BLOCK(ENTITY),
ITEM(ENTITY),
TNT(ENTITY),
LIGHTNING_BOLT(ENTITY),
LIVINGENTITY(-1, ENTITY),
ARMOR_STAND(1, LIVINGENTITY),
PLAYER(106, LIVINGENTITY),
ABSTRACT_INSENTIENT(-1, LIVINGENTITY),
ENDER_DRAGON(19, ABSTRACT_INSENTIENT),
BEE(4, ABSTRACT_INSENTIENT),
ABSTRACT_CREATURE(-1, ABSTRACT_INSENTIENT),
ABSTRACT_AGEABLE(-1, ABSTRACT_CREATURE),
VILLAGER(93, ABSTRACT_AGEABLE),
WANDERING_TRADER(95, ABSTRACT_AGEABLE),
// Animals
ABSTRACT_ANIMAL(-1, ABSTRACT_AGEABLE),
DOLPHIN(13, ABSTRACT_INSENTIENT),
CHICKEN(9, ABSTRACT_ANIMAL),
COW(11, ABSTRACT_ANIMAL),
MOOSHROOM(53, COW),
PANDA(56, ABSTRACT_INSENTIENT),
PIG(59, ABSTRACT_ANIMAL),
POLAR_BEAR(63, ABSTRACT_ANIMAL),
RABBIT(66, ABSTRACT_ANIMAL),
SHEEP(69, ABSTRACT_ANIMAL),
TURTLE(91, ABSTRACT_ANIMAL),
FOX(28, ABSTRACT_ANIMAL),
ABSTRACT_TAMEABLE_ANIMAL(-1, ABSTRACT_ANIMAL),
CAT(7, ABSTRACT_TAMEABLE_ANIMAL),
OCELOT(54, ABSTRACT_TAMEABLE_ANIMAL),
WOLF(100, ABSTRACT_TAMEABLE_ANIMAL),
ABSTRACT_PARROT(-1, ABSTRACT_TAMEABLE_ANIMAL),
PARROT(57, ABSTRACT_PARROT),
// Horses
ABSTRACT_HORSE(-1, ABSTRACT_ANIMAL),
CHESTED_HORSE(-1, ABSTRACT_HORSE),
DONKEY(14, CHESTED_HORSE),
MULE(52, CHESTED_HORSE),
LLAMA(42, CHESTED_HORSE),
TRADER_LLAMA(89, CHESTED_HORSE),
HORSE(33, ABSTRACT_HORSE),
SKELETON_HORSE(74, ABSTRACT_HORSE),
ZOMBIE_HORSE(103, ABSTRACT_HORSE),
// Golem
ABSTRACT_GOLEM(-1, ABSTRACT_CREATURE),
SNOW_GOLEM(77, ABSTRACT_GOLEM),
IRON_GOLEM(36, ABSTRACT_GOLEM),
SHULKER(70, ABSTRACT_GOLEM),
// Fish
ABSTRACT_FISHES(-1, ABSTRACT_CREATURE),
COD(10, ABSTRACT_FISHES),
PUFFERFISH(65, ABSTRACT_FISHES),
SALMON(68, ABSTRACT_FISHES),
TROPICAL_FISH(90, ABSTRACT_FISHES),
// Monsters
ABSTRACT_MONSTER(-1, ABSTRACT_CREATURE),
BLAZE(5, ABSTRACT_MONSTER),
CREEPER(12, ABSTRACT_MONSTER),
ENDERMITE(21, ABSTRACT_MONSTER),
ENDERMAN(20, ABSTRACT_MONSTER),
GIANT(30, ABSTRACT_MONSTER),
SILVERFISH(72, ABSTRACT_MONSTER),
VEX(92, ABSTRACT_MONSTER),
WITCH(96, ABSTRACT_MONSTER),
WITHER(97, ABSTRACT_MONSTER),
RAVAGER(67, ABSTRACT_MONSTER),
ABSTRACT_PIGLIN(-1, ABSTRACT_MONSTER),
PIGLIN(60, ABSTRACT_PIGLIN),
PIGLIN_BRUTE(61, ABSTRACT_PIGLIN),
HOGLIN(32, ABSTRACT_ANIMAL),
STRIDER(83, ABSTRACT_ANIMAL),
ZOGLIN(101, ABSTRACT_MONSTER),
// Illagers
ABSTRACT_ILLAGER_BASE(-1, ABSTRACT_MONSTER),
ABSTRACT_EVO_ILLU_ILLAGER(-1, ABSTRACT_ILLAGER_BASE),
EVOKER(22, ABSTRACT_EVO_ILLU_ILLAGER),
ILLUSIONER(35, ABSTRACT_EVO_ILLU_ILLAGER),
VINDICATOR(94, ABSTRACT_ILLAGER_BASE),
PILLAGER(62, ABSTRACT_ILLAGER_BASE),
// Skeletons
ABSTRACT_SKELETON(-1, ABSTRACT_MONSTER),
SKELETON(73, ABSTRACT_SKELETON),
STRAY(82, ABSTRACT_SKELETON),
WITHER_SKELETON(98, ABSTRACT_SKELETON),
// Guardians
GUARDIAN(31, ABSTRACT_MONSTER),
ELDER_GUARDIAN(17, GUARDIAN),
// Spiders
SPIDER(80, ABSTRACT_MONSTER),
CAVE_SPIDER(8, SPIDER),
// Zombies
ZOMBIE(102, ABSTRACT_MONSTER),
DROWNED(16, ZOMBIE),
HUSK(34, ZOMBIE),
ZOMBIFIED_PIGLIN(105, ZOMBIE),
ZOMBIE_VILLAGER(104, ZOMBIE),
// Flying entities
ABSTRACT_FLYING(-1, ABSTRACT_INSENTIENT),
GHAST(29, ABSTRACT_FLYING),
PHANTOM(58, ABSTRACT_FLYING),
ABSTRACT_AMBIENT(-1, ABSTRACT_INSENTIENT),
BAT(3, ABSTRACT_AMBIENT),
ABSTRACT_WATERMOB(-1, ABSTRACT_INSENTIENT),
SQUID(81, ABSTRACT_WATERMOB),
// Slimes
SLIME(75, ABSTRACT_INSENTIENT),
MAGMA_CUBE(44, SLIME),
// Hangable objects
ABSTRACT_HANGING(-1, ENTITY),
LEASH_KNOT(40, ABSTRACT_HANGING),
ITEM_FRAME(38, ABSTRACT_HANGING),
PAINTING(55, ABSTRACT_HANGING),
ABSTRACT_LIGHTNING(-1, ENTITY),
LIGHTNING_BOLT(41, ABSTRACT_LIGHTNING),
// Arrows
ABSTRACT_ARROW(-1, ENTITY),
ARROW(2, ABSTRACT_ARROW),
SPECTRAL_ARROW(79, ABSTRACT_ARROW),
TRIDENT(88, ABSTRACT_ARROW),
// Fireballs
ABSTRACT_FIREBALL(-1, ENTITY),
DRAGON_FIREBALL(15, ABSTRACT_FIREBALL),
FIREBALL(39, ABSTRACT_FIREBALL),
SMALL_FIREBALL(76, ABSTRACT_FIREBALL),
WITHER_SKULL(99, ABSTRACT_FIREBALL),
// Hanging entities
ABSTRACT_HANGING(ENTITY, null),
LEASH_KNOT(ABSTRACT_HANGING),
PAINTING(ABSTRACT_HANGING),
ITEM_FRAME(ABSTRACT_HANGING),
// Projectiles
PROJECTILE_ABSTRACT(-1, ENTITY),
SNOWBALL(78, PROJECTILE_ABSTRACT),
ENDER_PEARL(85, PROJECTILE_ABSTRACT),
EGG(84, PROJECTILE_ABSTRACT),
POTION(87, PROJECTILE_ABSTRACT),
EXPERIENCE_BOTTLE(86, PROJECTILE_ABSTRACT),
PROJECTILE_ABSTRACT(ENTITY, null), // Not actually its own abstract type, but useful for categorizing
SNOWBALL(PROJECTILE_ABSTRACT),
ENDER_PEARL(PROJECTILE_ABSTRACT),
EGG(PROJECTILE_ABSTRACT),
POTION(PROJECTILE_ABSTRACT),
EXPERIENCE_BOTTLE(PROJECTILE_ABSTRACT),
FIREWORK_ROCKET(PROJECTILE_ABSTRACT),
LLAMA_SPIT(PROJECTILE_ABSTRACT),
SHULKER_BULLET(PROJECTILE_ABSTRACT),
FISHING_BOBBER(PROJECTILE_ABSTRACT),
WITHER_SKULL(PROJECTILE_ABSTRACT),
DRAGON_FIREBALL(PROJECTILE_ABSTRACT), // Doesn't actually inherit fireball
ABSTRACT_ARROW(PROJECTILE_ABSTRACT, null),
ARROW(ABSTRACT_ARROW),
SPECTRAL_ARROW(ABSTRACT_ARROW),
TRIDENT(ABSTRACT_ARROW),
ABSTRACT_FIREBALL(ENTITY, null),
FIREBALL(ABSTRACT_FIREBALL),
SMALL_FIREBALL(ABSTRACT_FIREBALL),
// Vehicles
MINECART_ABSTRACT(-1, ENTITY),
CHESTED_MINECART_ABSTRACT(-1, MINECART_ABSTRACT),
CHEST_MINECART(46, CHESTED_MINECART_ABSTRACT),
HOPPER_MINECART(49, CHESTED_MINECART_ABSTRACT),
MINECART(45, MINECART_ABSTRACT),
FURNACE_MINECART(48, MINECART_ABSTRACT),
COMMAND_BLOCK_MINECART(47, MINECART_ABSTRACT),
TNT_MINECART(51, MINECART_ABSTRACT),
SPAWNER_MINECART(50, MINECART_ABSTRACT),
BOAT(6, ENTITY);
VEHICLE(ENTITY, null),
BOAT(VEHICLE),
private static final EntityType[] TYPES;
MINECART_ABSTRACT(VEHICLE, null),
MINECART(MINECART_ABSTRACT),
FURNACE_MINECART(MINECART_ABSTRACT),
COMMAND_BLOCK_MINECART(MINECART_ABSTRACT),
TNT_MINECART(MINECART_ABSTRACT),
SPAWNER_MINECART(MINECART_ABSTRACT),
private final int id;
CHESTED_MINECART_ABSTRACT(MINECART_ABSTRACT, null),
CHEST_MINECART(CHESTED_MINECART_ABSTRACT),
HOPPER_MINECART(CHESTED_MINECART_ABSTRACT),
// Living entities as a larger subclass
LIVINGENTITY(ENTITY, null),
ARMOR_STAND(LIVINGENTITY),
PLAYER(LIVINGENTITY),
// Mobs as a larger subclass
ABSTRACT_INSENTIENT(LIVINGENTITY, null),
ENDER_DRAGON(ABSTRACT_INSENTIENT),
SLIME(ABSTRACT_INSENTIENT),
MAGMA_CUBE(SLIME),
// Ambient mobs
ABSTRACT_AMBIENT(ABSTRACT_INSENTIENT, null),
BAT(ABSTRACT_AMBIENT),
// Flying mobs
ABSTRACT_FLYING(ABSTRACT_INSENTIENT, null),
GHAST(ABSTRACT_FLYING),
PHANTOM(ABSTRACT_FLYING),
// Pathfinder mobs and its subclasses
ABSTRACT_CREATURE(ABSTRACT_INSENTIENT, null),
ABSTRACT_GOLEM(ABSTRACT_CREATURE, null),
SNOW_GOLEM(ABSTRACT_GOLEM),
IRON_GOLEM(ABSTRACT_GOLEM),
SHULKER(ABSTRACT_GOLEM),
// Water mobs
ABSTRACT_WATERMOB(ABSTRACT_CREATURE, null),
DOLPHIN(ABSTRACT_WATERMOB),
SQUID(ABSTRACT_WATERMOB),
ABSTRACT_FISHES(ABSTRACT_WATERMOB, null),
PUFFERFISH(ABSTRACT_FISHES),
ABSTRACT_SCHOOLING_FISH(ABSTRACT_FISHES, null),
COD(ABSTRACT_SCHOOLING_FISH),
SALMON(ABSTRACT_SCHOOLING_FISH),
TROPICAL_FISH(ABSTRACT_SCHOOLING_FISH),
// Ageable mobs and (tamable) animals
ABSTRACT_AGEABLE(ABSTRACT_CREATURE, null),
ABSTRACT_VILLAGER(ABSTRACT_AGEABLE, null),
VILLAGER(ABSTRACT_VILLAGER),
WANDERING_TRADER(ABSTRACT_VILLAGER),
ABSTRACT_ANIMAL(ABSTRACT_AGEABLE, null),
CHICKEN(ABSTRACT_ANIMAL),
PANDA(ABSTRACT_ANIMAL),
PIG(ABSTRACT_ANIMAL),
POLAR_BEAR(ABSTRACT_ANIMAL),
RABBIT(ABSTRACT_ANIMAL),
SHEEP(ABSTRACT_ANIMAL),
BEE(ABSTRACT_ANIMAL),
TURTLE(ABSTRACT_ANIMAL),
FOX(ABSTRACT_ANIMAL),
HOGLIN(ABSTRACT_ANIMAL),
STRIDER(ABSTRACT_ANIMAL),
COW(ABSTRACT_ANIMAL),
MOOSHROOM(COW),
ABSTRACT_TAMEABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(ABSTRACT_TAMEABLE_ANIMAL),
OCELOT(ABSTRACT_TAMEABLE_ANIMAL),
WOLF(ABSTRACT_TAMEABLE_ANIMAL),
PARROT(ABSTRACT_TAMEABLE_ANIMAL),
ABSTRACT_HORSE(ABSTRACT_ANIMAL, null),
HORSE(ABSTRACT_HORSE),
SKELETON_HORSE(ABSTRACT_HORSE),
ZOMBIE_HORSE(ABSTRACT_HORSE),
CHESTED_HORSE(ABSTRACT_HORSE, null),
DONKEY(CHESTED_HORSE),
MULE(CHESTED_HORSE),
LLAMA(CHESTED_HORSE),
TRADER_LLAMA(LLAMA),
// Monsters
ABSTRACT_MONSTER(ABSTRACT_CREATURE, null),
BLAZE(ABSTRACT_MONSTER),
CREEPER(ABSTRACT_MONSTER),
ENDERMITE(ABSTRACT_MONSTER),
ENDERMAN(ABSTRACT_MONSTER),
GIANT(ABSTRACT_MONSTER),
SILVERFISH(ABSTRACT_MONSTER),
VEX(ABSTRACT_MONSTER),
WITHER(ABSTRACT_MONSTER),
ZOGLIN(ABSTRACT_MONSTER),
ABSTRACT_SKELETON(ABSTRACT_MONSTER, null),
SKELETON(ABSTRACT_SKELETON),
STRAY(ABSTRACT_SKELETON),
WITHER_SKELETON(ABSTRACT_SKELETON),
ZOMBIE(ABSTRACT_MONSTER),
DROWNED(ZOMBIE),
HUSK(ZOMBIE),
ZOMBIFIED_PIGLIN(ZOMBIE),
ZOMBIE_VILLAGER(ZOMBIE),
GUARDIAN(ABSTRACT_MONSTER),
ELDER_GUARDIAN(GUARDIAN),
SPIDER(ABSTRACT_MONSTER),
CAVE_SPIDER(SPIDER),
ABSTRACT_PIGLIN(ABSTRACT_MONSTER, null),
PIGLIN(ABSTRACT_PIGLIN),
PIGLIN_BRUTE(ABSTRACT_PIGLIN),
// Raiders
ABSTRACT_RAIDER(ABSTRACT_MONSTER, null),
WITCH(ABSTRACT_RAIDER),
RAVAGER(ABSTRACT_RAIDER),
ABSTRACT_ILLAGER_BASE(ABSTRACT_RAIDER, null),
ABSTRACT_EVO_ILLU_ILLAGER(ABSTRACT_ILLAGER_BASE, null),
VINDICATOR(ABSTRACT_ILLAGER_BASE),
PILLAGER(ABSTRACT_ILLAGER_BASE),
EVOKER(ABSTRACT_EVO_ILLU_ILLAGER),
ILLUSIONER(ABSTRACT_EVO_ILLU_ILLAGER);
private static final EntityType[] TYPES = EntityTypeUtil.createSizedArray(values());
private final EntityType parent;
private final String identifier;
private int id = -1;
EntityTypes1_16_2(int id) {
this.id = id;
this.parent = null;
EntityTypes1_16_2(final EntityType parent) {
this.parent = parent;
this.identifier = "minecraft:" + name().toLowerCase(Locale.ROOT);
}
EntityTypes1_16_2(int id, EntityType parent) {
this.id = id;
EntityTypes1_16_2(final EntityType parent, @Nullable final String identifier) {
this.parent = parent;
this.identifier = identifier;
}
@Override
public int getId() {
if (id == -1) {
throw new IllegalStateException("Ids have not been initialized yet (type " + name() + ")");
}
return id;
}
@Override
public EntityType getParent() {
public String identifier() {
Preconditions.checkArgument(identifier != null, "Called identifier method on abstract type");
return identifier;
}
@Override
public @Nullable EntityType getParent() {
return parent;
}
@Override
public String identifier() {
throw new UnsupportedOperationException();
}
@Override
public boolean isAbstractType() {
return id != -1;
return identifier == null;
}
static {
TYPES = EntityTypeUtil.toOrderedArray(values());
}
public static EntityType getTypeFromId(int typeId) {
public static EntityType getTypeFromId(final int typeId) {
return EntityTypeUtil.getTypeFromId(TYPES, typeId, ENTITY);
}
}
public static void initialize(final Protocol<?, ?, ?, ?> protocol) {
EntityTypeUtil.initialize(values(), TYPES, protocol, (type, id) -> type.id = id);
}
}

View File

@ -22,239 +22,246 @@
*/
package com.viaversion.viaversion.api.minecraft.entities;
import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.util.EntityTypeUtil;
import java.util.Locale;
import org.checkerframework.checker.nullness.qual.Nullable;
public enum EntityTypes1_17 implements EntityType {
ENTITY(-1),
ENTITY(null, null),
AREA_EFFECT_CLOUD(0, ENTITY),
END_CRYSTAL(19, ENTITY),
EVOKER_FANGS(24, ENTITY),
EXPERIENCE_ORB(25, ENTITY),
EYE_OF_ENDER(26, ENTITY),
FALLING_BLOCK(27, ENTITY),
FIREWORK_ROCKET(28, ENTITY),
ITEM(41, ENTITY),
LLAMA_SPIT(47, ENTITY),
TNT(69, ENTITY),
SHULKER_BULLET(76, ENTITY),
FISHING_BOBBER(112, ENTITY),
AREA_EFFECT_CLOUD(ENTITY),
END_CRYSTAL(ENTITY),
EVOKER_FANGS(ENTITY),
EXPERIENCE_ORB(ENTITY),
EYE_OF_ENDER(ENTITY),
FALLING_BLOCK(ENTITY),
ITEM(ENTITY),
TNT(ENTITY),
MARKER(ENTITY),
LIGHTNING_BOLT(ENTITY),
LIVINGENTITY(-1, ENTITY),
ARMOR_STAND(1, LIVINGENTITY),
MARKER(49, ENTITY),
PLAYER(111, LIVINGENTITY),
ABSTRACT_INSENTIENT(-1, LIVINGENTITY),
ENDER_DRAGON(20, ABSTRACT_INSENTIENT),
BEE(5, ABSTRACT_INSENTIENT),
ABSTRACT_CREATURE(-1, ABSTRACT_INSENTIENT),
ABSTRACT_AGEABLE(-1, ABSTRACT_CREATURE),
VILLAGER(98, ABSTRACT_AGEABLE),
WANDERING_TRADER(100, ABSTRACT_AGEABLE),
// Animals
ABSTRACT_ANIMAL(-1, ABSTRACT_AGEABLE),
AXOLOTL(3, ABSTRACT_ANIMAL),
DOLPHIN(14, ABSTRACT_INSENTIENT),
CHICKEN(10, ABSTRACT_ANIMAL),
COW(12, ABSTRACT_ANIMAL),
MOOSHROOM(58, COW),
PANDA(61, ABSTRACT_INSENTIENT),
PIG(64, ABSTRACT_ANIMAL),
POLAR_BEAR(68, ABSTRACT_ANIMAL),
RABBIT(71, ABSTRACT_ANIMAL),
SHEEP(74, ABSTRACT_ANIMAL),
TURTLE(96, ABSTRACT_ANIMAL),
FOX(29, ABSTRACT_ANIMAL),
GOAT(34, ABSTRACT_ANIMAL),
ABSTRACT_TAMEABLE_ANIMAL(-1, ABSTRACT_ANIMAL),
CAT(8, ABSTRACT_TAMEABLE_ANIMAL),
OCELOT(59, ABSTRACT_TAMEABLE_ANIMAL),
WOLF(105, ABSTRACT_TAMEABLE_ANIMAL),
ABSTRACT_PARROT(-1, ABSTRACT_TAMEABLE_ANIMAL),
PARROT(62, ABSTRACT_PARROT),
// Horses
ABSTRACT_HORSE(-1, ABSTRACT_ANIMAL),
CHESTED_HORSE(-1, ABSTRACT_HORSE),
DONKEY(15, CHESTED_HORSE),
MULE(57, CHESTED_HORSE),
LLAMA(46, CHESTED_HORSE),
TRADER_LLAMA(94, CHESTED_HORSE),
HORSE(37, ABSTRACT_HORSE),
SKELETON_HORSE(79, ABSTRACT_HORSE),
ZOMBIE_HORSE(108, ABSTRACT_HORSE),
// Golem
ABSTRACT_GOLEM(-1, ABSTRACT_CREATURE),
SNOW_GOLEM(82, ABSTRACT_GOLEM),
IRON_GOLEM(40, ABSTRACT_GOLEM),
SHULKER(75, ABSTRACT_GOLEM),
// Fish
ABSTRACT_FISHES(-1, ABSTRACT_CREATURE),
COD(11, ABSTRACT_FISHES),
PUFFERFISH(70, ABSTRACT_FISHES),
SALMON(73, ABSTRACT_FISHES),
TROPICAL_FISH(95, ABSTRACT_FISHES),
// Monsters
ABSTRACT_MONSTER(-1, ABSTRACT_CREATURE),
BLAZE(6, ABSTRACT_MONSTER),
CREEPER(13, ABSTRACT_MONSTER),
ENDERMITE(22, ABSTRACT_MONSTER),
ENDERMAN(21, ABSTRACT_MONSTER),
GIANT(31, ABSTRACT_MONSTER),
SILVERFISH(77, ABSTRACT_MONSTER),
VEX(97, ABSTRACT_MONSTER),
WITCH(101, ABSTRACT_MONSTER),
WITHER(102, ABSTRACT_MONSTER),
RAVAGER(72, ABSTRACT_MONSTER),
ABSTRACT_PIGLIN(-1, ABSTRACT_MONSTER),
PIGLIN(65, ABSTRACT_PIGLIN),
PIGLIN_BRUTE(66, ABSTRACT_PIGLIN),
HOGLIN(36, ABSTRACT_ANIMAL),
STRIDER(88, ABSTRACT_ANIMAL),
ZOGLIN(106, ABSTRACT_MONSTER),
// Illagers
ABSTRACT_ILLAGER_BASE(-1, ABSTRACT_MONSTER),
ABSTRACT_EVO_ILLU_ILLAGER(-1, ABSTRACT_ILLAGER_BASE),
EVOKER(23, ABSTRACT_EVO_ILLU_ILLAGER),
ILLUSIONER(39, ABSTRACT_EVO_ILLU_ILLAGER),
VINDICATOR(99, ABSTRACT_ILLAGER_BASE),
PILLAGER(67, ABSTRACT_ILLAGER_BASE),
// Skeletons
ABSTRACT_SKELETON(-1, ABSTRACT_MONSTER),
SKELETON(78, ABSTRACT_SKELETON),
STRAY(87, ABSTRACT_SKELETON),
WITHER_SKELETON(103, ABSTRACT_SKELETON),
// Guardians
GUARDIAN(35, ABSTRACT_MONSTER),
ELDER_GUARDIAN(18, GUARDIAN),
// Spiders
SPIDER(85, ABSTRACT_MONSTER),
CAVE_SPIDER(9, SPIDER),
// Zombies
ZOMBIE(107, ABSTRACT_MONSTER),
DROWNED(17, ZOMBIE),
HUSK(38, ZOMBIE),
ZOMBIFIED_PIGLIN(110, ZOMBIE),
ZOMBIE_VILLAGER(109, ZOMBIE),
// Flying entities
ABSTRACT_FLYING(-1, ABSTRACT_INSENTIENT),
GHAST(30, ABSTRACT_FLYING),
PHANTOM(63, ABSTRACT_FLYING),
ABSTRACT_AMBIENT(-1, ABSTRACT_INSENTIENT),
BAT(4, ABSTRACT_AMBIENT),
ABSTRACT_WATERMOB(-1, ABSTRACT_INSENTIENT),
SQUID(86, ABSTRACT_WATERMOB),
GLOW_SQUID(33, SQUID),
// Slimes
SLIME(80, ABSTRACT_INSENTIENT),
MAGMA_CUBE(48, SLIME),
// Hangable objects
ABSTRACT_HANGING(-1, ENTITY),
LEASH_KNOT(44, ABSTRACT_HANGING),
ITEM_FRAME(42, ABSTRACT_HANGING),
GLOW_ITEM_FRAME(32, ITEM_FRAME),
PAINTING(60, ABSTRACT_HANGING),
ABSTRACT_LIGHTNING(-1, ENTITY),
LIGHTNING_BOLT(45, ABSTRACT_LIGHTNING),
// Arrows
ABSTRACT_ARROW(-1, ENTITY),
ARROW(2, ABSTRACT_ARROW),
SPECTRAL_ARROW(84, ABSTRACT_ARROW),
TRIDENT(93, ABSTRACT_ARROW),
// Fireballs
ABSTRACT_FIREBALL(-1, ENTITY),
DRAGON_FIREBALL(16, ABSTRACT_FIREBALL),
FIREBALL(43, ABSTRACT_FIREBALL),
SMALL_FIREBALL(81, ABSTRACT_FIREBALL),
WITHER_SKULL(104, ABSTRACT_FIREBALL),
// Hanging entities
ABSTRACT_HANGING(ENTITY, null),
LEASH_KNOT(ABSTRACT_HANGING),
PAINTING(ABSTRACT_HANGING),
ITEM_FRAME(ABSTRACT_HANGING),
GLOW_ITEM_FRAME(ITEM_FRAME),
// Projectiles
PROJECTILE_ABSTRACT(-1, ENTITY),
SNOWBALL(83, PROJECTILE_ABSTRACT),
ENDER_PEARL(90, PROJECTILE_ABSTRACT),
EGG(89, PROJECTILE_ABSTRACT),
POTION(92, PROJECTILE_ABSTRACT),
EXPERIENCE_BOTTLE(91, PROJECTILE_ABSTRACT),
PROJECTILE_ABSTRACT(ENTITY, null), // Not actually its own abstract type, but useful for categorizing
SNOWBALL(PROJECTILE_ABSTRACT),
ENDER_PEARL(PROJECTILE_ABSTRACT),
EGG(PROJECTILE_ABSTRACT),
POTION(PROJECTILE_ABSTRACT),
EXPERIENCE_BOTTLE(PROJECTILE_ABSTRACT),
FIREWORK_ROCKET(PROJECTILE_ABSTRACT),
LLAMA_SPIT(PROJECTILE_ABSTRACT),
SHULKER_BULLET(PROJECTILE_ABSTRACT),
FISHING_BOBBER(PROJECTILE_ABSTRACT),
WITHER_SKULL(PROJECTILE_ABSTRACT),
DRAGON_FIREBALL(PROJECTILE_ABSTRACT), // Doesn't actually inherit fireball
ABSTRACT_ARROW(PROJECTILE_ABSTRACT, null),
ARROW(ABSTRACT_ARROW),
SPECTRAL_ARROW(ABSTRACT_ARROW),
TRIDENT(ABSTRACT_ARROW),
ABSTRACT_FIREBALL(ENTITY, null),
FIREBALL(ABSTRACT_FIREBALL),
SMALL_FIREBALL(ABSTRACT_FIREBALL),
// Vehicles
MINECART_ABSTRACT(-1, ENTITY),
CHESTED_MINECART_ABSTRACT(-1, MINECART_ABSTRACT),
CHEST_MINECART(51, CHESTED_MINECART_ABSTRACT),
HOPPER_MINECART(54, CHESTED_MINECART_ABSTRACT),
MINECART(50, MINECART_ABSTRACT),
FURNACE_MINECART(53, MINECART_ABSTRACT),
COMMAND_BLOCK_MINECART(52, MINECART_ABSTRACT),
TNT_MINECART(56, MINECART_ABSTRACT),
SPAWNER_MINECART(55, MINECART_ABSTRACT),
BOAT(7, ENTITY);
VEHICLE(ENTITY, null),
BOAT(VEHICLE),
private static final EntityType[] TYPES;
MINECART_ABSTRACT(VEHICLE, null),
MINECART(MINECART_ABSTRACT),
FURNACE_MINECART(MINECART_ABSTRACT),
COMMAND_BLOCK_MINECART(MINECART_ABSTRACT),
TNT_MINECART(MINECART_ABSTRACT),
SPAWNER_MINECART(MINECART_ABSTRACT),
private final int id;
CHESTED_MINECART_ABSTRACT(MINECART_ABSTRACT, null),
CHEST_MINECART(CHESTED_MINECART_ABSTRACT),
HOPPER_MINECART(CHESTED_MINECART_ABSTRACT),
// Living entities as a larger subclass
LIVINGENTITY(ENTITY, null),
ARMOR_STAND(LIVINGENTITY),
PLAYER(LIVINGENTITY),
// Mobs as a larger subclass
ABSTRACT_INSENTIENT(LIVINGENTITY, null),
ENDER_DRAGON(ABSTRACT_INSENTIENT),
SLIME(ABSTRACT_INSENTIENT),
MAGMA_CUBE(SLIME),
// Ambient mobs
ABSTRACT_AMBIENT(ABSTRACT_INSENTIENT, null),
BAT(ABSTRACT_AMBIENT),
// Flying mobs
ABSTRACT_FLYING(ABSTRACT_INSENTIENT, null),
GHAST(ABSTRACT_FLYING),
PHANTOM(ABSTRACT_FLYING),
// Pathfinder mobs and its subclasses
ABSTRACT_CREATURE(ABSTRACT_INSENTIENT, null),
ABSTRACT_GOLEM(ABSTRACT_CREATURE, null),
SNOW_GOLEM(ABSTRACT_GOLEM),
IRON_GOLEM(ABSTRACT_GOLEM),
SHULKER(ABSTRACT_GOLEM),
// Water mobs
ABSTRACT_WATERMOB(ABSTRACT_CREATURE, null),
DOLPHIN(ABSTRACT_WATERMOB),
SQUID(ABSTRACT_WATERMOB),
GLOW_SQUID(SQUID),
ABSTRACT_FISHES(ABSTRACT_WATERMOB, null),
PUFFERFISH(ABSTRACT_FISHES),
ABSTRACT_SCHOOLING_FISH(ABSTRACT_FISHES, null),
COD(ABSTRACT_SCHOOLING_FISH),
SALMON(ABSTRACT_SCHOOLING_FISH),
TROPICAL_FISH(ABSTRACT_SCHOOLING_FISH),
// Ageable mobs and (tamable) animals
ABSTRACT_AGEABLE(ABSTRACT_CREATURE, null),
ABSTRACT_VILLAGER(ABSTRACT_AGEABLE, null),
VILLAGER(ABSTRACT_VILLAGER),
WANDERING_TRADER(ABSTRACT_VILLAGER),
ABSTRACT_ANIMAL(ABSTRACT_AGEABLE, null),
AXOLOTL(ABSTRACT_ANIMAL),
CHICKEN(ABSTRACT_ANIMAL),
PANDA(ABSTRACT_ANIMAL),
PIG(ABSTRACT_ANIMAL),
POLAR_BEAR(ABSTRACT_ANIMAL),
RABBIT(ABSTRACT_ANIMAL),
SHEEP(ABSTRACT_ANIMAL),
BEE(ABSTRACT_ANIMAL),
TURTLE(ABSTRACT_ANIMAL),
FOX(ABSTRACT_ANIMAL),
GOAT(ABSTRACT_ANIMAL),
HOGLIN(ABSTRACT_ANIMAL),
STRIDER(ABSTRACT_ANIMAL),
COW(ABSTRACT_ANIMAL),
MOOSHROOM(COW),
ABSTRACT_TAMEABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(ABSTRACT_TAMEABLE_ANIMAL),
OCELOT(ABSTRACT_TAMEABLE_ANIMAL),
WOLF(ABSTRACT_TAMEABLE_ANIMAL),
PARROT(ABSTRACT_TAMEABLE_ANIMAL),
ABSTRACT_HORSE(ABSTRACT_ANIMAL, null),
HORSE(ABSTRACT_HORSE),
SKELETON_HORSE(ABSTRACT_HORSE),
ZOMBIE_HORSE(ABSTRACT_HORSE),
CHESTED_HORSE(ABSTRACT_HORSE, null),
DONKEY(CHESTED_HORSE),
MULE(CHESTED_HORSE),
LLAMA(CHESTED_HORSE),
TRADER_LLAMA(LLAMA),
// Monsters
ABSTRACT_MONSTER(ABSTRACT_CREATURE, null),
BLAZE(ABSTRACT_MONSTER),
CREEPER(ABSTRACT_MONSTER),
ENDERMITE(ABSTRACT_MONSTER),
ENDERMAN(ABSTRACT_MONSTER),
GIANT(ABSTRACT_MONSTER),
SILVERFISH(ABSTRACT_MONSTER),
VEX(ABSTRACT_MONSTER),
WITHER(ABSTRACT_MONSTER),
ZOGLIN(ABSTRACT_MONSTER),
ABSTRACT_SKELETON(ABSTRACT_MONSTER, null),
SKELETON(ABSTRACT_SKELETON),
STRAY(ABSTRACT_SKELETON),
WITHER_SKELETON(ABSTRACT_SKELETON),
ZOMBIE(ABSTRACT_MONSTER),
DROWNED(ZOMBIE),
HUSK(ZOMBIE),
ZOMBIFIED_PIGLIN(ZOMBIE),
ZOMBIE_VILLAGER(ZOMBIE),
GUARDIAN(ABSTRACT_MONSTER),
ELDER_GUARDIAN(GUARDIAN),
SPIDER(ABSTRACT_MONSTER),
CAVE_SPIDER(SPIDER),
ABSTRACT_PIGLIN(ABSTRACT_MONSTER, null),
PIGLIN(ABSTRACT_PIGLIN),
PIGLIN_BRUTE(ABSTRACT_PIGLIN),
// Raiders
ABSTRACT_RAIDER(ABSTRACT_MONSTER, null),
WITCH(ABSTRACT_RAIDER),
RAVAGER(ABSTRACT_RAIDER),
ABSTRACT_ILLAGER_BASE(ABSTRACT_RAIDER, null),
ABSTRACT_EVO_ILLU_ILLAGER(ABSTRACT_ILLAGER_BASE, null),
VINDICATOR(ABSTRACT_ILLAGER_BASE),
PILLAGER(ABSTRACT_ILLAGER_BASE),
EVOKER(ABSTRACT_EVO_ILLU_ILLAGER),
ILLUSIONER(ABSTRACT_EVO_ILLU_ILLAGER);
private static final EntityType[] TYPES = EntityTypeUtil.createSizedArray(values());
private final EntityType parent;
private final String identifier;
private int id = -1;
EntityTypes1_17(int id) {
this.id = id;
this.parent = null;
EntityTypes1_17(final EntityType parent) {
this.parent = parent;
this.identifier = "minecraft:" + name().toLowerCase(Locale.ROOT);
}
EntityTypes1_17(int id, EntityType parent) {
this.id = id;
EntityTypes1_17(final EntityType parent, @Nullable final String identifier) {
this.parent = parent;
this.identifier = identifier;
}
@Override
public int getId() {
if (id == -1) {
throw new IllegalStateException("Ids have not been initialized yet (type " + name() + ")");
}
return id;
}
@Override
public EntityType getParent() {
public String identifier() {
Preconditions.checkArgument(identifier != null, "Called identifier method on abstract type");
return identifier;
}
@Override
public @Nullable EntityType getParent() {
return parent;
}
@Override
public String identifier() {
throw new UnsupportedOperationException();
}
@Override
public boolean isAbstractType() {
return id != -1;
return identifier == null;
}
static {
TYPES = EntityTypeUtil.toOrderedArray(values());
}
public static EntityType getTypeFromId(int typeId) {
public static EntityType getTypeFromId(final int typeId) {
return EntityTypeUtil.getTypeFromId(TYPES, typeId, ENTITY);
}
public static void initialize(final Protocol<?, ?, ?, ?> protocol) {
EntityTypeUtil.initialize(values(), TYPES, protocol, (type, id) -> type.id = id);
}
}

View File

@ -38,77 +38,144 @@ public enum EntityTypes1_19 implements EntityType {
EXPERIENCE_ORB(ENTITY),
EYE_OF_ENDER(ENTITY),
FALLING_BLOCK(ENTITY),
FIREWORK_ROCKET(ENTITY),
ITEM(ENTITY),
LLAMA_SPIT(ENTITY),
TNT(ENTITY),
SHULKER_BULLET(ENTITY),
FISHING_BOBBER(ENTITY),
MARKER(ENTITY),
LIGHTNING_BOLT(ENTITY),
// Hanging entities
ABSTRACT_HANGING(ENTITY, null),
LEASH_KNOT(ABSTRACT_HANGING),
PAINTING(ABSTRACT_HANGING),
ITEM_FRAME(ABSTRACT_HANGING),
GLOW_ITEM_FRAME(ITEM_FRAME),
// Projectiles
PROJECTILE_ABSTRACT(ENTITY, null), // Not actually its own abstract type, but useful for categorizing
SNOWBALL(PROJECTILE_ABSTRACT),
ENDER_PEARL(PROJECTILE_ABSTRACT),
EGG(PROJECTILE_ABSTRACT),
POTION(PROJECTILE_ABSTRACT),
EXPERIENCE_BOTTLE(PROJECTILE_ABSTRACT),
FIREWORK_ROCKET(PROJECTILE_ABSTRACT),
LLAMA_SPIT(PROJECTILE_ABSTRACT),
SHULKER_BULLET(PROJECTILE_ABSTRACT),
FISHING_BOBBER(PROJECTILE_ABSTRACT),
WITHER_SKULL(PROJECTILE_ABSTRACT),
DRAGON_FIREBALL(PROJECTILE_ABSTRACT), // Doesn't actually inherit fireball
ABSTRACT_ARROW(PROJECTILE_ABSTRACT, null),
ARROW(ABSTRACT_ARROW),
SPECTRAL_ARROW(ABSTRACT_ARROW),
TRIDENT(ABSTRACT_ARROW),
ABSTRACT_FIREBALL(ENTITY, null),
FIREBALL(ABSTRACT_FIREBALL),
SMALL_FIREBALL(ABSTRACT_FIREBALL),
// Vehicles
VEHICLE(ENTITY, null),
BOAT(VEHICLE),
MINECART_ABSTRACT(VEHICLE, null),
MINECART(MINECART_ABSTRACT),
FURNACE_MINECART(MINECART_ABSTRACT),
COMMAND_BLOCK_MINECART(MINECART_ABSTRACT),
TNT_MINECART(MINECART_ABSTRACT),
SPAWNER_MINECART(MINECART_ABSTRACT),
CHEST_BOAT(BOAT),
CHESTED_MINECART_ABSTRACT(MINECART_ABSTRACT, null),
CHEST_MINECART(CHESTED_MINECART_ABSTRACT),
HOPPER_MINECART(CHESTED_MINECART_ABSTRACT),
// Living entities as a larger subclass
LIVINGENTITY(ENTITY, null),
ARMOR_STAND(LIVINGENTITY),
MARKER(ENTITY),
PLAYER(LIVINGENTITY),
// Mobs as a larger subclass
ABSTRACT_INSENTIENT(LIVINGENTITY, null),
ENDER_DRAGON(ABSTRACT_INSENTIENT),
BEE(ABSTRACT_INSENTIENT),
SLIME(ABSTRACT_INSENTIENT),
MAGMA_CUBE(SLIME),
// Ambient mobs
ABSTRACT_AMBIENT(ABSTRACT_INSENTIENT, null),
BAT(ABSTRACT_AMBIENT),
// Flying mobs
ABSTRACT_FLYING(ABSTRACT_INSENTIENT, null),
GHAST(ABSTRACT_FLYING),
PHANTOM(ABSTRACT_FLYING),
// Pathfinder mobs and its subclasses
ABSTRACT_CREATURE(ABSTRACT_INSENTIENT, null),
ALLAY(ABSTRACT_CREATURE),
ABSTRACT_AGEABLE(ABSTRACT_CREATURE, null),
VILLAGER(ABSTRACT_AGEABLE),
WANDERING_TRADER(ABSTRACT_AGEABLE),
// Animals
ABSTRACT_ANIMAL(ABSTRACT_AGEABLE, null),
AXOLOTL(ABSTRACT_ANIMAL),
DOLPHIN(ABSTRACT_INSENTIENT),
CHICKEN(ABSTRACT_ANIMAL),
COW(ABSTRACT_ANIMAL),
MOOSHROOM(COW),
PANDA(ABSTRACT_INSENTIENT),
PIG(ABSTRACT_ANIMAL),
POLAR_BEAR(ABSTRACT_ANIMAL),
RABBIT(ABSTRACT_ANIMAL),
SHEEP(ABSTRACT_ANIMAL),
TURTLE(ABSTRACT_ANIMAL),
FOX(ABSTRACT_ANIMAL),
FROG(ABSTRACT_ANIMAL),
GOAT(ABSTRACT_ANIMAL),
ABSTRACT_TAMEABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(ABSTRACT_TAMEABLE_ANIMAL),
OCELOT(ABSTRACT_TAMEABLE_ANIMAL),
WOLF(ABSTRACT_TAMEABLE_ANIMAL),
ABSTRACT_PARROT(ABSTRACT_TAMEABLE_ANIMAL, null),
PARROT(ABSTRACT_PARROT),
// Horses
ABSTRACT_HORSE(ABSTRACT_ANIMAL, null),
CHESTED_HORSE(ABSTRACT_HORSE, null),
DONKEY(CHESTED_HORSE),
MULE(CHESTED_HORSE),
LLAMA(CHESTED_HORSE),
TRADER_LLAMA(CHESTED_HORSE),
HORSE(ABSTRACT_HORSE),
SKELETON_HORSE(ABSTRACT_HORSE),
ZOMBIE_HORSE(ABSTRACT_HORSE),
// Golem
ABSTRACT_GOLEM(ABSTRACT_CREATURE, null),
SNOW_GOLEM(ABSTRACT_GOLEM),
IRON_GOLEM(ABSTRACT_GOLEM),
SHULKER(ABSTRACT_GOLEM),
// Fish
ABSTRACT_FISHES(ABSTRACT_CREATURE, null),
COD(ABSTRACT_FISHES),
// Water mobs
ABSTRACT_WATERMOB(ABSTRACT_CREATURE, null),
DOLPHIN(ABSTRACT_WATERMOB),
SQUID(ABSTRACT_WATERMOB),
GLOW_SQUID(SQUID),
ABSTRACT_FISHES(ABSTRACT_WATERMOB, null),
PUFFERFISH(ABSTRACT_FISHES),
SALMON(ABSTRACT_FISHES),
TROPICAL_FISH(ABSTRACT_FISHES),
TADPOLE(ABSTRACT_FISHES),
ABSTRACT_SCHOOLING_FISH(ABSTRACT_FISHES, null),
COD(ABSTRACT_SCHOOLING_FISH),
SALMON(ABSTRACT_SCHOOLING_FISH),
TROPICAL_FISH(ABSTRACT_SCHOOLING_FISH),
// Ageable mobs and (tamable) animals
ABSTRACT_AGEABLE(ABSTRACT_CREATURE, null),
ABSTRACT_VILLAGER(ABSTRACT_AGEABLE, null),
VILLAGER(ABSTRACT_VILLAGER),
WANDERING_TRADER(ABSTRACT_VILLAGER),
ABSTRACT_ANIMAL(ABSTRACT_AGEABLE, null),
AXOLOTL(ABSTRACT_ANIMAL),
CHICKEN(ABSTRACT_ANIMAL),
PANDA(ABSTRACT_ANIMAL),
PIG(ABSTRACT_ANIMAL),
POLAR_BEAR(ABSTRACT_ANIMAL),
RABBIT(ABSTRACT_ANIMAL),
SHEEP(ABSTRACT_ANIMAL),
BEE(ABSTRACT_ANIMAL),
TURTLE(ABSTRACT_ANIMAL),
FOX(ABSTRACT_ANIMAL),
FROG(ABSTRACT_ANIMAL),
GOAT(ABSTRACT_ANIMAL),
HOGLIN(ABSTRACT_ANIMAL),
STRIDER(ABSTRACT_ANIMAL),
COW(ABSTRACT_ANIMAL),
MOOSHROOM(COW),
ABSTRACT_TAMEABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(ABSTRACT_TAMEABLE_ANIMAL),
OCELOT(ABSTRACT_TAMEABLE_ANIMAL),
WOLF(ABSTRACT_TAMEABLE_ANIMAL),
PARROT(ABSTRACT_TAMEABLE_ANIMAL),
ABSTRACT_HORSE(ABSTRACT_ANIMAL, null),
HORSE(ABSTRACT_HORSE),
SKELETON_HORSE(ABSTRACT_HORSE),
ZOMBIE_HORSE(ABSTRACT_HORSE),
CHESTED_HORSE(ABSTRACT_HORSE, null),
DONKEY(CHESTED_HORSE),
MULE(CHESTED_HORSE),
LLAMA(CHESTED_HORSE),
TRADER_LLAMA(LLAMA),
// Monsters
ABSTRACT_MONSTER(ABSTRACT_CREATURE, null),
@ -119,110 +186,42 @@ public enum EntityTypes1_19 implements EntityType {
GIANT(ABSTRACT_MONSTER),
SILVERFISH(ABSTRACT_MONSTER),
VEX(ABSTRACT_MONSTER),
WITCH(ABSTRACT_MONSTER),
WITHER(ABSTRACT_MONSTER),
RAVAGER(ABSTRACT_MONSTER),
ABSTRACT_PIGLIN(ABSTRACT_MONSTER, null),
PIGLIN(ABSTRACT_PIGLIN),
PIGLIN_BRUTE(ABSTRACT_PIGLIN),
HOGLIN(ABSTRACT_ANIMAL),
STRIDER(ABSTRACT_ANIMAL),
TADPOLE(ABSTRACT_FISHES),
ZOGLIN(ABSTRACT_MONSTER),
WARDEN(ABSTRACT_MONSTER),
// Illagers
ABSTRACT_ILLAGER_BASE(ABSTRACT_MONSTER, null),
ABSTRACT_EVO_ILLU_ILLAGER(ABSTRACT_ILLAGER_BASE, null),
EVOKER(ABSTRACT_EVO_ILLU_ILLAGER),
ILLUSIONER(ABSTRACT_EVO_ILLU_ILLAGER),
VINDICATOR(ABSTRACT_ILLAGER_BASE),
PILLAGER(ABSTRACT_ILLAGER_BASE),
// Skeletons
ABSTRACT_SKELETON(ABSTRACT_MONSTER, null),
SKELETON(ABSTRACT_SKELETON),
STRAY(ABSTRACT_SKELETON),
WITHER_SKELETON(ABSTRACT_SKELETON),
// Guardians
GUARDIAN(ABSTRACT_MONSTER),
ELDER_GUARDIAN(GUARDIAN),
// Spiders
SPIDER(ABSTRACT_MONSTER),
CAVE_SPIDER(SPIDER),
// Zombies
ZOMBIE(ABSTRACT_MONSTER),
DROWNED(ZOMBIE),
HUSK(ZOMBIE),
ZOMBIFIED_PIGLIN(ZOMBIE),
ZOMBIE_VILLAGER(ZOMBIE),
// Flying entities
ABSTRACT_FLYING(ABSTRACT_INSENTIENT, null),
GHAST(ABSTRACT_FLYING),
PHANTOM(ABSTRACT_FLYING),
GUARDIAN(ABSTRACT_MONSTER),
ELDER_GUARDIAN(GUARDIAN),
ABSTRACT_AMBIENT(ABSTRACT_INSENTIENT, null),
BAT(ABSTRACT_AMBIENT),
ALLAY(ABSTRACT_CREATURE),
SPIDER(ABSTRACT_MONSTER),
CAVE_SPIDER(SPIDER),
ABSTRACT_WATERMOB(ABSTRACT_INSENTIENT, null),
SQUID(ABSTRACT_WATERMOB),
GLOW_SQUID(SQUID),
ABSTRACT_PIGLIN(ABSTRACT_MONSTER, null),
PIGLIN(ABSTRACT_PIGLIN),
PIGLIN_BRUTE(ABSTRACT_PIGLIN),
// Slimes
SLIME(ABSTRACT_INSENTIENT),
MAGMA_CUBE(SLIME),
// Raiders
ABSTRACT_RAIDER(ABSTRACT_MONSTER, null),
WITCH(ABSTRACT_RAIDER),
RAVAGER(ABSTRACT_RAIDER),
// Hangable objects
ABSTRACT_HANGING(ENTITY, null),
LEASH_KNOT(ABSTRACT_HANGING),
ITEM_FRAME(ABSTRACT_HANGING),
GLOW_ITEM_FRAME(ITEM_FRAME),
PAINTING(ABSTRACT_HANGING),
ABSTRACT_LIGHTNING(ENTITY, null),
LIGHTNING_BOLT(ABSTRACT_LIGHTNING),
// Arrows
ABSTRACT_ARROW(ENTITY, null),
ARROW(ABSTRACT_ARROW),
SPECTRAL_ARROW(ABSTRACT_ARROW),
TRIDENT(ABSTRACT_ARROW),
// Fireballs
ABSTRACT_FIREBALL(ENTITY, null),
DRAGON_FIREBALL(ABSTRACT_FIREBALL),
FIREBALL(ABSTRACT_FIREBALL),
SMALL_FIREBALL(ABSTRACT_FIREBALL),
WITHER_SKULL(ABSTRACT_FIREBALL),
// Projectiles
PROJECTILE_ABSTRACT(ENTITY, null),
SNOWBALL(PROJECTILE_ABSTRACT),
ENDER_PEARL(PROJECTILE_ABSTRACT),
EGG(PROJECTILE_ABSTRACT),
POTION(PROJECTILE_ABSTRACT),
EXPERIENCE_BOTTLE(PROJECTILE_ABSTRACT),
// Vehicles
MINECART_ABSTRACT(ENTITY, null),
CHESTED_MINECART_ABSTRACT(MINECART_ABSTRACT, null),
CHEST_MINECART(CHESTED_MINECART_ABSTRACT),
HOPPER_MINECART(CHESTED_MINECART_ABSTRACT),
MINECART(MINECART_ABSTRACT),
FURNACE_MINECART(MINECART_ABSTRACT),
COMMAND_BLOCK_MINECART(MINECART_ABSTRACT),
TNT_MINECART(MINECART_ABSTRACT),
SPAWNER_MINECART(MINECART_ABSTRACT),
BOAT(ENTITY),
CHEST_BOAT(BOAT);
ABSTRACT_ILLAGER_BASE(ABSTRACT_RAIDER, null),
ABSTRACT_EVO_ILLU_ILLAGER(ABSTRACT_ILLAGER_BASE, null),
VINDICATOR(ABSTRACT_ILLAGER_BASE),
PILLAGER(ABSTRACT_ILLAGER_BASE),
EVOKER(ABSTRACT_EVO_ILLU_ILLAGER),
ILLUSIONER(ABSTRACT_EVO_ILLU_ILLAGER);
private static final EntityType[] TYPES = EntityTypeUtil.createSizedArray(values());
private final EntityType parent;

View File

@ -38,78 +38,145 @@ public enum EntityTypes1_19_3 implements EntityType {
EXPERIENCE_ORB(ENTITY),
EYE_OF_ENDER(ENTITY),
FALLING_BLOCK(ENTITY),
FIREWORK_ROCKET(ENTITY),
ITEM(ENTITY),
LLAMA_SPIT(ENTITY),
TNT(ENTITY),
SHULKER_BULLET(ENTITY),
FISHING_BOBBER(ENTITY),
MARKER(ENTITY),
LIGHTNING_BOLT(ENTITY),
// Hanging entities
ABSTRACT_HANGING(ENTITY, null),
LEASH_KNOT(ABSTRACT_HANGING),
PAINTING(ABSTRACT_HANGING),
ITEM_FRAME(ABSTRACT_HANGING),
GLOW_ITEM_FRAME(ITEM_FRAME),
// Projectiles
PROJECTILE_ABSTRACT(ENTITY, null), // Not actually its own abstract type, but useful for categorizing
SNOWBALL(PROJECTILE_ABSTRACT),
ENDER_PEARL(PROJECTILE_ABSTRACT),
EGG(PROJECTILE_ABSTRACT),
POTION(PROJECTILE_ABSTRACT),
EXPERIENCE_BOTTLE(PROJECTILE_ABSTRACT),
FIREWORK_ROCKET(PROJECTILE_ABSTRACT),
LLAMA_SPIT(PROJECTILE_ABSTRACT),
SHULKER_BULLET(PROJECTILE_ABSTRACT),
FISHING_BOBBER(PROJECTILE_ABSTRACT),
WITHER_SKULL(PROJECTILE_ABSTRACT),
DRAGON_FIREBALL(PROJECTILE_ABSTRACT), // Doesn't actually inherit fireball
ABSTRACT_ARROW(PROJECTILE_ABSTRACT, null),
ARROW(ABSTRACT_ARROW),
SPECTRAL_ARROW(ABSTRACT_ARROW),
TRIDENT(ABSTRACT_ARROW),
ABSTRACT_FIREBALL(ENTITY, null),
FIREBALL(ABSTRACT_FIREBALL),
SMALL_FIREBALL(ABSTRACT_FIREBALL),
// Vehicles
VEHICLE(ENTITY, null),
BOAT(VEHICLE),
MINECART_ABSTRACT(VEHICLE, null),
MINECART(MINECART_ABSTRACT),
FURNACE_MINECART(MINECART_ABSTRACT),
COMMAND_BLOCK_MINECART(MINECART_ABSTRACT),
TNT_MINECART(MINECART_ABSTRACT),
SPAWNER_MINECART(MINECART_ABSTRACT),
CHEST_BOAT(BOAT),
CHESTED_MINECART_ABSTRACT(MINECART_ABSTRACT, null),
CHEST_MINECART(CHESTED_MINECART_ABSTRACT),
HOPPER_MINECART(CHESTED_MINECART_ABSTRACT),
// Living entities as a larger subclass
LIVINGENTITY(ENTITY, null),
ARMOR_STAND(LIVINGENTITY),
MARKER(ENTITY),
PLAYER(LIVINGENTITY),
// Mobs as a larger subclass
ABSTRACT_INSENTIENT(LIVINGENTITY, null),
ENDER_DRAGON(ABSTRACT_INSENTIENT),
BEE(ABSTRACT_INSENTIENT),
SLIME(ABSTRACT_INSENTIENT),
MAGMA_CUBE(SLIME),
// Ambient mobs
ABSTRACT_AMBIENT(ABSTRACT_INSENTIENT, null),
BAT(ABSTRACT_AMBIENT),
// Flying mobs
ABSTRACT_FLYING(ABSTRACT_INSENTIENT, null),
GHAST(ABSTRACT_FLYING),
PHANTOM(ABSTRACT_FLYING),
// Pathfinder mobs and its subclasses
ABSTRACT_CREATURE(ABSTRACT_INSENTIENT, null),
ALLAY(ABSTRACT_CREATURE),
ABSTRACT_AGEABLE(ABSTRACT_CREATURE, null),
VILLAGER(ABSTRACT_AGEABLE),
WANDERING_TRADER(ABSTRACT_AGEABLE),
// Animals
ABSTRACT_ANIMAL(ABSTRACT_AGEABLE, null),
AXOLOTL(ABSTRACT_ANIMAL),
DOLPHIN(ABSTRACT_INSENTIENT),
CHICKEN(ABSTRACT_ANIMAL),
COW(ABSTRACT_ANIMAL),
MOOSHROOM(COW),
PANDA(ABSTRACT_INSENTIENT),
PIG(ABSTRACT_ANIMAL),
POLAR_BEAR(ABSTRACT_ANIMAL),
RABBIT(ABSTRACT_ANIMAL),
SHEEP(ABSTRACT_ANIMAL),
TURTLE(ABSTRACT_ANIMAL),
FOX(ABSTRACT_ANIMAL),
FROG(ABSTRACT_ANIMAL),
GOAT(ABSTRACT_ANIMAL),
ABSTRACT_TAMEABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(ABSTRACT_TAMEABLE_ANIMAL),
OCELOT(ABSTRACT_TAMEABLE_ANIMAL),
WOLF(ABSTRACT_TAMEABLE_ANIMAL),
ABSTRACT_PARROT(ABSTRACT_TAMEABLE_ANIMAL, null),
PARROT(ABSTRACT_PARROT),
// Horses
ABSTRACT_HORSE(ABSTRACT_ANIMAL, null),
CHESTED_HORSE(ABSTRACT_HORSE, null),
DONKEY(CHESTED_HORSE),
MULE(CHESTED_HORSE),
LLAMA(CHESTED_HORSE),
TRADER_LLAMA(CHESTED_HORSE),
HORSE(ABSTRACT_HORSE),
SKELETON_HORSE(ABSTRACT_HORSE),
ZOMBIE_HORSE(ABSTRACT_HORSE),
CAMEL(ABSTRACT_HORSE),
// Golem
ABSTRACT_GOLEM(ABSTRACT_CREATURE, null),
SNOW_GOLEM(ABSTRACT_GOLEM),
IRON_GOLEM(ABSTRACT_GOLEM),
SHULKER(ABSTRACT_GOLEM),
// Fish
ABSTRACT_FISHES(ABSTRACT_CREATURE, null),
COD(ABSTRACT_FISHES),
// Water mobs
ABSTRACT_WATERMOB(ABSTRACT_CREATURE, null),
DOLPHIN(ABSTRACT_WATERMOB),
SQUID(ABSTRACT_WATERMOB),
GLOW_SQUID(SQUID),
ABSTRACT_FISHES(ABSTRACT_WATERMOB, null),
PUFFERFISH(ABSTRACT_FISHES),
SALMON(ABSTRACT_FISHES),
TROPICAL_FISH(ABSTRACT_FISHES),
TADPOLE(ABSTRACT_FISHES),
ABSTRACT_SCHOOLING_FISH(ABSTRACT_FISHES, null),
COD(ABSTRACT_SCHOOLING_FISH),
SALMON(ABSTRACT_SCHOOLING_FISH),
TROPICAL_FISH(ABSTRACT_SCHOOLING_FISH),
// Ageable mobs and (tamable) animals
ABSTRACT_AGEABLE(ABSTRACT_CREATURE, null),
ABSTRACT_VILLAGER(ABSTRACT_AGEABLE, null),
VILLAGER(ABSTRACT_VILLAGER),
WANDERING_TRADER(ABSTRACT_VILLAGER),
ABSTRACT_ANIMAL(ABSTRACT_AGEABLE, null),
AXOLOTL(ABSTRACT_ANIMAL),
CHICKEN(ABSTRACT_ANIMAL),
PANDA(ABSTRACT_ANIMAL),
PIG(ABSTRACT_ANIMAL),
POLAR_BEAR(ABSTRACT_ANIMAL),
RABBIT(ABSTRACT_ANIMAL),
SHEEP(ABSTRACT_ANIMAL),
BEE(ABSTRACT_ANIMAL),
TURTLE(ABSTRACT_ANIMAL),
FOX(ABSTRACT_ANIMAL),
FROG(ABSTRACT_ANIMAL),
GOAT(ABSTRACT_ANIMAL),
HOGLIN(ABSTRACT_ANIMAL),
STRIDER(ABSTRACT_ANIMAL),
COW(ABSTRACT_ANIMAL),
MOOSHROOM(COW),
ABSTRACT_TAMEABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(ABSTRACT_TAMEABLE_ANIMAL),
OCELOT(ABSTRACT_TAMEABLE_ANIMAL),
WOLF(ABSTRACT_TAMEABLE_ANIMAL),
PARROT(ABSTRACT_TAMEABLE_ANIMAL),
ABSTRACT_HORSE(ABSTRACT_ANIMAL, null),
HORSE(ABSTRACT_HORSE),
SKELETON_HORSE(ABSTRACT_HORSE),
ZOMBIE_HORSE(ABSTRACT_HORSE),
CAMEL(ABSTRACT_HORSE),
CHESTED_HORSE(ABSTRACT_HORSE, null),
DONKEY(CHESTED_HORSE),
MULE(CHESTED_HORSE),
LLAMA(CHESTED_HORSE),
TRADER_LLAMA(LLAMA),
// Monsters
ABSTRACT_MONSTER(ABSTRACT_CREATURE, null),
@ -120,110 +187,42 @@ public enum EntityTypes1_19_3 implements EntityType {
GIANT(ABSTRACT_MONSTER),
SILVERFISH(ABSTRACT_MONSTER),
VEX(ABSTRACT_MONSTER),
WITCH(ABSTRACT_MONSTER),
WITHER(ABSTRACT_MONSTER),
RAVAGER(ABSTRACT_MONSTER),
ABSTRACT_PIGLIN(ABSTRACT_MONSTER, null),
PIGLIN(ABSTRACT_PIGLIN),
PIGLIN_BRUTE(ABSTRACT_PIGLIN),
HOGLIN(ABSTRACT_ANIMAL),
STRIDER(ABSTRACT_ANIMAL),
TADPOLE(ABSTRACT_FISHES),
ZOGLIN(ABSTRACT_MONSTER),
WARDEN(ABSTRACT_MONSTER),
// Illagers
ABSTRACT_ILLAGER_BASE(ABSTRACT_MONSTER, null),
ABSTRACT_EVO_ILLU_ILLAGER(ABSTRACT_ILLAGER_BASE, null),
EVOKER(ABSTRACT_EVO_ILLU_ILLAGER),
ILLUSIONER(ABSTRACT_EVO_ILLU_ILLAGER),
VINDICATOR(ABSTRACT_ILLAGER_BASE),
PILLAGER(ABSTRACT_ILLAGER_BASE),
// Skeletons
ABSTRACT_SKELETON(ABSTRACT_MONSTER, null),
SKELETON(ABSTRACT_SKELETON),
STRAY(ABSTRACT_SKELETON),
WITHER_SKELETON(ABSTRACT_SKELETON),
// Guardians
GUARDIAN(ABSTRACT_MONSTER),
ELDER_GUARDIAN(GUARDIAN),
// Spiders
SPIDER(ABSTRACT_MONSTER),
CAVE_SPIDER(SPIDER),
// Zombies
ZOMBIE(ABSTRACT_MONSTER),
DROWNED(ZOMBIE),
HUSK(ZOMBIE),
ZOMBIFIED_PIGLIN(ZOMBIE),
ZOMBIE_VILLAGER(ZOMBIE),
// Flying entities
ABSTRACT_FLYING(ABSTRACT_INSENTIENT, null),
GHAST(ABSTRACT_FLYING),
PHANTOM(ABSTRACT_FLYING),
GUARDIAN(ABSTRACT_MONSTER),
ELDER_GUARDIAN(GUARDIAN),
ABSTRACT_AMBIENT(ABSTRACT_INSENTIENT, null),
BAT(ABSTRACT_AMBIENT),
ALLAY(ABSTRACT_CREATURE),
SPIDER(ABSTRACT_MONSTER),
CAVE_SPIDER(SPIDER),
ABSTRACT_WATERMOB(ABSTRACT_INSENTIENT, null),
SQUID(ABSTRACT_WATERMOB),
GLOW_SQUID(SQUID),
ABSTRACT_PIGLIN(ABSTRACT_MONSTER, null),
PIGLIN(ABSTRACT_PIGLIN),
PIGLIN_BRUTE(ABSTRACT_PIGLIN),
// Slimes
SLIME(ABSTRACT_INSENTIENT),
MAGMA_CUBE(SLIME),
// Raiders
ABSTRACT_RAIDER(ABSTRACT_MONSTER, null),
WITCH(ABSTRACT_RAIDER),
RAVAGER(ABSTRACT_RAIDER),
// Hangable objects
ABSTRACT_HANGING(ENTITY, null),
LEASH_KNOT(ABSTRACT_HANGING),
ITEM_FRAME(ABSTRACT_HANGING),
GLOW_ITEM_FRAME(ITEM_FRAME),
PAINTING(ABSTRACT_HANGING),
ABSTRACT_LIGHTNING(ENTITY, null),
LIGHTNING_BOLT(ABSTRACT_LIGHTNING),
// Arrows
ABSTRACT_ARROW(ENTITY, null),
ARROW(ABSTRACT_ARROW),
SPECTRAL_ARROW(ABSTRACT_ARROW),
TRIDENT(ABSTRACT_ARROW),
// Fireballs
ABSTRACT_FIREBALL(ENTITY, null),
DRAGON_FIREBALL(ABSTRACT_FIREBALL),
FIREBALL(ABSTRACT_FIREBALL),
SMALL_FIREBALL(ABSTRACT_FIREBALL),
WITHER_SKULL(ABSTRACT_FIREBALL),
// Projectiles
PROJECTILE_ABSTRACT(ENTITY, null),
SNOWBALL(PROJECTILE_ABSTRACT),
ENDER_PEARL(PROJECTILE_ABSTRACT),
EGG(PROJECTILE_ABSTRACT),
POTION(PROJECTILE_ABSTRACT),
EXPERIENCE_BOTTLE(PROJECTILE_ABSTRACT),
// Vehicles
MINECART_ABSTRACT(ENTITY, null),
CHESTED_MINECART_ABSTRACT(MINECART_ABSTRACT, null),
CHEST_MINECART(CHESTED_MINECART_ABSTRACT),
HOPPER_MINECART(CHESTED_MINECART_ABSTRACT),
MINECART(MINECART_ABSTRACT),
FURNACE_MINECART(MINECART_ABSTRACT),
COMMAND_BLOCK_MINECART(MINECART_ABSTRACT),
TNT_MINECART(MINECART_ABSTRACT),
SPAWNER_MINECART(MINECART_ABSTRACT),
BOAT(ENTITY),
CHEST_BOAT(BOAT);
ABSTRACT_ILLAGER_BASE(ABSTRACT_RAIDER, null),
ABSTRACT_EVO_ILLU_ILLAGER(ABSTRACT_ILLAGER_BASE, null),
VINDICATOR(ABSTRACT_ILLAGER_BASE),
PILLAGER(ABSTRACT_ILLAGER_BASE),
EVOKER(ABSTRACT_EVO_ILLU_ILLAGER),
ILLUSIONER(ABSTRACT_EVO_ILLU_ILLAGER);
private static final EntityType[] TYPES = EntityTypeUtil.createSizedArray(values());
private final EntityType parent;

View File

@ -38,85 +38,152 @@ public enum EntityTypes1_19_4 implements EntityType {
EXPERIENCE_ORB(ENTITY),
EYE_OF_ENDER(ENTITY),
FALLING_BLOCK(ENTITY),
FIREWORK_ROCKET(ENTITY),
ITEM(ENTITY),
LLAMA_SPIT(ENTITY),
TNT(ENTITY),
SHULKER_BULLET(ENTITY),
FISHING_BOBBER(ENTITY),
LIVINGENTITY(ENTITY, null),
ARMOR_STAND(LIVINGENTITY),
MARKER(ENTITY),
PLAYER(LIVINGENTITY),
LIGHTNING_BOLT(ENTITY),
INTERACTION(ENTITY),
DISPLAY(ENTITY, null),
BLOCK_DISPLAY(DISPLAY),
ITEM_DISPLAY(DISPLAY),
TEXT_DISPLAY(DISPLAY),
INTERACTION(ENTITY),
// Hanging entities
ABSTRACT_HANGING(ENTITY, null),
LEASH_KNOT(ABSTRACT_HANGING),
PAINTING(ABSTRACT_HANGING),
ITEM_FRAME(ABSTRACT_HANGING),
GLOW_ITEM_FRAME(ITEM_FRAME),
// Projectiles
PROJECTILE_ABSTRACT(ENTITY, null), // Not actually its own abstract type, but useful for categorizing
SNOWBALL(PROJECTILE_ABSTRACT),
ENDER_PEARL(PROJECTILE_ABSTRACT),
EGG(PROJECTILE_ABSTRACT),
POTION(PROJECTILE_ABSTRACT),
EXPERIENCE_BOTTLE(PROJECTILE_ABSTRACT),
FIREWORK_ROCKET(PROJECTILE_ABSTRACT),
LLAMA_SPIT(PROJECTILE_ABSTRACT),
SHULKER_BULLET(PROJECTILE_ABSTRACT),
FISHING_BOBBER(PROJECTILE_ABSTRACT),
WITHER_SKULL(PROJECTILE_ABSTRACT),
DRAGON_FIREBALL(PROJECTILE_ABSTRACT), // Doesn't actually inherit fireball
ABSTRACT_ARROW(PROJECTILE_ABSTRACT, null),
ARROW(ABSTRACT_ARROW),
SPECTRAL_ARROW(ABSTRACT_ARROW),
TRIDENT(ABSTRACT_ARROW),
ABSTRACT_FIREBALL(ENTITY, null),
FIREBALL(ABSTRACT_FIREBALL),
SMALL_FIREBALL(ABSTRACT_FIREBALL),
// Vehicles
VEHICLE(ENTITY, null),
BOAT(VEHICLE),
MINECART_ABSTRACT(VEHICLE, null),
MINECART(MINECART_ABSTRACT),
FURNACE_MINECART(MINECART_ABSTRACT),
COMMAND_BLOCK_MINECART(MINECART_ABSTRACT),
TNT_MINECART(MINECART_ABSTRACT),
SPAWNER_MINECART(MINECART_ABSTRACT),
CHEST_BOAT(BOAT),
CHESTED_MINECART_ABSTRACT(MINECART_ABSTRACT, null),
CHEST_MINECART(CHESTED_MINECART_ABSTRACT),
HOPPER_MINECART(CHESTED_MINECART_ABSTRACT),
// Living entities as a larger subclass
LIVINGENTITY(ENTITY, null),
ARMOR_STAND(LIVINGENTITY),
PLAYER(LIVINGENTITY),
// Mobs as a larger subclass
ABSTRACT_INSENTIENT(LIVINGENTITY, null),
ENDER_DRAGON(ABSTRACT_INSENTIENT),
BEE(ABSTRACT_INSENTIENT),
SLIME(ABSTRACT_INSENTIENT),
MAGMA_CUBE(SLIME),
// Ambient mobs
ABSTRACT_AMBIENT(ABSTRACT_INSENTIENT, null),
BAT(ABSTRACT_AMBIENT),
// Flying mobs
ABSTRACT_FLYING(ABSTRACT_INSENTIENT, null),
GHAST(ABSTRACT_FLYING),
PHANTOM(ABSTRACT_FLYING),
// Pathfinder mobs and its subclasses
ABSTRACT_CREATURE(ABSTRACT_INSENTIENT, null),
ALLAY(ABSTRACT_CREATURE),
ABSTRACT_AGEABLE(ABSTRACT_CREATURE, null),
VILLAGER(ABSTRACT_AGEABLE),
WANDERING_TRADER(ABSTRACT_AGEABLE),
// Animals
ABSTRACT_ANIMAL(ABSTRACT_AGEABLE, null),
AXOLOTL(ABSTRACT_ANIMAL),
DOLPHIN(ABSTRACT_INSENTIENT),
CHICKEN(ABSTRACT_ANIMAL),
COW(ABSTRACT_ANIMAL),
MOOSHROOM(COW),
PANDA(ABSTRACT_INSENTIENT),
PIG(ABSTRACT_ANIMAL),
POLAR_BEAR(ABSTRACT_ANIMAL),
RABBIT(ABSTRACT_ANIMAL),
SHEEP(ABSTRACT_ANIMAL),
TURTLE(ABSTRACT_ANIMAL),
FOX(ABSTRACT_ANIMAL),
FROG(ABSTRACT_ANIMAL),
GOAT(ABSTRACT_ANIMAL),
SNIFFER(ABSTRACT_ANIMAL),
ABSTRACT_TAMEABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(ABSTRACT_TAMEABLE_ANIMAL),
OCELOT(ABSTRACT_TAMEABLE_ANIMAL),
WOLF(ABSTRACT_TAMEABLE_ANIMAL),
ABSTRACT_PARROT(ABSTRACT_TAMEABLE_ANIMAL, null),
PARROT(ABSTRACT_PARROT),
// Horses
ABSTRACT_HORSE(ABSTRACT_ANIMAL, null),
CHESTED_HORSE(ABSTRACT_HORSE, null),
DONKEY(CHESTED_HORSE),
MULE(CHESTED_HORSE),
LLAMA(CHESTED_HORSE),
TRADER_LLAMA(CHESTED_HORSE),
HORSE(ABSTRACT_HORSE),
SKELETON_HORSE(ABSTRACT_HORSE),
ZOMBIE_HORSE(ABSTRACT_HORSE),
CAMEL(ABSTRACT_HORSE),
// Golem
ABSTRACT_GOLEM(ABSTRACT_CREATURE, null),
SNOW_GOLEM(ABSTRACT_GOLEM),
IRON_GOLEM(ABSTRACT_GOLEM),
SHULKER(ABSTRACT_GOLEM),
// Fish
ABSTRACT_FISHES(ABSTRACT_CREATURE, null),
COD(ABSTRACT_FISHES),
// Water mobs
ABSTRACT_WATERMOB(ABSTRACT_CREATURE, null),
DOLPHIN(ABSTRACT_WATERMOB),
SQUID(ABSTRACT_WATERMOB),
GLOW_SQUID(SQUID),
ABSTRACT_FISHES(ABSTRACT_WATERMOB, null),
PUFFERFISH(ABSTRACT_FISHES),
SALMON(ABSTRACT_FISHES),
TROPICAL_FISH(ABSTRACT_FISHES),
TADPOLE(ABSTRACT_FISHES),
ABSTRACT_SCHOOLING_FISH(ABSTRACT_FISHES, null),
COD(ABSTRACT_SCHOOLING_FISH),
SALMON(ABSTRACT_SCHOOLING_FISH),
TROPICAL_FISH(ABSTRACT_SCHOOLING_FISH),
// Ageable mobs and (tamable) animals
ABSTRACT_AGEABLE(ABSTRACT_CREATURE, null),
ABSTRACT_VILLAGER(ABSTRACT_AGEABLE, null),
VILLAGER(ABSTRACT_VILLAGER),
WANDERING_TRADER(ABSTRACT_VILLAGER),
ABSTRACT_ANIMAL(ABSTRACT_AGEABLE, null),
AXOLOTL(ABSTRACT_ANIMAL),
CHICKEN(ABSTRACT_ANIMAL),
PANDA(ABSTRACT_ANIMAL),
PIG(ABSTRACT_ANIMAL),
POLAR_BEAR(ABSTRACT_ANIMAL),
RABBIT(ABSTRACT_ANIMAL),
SHEEP(ABSTRACT_ANIMAL),
BEE(ABSTRACT_ANIMAL),
TURTLE(ABSTRACT_ANIMAL),
FOX(ABSTRACT_ANIMAL),
FROG(ABSTRACT_ANIMAL),
GOAT(ABSTRACT_ANIMAL),
HOGLIN(ABSTRACT_ANIMAL),
STRIDER(ABSTRACT_ANIMAL),
SNIFFER(ABSTRACT_ANIMAL),
COW(ABSTRACT_ANIMAL),
MOOSHROOM(COW),
ABSTRACT_TAMEABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(ABSTRACT_TAMEABLE_ANIMAL),
OCELOT(ABSTRACT_TAMEABLE_ANIMAL),
WOLF(ABSTRACT_TAMEABLE_ANIMAL),
PARROT(ABSTRACT_TAMEABLE_ANIMAL),
ABSTRACT_HORSE(ABSTRACT_ANIMAL, null),
HORSE(ABSTRACT_HORSE),
SKELETON_HORSE(ABSTRACT_HORSE),
ZOMBIE_HORSE(ABSTRACT_HORSE),
CAMEL(ABSTRACT_HORSE),
CHESTED_HORSE(ABSTRACT_HORSE, null),
DONKEY(CHESTED_HORSE),
MULE(CHESTED_HORSE),
LLAMA(CHESTED_HORSE),
TRADER_LLAMA(LLAMA),
// Monsters
ABSTRACT_MONSTER(ABSTRACT_CREATURE, null),
@ -127,110 +194,42 @@ public enum EntityTypes1_19_4 implements EntityType {
GIANT(ABSTRACT_MONSTER),
SILVERFISH(ABSTRACT_MONSTER),
VEX(ABSTRACT_MONSTER),
WITCH(ABSTRACT_MONSTER),
WITHER(ABSTRACT_MONSTER),
RAVAGER(ABSTRACT_MONSTER),
ABSTRACT_PIGLIN(ABSTRACT_MONSTER, null),
PIGLIN(ABSTRACT_PIGLIN),
PIGLIN_BRUTE(ABSTRACT_PIGLIN),
HOGLIN(ABSTRACT_ANIMAL),
STRIDER(ABSTRACT_ANIMAL),
TADPOLE(ABSTRACT_FISHES),
ZOGLIN(ABSTRACT_MONSTER),
WARDEN(ABSTRACT_MONSTER),
// Illagers
ABSTRACT_ILLAGER_BASE(ABSTRACT_MONSTER, null),
ABSTRACT_EVO_ILLU_ILLAGER(ABSTRACT_ILLAGER_BASE, null),
EVOKER(ABSTRACT_EVO_ILLU_ILLAGER),
ILLUSIONER(ABSTRACT_EVO_ILLU_ILLAGER),
VINDICATOR(ABSTRACT_ILLAGER_BASE),
PILLAGER(ABSTRACT_ILLAGER_BASE),
// Skeletons
ABSTRACT_SKELETON(ABSTRACT_MONSTER, null),
SKELETON(ABSTRACT_SKELETON),
STRAY(ABSTRACT_SKELETON),
WITHER_SKELETON(ABSTRACT_SKELETON),
// Guardians
GUARDIAN(ABSTRACT_MONSTER),
ELDER_GUARDIAN(GUARDIAN),
// Spiders
SPIDER(ABSTRACT_MONSTER),
CAVE_SPIDER(SPIDER),
// Zombies
ZOMBIE(ABSTRACT_MONSTER),
DROWNED(ZOMBIE),
HUSK(ZOMBIE),
ZOMBIFIED_PIGLIN(ZOMBIE),
ZOMBIE_VILLAGER(ZOMBIE),
// Flying entities
ABSTRACT_FLYING(ABSTRACT_INSENTIENT, null),
GHAST(ABSTRACT_FLYING),
PHANTOM(ABSTRACT_FLYING),
GUARDIAN(ABSTRACT_MONSTER),
ELDER_GUARDIAN(GUARDIAN),
ABSTRACT_AMBIENT(ABSTRACT_INSENTIENT, null),
BAT(ABSTRACT_AMBIENT),
ALLAY(ABSTRACT_CREATURE),
SPIDER(ABSTRACT_MONSTER),
CAVE_SPIDER(SPIDER),
ABSTRACT_WATERMOB(ABSTRACT_INSENTIENT, null),
SQUID(ABSTRACT_WATERMOB),
GLOW_SQUID(SQUID),
ABSTRACT_PIGLIN(ABSTRACT_MONSTER, null),
PIGLIN(ABSTRACT_PIGLIN),
PIGLIN_BRUTE(ABSTRACT_PIGLIN),
// Slimes
SLIME(ABSTRACT_INSENTIENT),
MAGMA_CUBE(SLIME),
// Raiders
ABSTRACT_RAIDER(ABSTRACT_MONSTER, null),
WITCH(ABSTRACT_RAIDER),
RAVAGER(ABSTRACT_RAIDER),
// Hangable objects
ABSTRACT_HANGING(ENTITY, null),
LEASH_KNOT(ABSTRACT_HANGING),
ITEM_FRAME(ABSTRACT_HANGING),
GLOW_ITEM_FRAME(ITEM_FRAME),
PAINTING(ABSTRACT_HANGING),
ABSTRACT_LIGHTNING(ENTITY, null),
LIGHTNING_BOLT(ABSTRACT_LIGHTNING),
// Arrows
ABSTRACT_ARROW(ENTITY, null),
ARROW(ABSTRACT_ARROW),
SPECTRAL_ARROW(ABSTRACT_ARROW),
TRIDENT(ABSTRACT_ARROW),
// Fireballs
ABSTRACT_FIREBALL(ENTITY, null),
DRAGON_FIREBALL(ABSTRACT_FIREBALL),
FIREBALL(ABSTRACT_FIREBALL),
SMALL_FIREBALL(ABSTRACT_FIREBALL),
WITHER_SKULL(ABSTRACT_FIREBALL),
// Projectiles
PROJECTILE_ABSTRACT(ENTITY, null),
SNOWBALL(PROJECTILE_ABSTRACT),
ENDER_PEARL(PROJECTILE_ABSTRACT),
EGG(PROJECTILE_ABSTRACT),
POTION(PROJECTILE_ABSTRACT),
EXPERIENCE_BOTTLE(PROJECTILE_ABSTRACT),
// Vehicles
MINECART_ABSTRACT(ENTITY, null),
CHESTED_MINECART_ABSTRACT(MINECART_ABSTRACT, null),
CHEST_MINECART(CHESTED_MINECART_ABSTRACT),
HOPPER_MINECART(CHESTED_MINECART_ABSTRACT),
MINECART(MINECART_ABSTRACT),
FURNACE_MINECART(MINECART_ABSTRACT),
COMMAND_BLOCK_MINECART(MINECART_ABSTRACT),
TNT_MINECART(MINECART_ABSTRACT),
SPAWNER_MINECART(MINECART_ABSTRACT),
BOAT(ENTITY),
CHEST_BOAT(BOAT);
ABSTRACT_ILLAGER_BASE(ABSTRACT_RAIDER, null),
ABSTRACT_EVO_ILLU_ILLAGER(ABSTRACT_ILLAGER_BASE, null),
VINDICATOR(ABSTRACT_ILLAGER_BASE),
PILLAGER(ABSTRACT_ILLAGER_BASE),
EVOKER(ABSTRACT_EVO_ILLU_ILLAGER),
ILLUSIONER(ABSTRACT_EVO_ILLU_ILLAGER);
private static final EntityType[] TYPES = EntityTypeUtil.createSizedArray(values());
private final EntityType parent;

View File

@ -38,85 +38,153 @@ public enum EntityTypes1_20_3 implements EntityType {
EXPERIENCE_ORB(ENTITY),
EYE_OF_ENDER(ENTITY),
FALLING_BLOCK(ENTITY),
FIREWORK_ROCKET(ENTITY),
ITEM(ENTITY),
LLAMA_SPIT(ENTITY),
TNT(ENTITY),
SHULKER_BULLET(ENTITY),
FISHING_BOBBER(ENTITY),
LIVINGENTITY(ENTITY, null),
ARMOR_STAND(LIVINGENTITY),
MARKER(ENTITY),
PLAYER(LIVINGENTITY),
LIGHTNING_BOLT(ENTITY),
INTERACTION(ENTITY),
DISPLAY(ENTITY, null),
BLOCK_DISPLAY(DISPLAY),
ITEM_DISPLAY(DISPLAY),
TEXT_DISPLAY(DISPLAY),
INTERACTION(ENTITY),
// Hanging entities
ABSTRACT_HANGING(ENTITY, null),
LEASH_KNOT(ABSTRACT_HANGING),
PAINTING(ABSTRACT_HANGING),
ITEM_FRAME(ABSTRACT_HANGING),
GLOW_ITEM_FRAME(ITEM_FRAME),
// Projectiles
PROJECTILE_ABSTRACT(ENTITY, null), // Not actually its own abstract type, but useful for categorizing
SNOWBALL(PROJECTILE_ABSTRACT),
ENDER_PEARL(PROJECTILE_ABSTRACT),
EGG(PROJECTILE_ABSTRACT),
POTION(PROJECTILE_ABSTRACT),
EXPERIENCE_BOTTLE(PROJECTILE_ABSTRACT),
FIREWORK_ROCKET(PROJECTILE_ABSTRACT),
LLAMA_SPIT(PROJECTILE_ABSTRACT),
SHULKER_BULLET(PROJECTILE_ABSTRACT),
FISHING_BOBBER(PROJECTILE_ABSTRACT),
WITHER_SKULL(PROJECTILE_ABSTRACT),
DRAGON_FIREBALL(PROJECTILE_ABSTRACT), // Doesn't actually inherit fireball
WIND_CHARGE(PROJECTILE_ABSTRACT),
ABSTRACT_ARROW(PROJECTILE_ABSTRACT, null),
ARROW(ABSTRACT_ARROW),
SPECTRAL_ARROW(ABSTRACT_ARROW),
TRIDENT(ABSTRACT_ARROW),
ABSTRACT_FIREBALL(ENTITY, null),
FIREBALL(ABSTRACT_FIREBALL),
SMALL_FIREBALL(ABSTRACT_FIREBALL),
// Vehicles
VEHICLE(ENTITY, null),
BOAT(VEHICLE),
MINECART_ABSTRACT(VEHICLE, null),
MINECART(MINECART_ABSTRACT),
FURNACE_MINECART(MINECART_ABSTRACT),
COMMAND_BLOCK_MINECART(MINECART_ABSTRACT),
TNT_MINECART(MINECART_ABSTRACT),
SPAWNER_MINECART(MINECART_ABSTRACT),
CHEST_BOAT(BOAT),
CHESTED_MINECART_ABSTRACT(MINECART_ABSTRACT, null),
CHEST_MINECART(CHESTED_MINECART_ABSTRACT),
HOPPER_MINECART(CHESTED_MINECART_ABSTRACT),
// Living entities as a larger subclass
LIVINGENTITY(ENTITY, null),
ARMOR_STAND(LIVINGENTITY),
PLAYER(LIVINGENTITY),
// Mobs as a larger subclass
ABSTRACT_INSENTIENT(LIVINGENTITY, null),
ENDER_DRAGON(ABSTRACT_INSENTIENT),
BEE(ABSTRACT_INSENTIENT),
SLIME(ABSTRACT_INSENTIENT),
MAGMA_CUBE(SLIME),
// Ambient mobs
ABSTRACT_AMBIENT(ABSTRACT_INSENTIENT, null),
BAT(ABSTRACT_AMBIENT),
// Flying mobs
ABSTRACT_FLYING(ABSTRACT_INSENTIENT, null),
GHAST(ABSTRACT_FLYING),
PHANTOM(ABSTRACT_FLYING),
// Pathfinder mobs and its subclasses
ABSTRACT_CREATURE(ABSTRACT_INSENTIENT, null),
ALLAY(ABSTRACT_CREATURE),
ABSTRACT_AGEABLE(ABSTRACT_CREATURE, null),
VILLAGER(ABSTRACT_AGEABLE),
WANDERING_TRADER(ABSTRACT_AGEABLE),
// Animals
ABSTRACT_ANIMAL(ABSTRACT_AGEABLE, null),
AXOLOTL(ABSTRACT_ANIMAL),
DOLPHIN(ABSTRACT_INSENTIENT),
CHICKEN(ABSTRACT_ANIMAL),
COW(ABSTRACT_ANIMAL),
MOOSHROOM(COW),
PANDA(ABSTRACT_INSENTIENT),
PIG(ABSTRACT_ANIMAL),
POLAR_BEAR(ABSTRACT_ANIMAL),
RABBIT(ABSTRACT_ANIMAL),
SHEEP(ABSTRACT_ANIMAL),
TURTLE(ABSTRACT_ANIMAL),
FOX(ABSTRACT_ANIMAL),
FROG(ABSTRACT_ANIMAL),
GOAT(ABSTRACT_ANIMAL),
SNIFFER(ABSTRACT_ANIMAL),
ABSTRACT_TAMEABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(ABSTRACT_TAMEABLE_ANIMAL),
OCELOT(ABSTRACT_TAMEABLE_ANIMAL),
WOLF(ABSTRACT_TAMEABLE_ANIMAL),
ABSTRACT_PARROT(ABSTRACT_TAMEABLE_ANIMAL, null),
PARROT(ABSTRACT_PARROT),
// Horses
ABSTRACT_HORSE(ABSTRACT_ANIMAL, null),
CHESTED_HORSE(ABSTRACT_HORSE, null),
DONKEY(CHESTED_HORSE),
MULE(CHESTED_HORSE),
LLAMA(CHESTED_HORSE),
TRADER_LLAMA(CHESTED_HORSE),
HORSE(ABSTRACT_HORSE),
SKELETON_HORSE(ABSTRACT_HORSE),
ZOMBIE_HORSE(ABSTRACT_HORSE),
CAMEL(ABSTRACT_HORSE),
// Golem
ABSTRACT_GOLEM(ABSTRACT_CREATURE, null),
SNOW_GOLEM(ABSTRACT_GOLEM),
IRON_GOLEM(ABSTRACT_GOLEM),
SHULKER(ABSTRACT_GOLEM),
// Fish
ABSTRACT_FISHES(ABSTRACT_CREATURE, null),
COD(ABSTRACT_FISHES),
// Water mobs
ABSTRACT_WATERMOB(ABSTRACT_CREATURE, null),
DOLPHIN(ABSTRACT_WATERMOB),
SQUID(ABSTRACT_WATERMOB),
GLOW_SQUID(SQUID),
ABSTRACT_FISHES(ABSTRACT_WATERMOB, null),
PUFFERFISH(ABSTRACT_FISHES),
SALMON(ABSTRACT_FISHES),
TROPICAL_FISH(ABSTRACT_FISHES),
TADPOLE(ABSTRACT_FISHES),
ABSTRACT_SCHOOLING_FISH(ABSTRACT_FISHES, null),
COD(ABSTRACT_SCHOOLING_FISH),
SALMON(ABSTRACT_SCHOOLING_FISH),
TROPICAL_FISH(ABSTRACT_SCHOOLING_FISH),
// Ageable mobs and (tamable) animals
ABSTRACT_AGEABLE(ABSTRACT_CREATURE, null),
ABSTRACT_VILLAGER(ABSTRACT_AGEABLE, null),
VILLAGER(ABSTRACT_VILLAGER),
WANDERING_TRADER(ABSTRACT_VILLAGER),
ABSTRACT_ANIMAL(ABSTRACT_AGEABLE, null),
AXOLOTL(ABSTRACT_ANIMAL),
CHICKEN(ABSTRACT_ANIMAL),
PANDA(ABSTRACT_ANIMAL),
PIG(ABSTRACT_ANIMAL),
POLAR_BEAR(ABSTRACT_ANIMAL),
RABBIT(ABSTRACT_ANIMAL),
SHEEP(ABSTRACT_ANIMAL),
BEE(ABSTRACT_ANIMAL),
TURTLE(ABSTRACT_ANIMAL),
FOX(ABSTRACT_ANIMAL),
FROG(ABSTRACT_ANIMAL),
GOAT(ABSTRACT_ANIMAL),
HOGLIN(ABSTRACT_ANIMAL),
STRIDER(ABSTRACT_ANIMAL),
SNIFFER(ABSTRACT_ANIMAL),
COW(ABSTRACT_ANIMAL),
MOOSHROOM(COW),
ABSTRACT_TAMEABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(ABSTRACT_TAMEABLE_ANIMAL),
OCELOT(ABSTRACT_TAMEABLE_ANIMAL),
WOLF(ABSTRACT_TAMEABLE_ANIMAL),
PARROT(ABSTRACT_TAMEABLE_ANIMAL),
ABSTRACT_HORSE(ABSTRACT_ANIMAL, null),
HORSE(ABSTRACT_HORSE),
SKELETON_HORSE(ABSTRACT_HORSE),
ZOMBIE_HORSE(ABSTRACT_HORSE),
CAMEL(ABSTRACT_HORSE),
CHESTED_HORSE(ABSTRACT_HORSE, null),
DONKEY(CHESTED_HORSE),
MULE(CHESTED_HORSE),
LLAMA(CHESTED_HORSE),
TRADER_LLAMA(LLAMA),
// Monsters
ABSTRACT_MONSTER(ABSTRACT_CREATURE, null),
@ -127,112 +195,43 @@ public enum EntityTypes1_20_3 implements EntityType {
GIANT(ABSTRACT_MONSTER),
SILVERFISH(ABSTRACT_MONSTER),
VEX(ABSTRACT_MONSTER),
WITCH(ABSTRACT_MONSTER),
WITHER(ABSTRACT_MONSTER),
RAVAGER(ABSTRACT_MONSTER),
BREEZE(ABSTRACT_MONSTER),
ABSTRACT_PIGLIN(ABSTRACT_MONSTER, null),
PIGLIN(ABSTRACT_PIGLIN),
PIGLIN_BRUTE(ABSTRACT_PIGLIN),
HOGLIN(ABSTRACT_ANIMAL),
STRIDER(ABSTRACT_ANIMAL),
TADPOLE(ABSTRACT_FISHES),
ZOGLIN(ABSTRACT_MONSTER),
WARDEN(ABSTRACT_MONSTER),
// Illagers
ABSTRACT_ILLAGER_BASE(ABSTRACT_MONSTER, null),
ABSTRACT_EVO_ILLU_ILLAGER(ABSTRACT_ILLAGER_BASE, null),
EVOKER(ABSTRACT_EVO_ILLU_ILLAGER),
ILLUSIONER(ABSTRACT_EVO_ILLU_ILLAGER),
VINDICATOR(ABSTRACT_ILLAGER_BASE),
PILLAGER(ABSTRACT_ILLAGER_BASE),
// Skeletons
ABSTRACT_SKELETON(ABSTRACT_MONSTER, null),
SKELETON(ABSTRACT_SKELETON),
STRAY(ABSTRACT_SKELETON),
WITHER_SKELETON(ABSTRACT_SKELETON),
// Guardians
GUARDIAN(ABSTRACT_MONSTER),
ELDER_GUARDIAN(GUARDIAN),
// Spiders
SPIDER(ABSTRACT_MONSTER),
CAVE_SPIDER(SPIDER),
// Zombies
ZOMBIE(ABSTRACT_MONSTER),
DROWNED(ZOMBIE),
HUSK(ZOMBIE),
ZOMBIFIED_PIGLIN(ZOMBIE),
ZOMBIE_VILLAGER(ZOMBIE),
// Flying entities
ABSTRACT_FLYING(ABSTRACT_INSENTIENT, null),
GHAST(ABSTRACT_FLYING),
PHANTOM(ABSTRACT_FLYING),
GUARDIAN(ABSTRACT_MONSTER),
ELDER_GUARDIAN(GUARDIAN),
ABSTRACT_AMBIENT(ABSTRACT_INSENTIENT, null),
BAT(ABSTRACT_AMBIENT),
ALLAY(ABSTRACT_CREATURE),
SPIDER(ABSTRACT_MONSTER),
CAVE_SPIDER(SPIDER),
ABSTRACT_WATERMOB(ABSTRACT_INSENTIENT, null),
SQUID(ABSTRACT_WATERMOB),
GLOW_SQUID(SQUID),
ABSTRACT_PIGLIN(ABSTRACT_MONSTER, null),
PIGLIN(ABSTRACT_PIGLIN),
PIGLIN_BRUTE(ABSTRACT_PIGLIN),
// Slimes
SLIME(ABSTRACT_INSENTIENT),
MAGMA_CUBE(SLIME),
// Raiders
ABSTRACT_RAIDER(ABSTRACT_MONSTER, null),
WITCH(ABSTRACT_RAIDER),
RAVAGER(ABSTRACT_RAIDER),
// Hangable objects
ABSTRACT_HANGING(ENTITY, null),
LEASH_KNOT(ABSTRACT_HANGING),
ITEM_FRAME(ABSTRACT_HANGING),
GLOW_ITEM_FRAME(ITEM_FRAME),
PAINTING(ABSTRACT_HANGING),
ABSTRACT_LIGHTNING(ENTITY, null),
LIGHTNING_BOLT(ABSTRACT_LIGHTNING),
// Arrows
ABSTRACT_ARROW(ENTITY, null),
ARROW(ABSTRACT_ARROW),
SPECTRAL_ARROW(ABSTRACT_ARROW),
TRIDENT(ABSTRACT_ARROW),
// Fireballs
ABSTRACT_FIREBALL(ENTITY, null),
DRAGON_FIREBALL(ABSTRACT_FIREBALL),
FIREBALL(ABSTRACT_FIREBALL),
SMALL_FIREBALL(ABSTRACT_FIREBALL),
WITHER_SKULL(ABSTRACT_FIREBALL),
// Projectiles
PROJECTILE_ABSTRACT(ENTITY, null),
SNOWBALL(PROJECTILE_ABSTRACT),
ENDER_PEARL(PROJECTILE_ABSTRACT),
EGG(PROJECTILE_ABSTRACT),
POTION(PROJECTILE_ABSTRACT),
EXPERIENCE_BOTTLE(PROJECTILE_ABSTRACT),
WIND_CHARGE(PROJECTILE_ABSTRACT),
// Vehicles
MINECART_ABSTRACT(ENTITY, null),
CHESTED_MINECART_ABSTRACT(MINECART_ABSTRACT, null),
CHEST_MINECART(CHESTED_MINECART_ABSTRACT),
HOPPER_MINECART(CHESTED_MINECART_ABSTRACT),
MINECART(MINECART_ABSTRACT),
FURNACE_MINECART(MINECART_ABSTRACT),
COMMAND_BLOCK_MINECART(MINECART_ABSTRACT),
TNT_MINECART(MINECART_ABSTRACT),
SPAWNER_MINECART(MINECART_ABSTRACT),
BOAT(ENTITY),
CHEST_BOAT(BOAT);
ABSTRACT_ILLAGER_BASE(ABSTRACT_RAIDER, null),
ABSTRACT_EVO_ILLU_ILLAGER(ABSTRACT_ILLAGER_BASE, null),
VINDICATOR(ABSTRACT_ILLAGER_BASE),
PILLAGER(ABSTRACT_ILLAGER_BASE),
EVOKER(ABSTRACT_EVO_ILLU_ILLAGER),
ILLUSIONER(ABSTRACT_EVO_ILLU_ILLAGER);
private static final EntityType[] TYPES = EntityTypeUtil.createSizedArray(values());
private final EntityType parent;

View File

@ -0,0 +1,288 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.entities;
import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.util.EntityTypeUtil;
import java.util.Locale;
import org.checkerframework.checker.nullness.qual.Nullable;
public enum EntityTypes1_20_5 implements EntityType {
ENTITY(null, null),
AREA_EFFECT_CLOUD(ENTITY),
END_CRYSTAL(ENTITY),
EVOKER_FANGS(ENTITY),
EXPERIENCE_ORB(ENTITY),
EYE_OF_ENDER(ENTITY),
FALLING_BLOCK(ENTITY),
ITEM(ENTITY),
TNT(ENTITY),
OMINOUS_ITEM_SPAWNER(ENTITY),
MARKER(ENTITY),
LIGHTNING_BOLT(ENTITY),
INTERACTION(ENTITY),
DISPLAY(ENTITY, null),
BLOCK_DISPLAY(DISPLAY),
ITEM_DISPLAY(DISPLAY),
TEXT_DISPLAY(DISPLAY),
// Hanging entities
ABSTRACT_HANGING(ENTITY, null),
LEASH_KNOT(ABSTRACT_HANGING),
PAINTING(ABSTRACT_HANGING),
ITEM_FRAME(ABSTRACT_HANGING),
GLOW_ITEM_FRAME(ITEM_FRAME),
// Projectiles
PROJECTILE_ABSTRACT(ENTITY, null), // Not actually its own abstract type, but useful for categorizing
SNOWBALL(PROJECTILE_ABSTRACT),
ENDER_PEARL(PROJECTILE_ABSTRACT),
EGG(PROJECTILE_ABSTRACT),
POTION(PROJECTILE_ABSTRACT),
EXPERIENCE_BOTTLE(PROJECTILE_ABSTRACT),
FIREWORK_ROCKET(PROJECTILE_ABSTRACT),
LLAMA_SPIT(PROJECTILE_ABSTRACT),
SHULKER_BULLET(PROJECTILE_ABSTRACT),
FISHING_BOBBER(PROJECTILE_ABSTRACT),
WITHER_SKULL(PROJECTILE_ABSTRACT),
DRAGON_FIREBALL(PROJECTILE_ABSTRACT), // Doesn't actually inherit fireball
ABSTRACT_ARROW(PROJECTILE_ABSTRACT, null),
ARROW(ABSTRACT_ARROW),
SPECTRAL_ARROW(ABSTRACT_ARROW),
TRIDENT(ABSTRACT_ARROW),
ABSTRACT_FIREBALL(ENTITY, null),
FIREBALL(ABSTRACT_FIREBALL),
SMALL_FIREBALL(ABSTRACT_FIREBALL),
ABSTRACT_WIND_CHARGE(PROJECTILE_ABSTRACT, null),
WIND_CHARGE(ABSTRACT_WIND_CHARGE),
BREEZE_WIND_CHARGE(ABSTRACT_WIND_CHARGE),
// Vehicles
VEHICLE(ENTITY, null),
BOAT(VEHICLE),
MINECART_ABSTRACT(VEHICLE, null),
MINECART(MINECART_ABSTRACT),
FURNACE_MINECART(MINECART_ABSTRACT),
COMMAND_BLOCK_MINECART(MINECART_ABSTRACT),
TNT_MINECART(MINECART_ABSTRACT),
SPAWNER_MINECART(MINECART_ABSTRACT),
CHEST_BOAT(BOAT),
CHESTED_MINECART_ABSTRACT(MINECART_ABSTRACT, null),
CHEST_MINECART(CHESTED_MINECART_ABSTRACT),
HOPPER_MINECART(CHESTED_MINECART_ABSTRACT),
// Living entities as a larger subclass
LIVINGENTITY(ENTITY, null),
ARMOR_STAND(LIVINGENTITY),
PLAYER(LIVINGENTITY),
// Mobs as a larger subclass
ABSTRACT_INSENTIENT(LIVINGENTITY, null),
ENDER_DRAGON(ABSTRACT_INSENTIENT),
SLIME(ABSTRACT_INSENTIENT),
MAGMA_CUBE(SLIME),
// Ambient mobs
ABSTRACT_AMBIENT(ABSTRACT_INSENTIENT, null),
BAT(ABSTRACT_AMBIENT),
// Flying mobs
ABSTRACT_FLYING(ABSTRACT_INSENTIENT, null),
GHAST(ABSTRACT_FLYING),
PHANTOM(ABSTRACT_FLYING),
// Pathfinder mobs and its subclasses
ABSTRACT_CREATURE(ABSTRACT_INSENTIENT, null),
ALLAY(ABSTRACT_CREATURE),
ABSTRACT_GOLEM(ABSTRACT_CREATURE, null),
SNOW_GOLEM(ABSTRACT_GOLEM),
IRON_GOLEM(ABSTRACT_GOLEM),
SHULKER(ABSTRACT_GOLEM),
// Water mobs
ABSTRACT_WATERMOB(ABSTRACT_CREATURE, null),
DOLPHIN(ABSTRACT_WATERMOB),
SQUID(ABSTRACT_WATERMOB),
GLOW_SQUID(SQUID),
ABSTRACT_FISHES(ABSTRACT_WATERMOB, null),
PUFFERFISH(ABSTRACT_FISHES),
TADPOLE(ABSTRACT_FISHES),
ABSTRACT_SCHOOLING_FISH(ABSTRACT_FISHES, null),
COD(ABSTRACT_SCHOOLING_FISH),
SALMON(ABSTRACT_SCHOOLING_FISH),
TROPICAL_FISH(ABSTRACT_SCHOOLING_FISH),
// Ageable mobs and (tamable) animals
ABSTRACT_AGEABLE(ABSTRACT_CREATURE, null),
ABSTRACT_VILLAGER(ABSTRACT_AGEABLE, null),
VILLAGER(ABSTRACT_VILLAGER),
WANDERING_TRADER(ABSTRACT_VILLAGER),
ABSTRACT_ANIMAL(ABSTRACT_AGEABLE, null),
AXOLOTL(ABSTRACT_ANIMAL),
CHICKEN(ABSTRACT_ANIMAL),
PANDA(ABSTRACT_ANIMAL),
PIG(ABSTRACT_ANIMAL),
POLAR_BEAR(ABSTRACT_ANIMAL),
RABBIT(ABSTRACT_ANIMAL),
SHEEP(ABSTRACT_ANIMAL),
BEE(ABSTRACT_ANIMAL),
TURTLE(ABSTRACT_ANIMAL),
FOX(ABSTRACT_ANIMAL),
FROG(ABSTRACT_ANIMAL),
GOAT(ABSTRACT_ANIMAL),
HOGLIN(ABSTRACT_ANIMAL),
STRIDER(ABSTRACT_ANIMAL),
SNIFFER(ABSTRACT_ANIMAL),
ARMADILLO(ABSTRACT_ANIMAL),
COW(ABSTRACT_ANIMAL),
MOOSHROOM(COW),
ABSTRACT_TAMEABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(ABSTRACT_TAMEABLE_ANIMAL),
OCELOT(ABSTRACT_TAMEABLE_ANIMAL),
WOLF(ABSTRACT_TAMEABLE_ANIMAL),
PARROT(ABSTRACT_TAMEABLE_ANIMAL),
ABSTRACT_HORSE(ABSTRACT_ANIMAL, null),
HORSE(ABSTRACT_HORSE),
SKELETON_HORSE(ABSTRACT_HORSE),
ZOMBIE_HORSE(ABSTRACT_HORSE),
CAMEL(ABSTRACT_HORSE),
CHESTED_HORSE(ABSTRACT_HORSE, null),
DONKEY(CHESTED_HORSE),
MULE(CHESTED_HORSE),
LLAMA(CHESTED_HORSE),
TRADER_LLAMA(LLAMA),
// Monsters
ABSTRACT_MONSTER(ABSTRACT_CREATURE, null),
BLAZE(ABSTRACT_MONSTER),
CREEPER(ABSTRACT_MONSTER),
ENDERMITE(ABSTRACT_MONSTER),
ENDERMAN(ABSTRACT_MONSTER),
GIANT(ABSTRACT_MONSTER),
SILVERFISH(ABSTRACT_MONSTER),
VEX(ABSTRACT_MONSTER),
WITHER(ABSTRACT_MONSTER),
BREEZE(ABSTRACT_MONSTER),
ZOGLIN(ABSTRACT_MONSTER),
WARDEN(ABSTRACT_MONSTER),
ABSTRACT_SKELETON(ABSTRACT_MONSTER, null),
SKELETON(ABSTRACT_SKELETON),
STRAY(ABSTRACT_SKELETON),
WITHER_SKELETON(ABSTRACT_SKELETON),
BOGGED(ABSTRACT_SKELETON),
ZOMBIE(ABSTRACT_MONSTER),
DROWNED(ZOMBIE),
HUSK(ZOMBIE),
ZOMBIFIED_PIGLIN(ZOMBIE),
ZOMBIE_VILLAGER(ZOMBIE),
GUARDIAN(ABSTRACT_MONSTER),
ELDER_GUARDIAN(GUARDIAN),
SPIDER(ABSTRACT_MONSTER),
CAVE_SPIDER(SPIDER),
ABSTRACT_PIGLIN(ABSTRACT_MONSTER, null),
PIGLIN(ABSTRACT_PIGLIN),
PIGLIN_BRUTE(ABSTRACT_PIGLIN),
// Raiders
ABSTRACT_RAIDER(ABSTRACT_MONSTER, null),
WITCH(ABSTRACT_RAIDER),
RAVAGER(ABSTRACT_RAIDER),
ABSTRACT_ILLAGER_BASE(ABSTRACT_RAIDER, null),
ABSTRACT_EVO_ILLU_ILLAGER(ABSTRACT_ILLAGER_BASE, null),
VINDICATOR(ABSTRACT_ILLAGER_BASE),
PILLAGER(ABSTRACT_ILLAGER_BASE),
EVOKER(ABSTRACT_EVO_ILLU_ILLAGER),
ILLUSIONER(ABSTRACT_EVO_ILLU_ILLAGER);
private static final EntityType[] TYPES = EntityTypeUtil.createSizedArray(values());
private final EntityType parent;
private final String identifier;
private int id = -1;
EntityTypes1_20_5(final EntityType parent) {
this.parent = parent;
this.identifier = "minecraft:" + name().toLowerCase(Locale.ROOT);
}
EntityTypes1_20_5(final EntityType parent, @Nullable final String identifier) {
this.parent = parent;
this.identifier = identifier;
}
@Override
public int getId() {
if (id == -1) {
throw new IllegalStateException("Ids have not been initialized yet (type " + name() + ")");
}
return id;
}
@Override
public String identifier() {
Preconditions.checkArgument(identifier != null, "Called identifier method on abstract type");
return identifier;
}
@Override
public @Nullable EntityType getParent() {
return parent;
}
@Override
public boolean isAbstractType() {
return identifier == null;
}
public static EntityType getTypeFromId(final int typeId) {
return EntityTypeUtil.getTypeFromId(TYPES, typeId, ENTITY);
}
public static void initialize(final Protocol<?, ?, ?, ?> protocol) {
EntityTypeUtil.initialize(values(), TYPES, protocol, (type, id) -> type.id = id);
}
}

View File

@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.minecraft.item;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.google.gson.annotations.SerializedName;
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
import java.util.Objects;
import org.checkerframework.checker.nullness.qual.Nullable;
@ -91,6 +92,11 @@ public class DataItem implements Item {
this.tag = tag;
}
@Override
public StructuredDataContainer structuredData() {
throw new UnsupportedOperationException();
}
@Override
public Item copy() {
return new DataItem(identifier, amount, data, tag);
@ -119,10 +125,10 @@ public class DataItem implements Item {
@Override
public String toString() {
return "Item{" +
"identifier=" + identifier +
", amount=" + amount +
", data=" + data +
", tag=" + tag +
'}';
"identifier=" + identifier +
", amount=" + amount +
", data=" + data +
", tag=" + tag +
'}';
}
}

View File

@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.minecraft.item;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
import org.checkerframework.checker.nullness.qual.Nullable;
public interface Item {
@ -79,7 +80,8 @@ public interface Item {
*
* @return item tag
*/
@Nullable CompoundTag tag();
@Nullable
CompoundTag tag();
/**
* Sets the item compound tag.
@ -88,10 +90,21 @@ public interface Item {
*/
void setTag(@Nullable CompoundTag tag);
StructuredDataContainer structuredData();
/**
* Returns a copy of the item.
*
* @return copy of the item
*/
Item copy();
/**
* Returns true if the item is empty.
*
* @return true if the item is empty
*/
default boolean isEmpty() {
return identifier() == 0 || amount() <= 0;
}
}

View File

@ -0,0 +1,110 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
import org.checkerframework.checker.nullness.qual.Nullable;
public class StructuredItem implements Item {
private final StructuredDataContainer data;
private int identifier;
private int amount;
public StructuredItem(final int identifier, final int amount) {
this(identifier, amount, new StructuredDataContainer());
}
public StructuredItem(final int identifier, final int amount, final StructuredDataContainer data) {
this.identifier = identifier;
this.amount = amount;
this.data = data;
}
@Override
public int identifier() {
return identifier;
}
@Override
public void setIdentifier(final int identifier) {
this.identifier = identifier;
}
@Override
public int amount() {
return amount;
}
@Override
public void setAmount(final int amount) {
this.amount = amount;
}
@Override
public @Nullable CompoundTag tag() {
return null;
}
@Override
public void setTag(@Nullable final CompoundTag tag) {
throw new UnsupportedOperationException();
}
@Override
public StructuredDataContainer structuredData() {
return data;
}
@Override
public StructuredItem copy() {
return new StructuredItem(identifier, amount, data.copy());
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final StructuredItem that = (StructuredItem) o;
if (identifier != that.identifier) return false;
if (amount != that.amount) return false;
return data.equals(that.data);
}
@Override
public int hashCode() {
int result = data.hashCode();
result = 31 * result + identifier;
result = 31 * result + amount;
return result;
}
@Override
public String toString() {
return "StructuredItem{" +
"data=" + data +
", identifier=" + identifier +
", amount=" + amount +
'}';
}
}

View File

@ -0,0 +1,60 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
public final class AdventureModePredicate {
public static final Type<AdventureModePredicate> TYPE = new Type<AdventureModePredicate>(AdventureModePredicate.class) {
@Override
public AdventureModePredicate read(final ByteBuf buffer) throws Exception {
final BlockPredicate[] predicates = BlockPredicate.ARRAY_TYPE.read(buffer);
final boolean showInTooltip = buffer.readBoolean();
return new AdventureModePredicate(predicates, showInTooltip);
}
@Override
public void write(final ByteBuf buffer, final AdventureModePredicate value) throws Exception {
BlockPredicate.ARRAY_TYPE.write(buffer, value.predicates);
buffer.writeBoolean(value.showInTooltip);
}
};
private final BlockPredicate[] predicates;
private final boolean showInTooltip;
public AdventureModePredicate(final BlockPredicate[] predicates, final boolean showInTooltip) {
this.predicates = predicates;
this.showInTooltip = showInTooltip;
}
public BlockPredicate[] predicates() {
return predicates;
}
public boolean showInTooltip() {
return showInTooltip;
}
}

View File

@ -0,0 +1,69 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.minecraft.Holder;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
public final class ArmorTrim {
public static final Type<ArmorTrim> TYPE = new Type<ArmorTrim>(ArmorTrim.class) {
@Override
public ArmorTrim read(final ByteBuf buffer) throws Exception {
final Holder<ArmorTrimMaterial> material = ArmorTrimMaterial.TYPE.read(buffer);
final Holder<ArmorTrimPattern> pattern = ArmorTrimPattern.TYPE.read(buffer);
final boolean showInTooltip = buffer.readBoolean();
return new ArmorTrim(material, pattern, showInTooltip);
}
@Override
public void write(final ByteBuf buffer, final ArmorTrim value) throws Exception {
ArmorTrimMaterial.TYPE.write(buffer, value.material);
ArmorTrimPattern.TYPE.write(buffer, value.pattern);
buffer.writeBoolean(value.showInTooltip);
}
};
private final Holder<ArmorTrimMaterial> material;
private final Holder<ArmorTrimPattern> pattern;
private final boolean showInTooltip;
public ArmorTrim(final Holder<ArmorTrimMaterial> material, final Holder<ArmorTrimPattern> pattern, final boolean showInTooltip) {
this.material = material;
this.pattern = pattern;
this.showInTooltip = showInTooltip;
}
public Holder<ArmorTrimMaterial> material() {
return material;
}
public Holder<ArmorTrimPattern> pattern() {
return pattern;
}
public boolean showInTooltip() {
return showInTooltip;
}
}

View File

@ -0,0 +1,102 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.misc.HolderType;
import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
public final class ArmorTrimMaterial {
public static final HolderType<ArmorTrimMaterial> TYPE = new HolderType<ArmorTrimMaterial>() {
@Override
public ArmorTrimMaterial readDirect(final ByteBuf buffer) throws Exception {
final String assetName = Type.STRING.read(buffer);
final int item = Type.VAR_INT.readPrimitive(buffer);
final float itemModelIndex = buffer.readFloat();
final int overrideArmorMaterialsSize = Type.VAR_INT.readPrimitive(buffer);
final Int2ObjectMap<String> overrideArmorMaterials = new Int2ObjectOpenHashMap<>(overrideArmorMaterialsSize);
for (int i = 0; i < overrideArmorMaterialsSize; i++) {
final int key = Type.VAR_INT.readPrimitive(buffer);
final String value = Type.STRING.read(buffer);
overrideArmorMaterials.put(key, value);
}
final Tag description = Type.TAG.read(buffer);
return new ArmorTrimMaterial(assetName, item, itemModelIndex, overrideArmorMaterials, description);
}
@Override
public void writeDirect(final ByteBuf buffer, final ArmorTrimMaterial value) throws Exception {
Type.STRING.write(buffer, value.assetName());
Type.VAR_INT.writePrimitive(buffer, value.itemId());
buffer.writeFloat(value.itemModelIndex());
Type.VAR_INT.writePrimitive(buffer, value.overrideArmorMaterials().size());
for (final Int2ObjectMap.Entry<String> entry : value.overrideArmorMaterials().int2ObjectEntrySet()) {
Type.VAR_INT.writePrimitive(buffer, entry.getIntKey());
Type.STRING.write(buffer, entry.getValue());
}
Type.TAG.write(buffer, value.description());
}
};
private final String assetName;
private final int itemId;
private final float itemModelIndex;
private final Int2ObjectMap<String> overrideArmorMaterials;
private final Tag description;
public ArmorTrimMaterial(final String assetName, final int itemId, final float itemModelIndex, final Int2ObjectMap<String> overrideArmorMaterials, final Tag description) {
this.assetName = assetName;
this.itemId = itemId;
this.itemModelIndex = itemModelIndex;
this.overrideArmorMaterials = overrideArmorMaterials;
this.description = description;
}
public String assetName() {
return assetName;
}
public int itemId() {
return itemId;
}
public float itemModelIndex() {
return itemModelIndex;
}
public Int2ObjectMap<String> overrideArmorMaterials() {
return overrideArmorMaterials;
}
public Tag description() {
return description;
}
}

View File

@ -0,0 +1,78 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.misc.HolderType;
import io.netty.buffer.ByteBuf;
public final class ArmorTrimPattern {
public static final HolderType<ArmorTrimPattern> TYPE = new HolderType<ArmorTrimPattern>() {
@Override
public ArmorTrimPattern readDirect(final ByteBuf buffer) throws Exception {
final String assetName = Type.STRING.read(buffer);
final int itemId = Type.VAR_INT.readPrimitive(buffer);
final Tag description = Type.TAG.read(buffer);
final boolean decal = buffer.readBoolean();
return new ArmorTrimPattern(assetName, itemId, description, decal);
}
@Override
public void writeDirect(final ByteBuf buffer, final ArmorTrimPattern value) throws Exception {
Type.STRING.write(buffer, value.assetName());
Type.VAR_INT.writePrimitive(buffer, value.itemId());
Type.TAG.write(buffer, value.description());
buffer.writeBoolean(value.decal());
}
};
private final String assetName;
private final int itemId;
private final Tag description;
private final boolean decal;
public ArmorTrimPattern(final String assetName, final int itemId, final Tag description, final boolean decal) {
this.assetName = assetName;
this.itemId = itemId;
this.description = description;
this.decal = decal;
}
public String assetName() {
return assetName;
}
public int itemId() {
return itemId;
}
public Tag description() {
return description;
}
public boolean decal() {
return decal;
}
}

View File

@ -0,0 +1,70 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.ArrayType;
import io.netty.buffer.ByteBuf;
public final class AttributeModifier {
public static final Type<AttributeModifier> TYPE = new Type<AttributeModifier>(AttributeModifier.class) {
@Override
public AttributeModifier read(final ByteBuf buffer) throws Exception {
final int attribute = Type.VAR_INT.readPrimitive(buffer);
final ModifierData modifier = ModifierData.TYPE.read(buffer);
final int slot = Type.VAR_INT.readPrimitive(buffer);
return new AttributeModifier(attribute, modifier, slot);
}
@Override
public void write(final ByteBuf buffer, final AttributeModifier value) throws Exception {
Type.VAR_INT.writePrimitive(buffer, value.attribute);
ModifierData.TYPE.write(buffer, value.modifier);
Type.VAR_INT.writePrimitive(buffer, value.slotType);
}
};
public static final Type<AttributeModifier[]> ARRAY_TYPE = new ArrayType<>(TYPE);
private final int attribute;
private final ModifierData modifier;
private final int slotType;
public AttributeModifier(final int attribute, final ModifierData modifier, final int slotType) {
this.attribute = attribute;
this.modifier = modifier;
this.slotType = slotType;
}
public int attribute() {
return attribute;
}
public ModifierData modifier() {
return modifier;
}
public int slotType() {
return slotType;
}
}

View File

@ -0,0 +1,60 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
public final class AttributeModifiers {
public static final Type<AttributeModifiers> TYPE = new Type<AttributeModifiers>(AttributeModifiers.class) {
@Override
public AttributeModifiers read(final ByteBuf buffer) throws Exception {
final AttributeModifier[] modifiers = AttributeModifier.ARRAY_TYPE.read(buffer);
final boolean showInTooltip = buffer.readBoolean();
return new AttributeModifiers(modifiers, showInTooltip);
}
@Override
public void write(final ByteBuf buffer, final AttributeModifiers value) throws Exception {
AttributeModifier.ARRAY_TYPE.write(buffer, value.modifiers());
buffer.writeBoolean(value.showInTooltip());
}
};
private final AttributeModifier[] modifiers;
private final boolean showInTooltip;
public AttributeModifiers(final AttributeModifier[] modifiers, final boolean showInTooltip) {
this.modifiers = modifiers;
this.showInTooltip = showInTooltip;
}
public AttributeModifier[] modifiers() {
return modifiers;
}
public boolean showInTooltip() {
return showInTooltip;
}
}

View File

@ -0,0 +1,61 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.misc.HolderType;
import io.netty.buffer.ByteBuf;
public final class BannerPattern {
public static final HolderType<BannerPattern> TYPE = new HolderType<BannerPattern>() {
@Override
public BannerPattern readDirect(final ByteBuf buffer) throws Exception {
final String assetId = Type.STRING.read(buffer);
final String translationKey = Type.STRING.read(buffer);
return new BannerPattern(assetId, translationKey);
}
@Override
public void writeDirect(final ByteBuf buffer, final BannerPattern value) throws Exception {
Type.STRING.write(buffer, value.assetId);
Type.STRING.write(buffer, value.translationKey);
}
};
private final String assetId;
private final String translationKey;
public BannerPattern(final String assetId, final String translationKey) {
this.assetId = assetId;
this.translationKey = translationKey;
}
public String assetId() {
return assetId;
}
public String translationKey() {
return translationKey;
}
}

View File

@ -0,0 +1,63 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.minecraft.Holder;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.ArrayType;
import io.netty.buffer.ByteBuf;
public final class BannerPatternLayer {
public static final Type<BannerPatternLayer> TYPE = new Type<BannerPatternLayer>(BannerPatternLayer.class) {
@Override
public BannerPatternLayer read(final ByteBuf buffer) throws Exception {
final Holder<BannerPattern> pattern = BannerPattern.TYPE.read(buffer);
final int color = Type.VAR_INT.readPrimitive(buffer);
return new BannerPatternLayer(pattern, color);
}
@Override
public void write(final ByteBuf buffer, final BannerPatternLayer value) throws Exception {
BannerPattern.TYPE.write(buffer, value.pattern);
Type.VAR_INT.writePrimitive(buffer, value.dyeColor);
}
};
public static final Type<BannerPatternLayer[]> ARRAY_TYPE = new ArrayType<>(TYPE);
private final Holder<BannerPattern> pattern;
private final int dyeColor;
public BannerPatternLayer(final Holder<BannerPattern> pattern, final int dyeColor) {
this.pattern = pattern;
this.dyeColor = dyeColor;
}
public Holder<BannerPattern> pattern() {
return pattern;
}
public int dyeColor() {
return dyeColor;
}
}

View File

@ -0,0 +1,71 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.ArrayType;
import io.netty.buffer.ByteBuf;
public final class Bee {
public static final Type<Bee> TYPE = new Type<Bee>(Bee.class) {
@Override
public Bee read(final ByteBuf buffer) throws Exception {
final CompoundTag entityData = Type.COMPOUND_TAG.read(buffer);
final int ticksInHive = Type.VAR_INT.readPrimitive(buffer);
final int minTicksInHive = Type.VAR_INT.readPrimitive(buffer);
return new Bee(entityData, ticksInHive, minTicksInHive);
}
@Override
public void write(final ByteBuf buffer, final Bee value) throws Exception {
Type.COMPOUND_TAG.write(buffer, value.entityData);
Type.VAR_INT.writePrimitive(buffer, value.ticksInHive);
Type.VAR_INT.writePrimitive(buffer, value.minTicksInHive);
}
};
public static final Type<Bee[]> ARRAY_TYPE = new ArrayType<>(TYPE);
private final CompoundTag entityData;
private final int ticksInHive;
private final int minTicksInHive;
public Bee(CompoundTag entityData, int ticksInHive, int minTicksInHive) {
this.entityData = entityData;
this.ticksInHive = ticksInHive;
this.minTicksInHive = minTicksInHive;
}
public CompoundTag entityData() {
return entityData;
}
public int ticksInHive() {
return ticksInHive;
}
public int minTicksInHive() {
return minTicksInHive;
}
}

View File

@ -0,0 +1,78 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.api.minecraft.HolderSet;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.ArrayType;
import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class BlockPredicate {
public static final Type<BlockPredicate> TYPE = new Type<BlockPredicate>(BlockPredicate.class) {
@Override
public BlockPredicate read(final ByteBuf buffer) throws Exception {
final HolderSet holders = Type.OPTIONAL_HOLDER_SET.read(buffer);
final StatePropertyMatcher[] propertyMatchers = buffer.readBoolean() ? StatePropertyMatcher.ARRAY_TYPE.read(buffer) : null;
final CompoundTag tag = Type.OPTIONAL_COMPOUND_TAG.read(buffer);
return new BlockPredicate(holders, propertyMatchers, tag);
}
@Override
public void write(final ByteBuf buffer, final BlockPredicate value) throws Exception {
Type.OPTIONAL_HOLDER_SET.write(buffer, value.holderSet);
buffer.writeBoolean(value.propertyMatchers != null);
if (value.propertyMatchers != null) {
StatePropertyMatcher.ARRAY_TYPE.write(buffer, value.propertyMatchers);
}
Type.OPTIONAL_COMPOUND_TAG.write(buffer, value.tag);
}
};
public static final Type<BlockPredicate[]> ARRAY_TYPE = new ArrayType<>(TYPE);
private final HolderSet holderSet;
private final StatePropertyMatcher[] propertyMatchers;
private final CompoundTag tag;
public BlockPredicate(@Nullable final HolderSet holderSet, final StatePropertyMatcher @Nullable [] propertyMatchers, @Nullable final CompoundTag tag) {
this.holderSet = holderSet;
this.propertyMatchers = propertyMatchers;
this.tag = tag;
}
public @Nullable HolderSet holderSet() {
return holderSet;
}
public StatePropertyMatcher @Nullable [] propertyMatchers() {
return propertyMatchers;
}
public @Nullable CompoundTag tag() {
return tag;
}
}

View File

@ -0,0 +1,62 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import java.util.Map;
public final class BlockStateProperties {
public static final Type<BlockStateProperties> TYPE = new Type<BlockStateProperties>(BlockStateProperties.class) {
@Override
public BlockStateProperties read(final ByteBuf buffer) throws Exception {
final int size = Type.VAR_INT.readPrimitive(buffer);
final Map<String, String> properties = new Object2ObjectOpenHashMap<>(size);
for (int i = 0; i < size; i++) {
properties.put(Type.STRING.read(buffer), Type.STRING.read(buffer));
}
return new BlockStateProperties(properties);
}
@Override
public void write(final ByteBuf buffer, final BlockStateProperties value) throws Exception {
Type.VAR_INT.writePrimitive(buffer, value.properties.size());
for (final Map.Entry<String, String> entry : value.properties.entrySet()) {
Type.STRING.write(buffer, entry.getKey());
Type.STRING.write(buffer, entry.getValue());
}
}
};
private final Map<String, String> properties;
public BlockStateProperties(final Map<String, String> properties) {
this.properties = properties;
}
public Map<String, String> properties() {
return properties;
}
}

View File

@ -0,0 +1,60 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
public final class DyedColor {
public static final Type<DyedColor> TYPE = new Type<DyedColor>(DyedColor.class) {
@Override
public DyedColor read(final ByteBuf buffer) {
final int rgb = buffer.readInt();
final boolean showInTooltip = buffer.readBoolean();
return new DyedColor(rgb, showInTooltip);
}
@Override
public void write(final ByteBuf buffer, final DyedColor value) {
buffer.writeInt(value.rgb);
buffer.writeBoolean(value.showInTooltip);
}
};
private final int rgb;
private final boolean showInTooltip;
public DyedColor(final int rgb, final boolean showInTooltip) {
this.rgb = rgb;
this.showInTooltip = showInTooltip;
}
public int rgb() {
return this.rgb;
}
public boolean showInTooltip() {
return this.showInTooltip;
}
}

View File

@ -0,0 +1,96 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
public final class Enchantments {
public static final Type<Enchantments> TYPE = new Type<Enchantments>(Enchantments.class) {
@Override
public Enchantments read(final ByteBuf buffer) {
final Int2IntMap enchantments = new Int2IntOpenHashMap();
final int size = Type.VAR_INT.readPrimitive(buffer);
for (int i = 0; i < size; i++) {
final int id = Type.VAR_INT.readPrimitive(buffer);
final int level = Type.VAR_INT.readPrimitive(buffer);
enchantments.put(id, level);
}
return new Enchantments(enchantments, buffer.readBoolean());
}
@Override
public void write(final ByteBuf buffer, final Enchantments value) {
Type.VAR_INT.writePrimitive(buffer, value.enchantments.size());
for (final Int2IntMap.Entry entry : value.enchantments.int2IntEntrySet()) {
Type.VAR_INT.writePrimitive(buffer, entry.getIntKey());
Type.VAR_INT.writePrimitive(buffer, entry.getIntValue());
}
buffer.writeBoolean(value.showInTooltip());
}
};
private final Int2IntMap enchantments;
private final boolean showInTooltip;
public Enchantments(final Int2IntMap enchantments, final boolean showInTooltip) {
this.enchantments = enchantments;
this.showInTooltip = showInTooltip;
}
public Enchantments(final boolean showInTooltip) {
this(new Int2IntOpenHashMap(), showInTooltip);
}
public Int2IntMap enchantments() {
return enchantments;
}
public int size() {
return enchantments.size();
}
public boolean showInTooltip() {
return showInTooltip;
}
public void add(final int id, final int level) {
enchantments.put(id, level);
}
public void remove(final int id) {
enchantments.remove(id);
}
public void clear() {
enchantments.clear();
}
public int getLevel(final int id) {
return enchantments.getOrDefault(id, -1);
}
}

View File

@ -0,0 +1,79 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable;
public abstract class Filterable<T> {
private final T raw;
private final T filtered;
protected Filterable(final T raw, @Nullable final T filtered) {
this.raw = raw;
this.filtered = filtered;
}
public T raw() {
return raw;
}
public boolean isFiltered() {
return filtered != null;
}
public @Nullable T filtered() {
return filtered;
}
public T get() {
return filtered != null ? filtered : raw;
}
public abstract static class FilterableType<T, F extends Filterable<T>> extends Type<F> {
private final Type<T> elementType;
private final Type<T> optionalElementType;
protected FilterableType(final Type<T> elementType, final Type<T> optionalElementType, final Class<F> outputClass) {
super(outputClass);
this.elementType = elementType;
this.optionalElementType = optionalElementType;
}
@Override
public F read(final ByteBuf buffer) throws Exception {
final T raw = elementType.read(buffer);
final T filtered = optionalElementType.read(buffer);
return create(raw, filtered);
}
@Override
public void write(final ByteBuf buffer, final F value) throws Exception {
elementType.write(buffer, value.raw());
optionalElementType.write(buffer, value.filtered());
}
protected abstract F create(T raw, T filtered);
}
}

View File

@ -0,0 +1,43 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.ArrayType;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class FilterableComponent extends Filterable<Tag> {
public static final Type<FilterableComponent> TYPE = new FilterableType<Tag, FilterableComponent>(Type.TAG, Type.OPTIONAL_TAG, FilterableComponent.class) {
@Override
protected FilterableComponent create(final Tag raw, final Tag filtered) {
return new FilterableComponent(raw, filtered);
}
};
public static final Type<FilterableComponent[]> ARRAY_TYPE = new ArrayType<>(FilterableComponent.TYPE);
public FilterableComponent(final Tag raw, @Nullable final Tag filtered) {
super(raw, filtered);
}
}

View File

@ -0,0 +1,42 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.ArrayType;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class FilterableString extends Filterable<String> {
public static final Type<FilterableString> TYPE = new FilterableType<String, FilterableString>(Type.STRING, Type.OPTIONAL_STRING, FilterableString.class) {
@Override
protected FilterableString create(final String raw, final String filtered) {
return new FilterableString(raw, filtered);
}
};
public static final Type<FilterableString[]> ARRAY_TYPE = new ArrayType<>(TYPE);
public FilterableString(final String raw, @Nullable final String filtered) {
super(raw, filtered);
}
}

View File

@ -0,0 +1,85 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.ArrayType;
import io.netty.buffer.ByteBuf;
public final class FireworkExplosion {
public static final Type<FireworkExplosion> TYPE = new Type<FireworkExplosion>(FireworkExplosion.class) {
@Override
public FireworkExplosion read(final ByteBuf buffer) throws Exception {
final int shape = Type.VAR_INT.readPrimitive(buffer);
final int[] colors = Type.INT_ARRAY_PRIMITIVE.read(buffer);
final int[] fadeColors = Type.INT_ARRAY_PRIMITIVE.read(buffer);
final boolean hasTrail = buffer.readBoolean();
final boolean hasTwinkle = buffer.readBoolean();
return new FireworkExplosion(shape, colors, fadeColors, hasTrail, hasTwinkle);
}
@Override
public void write(final ByteBuf buffer, final FireworkExplosion value) throws Exception {
Type.VAR_INT.writePrimitive(buffer, value.shape);
Type.INT_ARRAY_PRIMITIVE.write(buffer, value.colors);
Type.INT_ARRAY_PRIMITIVE.write(buffer, value.fadeColors);
buffer.writeBoolean(value.hasTrail);
buffer.writeBoolean(value.hasTwinkle);
}
};
public static final Type<FireworkExplosion[]> ARRAY_TYPE = new ArrayType<>(TYPE);
private final int shape;
private final int[] colors;
private final int[] fadeColors;
private final boolean hasTrail;
private final boolean hasTwinkle;
public FireworkExplosion(final int shape, final int[] colors, final int[] fadeColors, final boolean hasTrail, final boolean hasTwinkle) {
this.shape = shape;
this.colors = colors;
this.fadeColors = fadeColors;
this.hasTrail = hasTrail;
this.hasTwinkle = hasTwinkle;
}
public int shape() {
return shape;
}
public int[] colors() {
return colors;
}
public int[] fadeColors() {
return fadeColors;
}
public boolean hasTrail() {
return hasTrail;
}
public boolean hasTwinkle() {
return hasTwinkle;
}
}

View File

@ -0,0 +1,60 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
public final class Fireworks {
public static final Type<Fireworks> TYPE = new Type<Fireworks>(Fireworks.class) {
@Override
public Fireworks read(final ByteBuf buffer) throws Exception {
final int flightDuration = Type.VAR_INT.readPrimitive(buffer);
final FireworkExplosion[] explosions = FireworkExplosion.ARRAY_TYPE.read(buffer);
return new Fireworks(flightDuration, explosions);
}
@Override
public void write(final ByteBuf buffer, final Fireworks value) throws Exception {
Type.VAR_INT.writePrimitive(buffer, value.flightDuration);
FireworkExplosion.ARRAY_TYPE.write(buffer, value.explosions);
}
};
private final FireworkExplosion[] explosions;
private final int flightDuration;
public Fireworks(final int flightDuration, final FireworkExplosion[] explosions) {
this.flightDuration = flightDuration;
this.explosions = explosions;
}
public int flightDuration() {
return flightDuration;
}
public FireworkExplosion[] explosions() {
return explosions;
}
}

View File

@ -0,0 +1,62 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.ArrayType;
import io.netty.buffer.ByteBuf;
public final class FoodEffect {
public static final Type<FoodEffect> TYPE = new Type<FoodEffect>(FoodEffect.class) {
@Override
public FoodEffect read(final ByteBuf buffer) throws Exception {
final PotionEffect effect = PotionEffect.TYPE.read(buffer);
final float probability = buffer.readFloat();
return new FoodEffect(effect, probability);
}
@Override
public void write(final ByteBuf buffer, final FoodEffect value) throws Exception {
PotionEffect.TYPE.write(buffer, value.effect);
buffer.writeFloat(value.probability);
}
};
public static final Type<FoodEffect[]> ARRAY_TYPE = new ArrayType<>(TYPE);
private final PotionEffect effect;
private final float probability;
public FoodEffect(final PotionEffect effect, final float probability) {
this.effect = effect;
this.probability = probability;
}
public PotionEffect effect() {
return effect;
}
public float probability() {
return probability;
}
}

View File

@ -0,0 +1,84 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
public final class FoodProperties {
public static final Type<FoodProperties> TYPE = new Type<FoodProperties>(FoodProperties.class) {
@Override
public FoodProperties read(final ByteBuf buffer) throws Exception {
final int nutrition = Type.VAR_INT.readPrimitive(buffer);
final float saturationModifier = buffer.readFloat();
final boolean canAlwaysEat = buffer.readBoolean();
final float eatSeconds = buffer.readFloat();
final FoodEffect[] possibleEffects = FoodEffect.ARRAY_TYPE.read(buffer);
return new FoodProperties(nutrition, saturationModifier, canAlwaysEat, eatSeconds, possibleEffects);
}
@Override
public void write(final ByteBuf buffer, final FoodProperties value) throws Exception {
Type.VAR_INT.writePrimitive(buffer, value.nutrition);
buffer.writeFloat(value.saturationModifier);
buffer.writeBoolean(value.canAlwaysEat);
buffer.writeFloat(value.eatSeconds);
FoodEffect.ARRAY_TYPE.write(buffer, value.possibleEffects);
}
};
private final int nutrition;
private final float saturationModifier;
private final boolean canAlwaysEat;
private final float eatSeconds;
private final FoodEffect[] possibleEffects;
public FoodProperties(final int nutrition, final float saturationModifier, final boolean canAlwaysEat, final float eatSeconds, final FoodEffect[] possibleEffects) {
this.nutrition = nutrition;
this.saturationModifier = saturationModifier;
this.canAlwaysEat = canAlwaysEat;
this.eatSeconds = eatSeconds;
this.possibleEffects = possibleEffects;
}
public int nutrition() {
return nutrition;
}
public float saturationModifier() {
return saturationModifier;
}
public boolean canAlwaysEat() {
return canAlwaysEat;
}
public float eatSeconds() {
return eatSeconds;
}
public FoodEffect[] possibleEffects() {
return possibleEffects;
}
}

View File

@ -0,0 +1,71 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.minecraft.Holder;
import com.viaversion.viaversion.api.minecraft.SoundEvent;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.misc.HolderType;
import io.netty.buffer.ByteBuf;
public final class Instrument {
public static final HolderType<Instrument> TYPE = new HolderType<Instrument>() {
@Override
public Instrument readDirect(final ByteBuf buffer) throws Exception {
final Holder<SoundEvent> soundEvent = Type.SOUND_EVENT.read(buffer);
final int useDuration = Type.VAR_INT.readPrimitive(buffer);
final float range = buffer.readFloat();
return new Instrument(soundEvent, useDuration, range);
}
@Override
public void writeDirect(final ByteBuf buffer, final Instrument value) throws Exception {
Type.SOUND_EVENT.write(buffer, value.soundEvent());
Type.VAR_INT.writePrimitive(buffer, value.useDuration());
buffer.writeFloat(value.range());
}
};
private final Holder<SoundEvent> soundEvent;
private final int useDuration;
private final float range;
public Instrument(final Holder<SoundEvent> soundEvent, final int useDuration, final float range) {
this.soundEvent = soundEvent;
this.useDuration = useDuration;
this.range = range;
}
public Holder<SoundEvent> soundEvent() {
return soundEvent;
}
public int useDuration() {
return useDuration;
}
public float range() {
return range;
}
}

View File

@ -0,0 +1,62 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.minecraft.GlobalPosition;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class LodestoneTracker {
public static final Type<LodestoneTracker> TYPE = new Type<LodestoneTracker>(LodestoneTracker.class) {
@Override
public LodestoneTracker read(final ByteBuf buffer) throws Exception {
final GlobalPosition position = Type.OPTIONAL_GLOBAL_POSITION.read(buffer);
final boolean tracked = buffer.readBoolean();
return new LodestoneTracker(position, tracked);
}
@Override
public void write(final ByteBuf buffer, final LodestoneTracker value) throws Exception {
Type.OPTIONAL_GLOBAL_POSITION.write(buffer, value.position);
buffer.writeBoolean(value.tracked);
}
};
private final GlobalPosition position;
private final boolean tracked;
public LodestoneTracker(@Nullable final GlobalPosition position, final boolean tracked) {
this.position = position;
this.tracked = tracked;
}
public @Nullable GlobalPosition pos() {
return this.position;
}
public boolean tracked() {
return this.tracked;
}
}

View File

@ -0,0 +1,77 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
public final class MapDecoration {
public static final Type<MapDecoration> TYPE = new Type<MapDecoration>(MapDecoration.class) {
@Override
public MapDecoration read(final ByteBuf buffer) throws Exception {
final String type = Type.STRING.read(buffer);
final double x = Type.DOUBLE.readPrimitive(buffer);
final double z = Type.DOUBLE.readPrimitive(buffer);
final float rotation = Type.FLOAT.readPrimitive(buffer);
return new MapDecoration(type, x, z, rotation);
}
@Override
public void write(final ByteBuf buffer, final MapDecoration value) throws Exception {
Type.STRING.write(buffer, value.type);
buffer.writeDouble(value.x);
buffer.writeDouble(value.z);
buffer.writeFloat(value.rotation);
}
};
private final String type;
private final double x;
private final double z;
private final float rotation;
public MapDecoration(final String type, final double x, final double z, final float rotation) {
this.type = type;
this.x = x;
this.z = z;
this.rotation = rotation;
}
public String type() {
return type;
}
public double x() {
return x;
}
public double z() {
return z;
}
public float rotation() {
return rotation;
}
}

View File

@ -0,0 +1,65 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import java.util.Map;
public final class MapDecorations {
public static final Type<MapDecorations> TYPE = new Type<MapDecorations>(MapDecorations.class) {
@Override
public MapDecorations read(final ByteBuf buffer) throws Exception {
final Object2ObjectMap<String, MapDecoration> decorations = new Object2ObjectOpenHashMap<>();
final int size = Type.VAR_INT.readPrimitive(buffer);
for (int i = 0; i < size; i++) {
final String id = Type.STRING.read(buffer);
final MapDecoration decoration = MapDecoration.TYPE.read(buffer);
decorations.put(id, decoration);
}
return new MapDecorations(decorations);
}
@Override
public void write(final ByteBuf buffer, final MapDecorations value) throws Exception {
Type.VAR_INT.writePrimitive(buffer, value.decorations.size());
for (final Map.Entry<String, MapDecoration> entry : value.decorations.entrySet()) {
Type.STRING.write(buffer, entry.getKey());
MapDecoration.TYPE.write(buffer, entry.getValue());
}
}
};
private final Map<String, MapDecoration> decorations;
public MapDecorations(final Map<String, MapDecoration> decorations) {
this.decorations = decorations;
}
public Map<String, MapDecoration> decorations() {
return decorations;
}
}

View File

@ -0,0 +1,77 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
import java.util.UUID;
public final class ModifierData {
public static final Type<ModifierData> TYPE = new Type<ModifierData>(ModifierData.class) {
@Override
public ModifierData read(final ByteBuf buffer) throws Exception {
final UUID uuid = Type.UUID.read(buffer);
final String name = Type.STRING.read(buffer);
final double amount = buffer.readDouble();
final int operation = Type.VAR_INT.readPrimitive(buffer);
return new ModifierData(uuid, name, amount, operation);
}
@Override
public void write(final ByteBuf buffer, final ModifierData value) throws Exception {
Type.UUID.write(buffer, value.uuid);
Type.STRING.write(buffer, value.name);
buffer.writeDouble(value.amount);
Type.VAR_INT.writePrimitive(buffer, value.operation);
}
};
private final UUID uuid;
private final String name;
private final double amount;
private final int operation;
public ModifierData(final UUID uuid, final String name, final double amount, final int operation) {
this.uuid = uuid;
this.name = name;
this.amount = amount;
this.operation = operation;
}
public UUID uuid() {
return uuid;
}
public String name() {
return name;
}
public double amount() {
return amount;
}
public int operation() {
return operation;
}
}

View File

@ -0,0 +1,75 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
public final class PotDecorations {
public static final Type<PotDecorations> TYPE = new Type<PotDecorations>(PotDecorations.class) {
@Override
public PotDecorations read(final ByteBuf buffer) throws Exception {
return new PotDecorations(Type.VAR_INT_ARRAY_PRIMITIVE.read(buffer));
}
@Override
public void write(final ByteBuf buffer, final PotDecorations value) throws Exception {
Type.VAR_INT_ARRAY_PRIMITIVE.write(buffer, value.itemIds());
}
};
private final int[] itemIds;
public PotDecorations(final int[] itemIds) {
this.itemIds = itemIds;
}
public PotDecorations(final int backItem, final int leftItem, final int rightItem, final int frontItem) {
this.itemIds = new int[]{backItem, leftItem, rightItem, frontItem};
}
public int[] itemIds() {
return itemIds;
}
public int backItem() {
return item(0);
}
public int leftItem() {
return item(1);
}
public int rightItem() {
return item(2);
}
public int frontItem() {
return item(3);
}
private int item(final int index) {
return index < 0 || index >= itemIds.length ? -1 : itemIds[index];
}
}

View File

@ -0,0 +1,77 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class PotionContents {
public static final Type<PotionContents> TYPE = new Type<PotionContents>(PotionContents.class) {
@Override
public PotionContents read(final ByteBuf buffer) throws Exception {
final Integer potion = buffer.readBoolean() ? Type.VAR_INT.readPrimitive(buffer) : null;
final Integer customColor = buffer.readBoolean() ? buffer.readInt() : null;
final PotionEffect[] customEffects = PotionEffect.ARRAY_TYPE.read(buffer);
return new PotionContents(potion, customColor, customEffects);
}
@Override
public void write(final ByteBuf buffer, final PotionContents value) throws Exception {
buffer.writeBoolean(value.potion != null);
if (value.potion != null) {
Type.VAR_INT.writePrimitive(buffer, value.potion);
}
buffer.writeBoolean(value.customColor != null);
if (value.customColor != null) {
buffer.writeInt(value.customColor);
}
PotionEffect.ARRAY_TYPE.write(buffer, value.customEffects);
}
};
private final Integer potion;
private final Integer customColor;
private final PotionEffect[] customEffects;
public PotionContents(@Nullable final Integer potion, @Nullable final Integer customColor, final PotionEffect[] customEffects) {
this.potion = potion;
this.customColor = customColor;
this.customEffects = customEffects;
}
public @Nullable Integer potion() {
return potion;
}
public @Nullable Integer customColor() {
return customColor;
}
public PotionEffect[] customEffects() {
return customEffects;
}
}

View File

@ -0,0 +1,62 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.ArrayType;
import io.netty.buffer.ByteBuf;
public final class PotionEffect {
public static final Type<PotionEffect> TYPE = new Type<PotionEffect>(PotionEffect.class) {
@Override
public PotionEffect read(final ByteBuf buffer) throws Exception {
final int effect = Type.VAR_INT.readPrimitive(buffer);
final PotionEffectData effectData = PotionEffectData.TYPE.read(buffer);
return new PotionEffect(effect, effectData);
}
@Override
public void write(final ByteBuf buffer, final PotionEffect value) throws Exception {
Type.VAR_INT.writePrimitive(buffer, value.effect);
PotionEffectData.TYPE.write(buffer, value.effectData);
}
};
public static final Type<PotionEffect[]> ARRAY_TYPE = new ArrayType<>(TYPE);
private final int effect;
private final PotionEffectData effectData;
public PotionEffect(final int effect, final PotionEffectData effectData) {
this.effect = effect;
this.effectData = effectData;
}
public int effect() {
return effect;
}
public PotionEffectData effectData() {
return effectData;
}
}

View File

@ -0,0 +1,97 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.OptionalType;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class PotionEffectData {
public static final Type<PotionEffectData> TYPE = new Type<PotionEffectData>(PotionEffectData.class) {
@Override
public PotionEffectData read(final ByteBuf buffer) throws Exception {
final int amplifier = Type.VAR_INT.readPrimitive(buffer);
final int duration = Type.VAR_INT.readPrimitive(buffer);
final boolean ambient = buffer.readBoolean();
final boolean showParticles = buffer.readBoolean();
final boolean showIcon = buffer.readBoolean();
final PotionEffectData hiddenEffect = OPTIONAL_TYPE.read(buffer);
return new PotionEffectData(amplifier, duration, ambient, showParticles, showIcon, hiddenEffect);
}
@Override
public void write(final ByteBuf buffer, final PotionEffectData value) throws Exception {
Type.VAR_INT.writePrimitive(buffer, value.amplifier);
Type.VAR_INT.writePrimitive(buffer, value.duration);
buffer.writeBoolean(value.ambient);
buffer.writeBoolean(value.showParticles);
buffer.writeBoolean(value.showIcon);
OPTIONAL_TYPE.write(buffer, value.hiddenEffect);
}
};
public static final Type<PotionEffectData> OPTIONAL_TYPE = new OptionalType<PotionEffectData>(TYPE) {
};
private final int amplifier;
private final int duration;
private final boolean ambient;
private final boolean showParticles;
private final boolean showIcon;
private final PotionEffectData hiddenEffect;
public PotionEffectData(final int amplifier, final int duration, final boolean ambient, final boolean showParticles,
final boolean showIcon, @Nullable final PotionEffectData hiddenEffect) {
this.amplifier = amplifier;
this.duration = duration;
this.ambient = ambient;
this.showParticles = showParticles;
this.showIcon = showIcon;
this.hiddenEffect = hiddenEffect;
}
public int amplifier() {
return amplifier;
}
public int duration() {
return duration;
}
public boolean ambient() {
return ambient;
}
public boolean showParticles() {
return showParticles;
}
public boolean showIcon() {
return showIcon;
}
public @Nullable PotionEffectData hiddenEffect() {
return hiddenEffect;
}
}

View File

@ -0,0 +1,96 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.ArrayType;
import com.viaversion.viaversion.util.Either;
import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class StatePropertyMatcher {
// TODO Abstract Either reading
public static final Type<StatePropertyMatcher> TYPE = new Type<StatePropertyMatcher>(StatePropertyMatcher.class) {
@Override
public StatePropertyMatcher read(final ByteBuf buffer) throws Exception {
final String name = Type.STRING.read(buffer);
if (buffer.readBoolean()) {
final String value = Type.STRING.read(buffer);
return new StatePropertyMatcher(name, Either.left(value));
} else {
final String minValue = Type.OPTIONAL_STRING.read(buffer);
final String maxValue = Type.OPTIONAL_STRING.read(buffer);
return new StatePropertyMatcher(name, Either.right(new RangedMatcher(minValue, maxValue)));
}
}
@Override
public void write(final ByteBuf buffer, final StatePropertyMatcher value) throws Exception {
Type.STRING.write(buffer, value.name);
if (value.matcher.isLeft()) {
buffer.writeBoolean(true);
Type.STRING.write(buffer, value.matcher.left());
} else {
buffer.writeBoolean(false);
Type.OPTIONAL_STRING.write(buffer, value.matcher.right().minValue());
Type.OPTIONAL_STRING.write(buffer, value.matcher.right().maxValue());
}
}
};
public static final Type<StatePropertyMatcher[]> ARRAY_TYPE = new ArrayType<>(TYPE);
private final String name;
private final Either<String, RangedMatcher> matcher;
public StatePropertyMatcher(final String name, final Either<String, RangedMatcher> matcher) {
this.name = name;
this.matcher = matcher;
}
public String name() {
return name;
}
public Either<String, RangedMatcher> matcher() {
return matcher;
}
public static final class RangedMatcher {
private final String minValue;
private final String maxValue;
public RangedMatcher(@Nullable final String minValue, @Nullable final String maxValue) {
this.minValue = minValue;
this.maxValue = maxValue;
}
public @Nullable String minValue() {
return minValue;
}
public @Nullable String maxValue() {
return maxValue;
}
}
}

View File

@ -0,0 +1,62 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.ArrayType;
import io.netty.buffer.ByteBuf;
public final class SuspiciousStewEffect {
public static final Type<SuspiciousStewEffect> TYPE = new Type<SuspiciousStewEffect>(SuspiciousStewEffect.class) {
@Override
public SuspiciousStewEffect read(final ByteBuf buffer) {
final int effect = Type.VAR_INT.readPrimitive(buffer);
final int duration = Type.VAR_INT.readPrimitive(buffer);
return new SuspiciousStewEffect(effect, duration);
}
@Override
public void write(final ByteBuf buffer, final SuspiciousStewEffect value) {
Type.VAR_INT.writePrimitive(buffer, value.effect);
Type.VAR_INT.writePrimitive(buffer, value.duration);
}
};
public static final Type<SuspiciousStewEffect[]> ARRAY_TYPE = new ArrayType<>(TYPE);
private final int effect;
private final int duration;
public SuspiciousStewEffect(final int effect, final int duration) {
this.effect = effect;
this.duration = duration;
}
public int mobEffect() {
return effect;
}
public int duration() {
return duration;
}
}

View File

@ -0,0 +1,68 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
public final class ToolProperties {
public static final Type<ToolProperties> TYPE = new Type<ToolProperties>(ToolProperties.class) {
@Override
public ToolProperties read(final ByteBuf buffer) throws Exception {
final ToolRule[] rules = ToolRule.ARRAY_TYPE.read(buffer);
final float defaultMiningSpeed = buffer.readFloat();
final int damagePerBlock = Type.VAR_INT.readPrimitive(buffer);
return new ToolProperties(rules, defaultMiningSpeed, damagePerBlock);
}
@Override
public void write(final ByteBuf buffer, final ToolProperties value) throws Exception {
ToolRule.ARRAY_TYPE.write(buffer, value.rules());
buffer.writeFloat(value.defaultMiningSpeed());
Type.VAR_INT.writePrimitive(buffer, value.damagePerBlock());
}
};
private final ToolRule[] rules;
private final float defaultMiningSpeed;
private final int damagePerBlock;
public ToolProperties(final ToolRule[] rules, final float defaultMiningSpeed, final int damagePerBlock) {
this.rules = rules;
this.defaultMiningSpeed = defaultMiningSpeed;
this.damagePerBlock = damagePerBlock;
}
public ToolRule[] rules() {
return rules;
}
public float defaultMiningSpeed() {
return defaultMiningSpeed;
}
public int damagePerBlock() {
return damagePerBlock;
}
}

View File

@ -0,0 +1,72 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.minecraft.HolderSet;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.ArrayType;
import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class ToolRule {
public static final Type<ToolRule> TYPE = new Type<ToolRule>(ToolRule.class) {
@Override
public ToolRule read(final ByteBuf buffer) throws Exception {
final HolderSet blocks = Type.HOLDER_SET.read(buffer);
final Float speed = Type.OPTIONAL_FLOAT.read(buffer);
final Boolean correctForDrops = Type.OPTIONAL_BOOLEAN.read(buffer);
return new ToolRule(blocks, speed, correctForDrops);
}
@Override
public void write(final ByteBuf buffer, final ToolRule value) throws Exception {
Type.HOLDER_SET.write(buffer, value.blocks);
Type.OPTIONAL_FLOAT.write(buffer, value.speed);
Type.OPTIONAL_BOOLEAN.write(buffer, value.correctForDrops);
}
};
public static final Type<ToolRule[]> ARRAY_TYPE = new ArrayType<>(TYPE);
private final HolderSet blocks;
private final Float speed;
private final Boolean correctForDrops;
public ToolRule(final HolderSet blocks, @Nullable final Float speed, @Nullable final Boolean correctForDrops) {
this.blocks = blocks;
this.speed = speed;
this.correctForDrops = correctForDrops;
}
public HolderSet blocks() {
return blocks;
}
public @Nullable Float speed() {
return speed;
}
public @Nullable Boolean correctForDrops() {
return correctForDrops;
}
}

View File

@ -0,0 +1,51 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
public final class Unbreakable {
public static final Type<Unbreakable> TYPE = new Type<Unbreakable>(Unbreakable.class) {
@Override
public Unbreakable read(final ByteBuf buffer) {
return new Unbreakable(buffer.readBoolean());
}
@Override
public void write(final ByteBuf buffer, final Unbreakable value) {
buffer.writeBoolean(value.showInTooltip());
}
};
private final boolean showInTooltip;
public Unbreakable(final boolean showInTooltip) {
this.showInTooltip = showInTooltip;
}
public boolean showInTooltip() {
return showInTooltip;
}
}

View File

@ -0,0 +1,84 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
public final class WrittenBook {
public static final Type<WrittenBook> TYPE = new Type<WrittenBook>(WrittenBook.class) {
@Override
public WrittenBook read(final ByteBuf buffer) throws Exception {
final FilterableString title = FilterableString.TYPE.read(buffer);
final String author = Type.STRING.read(buffer);
final int generation = Type.VAR_INT.readPrimitive(buffer);
final FilterableComponent[] pages = FilterableComponent.ARRAY_TYPE.read(buffer);
final boolean resolved = buffer.readBoolean();
return new WrittenBook(title, author, generation, pages, resolved);
}
@Override
public void write(final ByteBuf buffer, final WrittenBook value) throws Exception {
FilterableString.TYPE.write(buffer, value.title);
Type.STRING.write(buffer, value.author);
Type.VAR_INT.writePrimitive(buffer, value.generation);
FilterableComponent.ARRAY_TYPE.write(buffer, value.pages);
buffer.writeBoolean(value.resolved);
}
};
private final FilterableString title;
private final String author;
private final int generation;
private final FilterableComponent[] pages;
private final boolean resolved;
public WrittenBook(final FilterableString title, final String author, final int generation, final FilterableComponent[] pages, final boolean resolved) {
this.title = title;
this.author = author;
this.generation = generation;
this.pages = pages;
this.resolved = resolved;
}
public FilterableString title() {
return title;
}
public String author() {
return author;
}
public int generation() {
return generation;
}
public FilterableComponent[] pages() {
return pages;
}
public boolean resolved() {
return resolved;
}
}

View File

@ -22,6 +22,7 @@
*/
package com.viaversion.viaversion.api.minecraft.metadata;
import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.type.Type;
public interface MetaType {
@ -49,6 +50,7 @@ public interface MetaType {
private final Type<?> type;
MetaTypeImpl(final int typeId, final Type<?> type) {
Preconditions.checkNotNull(type);
this.typeId = typeId;
this.type = type;
}

View File

@ -24,7 +24,6 @@ package com.viaversion.viaversion.api.minecraft.metadata.types;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.VoidType;
public enum MetaType1_8 implements MetaType {
Byte(0, Type.BYTE),
@ -34,9 +33,7 @@ public enum MetaType1_8 implements MetaType {
String(4, Type.STRING),
Slot(5, Type.ITEM1_8),
Position(6, Type.VECTOR),
Rotation(7, Type.ROTATION),
@Deprecated
NonExistent(-1, new VoidType());
Rotation(7, Type.ROTATION);
private final int typeID;
private final Type type;

View File

@ -0,0 +1,71 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.metadata.types;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.ArrayType;
import com.viaversion.viaversion.api.type.types.misc.ParticleType;
import com.viaversion.viaversion.api.type.types.version.Types1_20_5;
public final class MetaTypes1_20_5 extends AbstractMetaTypes {
public final MetaType byteType = add(0, Type.BYTE);
public final MetaType varIntType = add(1, Type.VAR_INT);
public final MetaType longType = add(2, Type.VAR_LONG);
public final MetaType floatType = add(3, Type.FLOAT);
public final MetaType stringType = add(4, Type.STRING);
public final MetaType componentType = add(5, Type.TAG);
public final MetaType optionalComponentType = add(6, Type.OPTIONAL_TAG);
public final MetaType itemType = add(7, Types1_20_5.ITEM);
public final MetaType booleanType = add(8, Type.BOOLEAN);
public final MetaType rotationType = add(9, Type.ROTATION);
public final MetaType positionType = add(10, Type.POSITION1_14);
public final MetaType optionalPositionType = add(11, Type.OPTIONAL_POSITION_1_14);
public final MetaType directionType = add(12, Type.VAR_INT);
public final MetaType optionalUUIDType = add(13, Type.OPTIONAL_UUID);
public final MetaType blockStateType = add(14, Type.VAR_INT);
public final MetaType optionalBlockStateType = add(15, Type.VAR_INT);
public final MetaType nbtType = add(16, Type.COMPOUND_TAG);
public final MetaType particleType;
public final MetaType particlesType;
public final MetaType villagerDatatType = add(19, Type.VILLAGER_DATA);
public final MetaType optionalVarIntType = add(20, Type.OPTIONAL_VAR_INT);
public final MetaType poseType = add(21, Type.VAR_INT);
public final MetaType catVariantType = add(22, Type.VAR_INT);
public final MetaType wolfVariantType = add(23, Type.VAR_INT);
public final MetaType frogVariantType = add(24, Type.VAR_INT);
public final MetaType optionalGlobalPosition = add(25, Type.OPTIONAL_GLOBAL_POSITION);
public final MetaType paintingVariantType = add(26, Type.VAR_INT);
public final MetaType snifferState = add(27, Type.VAR_INT);
public final MetaType armadilloState = add(28, Type.VAR_INT);
public final MetaType vectorType = add(29, Type.VECTOR3F);
public final MetaType quaternionType = add(30, Type.QUATERNION);
public MetaTypes1_20_5(final ParticleType particleType, final ArrayType<Particle> particlesType) {
super(31);
this.particleType = add(17, particleType);
this.particlesType = add(18, particlesType);
}
}

View File

@ -25,7 +25,7 @@ package com.viaversion.viaversion.api.minecraft.signature.model.chain.v1_19_1;
import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature;
import com.viaversion.viaversion.api.minecraft.signature.model.DecoratableMessage;
import com.viaversion.viaversion.api.minecraft.signature.util.DataConsumer;
import net.lenni0451.mcstructs.text.utils.JsonUtils;
import com.viaversion.viaversion.util.GsonUtil;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
@ -62,7 +62,7 @@ public class MessageBody {
dataOutputStream.write(this.content.plain().getBytes(StandardCharsets.UTF_8));
dataOutputStream.write(HASH_SEPARATOR_BYTE);
if (this.content.isDecorated()) {
dataOutputStream.write(JsonUtils.toSortedString(this.content.decorated(), null).getBytes(StandardCharsets.UTF_8));
dataOutputStream.write(GsonUtil.sort(this.content.decorated()).toString().getBytes(StandardCharsets.UTF_8));
}
for (PlayerMessageSignature lastSeenMessage : this.lastSeenMessages) {

View File

@ -25,7 +25,7 @@ package com.viaversion.viaversion.api.minecraft.signature.storage;
import com.viaversion.viaversion.api.minecraft.ProfileKey;
import com.viaversion.viaversion.api.minecraft.signature.model.DecoratableMessage;
import com.viaversion.viaversion.api.minecraft.signature.model.MessageMetadata;
import net.lenni0451.mcstructs.text.utils.JsonUtils;
import com.viaversion.viaversion.util.GsonUtil;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@ -48,7 +48,7 @@ public class ChatSession1_19_0 extends ChatSession {
buffer.putLong(metadata.sender().getMostSignificantBits()).putLong(metadata.sender().getLeastSignificantBits());
buffer.putLong(metadata.timestamp().getEpochSecond());
signer.accept(data);
signer.accept(JsonUtils.toSortedString(content.decorated(), null).getBytes(StandardCharsets.UTF_8));
signer.accept(GsonUtil.sort(content.decorated()).toString().getBytes(StandardCharsets.UTF_8));
});
}

View File

@ -22,6 +22,7 @@
*/
package com.viaversion.viaversion.api.platform;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
public interface ProtocolDetectorService {
@ -32,7 +33,7 @@ public interface ProtocolDetectorService {
* @param serverName name of the proxied server
* @return protocol version of the proxied server, or -1 if unknown
*/
int serverProtocolVersion(String serverName);
ProtocolVersion serverProtocolVersion(String serverName);
/**
* Probes all registered proxied servers for their protocol version.

View File

@ -23,8 +23,9 @@
package com.viaversion.viaversion.api.platform;
import com.google.gson.JsonObject;
import it.unimi.dsi.fastutil.ints.IntSortedSet;
import it.unimi.dsi.fastutil.ints.IntSortedSets;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet;
import java.util.SortedSet;
public interface ViaInjector {
@ -60,7 +61,7 @@ public interface ViaInjector {
* @throws Exception if there is an error with getting this info, e.g. not binded
* @see ViaPlatform#isProxy()
*/
int getServerProtocolVersion() throws Exception;
ProtocolVersion getServerProtocolVersion() throws Exception;
/**
* Returns the supported server protocol versions.
@ -69,8 +70,10 @@ public interface ViaInjector {
* @throws Exception if there is an error with getting this info, e.g. not binded
* @see ViaPlatform#isProxy()
*/
default IntSortedSet getServerProtocolVersions() throws Exception {
return IntSortedSets.singleton(getServerProtocolVersion());
default SortedSet<ProtocolVersion> getServerProtocolVersions() throws Exception {
final SortedSet<ProtocolVersion> versions = new ObjectLinkedOpenHashSet<>();
versions.add(getServerProtocolVersion());
return versions;
}
/**

View File

@ -38,11 +38,11 @@ import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypeMap;
import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider;
import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.rewriter.MappingDataListener;
import com.viaversion.viaversion.api.rewriter.Rewriter;
import com.viaversion.viaversion.exception.CancelException;
import com.viaversion.viaversion.exception.InformativeException;
import java.util.Collections;
import java.util.EnumMap;
import com.viaversion.viaversion.util.ProtocolUtil;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
@ -50,6 +50,8 @@ import java.util.function.Predicate;
import java.util.logging.Level;
import org.checkerframework.checker.nullness.qual.Nullable;
import static com.viaversion.viaversion.util.ProtocolUtil.packetTypeMap;
/**
* Abstract protocol class to handle packet transformation between two protocol versions.
*
@ -125,24 +127,42 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
// even if there will be multiple of these handlers
final SU configurationAcknowledgedPacket = configurationAcknowledgedPacket();
if (configurationAcknowledgedPacket != null) {
registerServerbound(configurationAcknowledgedPacket, setClientStateHandler(State.CONFIGURATION));
appendServerbound(configurationAcknowledgedPacket, setClientStateHandler(State.CONFIGURATION));
}
final CU startConfigurationPacket = startConfigurationPacket();
if (startConfigurationPacket != null) {
registerClientbound(startConfigurationPacket, setServerStateHandler(State.CONFIGURATION));
appendClientbound(startConfigurationPacket, setServerStateHandler(State.CONFIGURATION));
}
final ServerboundPacketType finishConfigurationPacket = serverboundFinishConfigurationPacket();
final SU finishConfigurationPacket = serverboundFinishConfigurationPacket();
if (finishConfigurationPacket != null) {
final int id = finishConfigurationPacket.getId();
registerServerbound(State.CONFIGURATION, id, id, setClientStateHandler(State.PLAY));
appendServerbound(finishConfigurationPacket, setClientStateHandler(State.PLAY));
}
final ClientboundPacketType clientboundFinishConfigurationPacket = clientboundFinishConfigurationPacket();
final CU clientboundFinishConfigurationPacket = clientboundFinishConfigurationPacket();
if (clientboundFinishConfigurationPacket != null) {
final int id = clientboundFinishConfigurationPacket.getId();
registerClientbound(State.CONFIGURATION, id, id, setServerStateHandler(State.PLAY));
appendClientbound(clientboundFinishConfigurationPacket, setServerStateHandler(State.PLAY));
}
}
@Override
public void appendClientbound(final CU type, final PacketHandler handler) {
final PacketMapping mapping = clientboundMappings.mappedPacket(type.state(), type.getId());
if (mapping != null) {
mapping.appendHandler(handler);
} else {
registerClientbound(type, handler);
}
}
@Override
public void appendServerbound(final SU type, final PacketHandler handler) {
final PacketMapping mapping = serverboundMappings.mappedPacket(type.state(), type.getId());
if (mapping != null) {
mapping.appendHandler(handler);
} else {
registerServerbound(type, handler);
}
}
@ -154,18 +174,19 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
) {
for (Map.Entry<State, PacketTypeMap<M>> entry : mappedPacketTypes.entrySet()) {
PacketTypeMap<M> mappedTypes = entry.getValue();
for (U unmappedType : unmappedPacketTypes.get(entry.getKey()).types()) {
PacketTypeMap<U> unmappedTypes = unmappedPacketTypes.get(entry.getKey());
for (U unmappedType : unmappedTypes.types()) {
M mappedType = mappedTypes.typeByName(unmappedType.getName());
if (mappedType == null) {
// No mapped packet of the same name exists
Preconditions.checkArgument(registeredPredicate.test(unmappedType),
"Packet %s in %s has no mapping - it needs to be manually cancelled or remapped", unmappedType, getClass());
Preconditions.checkArgument(registeredPredicate.test(unmappedType), "Packet %s in %s has no mapping - it needs to be manually cancelled or remapped", unmappedType, getClass());
continue;
}
// Register if no custom handler exists and ids are different
if (unmappedType.getId() != mappedType.getId() && !registeredPredicate.test(unmappedType)) {
registerConsumer.accept(unmappedType, mappedType);
}
}
}
@ -193,6 +214,7 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
protected void onMappingDataLoaded() {
callOnMappingDataLoaded(getEntityRewriter());
callOnMappingDataLoaded(getItemRewriter());
callOnMappingDataLoaded(getTagRewriter());
}
private void callRegister(@Nullable Rewriter<?> rewriter) {
@ -201,7 +223,7 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
}
}
private void callOnMappingDataLoaded(@Nullable Rewriter<?> rewriter) {
private void callOnMappingDataLoaded(@Nullable MappingDataListener rewriter) {
if (rewriter != null) {
rewriter.onMappingDataLoaded();
}
@ -213,10 +235,10 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
protected PacketTypesProvider<CU, CM, SM, SU> createPacketTypesProvider() {
return new SimplePacketTypesProvider<>(
packetTypeMap(unmappedClientboundPacketType),
packetTypeMap(mappedClientboundPacketType),
packetTypeMap(mappedServerboundPacketType),
packetTypeMap(unmappedServerboundPacketType)
packetTypeMap(unmappedClientboundPacketType, unmappedClientboundPacketType),
packetTypeMap(mappedClientboundPacketType, mappedClientboundPacketType),
packetTypeMap(mappedServerboundPacketType, mappedServerboundPacketType),
packetTypeMap(unmappedServerboundPacketType, unmappedServerboundPacketType)
);
}
@ -228,35 +250,20 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
return PacketMappings.arrayMappings();
}
private <P extends PacketType> Map<State, PacketTypeMap<P>> packetTypeMap(Class<P> packetTypeClass) {
if (packetTypeClass != null) {
Map<State, PacketTypeMap<P>> map = new EnumMap<>(State.class);
map.put(State.PLAY, PacketTypeMap.of(packetTypeClass));
return map;
}
return Collections.emptyMap();
}
protected @Nullable SU configurationAcknowledgedPacket() {
final Map<State, PacketTypeMap<SU>> packetTypes = packetTypesProvider.unmappedServerboundPacketTypes();
final PacketTypeMap<SU> packetTypeMap = packetTypes.get(State.PLAY);
return packetTypeMap != null ? packetTypeMap.typeByName("CONFIGURATION_ACKNOWLEDGED") : null;
return packetTypesProvider.unmappedServerboundType(State.PLAY, "CONFIGURATION_ACKNOWLEDGED");
}
protected @Nullable CU startConfigurationPacket() {
final Map<State, PacketTypeMap<CU>> packetTypes = packetTypesProvider.unmappedClientboundPacketTypes();
final PacketTypeMap<CU> packetTypeMap = packetTypes.get(State.PLAY);
return packetTypeMap != null ? packetTypeMap.typeByName("START_CONFIGURATION") : null;
return packetTypesProvider.unmappedClientboundType(State.PLAY, "START_CONFIGURATION");
}
protected @Nullable ServerboundPacketType serverboundFinishConfigurationPacket() {
// To be overridden
return null;
protected @Nullable SU serverboundFinishConfigurationPacket() {
return packetTypesProvider.unmappedServerboundType(State.CONFIGURATION, "FINISH_CONFIGURATION");
}
protected @Nullable ClientboundPacketType clientboundFinishConfigurationPacket() {
// To be overridden
return null;
protected @Nullable CU clientboundFinishConfigurationPacket() {
return packetTypesProvider.unmappedClientboundType(State.CONFIGURATION, "FINISH_CONFIGURATION");
}
// ---------------------------------------------------------------------------------
@ -391,19 +398,17 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
try {
handler.handle(packetWrapper);
} catch (CancelException e) {
// Pass through CancelExceptions
throw e;
throw e; // Pass through CancelExceptions
} catch (InformativeException e) {
// Catch InformativeExceptions
e.addSource(handler.getClass());
throwRemapError(direction, state, unmappedId, packetWrapper.getId(), e);
return;
printRemapError(direction, state, unmappedId, packetWrapper.getId(), e);
throw e;
} catch (Exception e) {
// Wrap other exceptions during packet handling
InformativeException ex = new InformativeException(e);
ex.addSource(handler.getClass());
throwRemapError(direction, state, unmappedId, packetWrapper.getId(), ex);
return;
printRemapError(direction, state, unmappedId, packetWrapper.getId(), ex);
throw ex;
}
if (packetWrapper.isCancelled()) {
@ -412,36 +417,22 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
}
}
protected void throwRemapError(Direction direction, State state, int unmappedPacketId, int mappedPacketId, InformativeException e) throws InformativeException {
private void printRemapError(Direction direction, State state, int unmappedPacketId, int mappedPacketId, InformativeException e) {
// Don't print errors during handshake/login/status
if (state != State.PLAY && direction == Direction.SERVERBOUND && !Via.getManager().debugHandler().enabled()) {
e.setShouldBePrinted(false);
throw e;
return;
}
PacketType packetType = direction == Direction.CLIENTBOUND ? unmappedClientboundPacketType(state, unmappedPacketId) : unmappedServerboundPacketType(state, unmappedPacketId);
PacketType packetType = direction == Direction.CLIENTBOUND
? packetTypesProvider.unmappedClientboundType(state, unmappedPacketId)
: packetTypesProvider.unmappedServerboundType(state, unmappedPacketId);
if (packetType != null) {
Via.getPlatform().getLogger().warning("ERROR IN " + getClass().getSimpleName() + " IN REMAP OF " + packetType + " (" + toNiceHex(unmappedPacketId) + ")");
Via.getPlatform().getLogger().warning("ERROR IN " + getClass().getSimpleName() + " IN REMAP OF " + packetType + " (" + ProtocolUtil.toNiceHex(unmappedPacketId) + ")");
} else {
Via.getPlatform().getLogger().warning("ERROR IN " + getClass().getSimpleName()
+ " IN REMAP OF " + state + " " + toNiceHex(unmappedPacketId) + "->" + toNiceHex(mappedPacketId));
+ " IN REMAP OF " + state + " " + ProtocolUtil.toNiceHex(unmappedPacketId) + "->" + ProtocolUtil.toNiceHex(mappedPacketId));
}
throw e;
}
private @Nullable CU unmappedClientboundPacketType(final State state, final int packetId) {
PacketTypeMap<CU> map = packetTypesProvider.unmappedClientboundPacketTypes().get(state);
return map != null ? map.typeById(packetId) : null;
}
private @Nullable SU unmappedServerboundPacketType(final State state, final int packetId) {
PacketTypeMap<SU> map = packetTypesProvider.unmappedServerboundPacketTypes().get(state);
return map != null ? map.typeById(packetId) : null;
}
public static String toNiceHex(int id) {
String hex = Integer.toHexString(id).toUpperCase();
return (hex.length() == 1 ? "0x0" : "0x") + hex;
}
/**
@ -455,16 +446,16 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
}
}
protected PacketHandler setClientStateHandler(final State state) {
private PacketHandler setClientStateHandler(final State state) {
return wrapper -> wrapper.user().getProtocolInfo().setClientState(state);
}
protected PacketHandler setServerStateHandler(final State state) {
private PacketHandler setServerStateHandler(final State state) {
return wrapper -> wrapper.user().getProtocolInfo().setServerState(state);
}
@Override
public PacketTypesProvider<CU, CM, SM, SU> getPacketTypesProvider() {
public final PacketTypesProvider<CU, CM, SM, SU> getPacketTypesProvider() {
return packetTypesProvider;
}
@ -479,10 +470,6 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
storedObjects.put(object.getClass(), object);
}
public PacketTypesProvider<CU, CM, SM, SU> packetTypesProvider() {
return packetTypesProvider;
}
@Override
public String toString() {
return "Protocol:" + getClass().getSimpleName();

View File

@ -22,7 +22,6 @@
*/
package com.viaversion.viaversion.api.protocol;
import com.google.common.annotations.Beta;
import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.MappingData;
@ -37,6 +36,8 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.rewriter.EntityRewriter;
import com.viaversion.viaversion.api.rewriter.ItemRewriter;
import com.viaversion.viaversion.api.rewriter.TagRewriter;
import com.viaversion.viaversion.api.type.Type;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
@ -51,24 +52,25 @@ import org.checkerframework.checker.nullness.qual.Nullable;
*/
public interface Protocol<CU extends ClientboundPacketType, CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> {
default void registerServerbound(State state, int unmappedPacketId, int mappedPacketId) {
registerServerbound(state, unmappedPacketId, mappedPacketId, (PacketHandler) null);
}
default void registerServerbound(State state, int unmappedPacketId, int mappedPacketId, PacketHandler handler) {
registerServerbound(state, unmappedPacketId, mappedPacketId, handler, false);
}
default void registerClientbound(State state, ClientboundPacketType packetType, PacketHandler handler) {
default void registerClientbound(State state, ClientboundPacketType packetType, @Nullable PacketHandler handler) {
Preconditions.checkArgument(packetType.state() == state);
registerClientbound(state, packetType.getId(), packetType.getId(), handler, false);
}
default void registerServerbound(State state, ServerboundPacketType packetType, PacketHandler handler) {
default void registerServerbound(State state, ServerboundPacketType packetType, @Nullable PacketHandler handler) {
Preconditions.checkArgument(packetType.state() == state);
registerServerbound(state, packetType.getId(), packetType.getId(), handler, false);
}
@Deprecated/*(forRemoval = true)*/
default void registerServerbound(State state, int unmappedPacketId, int mappedPacketId) {
registerServerbound(state, unmappedPacketId, mappedPacketId, (PacketHandler) null);
}
default void registerServerbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler) {
registerServerbound(state, unmappedPacketId, mappedPacketId, handler, false);
}
/**
* Registers a serverbound packet, with id transformation and remapper.
*
@ -79,15 +81,16 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
* @param override whether an existing mapper should be overridden
* @see #registerServerbound(ServerboundPacketType, ServerboundPacketType, PacketHandler, boolean)
*/
void registerServerbound(State state, int unmappedPacketId, int mappedPacketId, PacketHandler handler, boolean override);
void registerServerbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler, boolean override);
void cancelServerbound(State state, int mappedPacketId);
@Deprecated/*(forRemoval = true)*/
default void registerClientbound(State state, int unmappedPacketId, int mappedPacketId) {
registerClientbound(state, unmappedPacketId, mappedPacketId, (PacketHandler) null);
}
default void registerClientbound(State state, int unmappedPacketId, int mappedPacketId, PacketHandler handler) {
default void registerClientbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler) {
registerClientbound(state, unmappedPacketId, mappedPacketId, handler, false);
}
@ -103,7 +106,7 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
* @param override whether an existing mapper should be overridden
* @see #registerClientbound(ClientboundPacketType, ClientboundPacketType, PacketHandler, boolean)
*/
void registerClientbound(State state, int unmappedPacketId, int mappedPacketId, PacketHandler handler, boolean override);
void registerClientbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler, boolean override);
// ---------------------------------------------------------------------------------------
@ -239,6 +242,28 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
*/
boolean hasRegisteredServerbound(State state, int unmappedPacketId);
/**
* Appends a clientbound packet type handler with another, as opposed to replacing it entirely.
* <p>
* Use {@link PacketWrapper#set(Type, int, Object)} to change individual parts, or call
* {@link PacketWrapper#resetReader()} to reset the reader index.
*
* @param type clientbound packet type
* @param handler packet handler
*/
void appendClientbound(CU type, PacketHandler handler);
/**
* Appends a serverbound packet type handler with another, as opposed to replacing it entirely.
* <p>
* Use {@link PacketWrapper#set(Type, int, Object)} to change individual parts, or call
* {@link PacketWrapper#resetReader()} to reset the reader index.
*
* @param type serverbound packet type
* @param handler packet handler
*/
void appendServerbound(SU type, PacketHandler handler);
/**
* Transform a packet using this protocol
*
@ -255,7 +280,6 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
*
* @return the packet types provider
*/
@Beta
PacketTypesProvider<CU, CM, SM, SU> getPacketTypesProvider();
/**
@ -265,13 +289,16 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
* @param <T> type
* @return object if present, else null
*/
@Nullable <T> T get(Class<T> objectClass);
@Deprecated
@Nullable
<T> T get(Class<T> objectClass);
/**
* Caches an object, retrievable by using {@link #get(Class)}.
*
* @param object object to cache
*/
@Deprecated
void put(Object object);
/**
@ -348,6 +375,15 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
return null;
}
/**
* Returns the protocol's tag rewriter if present.
*
* @return tag rewriter
*/
default @Nullable TagRewriter getTagRewriter() {
return null;
}
/**
* Returns whether this protocol is a base protocol.
*

View File

@ -31,6 +31,7 @@ import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.VersionedPacketTransformer;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.protocol.version.ServerProtocolVersion;
import com.viaversion.viaversion.api.protocol.version.VersionType;
import io.netty.buffer.ByteBuf;
import java.util.Collection;
import java.util.List;
@ -62,21 +63,8 @@ public interface ProtocolManager {
* @param clientVersion client protocol version
* @param serverVersion server protocol version
* @return protocol if present, else null
* @see #getProtocolPath(int, int) to get a full path of Protocols between a larger gap of versions
*/
default @Nullable Protocol getProtocol(ProtocolVersion clientVersion, ProtocolVersion serverVersion) {
return getProtocol(clientVersion.getVersion(), serverVersion.getVersion());
}
/**
* Returns a protocol transforming packets for server version to the given client version.
*
* @param clientVersion client protocol version
* @param serverVersion server protocol version
* @return protocol if present, else null
* @see #getProtocolPath(int, int) to get a full path of Protocols between a larger gap of versions
*/
@Nullable Protocol getProtocol(int clientVersion, int serverVersion);
@Nullable Protocol getProtocol(ProtocolVersion clientVersion, ProtocolVersion serverVersion);
/**
* Returns the base protocol handling serverbound handshake packets.
@ -90,10 +78,9 @@ public interface ProtocolManager {
* The standard base protocols deal with status and login packets for userconnection initialization.
*
* @param serverVersion server protocol version
* @return base protocol for the given server protocol version
* @throws IllegalStateException if no base protocol could be found
* @return base protocol for the given server protocol version if present, else null
*/
Protocol getBaseProtocol(int serverVersion);
@Nullable Protocol getBaseProtocol(ProtocolVersion serverVersion);
/**
* Returns an immutable collection of registered protocols.
@ -128,7 +115,7 @@ public interface ProtocolManager {
* @param serverVersion output server protocol version the protocol converts to
* @throws IllegalArgumentException if a supported client protocol version is equal to the server protocol version
*/
void registerProtocol(Protocol protocol, List<Integer> supportedClientVersion, int serverVersion);
void registerProtocol(Protocol protocol, List<ProtocolVersion> supportedClientVersion, ProtocolVersion serverVersion);
/**
* Registers and initializes a base protocol. Base Protocols registered later have higher priority.
@ -138,7 +125,7 @@ public interface ProtocolManager {
* @param supportedProtocols protocol versions supported by the base protocol
* @throws IllegalArgumentException if the protocol is not a base protocol as given by {@link Protocol#isBaseProtocol()}
*/
void registerBaseProtocol(Protocol baseProtocol, Range<Integer> supportedProtocols);
void registerBaseProtocol(Protocol baseProtocol, Range<ProtocolVersion> supportedProtocols);
/**
* Calculates and returns the protocol path from a client protocol version to server protocol version.
@ -148,7 +135,12 @@ public interface ProtocolManager {
* @param serverVersion desired output server protocol version
* @return path generated, or null if not supported or the length exceeds {@link #getMaxProtocolPathSize()}
*/
@Nullable List<ProtocolPathEntry> getProtocolPath(int clientVersion, int serverVersion);
@Nullable List<ProtocolPathEntry> getProtocolPath(ProtocolVersion clientVersion, ProtocolVersion serverVersion);
@Deprecated
default @Nullable List<ProtocolPathEntry> getProtocolPath(int clientVersion, int serverVersion) {
return getProtocolPath(ProtocolVersion.getProtocol(clientVersion), ProtocolVersion.getProtocol(serverVersion));
}
/**
* Returns a versioned packet transformer to transform and send packets from a given base version to any client version supported by Via.
@ -175,10 +167,10 @@ public interface ProtocolManager {
* @throws IllegalArgumentException if both packet classes are null
*/
<C extends ClientboundPacketType,
S extends ServerboundPacketType
> VersionedPacketTransformer<C, S> createPacketTransformer(ProtocolVersion inputVersion,
@Nullable Class<C> clientboundPacketsClass,
@Nullable Class<S> serverboundPacketsClass);
S extends ServerboundPacketType
> VersionedPacketTransformer<C, S> createPacketTransformer(ProtocolVersion inputVersion,
@Nullable Class<C> clientboundPacketsClass,
@Nullable Class<S> serverboundPacketsClass);
/**
* Sets the max delta the path calculation allows the distance to the target protocol version to increase.
@ -226,14 +218,14 @@ public interface ProtocolManager {
}
/**
* Returns the maximum protocol path size applied to {@link #getProtocolPath(int, int)}.
* Returns the maximum protocol path size applied to {@link #getProtocolPath(ProtocolVersion, ProtocolVersion)}.
*
* @return maximum protocol path size
*/
int getMaxProtocolPathSize();
/**
* Sets the maximum protocol path size applied to {@link #getProtocolPath(int, int)}.
* Sets the maximum protocol path size applied to {@link #getProtocolPath(ProtocolVersion, ProtocolVersion)}.
* Its default is 50.
*
* @param maxProtocolPathSize maximum protocol path size
@ -245,7 +237,7 @@ public interface ProtocolManager {
*
* @return sorted, immutable set of supported protocol versions
*/
SortedSet<Integer> getSupportedVersions();
SortedSet<ProtocolVersion> getSupportedVersions();
/**
* Check if this plugin is useful to the server.
@ -318,4 +310,11 @@ public interface ProtocolManager {
*/
@Deprecated
PacketWrapper createPacketWrapper(int packetId, @Nullable ByteBuf buf, UserConnection connection);
/**
* Returns whether the mappings have been loaded and the mapping loader executor shutdown.
*
* @return whether the mappings have been loaded
*/
boolean hasLoadedMappings();
}

View File

@ -22,6 +22,8 @@
*/
package com.viaversion.viaversion.api.protocol;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
public interface ProtocolPathEntry {
/**
@ -30,7 +32,7 @@ public interface ProtocolPathEntry {
*
* @return output protocol version after transformation
*/
int outputProtocolVersion();
ProtocolVersion outputProtocolVersion();
/**
* Returns the protocol to be applied with this entry.
@ -39,13 +41,4 @@ public interface ProtocolPathEntry {
*/
Protocol<?, ?, ?, ?> protocol();
@Deprecated/*(forRemoval = true)*/
default int getOutputProtocolVersion() {
return outputProtocolVersion();
}
@Deprecated/*(forRemoval = true)*/
default Protocol getProtocol() {
return protocol();
}
}

View File

@ -22,6 +22,8 @@
*/
package com.viaversion.viaversion.api.protocol;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
public interface ProtocolPathKey {
/**
@ -29,22 +31,13 @@ public interface ProtocolPathKey {
*
* @return client protocol version
*/
int clientProtocolVersion();
ProtocolVersion clientProtocolVersion();
/**
* Returns the server protocol version.
*
* @return server protocol version
*/
int serverProtocolVersion();
ProtocolVersion serverProtocolVersion();
@Deprecated/*(forRemoval = true)*/
default int getClientProtocolVersion() {
return clientProtocolVersion();
}
@Deprecated/*(forRemoval = true)*/
default int getServerProtocolVersion() {
return serverProtocolVersion();
}
}

View File

@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.protocol;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.Direction;
import java.util.Collection;
import java.util.List;
import org.checkerframework.checker.nullness.qual.Nullable;
@ -61,25 +62,34 @@ public interface ProtocolPipeline extends SimpleProtocol {
* @param pipeClass protocol class
* @param <P> protocol
* @return protocol from class
* @see #contains(Class)
* @see ProtocolManager#getProtocol(Class) for a faster implementation
* @deprecated use {@link ProtocolManager#getProtocol(Class)} and/or {@link #contains(Class)}
*/
@Deprecated
@Nullable <P extends Protocol> P getProtocol(Class<P> pipeClass);
List<Protocol> pipes(@Nullable Class<? extends Protocol> protocolClass, boolean skipCurrentPipeline, Direction direction);
/**
* Returns the list of protocols this pipeline contains.
* Returns the list of protocols this pipeline contains, lead by base protocols.
*
* @return immutable list of protocols in this pipe
*/
List<Protocol> pipes();
/**
* Returns the list of protocols this pipeline contains in reversed order.
* Returns the list of protocols this pipeline contains in reversed order, although still lead by base protocols.
*
* @return immutable list of protocols in reversed direction
*/
List<Protocol> reversedPipes();
/**
* Returns the number of base protocols in this pipeline.
*
* @return the number of base protocols in this pipeline
*/
int baseProtocolCount();
/**
* Returns whether this pipe has protocols that are not base protocols, as given by {@link Protocol#isBaseProtocol()}.
*

View File

@ -92,6 +92,7 @@ public interface PacketWrapper {
* @param index The index of the part (relative to the type)
* @return True if the type is at the index
*/
@Deprecated
boolean is(Type type, int index);
/**
@ -212,11 +213,11 @@ public interface PacketWrapper {
* (Sends it after current)
* Also returns the packets ChannelFuture
*
* @param packetProtocol The protocol version of the packet.
* @return The packets ChannelFuture
* @param protocolClass the protocol class to start from in the pipeline
* @return new ChannelFuture for the write operation
* @throws Exception if it fails to write
*/
ChannelFuture sendFuture(Class<? extends Protocol> packetProtocol) throws Exception;
ChannelFuture sendFuture(Class<? extends Protocol> protocolClass) throws Exception;
/**
* @deprecated misleading; use {@link #sendRaw()}. This method will be removed in 5.0.0
@ -287,18 +288,24 @@ public interface PacketWrapper {
*
* @param direction protocol direction
* @param state protocol state
* @param index index to start from, will be reversed depending on the reverse parameter
* @param pipeline protocol pipeline
* @param reverse whether the array should be looped in reverse, will also reverse the given index
* @return The current packetwrapper
* @throws Exception If it fails to transform a packet, exception will be thrown
*/
void apply(Direction direction, State state, List<Protocol> pipeline) throws Exception;
/**
* @deprecated use {@link #apply(Direction, State, List)}
*/
@Deprecated
PacketWrapper apply(Direction direction, State state, int index, List<Protocol> pipeline, boolean reverse) throws Exception;
/**
* @see #apply(Direction, State, int, List, boolean)
* @deprecated use {@link #apply(Direction, State, List)}
*/
PacketWrapper apply(Direction direction, State state, int index, List<Protocol> pipeline) throws Exception;
@Deprecated
default PacketWrapper apply(Direction direction, State state, int index, List<Protocol> pipeline) throws Exception {
return apply(direction, state, index, pipeline, false);
}
/**
* Check if this packet is cancelled.

View File

@ -28,7 +28,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
final class PacketIdMapping implements PacketMapping {
private final int mappedPacketId;
private final PacketHandler handler;
private PacketHandler handler;
PacketIdMapping(int mappedPacketId, @Nullable PacketHandler handler) {
this.mappedPacketId = mappedPacketId;
@ -41,6 +41,15 @@ final class PacketIdMapping implements PacketMapping {
wrapper.setId(mappedPacketId);
}
@Override
public void appendHandler(final PacketHandler handler) {
if (this.handler == null) {
this.handler = handler;
} else {
this.handler = this.handler.then(handler);
}
}
@Override
public @Nullable PacketHandler handler() {
return handler;

View File

@ -46,6 +46,13 @@ public interface PacketMapping {
*/
@Nullable PacketHandler handler();
/**
* Appends a packet transformer to the current packet transformer.
*
* @param handler packet transformer
*/
void appendHandler(PacketHandler handler);
static PacketMapping of(final int mappedPacketId, @Nullable final PacketHandler handler) {
return new PacketIdMapping(mappedPacketId, handler);
}

View File

@ -29,7 +29,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
final class PacketTypeMapping implements PacketMapping {
private final PacketType mappedPacketType;
private final PacketHandler handler;
private PacketHandler handler;
PacketTypeMapping(@Nullable PacketType mappedPacketType, @Nullable PacketHandler handler) {
this.mappedPacketType = mappedPacketType;
@ -43,6 +43,15 @@ final class PacketTypeMapping implements PacketMapping {
}
}
@Override
public void appendHandler(final PacketHandler handler) {
if (this.handler == null) {
this.handler = handler;
} else {
this.handler = this.handler.then(handler);
}
}
@Override
public @Nullable PacketHandler handler() {
return handler;

View File

@ -22,6 +22,7 @@
*/
package com.viaversion.viaversion.api.protocol.packet.provider;
import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.protocol.packet.PacketType;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import java.util.Collection;
@ -54,14 +55,11 @@ public interface PacketTypeMap<P extends PacketType> {
*/
Collection<P> types();
static <S extends PacketType, T extends S> PacketTypeMap<S> of(final Class<T> enumClass) {
if (!enumClass.isEnum()) {
throw new IllegalArgumentException("Given class is not an enum");
}
final S[] types = enumClass.getEnumConstants();
final Map<String, S> byName = new HashMap<>(types.length);
for (final S type : types) {
static <T extends PacketType, E extends T> PacketTypeMap<T> of(final Class<E> enumClass) {
final T[] types = enumClass.getEnumConstants();
Preconditions.checkArgument(types != null, "%s is not an enum", enumClass);
final Map<String, T> byName = new HashMap<>(types.length);
for (final T type : types) {
byName.put(type.getName(), type);
}
return of(byName, types);

View File

@ -22,11 +22,11 @@
*/
package com.viaversion.viaversion.api.protocol.packet.provider;
import com.google.common.annotations.Beta;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.State;
import java.util.Map;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Provides unmapped and mapped packet types for a Protocol.
@ -37,7 +37,6 @@ import java.util.Map;
* @param <SU> unmapped serverbound packet type
* @see SimplePacketTypesProvider
*/
@Beta
public interface PacketTypesProvider<CU extends ClientboundPacketType, CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> {
/**
@ -69,4 +68,24 @@ public interface PacketTypesProvider<CU extends ClientboundPacketType, CM extend
* @return map of mapped serverbound packet types
*/
Map<State, PacketTypeMap<SM>> mappedServerboundPacketTypes();
default @Nullable CU unmappedClientboundType(final State state, final String typeName) {
PacketTypeMap<CU> map = unmappedClientboundPacketTypes().get(state);
return map != null ? map.typeByName(typeName) : null;
}
default @Nullable SU unmappedServerboundType(final State state, final String typeName) {
PacketTypeMap<SU> map = unmappedServerboundPacketTypes().get(state);
return map != null ? map.typeByName(typeName) : null;
}
default @Nullable CU unmappedClientboundType(final State state, final int packetId) {
PacketTypeMap<CU> map = unmappedClientboundPacketTypes().get(state);
return map != null ? map.typeById(packetId) : null;
}
default @Nullable SU unmappedServerboundType(final State state, final int packetId) {
PacketTypeMap<SU> map = unmappedServerboundPacketTypes().get(state);
return map != null ? map.typeById(packetId) : null;
}
}

View File

@ -22,13 +22,11 @@
*/
package com.viaversion.viaversion.api.protocol.packet.provider;
import com.google.common.annotations.Beta;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.State;
import java.util.Map;
@Beta
public final class SimplePacketTypesProvider<CU extends ClientboundPacketType, CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> implements PacketTypesProvider<CU, CM, SM, SU> {
private final Map<State, PacketTypeMap<CU>> unmappedClientboundPacketTypes;
private final Map<State, PacketTypeMap<CM>> mappedClientboundPacketTypes;

View File

@ -34,4 +34,17 @@ public interface PacketHandler {
* @throws Exception if an error occurs during the packet handling
*/
void handle(PacketWrapper wrapper) throws Exception;
/**
* Returns a new packet handler that runs the provided handler after this one.
*
* @param handler packet handler to run aftet this one
* @return a new packet handler that runs the provided handler after this one
*/
default PacketHandler then(final PacketHandler handler) {
return wrapper -> {
this.handle(wrapper);
handler.handle(wrapper);
};
}
}

Some files were not shown because too many files have changed in this diff Show More