Skip to content

Instantly share code, notes, and snippets.

@apple502j
Last active April 17, 2022 04:04
Show Gist options
  • Save apple502j/f20dd720ca4fc292a87c7ad9dbed8dfa to your computer and use it in GitHub Desktop.
Save apple502j/f20dd720ca4fc292a87c7ad9dbed8dfa to your computer and use it in GitHub Desktop.
1.18.2 update guide for Fabric modders

1.18.2 Update Info

Please contact apple502j for any corrections, suggestions etc! (available on Fabricord https://fabricmc.net/discuss/)

TLDR

Mods will be broken, especially if it adds new contents.

Major Changes

  • Registry modification/adding custom content to registry now requires Fabric API due to the addition of "frozen registry". Either add Fabric API or fabric-registry-sync-v0 as an dependency.
  • Tags and Registries Update. Tag is gone and you need TagKey. However, if you're just using isOf call with a vanilla tag, there should be no refactor. To understand TagKey and other new classes, I've prepared a separate TLDR document.
  • Several Fabric API modules removed, mostly deprecated ones. This includes Tag Extension API which has a separate migration guide. Unless you are using tag replacement stuff, vanilla code should be used.
  • Structures need to be registered to StructuresToConfiguredStructuresFix to allow world upgrade, since the save files will now store configured structure features instead of structures.
  • Mojang migrates to SLF4J, so you should too. (see below)
  • Loader 0.13 is out, which supports SLF4J, fixes Mixin bugs, etc. Required for newer Fabric API.
  • Loom 0.11 is out as well, supporting interface injection (injecting mod's interfaces to vanilla classes to be implemented using Mixin) and server-only option (can avoid accidental usage of client-side code).

SLF4J Migration

Import these:

import com.mojang.logging.LogUtils;
import org.slf4j.Logger;

Replace LOGGER = LogManager.getLogger(); with LOGGER = LogUtils.getLogger();. For logging itself, Logger#fatal is not supported in SLF4J and needs to be replaced with error and LogUtils.FATAL_MARKER:

LOGGER.error(LogUtils.FATAL_MARKER, "Fatal error! I don't know what's causing this but who cares!");

Also, you should always pass a string (or FATAL marker) as the first argument. To log an object, pass "{}".

LOGGER.error("Exception while admiring a tater: {}", exc);

World generation

There are too many changes to cover here. Watch a slicedlime video. Check out the gist on custom structures using datapacks. Note that the bugfix mixin for using worldgen datapacks in dedicated server is missing from Fabric API for now.

Resource Loading/Manager

Resource loading has changed significantly.

The previously called ServerResourceManager is no longer a ResourceManager, instead it simply holds data pack loaders (FunctionLoader, ServerAdvancementLoader, etc). The class has been renamed to DataPackContents.

To get a ResourceManager for a server, call MinecraftServer#getResourceManager(). To get DataPackContents, you need to use accessor to access MinecraftServer#resourceManagerHolder, use an access widener to make MinecraftServer$ResourceManagerHolder public, and finally call dataPackContents() - however in most cases there are shortcut methods in MinecraftServer. (See the javadoc)

START_DATA_PACK_RELOAD/END_DATA_PACK_RELOAD events in Fabric API is also changed to pass LifecycledResourceManager instead. Should not affect people who use these hooks for configuration reload, though.

Misc changes

  • BlockPos#getSquaredDistance was previously incorrectly adding 0.5 to X and Z positions when comparing coordinates. This has been changed to use the normal Euclidean distance. To keep the result (for compatibility reasons) use getSquaredDistanceFromCenter.
  • Packets related to entity status effect now store the effect as an integer, instead of a byte.
  • New command argument types: RegistryKeyArgumentType (used in /placefeature and /attribute) and RegistryPredicateArgumentType (used in /locate and /locatebiome). Predicate argument type allows tags to be used. Check vanilla usage and refactor code using IdentifierArgumentType as needed.

New classes

  • WarningScreen for a generic warning screen with a checkbox (see Realms32BitWarningScreen)
  • PressableTextWidget for a button that renders like a normal text (used in copyright notice/credits button)
  • ConfiguredStructureFeatureTags and BiomeTags
  • SaveLoader which is responsible for loading data packs, level.dat, etc
  • TagPacketSerializer to serialize and load tag packets
  • RegistryLoader which is a wrapper of EntryLoader. RegistryLoader.LoaderAccess is a record of the loader and DynamicRegistryManager.
  • RegistryCodecs for various registry-related codec utils
  • PeriodicNotificationManager for handling periodic notifications, such as South Korean health message
  • LifecycledResourceManager and LifecycledResourceManagerImpl. This resource manager can be used until it is close()d.
  • PowderSnowJumpGoal which is a goal for jumping out of powder snow used by powder snow walkable mobs
  • FogShape which is an enum of fog shapes (sphere or cylinder)
  • ExclusiveNbtCollector to collect all NBT objects except for specified ones

New useful methods

  • DrawableHelper#fillBackground to fill background to render text
  • EnchantingTableBlock#canAccessBookshelf to see if an bookshelf is accessible from a table
  • ClientPlayNetworkHandler#loadTags to load tags from packets
  • Entity#getHandPosOffset to get the offset of the hand that the item is held by (used by fireworks)
  • ServerLoginNetworkHandler#isValidName to validate usernames. Vanilla implementation will return false for ASCII control characters or non-ASCII letters.
  • SimpleResourceReload#start to start a reload of resources
  • Entity#shouldEscapePowderSnow which returns true if the entity is not immune to freezing but is inside powder snow
  • PointedDripstoneBlock#canDripThrough which returns true if the block cannot obstruct stalagmites' growth or fluids dripping to cauldrons
  • FontStorage#getEmptyGlyph which returns pre-existing empty glyphs for certain characters and Optional.empty() for others
  • Screen#hide which hides certain widgets from the screen
  • WorldRenderer#isRenderingReady which returns true if pos is ready to be rendered
  • FallingBlockEntity#spawnFromBlock which spawns a falling block from the given position and replaces the block there with the fluid (e.g. water for falling waterloggd stalactite)
  • NbtIo#scanCompressed for scanning Gzip-compressed NBT using a scanner
  • PacketListener#shouldCrashOnException which returns true if fatal error in main thread-executed code should crash instead of log error. true in client, false in server. Does not affect Fabric Networking API.
  • LevelStorage#loadCompactLevelData to quickly load level.dat, without player or worldgen info

FAQ

java.lang.IllegalStateException: Some intrusive holders were not added to registry: [Reference{null=Block{minecraft:air}}]

You forgot to (or deliterately didn't) register a block, an item, etc. Registration is now a hard requirement in 1.18.2. If you do not want it to crash, register it. For conditional adding of stuff, the instance creation should be conditional as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment