Skip to content

Instantly share code, notes, and snippets.

@apple502j
Created May 13, 2022 12:33
Show Gist options
  • Save apple502j/990ade8cce33b8feddd788667e9b25f0 to your computer and use it in GitHub Desktop.
Save apple502j/990ade8cce33b8feddd788667e9b25f0 to your computer and use it in GitHub Desktop.

22w19a docs

Known Issues

  • Crash when warden gets angry at multiple mobs MC-251641

Changes

Note that for convenience, the following will use proposed Yarn names that are not yet merged.

Chat and Networking

Chat Preview was added, allowing server-side decorated messages to be signed. Basically this works like this:

  1. Server enables chat preview (with server.properties)
  2. Client joins
  3. Warning screen appears (that the server can read chat message before they are sent)
  4. Client types on chat screen
  5. New packet, QueryChatPreviewC2SPacket, is sent after 100ms
  6. The query is stored in ChatPreview
  7. Server calls ChatDecorator#decorate
  8. Server responds with ChatPreviewS2CPacket which contains the decorated text, the query ID, and the query string
  9. Chat preview appears above chat screen (like command parsing error)
  10. After a few milliseconds, the chat consumes the response - this is done so that the player has time to cancel the submission, otherwise with precise timing the player might not see the preview.
  11. Steps 4-9 repeated except the interval is now 1000ms
  12. The latest response text is included in the SignedChatMessage sent by the client, and the response text can now be considered signed
  13. Server calls ChatDecorator#decorate again; If the returned message differs from the one sent by the client, it will discard the message because it means the client has attempted to send arbitrary Text.

As seen above, chat preview is a security feature, the compromise between messages being unsigned and messages being non-decoratable - the server decorates the message and sends that as a preview, and the player can either accept the previewed text (which is used as the chat message as-is) or reject it (by simply not sending). Note that the client can disable chat preview which makes the server-decorated message unsigned.

Given the relatively common nature of the preview query, and the requirement of decorating the message in the same way between the preview and the submission, caching the decorated data is highly recommended.

Of course, you can still use other (not recommended) ways of transformation - the server, for example, can strip signatures or send the message as a game message instead of chat message. However, this change also came with a new client-side option to hide unsigned messages and only show signed ones (or, in case of partially-signed, server-side-decorated message, the signed, raw message). It's therefore recommended to make sure the signature stays valid. Vanilla chat filter will filter the signed content only.

Client-side transformation via Decoration/custom MessageType still works. Note that there was a code refactor around these: the registry is now properly managed by the DRM, so the registry previously obtained via Registry.MESSAGE_TYPE must now be obtained from the DRM (or BuiltinRegistries). Registering new message types will now use BuiltinRegistries.add like other dynamic registries.

Data Generator

Data generators now have "path resolvers". This is stored in the generator and can be created using DataGenerator#createPathResolver. To get the path, use resolveRootDirectoryPath. With this change, various path parameters in datagen methods have been removed.

Path path = this.generator.resolveRootDirectoryPath(DataGenerator.OutputType.REPORTS).resolve("blocks.json");

POI Changes

POI tags have been added - and together with this, code that previously took PointOfInteresetType/Predicate<PointOfInterestType> will now take Predicate<RegistryEntry<PointOfInterestType>>, allowing multiple types and tags to be referenced. Fields and methods taking that instance will now also ask for the predicate.

// Old
poiStorage.getPositions(PointOfInterestType.HOME.getCompletionCondition(), ...);

// New
poiStorage.getTypesAndPositions(entry -> entry.matchesKey(PointOfInterestTypes.HOME), ...)

PointOfInterestTypes is a new class holding registry keys for the point of interest types. Notably, this class is also responsible for registering new PointOfInterestType; the helper methods from Fabric API have been removed and instead the register method (access-widened by Fabric API) should be used.

There is also a change to the registry of PointOfInterestType - it is no longer a DefaultedRegistry.

Let's mention changes to VillagerProfession here as well; it's now a record and contains acquirableJobSite field which is a POI entry predicate used by unemployed villagers to see which job sites they can acquire. To register

RIP Tag, 2017-2022

Tag class was removed. The functionalities were already moved to the registry/TagKey in 1.18.2. The inner classes, which are still in use, have been moved to TagBuilder/TagEntry. The remaining usages in functions now use Collection.

Misc

  • Vanilla code that called Entity#damage with fire damage will no longer check that the entity is fire-immune, since it prevented the damage from provoking the mob. Together with this Entity#isInvulnerableTo was updated to return true for fire damages to fire-immune mobs.
  • Screen#sendMessage was removed. Use ClientPlayerEntity#sendMessage instead.
  • WarningScreen#parent was removed. Subclasses need to track it themselves.
  • EnumArgumentType, BlockMirrorArgumentType, and BlockRotationArgumentType were added.
  • DamageSource#SONIC_BOOM became a static method sonicBoom allowing attacker to be specified.
  • PacketByteBuf now contains methods for reading and writing RegistryKey, GlobalPos, Instant, and PublicKey.
  • GameJoinS2CPacket's dimensionType field is now RegistryKey instead of RegistryEntry.
  • Invalid public keys no longer cause disconnection in local integrated server.
  • ServerMetadataS2CPacket was added. This is sent during the play packet phase, used for servers that have enable-status=false.
  • Profiler for world ticking now works properly. Previously it lacked pop.
  • initAndGetDefault methods now take the Registry to add.
  • Texts#hasTranslation will work properly again. Previously it was alwyas returning true.
  • Codecs now contains BASE_64 and TAG_ENTRY codecs.
  • AbstractRandom now creates the new random using seed uniquifier with RandomSeed#getSeed. Previously it used system nano time only.
  • BlockMirror and BlockRotation now implement StringIdentifiable and have codecs.
  • Util#map and Util#mapOrElse were added, which is a nullable equivalent of optional.map(...) and optional.map(...).orElse(...).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment