tutorial:locate
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| tutorial:locate [2019/10/20 23:17] – draylar | tutorial:locate [2020/09/06 17:27] (current) – /locate no longer requires manual intervention siglong | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Locate ====== | ||
| - | While testing new '' | ||
| - | |||
| - | To add your feature to the locate command, you'll need | ||
| - | * a '' | ||
| - | * a mixin to '' | ||
| - | * to add your feature to the '' | ||
| - | |||
| - | ==== Mixin Time ==== | ||
| - | Create a mixin to '' | ||
| - | <code java [enable_line_numbers=" | ||
| - | @Inject(method = " | ||
| - | private static void onRegister(CommandDispatcher< | ||
| - | dispatcher.register(literal(" | ||
| - | .then(literal(" | ||
| - | } | ||
| - | </ | ||
| - | We're tagging onto the existing /locate command here. | ||
| - | //" | ||
| - | //" | ||
| - | |||
| - | Note that: | ||
| - | * the literal label can have no spaces | ||
| - | * the execute string is converted to lowercase for comparison and can have spaces | ||
| - | * the literal label does //not// need to be the same as the execute string | ||
| - | |||
| - | The finalized mixin class: | ||
| - | <code java [enable_line_numbers=" | ||
| - | import com.mojang.brigadier.CommandDispatcher; | ||
| - | import net.minecraft.server.command.LocateCommand; | ||
| - | import net.minecraft.server.command.ServerCommandSource; | ||
| - | import org.spongepowered.asm.mixin.Mixin; | ||
| - | import org.spongepowered.asm.mixin.Shadow; | ||
| - | import org.spongepowered.asm.mixin.injection.At; | ||
| - | import org.spongepowered.asm.mixin.injection.Inject; | ||
| - | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
| - | |||
| - | import static net.minecraft.server.command.CommandManager.literal; | ||
| - | |||
| - | @Mixin(LocateCommand.class) | ||
| - | public abstract class LocateCommandMixin { | ||
| - | |||
| - | private LocateCommandMixin() { | ||
| - | // NO-OP | ||
| - | } | ||
| - | |||
| - | @Shadow | ||
| - | private static int execute(ServerCommandSource source, String name) { | ||
| - | throw new AssertionError(); | ||
| - | } | ||
| - | |||
| - | @Inject(method = " | ||
| - | private static void onRegister(CommandDispatcher< | ||
| - | dispatcher.register(literal(" | ||
| - | .then(literal(" | ||
| - | } | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | ==== Adding to STRUCTURES ==== | ||
| - | Vanilla Minecraft has a hardcoded list of locatable Structure Features in the Feature class. Fun, right? Thankfully it's public, so we can add to it directly: | ||
| - | <code java [enable_line_numbers=" | ||
| - | Feature.STRUCTURES.put(" | ||
| - | </ | ||
| - | " | ||
| - | FEATURE is an instance of your StructureFeature registered from the FEATURE registry. An example would be like so: | ||
| - | <code java [enable_line_numbers=" | ||
| - | public static final StructureFeature< | ||
| - | Registry.FEATURE, | ||
| - | new Identifier(" | ||
| - | new ExampleFeature(DefaultFeatureConfig:: | ||
| - | ); | ||
| - | </ | ||
| - | |||
| - | === Finished! === | ||
| - | Go in game, and type /locate TutorialStructure. | ||
| - | Assuming your structure was properly generated, you'll get a message in chat leading you to the closest one. | ||
tutorial/locate.1571613437.txt.gz · Last modified: 2019/10/20 23:17 by draylar