Fabric 教程
安装
- 启用 log4j 调试信息(英文)
基础
- 约定和术语
- 注册
- 开发工具
物品
方块和方块实体
数据生成
世界生成
命令
事件
实体
流体
Mixin 和 ASM
杂项
Yarn
贡献 Fabric
- FabLabs - 在提交 PR 之前起草新功能的试验场
Mixin 访问器和调用器允许你访问不可见的(私有的)或者常量的字段以及调用方法。
@Accessor
允许你访问字段。假如要访问 MinecraftClient
类中的 itemUseCooldown
字段。
@Mixin(MinecraftClient.class) public interface MinecraftClientAccessor { @Accessor int getItemUseCooldown(); }
用法:
int itemUseCooldown = ((MinecraftClientAccessor) MinecraftClient.getInstance()).getItemUseCooldown();
@Mixin(MinecraftClient.class) public interface MinecraftClientAccessor { @Accessor("itemUseCooldown") public void setItemUseCooldown(int itemUseCooldown); }
用法:
((MinecraftClientAccessor) MinecraftClient.getInstance()).setItemUseCooldown(100);
假如要访问 VanillaLayeredBiomeSource
类中的 BIOMES
字段。
@Mixin(VanillaLayeredBiomeSource.class) public interface VanillaLayeredBiomeSourceAccessor { @Accessor("BIOMES") public static List<RegistryKey<Biome>> getBiomes() { throw new AssertionError(); } }
用法:
List<RegistryKey<Biome>> biomes = VanillaLayeredBiomeSourceAccessor.getBiomes();
@Mixin(VanillaLayeredBiomeSource.class) public interface VanillaLayeredBiomeSourceAccessor { @Accessor("BIOMES") public static void setBiomes(List<RegistryKey<Biome>> biomes) { throw new AssertionError(); } }
用法:
VanillaLayeredBiomeSourceAccessor.setBiomes(biomes);
@Invoker
允许你访问方法。假如要调用 EndermanEntity
类的 teleportTo
方法。
@Mixin(EndermanEntity.class) public interface EndermanEntityInvoker { @Invoker("teleportTo") public boolean invokeTeleportTo(double x, double y, double z); }
用法
EndermanEntity enderman = ...; ((EndermanEntityInvoker) enderman).invokeTeleportTo(0.0D, 70.0D, 0.0D);
假如要调用 BrweingRecipeRegistry
类的 registerPotionType
方法。
@Mixin(BrewingRecipeRegistry.class) public interface BrewingRecipeRegistryInvoker { @Invoker("registerPotionType") public static void invokeRegisterPotionType(Item item) { throw new AssertionError(); } }
用法:
BrewingRecipeRegistryInvoker.invokeRegisterPotionType(item);