tutorial:mixin_accessors
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
tutorial:mixin_accessors [2020/08/29 15:18] – Add how to add ores to the end biomes siglong | tutorial:mixin_accessors [2020/08/30 10:15] – Restore old revision siglong | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
- | A lot of mods add their own ores, and you'll need a way to place them in existing biomes for players to find. In this tutorial, we'll look at adding ores to existing biomes. There are 2 steps that are required to add ores to biomes. | + | |
- | * Make a ConfiguredFeatures. This defines how your ore block is spawned. | + | |
- | * Register your feature by using [[tutorial: | + | |
- | We'll assume | + | ===== Introduction ===== |
+ | Mixin Accessors allow you to access fields and methods that are not visible (private) or final. | ||
- | ==== Adding to the overworld | + | ==== Accessor |
- | In this section, our goal will be spawning the ore in the overworld. | + | '' |
- | === Making | + | === Getting |
- | First we need to create a ConfiguredFeatures. Make sure to register your ConfiguredFeature at '' | + | <code java> |
+ | @Mixin(MinecraftClient.class) | ||
+ | public interface MinecraftClientAccessor { | ||
+ | @Accessor(" | ||
+ | public int getItemUseCooldown(); | ||
+ | } | ||
+ | </ | ||
- | <code java [enable_line_numbers=" | + | Usage: |
- | public class ExampleMod implements ModInitializer { | + | |
- | public static ConfiguredFeature<?, | + | |
- | .configure(new OreFeatureConfig( | + | |
- | OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, | + | |
- | Blocks.NETHER_QUARTZ_ORE.getDefaultState(), | + | |
- | 9)) // vein size | + | |
- | .decorate(Decorator.RANGE.configure(new RangeDecoratorConfig( | + | |
- | 0, // bottom offset | + | |
- | 0, // min y level | + | |
- | 64))) // max y level | + | |
- | .spreadHorizontally() | + | |
- | .repeat(20); | + | |
- | @Override | + | <code java> |
- | | + | int itemUseCooldown = ((MinecraftClientAccessor) MinecraftClient.getInstance()).getItemUseCooldown(); |
- | Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, | + | |
- | } | + | |
- | } | + | |
</ | </ | ||
- | === Registering | + | === Setting a value to the field === |
- | Vanilla ore features that spawn in the overworld biomes are listed in '' | + | <code java> |
- | + | @Mixin(MinecraftClient.class) | |
- | <code java [enable_line_numbers=" | + | public |
- | @Mixin(DefaultBiomeFeatures.class) | + | @Accessor("itemUseCooldown") |
- | public | + | |
- | @Inject(method = "addDefaultOres(Lnet/ | + | |
- | | + | |
- | builder.feature(GenerationStep.Feature.UNDERGROUND_ORES, | + | |
- | } | + | |
} | } | ||
</ | </ | ||
- | === Result === | + | Usage: |
- | You should see quartz ore spawning in the overworld. You can use fill command to remove stone blocks surrounding you like this: ''/ | + | |
- | {{tutorial: | + | <code java> |
+ | ((MinecraftClientAccessor) MinecraftClient.getInstance()).setItemUseCooldown(100); | ||
+ | </ | ||
- | ==== Adding to the end ==== | + | ==== Invoker |
- | In this section, based on the code in the previous section, | + | '' |
- | === Making a ConfiguredFeatures === | + | <code java> |
- | We replace '' | + | @Mixin(EndermanEntity.class) |
- | + | public interface EndermanEntityInvoker { | |
- | <code java [enable_line_numbers=" | + | |
- | public class ExampleMod implements ModInitializer { | + | public |
- | public static ConfiguredFeature<?, | + | |
- | .configure(new OreFeatureConfig( | + | |
- | new BlockMatchRuleTest(Blocks.END_STONE), /* We use endstone! */ | + | |
- | | + | |
- | 9)) | + | |
- | .decorate(Decorator.RANGE.configure(new RangeDecoratorConfig( | + | |
- | 0, | + | |
- | 0, | + | |
- | 64))) | + | |
- | .spreadHorizontally() | + | |
- | .repeat(20); | + | |
- | + | ||
- | @Override | + | |
- | public | + | |
- | Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new Identifier(" | + | |
- | } | + | |
} | } | ||
</ | </ | ||
- | === Registering the feature === | + | Usage: |
- | Considering that no ore is generated in the end biomes on vanilla minecraft, '' | + | |
- | <code java [enable_line_numbers=" | + | <code java> |
- | @Mixin(DefaultBiomeCreator.class) | + | EndermanEntity enderman = ...; |
- | public class DefaultBiomeCreatorMixin { | + | ((EndermanEntityInvoker) enderman).invokeTeleportTo(0.0D, 70.0D, 0.0D); |
- | @Inject(method = " | + | |
- | private static void addEndOres(GenerationSettings.Builder builder, CallbackInfoReturnable< | + | |
- | builder.feature(GenerationStep.Feature.UNDERGROUND_ORES, ExampleMod.ORE_QUARTZ_END); | + | |
- | } | + | |
- | } | + | |
</ | </ | ||
tutorial/mixin_accessors.txt · Last modified: 2022/04/29 09:54 by solidblock