tutorial:mixin_accessors
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:mixin_accessors [2020/08/29 15:18] – Add how to add ores to the end biomes siglong | tutorial:mixin_accessors [2022/04/29 09:54] (current) – [Mixin Accessors] solidblock | ||
---|---|---|---|
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. | + | Mixin accessors |
- | * Make a ConfiguredFeatures. This defines how your ore block is spawned. | + | |
- | * Register your feature by using [[tutorial: | + | |
- | We'll assume you've already created your own ore block at this point. Quartz Ore will serve as our replacement throughout this tutorial. Replace references | + | ===== Accessor ===== |
+ | '' | ||
- | ==== Adding to the overworld | + | ==== Getting a value from the field ==== |
- | In this section, our goal will be spawning the ore in the overworld. | + | <code java> |
+ | @Mixin(MinecraftClient.class) | ||
+ | public interface MinecraftClientAccessor { | ||
+ | @Accessor | ||
+ | int getItemUseCooldown(); | ||
+ | } | ||
+ | </ | ||
- | === Making a ConfiguredFeatures === | + | Usage: |
- | First we need to create a ConfiguredFeatures. Make sure to register your ConfiguredFeature at '' | + | |
- | <code java [enable_line_numbers=" | + | <code java> |
- | public class ExampleMod implements ModInitializer { | + | int itemUseCooldown |
- | public static ConfiguredFeature<?, | + | </code> |
- | .configure(new OreFeatureConfig( | + | |
- | OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, | + | |
- | Blocks.NETHER_QUARTZ_ORE.getDefaultState(), | + | |
- | 9)) // vein size | + | |
- | | + | |
- | 0, // bottom offset | + | |
- | 0, // min y level | + | |
- | 64))) // max y level | + | |
- | | + | |
- | | + | |
- | @Override | + | ==== Setting a value to the field ==== |
- | | + | <code java> |
- | | + | @Mixin(MinecraftClient.class) |
- | } | + | public interface MinecraftClientAccessor |
+ | | ||
+ | public void setItemUseCooldown(int itemUseCooldown); | ||
} | } | ||
</ | </ | ||
- | === Registering the feature === | + | Usage: |
- | Vanilla ore features that spawn in the overworld biomes are listed in '' | + | |
- | <code java [enable_line_numbers=" | + | <code java> |
- | @Mixin(DefaultBiomeFeatures.class) | + | ((MinecraftClientAccessor) MinecraftClient.getInstance()).setItemUseCooldown(100); |
- | public | + | </ |
- | @Inject(method = "addDefaultOres(Lnet/ | + | |
- | | + | ===== Accessor for static fields ===== |
- | | + | Suppose we want to access '' |
+ | |||
+ | ==== Getting a value from the field ==== | ||
+ | <code java> | ||
+ | @Mixin(VanillaLayeredBiomeSource.class) | ||
+ | public | ||
+ | @Accessor("BIOMES") | ||
+ | | ||
+ | | ||
} | } | ||
} | } | ||
</ | </ | ||
- | === 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> |
+ | List< | ||
+ | </ | ||
- | ==== Adding | + | ==== Setting a value to the field ==== |
- | In this section, based on the code in the previous section, we will add the ore to the end biomes. | + | <code java> |
+ | @Mixin(VanillaLayeredBiomeSource.class) | ||
+ | public interface VanillaLayeredBiomeSourceAccessor { | ||
+ | @Accessor(" | ||
+ | public static void setBiomes(List< | ||
+ | throw new AssertionError(); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
- | === Making a ConfiguredFeatures === | + | Usage: |
- | We replace '' | + | |
- | <code java [enable_line_numbers=" | + | <code java> |
- | public class ExampleMod implements ModInitializer { | + | VanillaLayeredBiomeSourceAccessor.setBiomes(biomes); |
- | public static ConfiguredFeature<?, | + | </code> |
- | .configure(new OreFeatureConfig( | + | |
- | new BlockMatchRuleTest(Blocks.END_STONE), | + | |
- | Blocks.NETHER_QUARTZ_ORE.getDefaultState(), | + | |
- | 9)) | + | |
- | .decorate(Decorator.RANGE.configure(new RangeDecoratorConfig( | + | |
- | 0, | + | |
- | 0, | + | |
- | 64))) | + | |
- | .spreadHorizontally() | + | |
- | .repeat(20); | + | |
- | | + | ===== Invoker ===== |
- | | + | '' |
- | | + | |
- | } | + | <code java> |
+ | @Mixin(EndermanEntity.class) | ||
+ | public interface EndermanEntityInvoker | ||
+ | | ||
+ | public boolean invokeTeleportTo(double x, double y, double z); | ||
} | } | ||
</ | </ | ||
- | === 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 | + | ((EndermanEntityInvoker) enderman).invokeTeleportTo(0.0D, |
- | @Inject(method = "method_31065(Lnet/ | + | </ |
- | | + | |
- | | + | ===== Invoker for static methods ===== |
+ | Suppose we want to invoke '' | ||
+ | |||
+ | <code java> | ||
+ | @Mixin(BrewingRecipeRegistry.class) | ||
+ | public | ||
+ | @Invoker("registerPotionType") | ||
+ | | ||
+ | | ||
} | } | ||
} | } | ||
</ | </ | ||
+ | Usage: | ||
+ | |||
+ | <code java> | ||
+ | BrewingRecipeRegistryInvoker.invokeRegisterPotionType(item); | ||
+ | </ |
tutorial/mixin_accessors.1598714307.txt.gz · Last modified: 2020/08/29 15:18 by siglong