/* * Copyright (c) Forge Development LLC and contributors * SPDX-License-Identifier: LGPL-2.1-only */ package net.minecraftforge.event; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.datafix.fixes.StructuresBecomeConfiguredFix; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.Cancelable; import net.minecraftforge.eventbus.api.Event; import java.util.Locale; import java.util.Map; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; /** * Fired for registering structure conversions for pre-1.18.2 worlds. This is used by {@link StructuresBecomeConfiguredFix} * for converting old structure IDs in pre-1.18.2 worlds to their new equivalents, which can be differentiated per biome. * *

By default, structures whose old ID has a namespace which is not equal to {@value ResourceLocation#DEFAULT_NAMESPACE} * will be assumed to belong to a modded structure and will be used as the new ID. Mods may choose to register structure * conversions for their structures, if they wish to override this default behavior.

* *

This event will only fire if {@link StructuresBecomeConfiguredFix} is used, as a result of converting a * pre-1.18.2 world to the current version.

* *

This event is not {@linkplain Cancelable cancelable}, and does not {@linkplain HasResult have a result}.

* *

This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}, * only on the {@linkplain net.minecraftforge.fml.LogicalSide#SERVER logical server}.

* * @see StructuresBecomeConfiguredFix * @see #register(String, StructuresBecomeConfiguredFix.Conversion) */ public class RegisterStructureConversionsEvent extends Event { private final Map map; /** * @hidden For internal use only. */ public RegisterStructureConversionsEvent(Map map) { this.map = map; } /** * Registers a conversion for a structure. * *

A structure conversion can be of two kinds:

* * * @param oldStructureID the old structure ID, in all lowercase * @param conversion the conversion data * @throws NullPointerException if the old structure ID, the conversion data, or the fallback structure ID in * the conversion data is null * @throws IllegalArgumentException if the old structure ID is not in full lowercase, or if a conversion for that * structure ID has already been registered previously */ public void register(String oldStructureID, StructuresBecomeConfiguredFix.Conversion conversion) { checkNotNull(oldStructureID, "Original structure ID must not be null"); checkArgument(oldStructureID.toLowerCase(Locale.ROOT).equals(oldStructureID), "Original structure ID should be in all lowercase"); checkNotNull(conversion, "Structure conversion must not be null"); checkNotNull(conversion.fallback(), "Fallback structure ID in structure conversion must not be null"); if (map.putIfAbsent(oldStructureID.toLowerCase(Locale.ROOT), conversion) != null) { throw new IllegalArgumentException("Conversion has already been registered for structure " + oldStructureID); } } }