花盆兼容

基本信息

属性 值
接口 com.gtnewhorizon.gtnhlib.api.IFlowerPottable
源码 src/main/java/com/gtnewhorizon/gtnhlib/api/IFlowerPottable.java
控制的 mixin 组 Mixins.MODDED_FLOWERS_IN_FLOWER_POT、Mixins.BIOMES_O_PLENTY_FLOWER_POT
开关配置 GTNHLibConfig.enableMoreFlowerPottage(默认 true)
作用面 双方 + 客户端渲染

功能

允许模组方块被放进原版花盆(Flower Pot)。1.7.10 的 BlockFlowerPot 只认原版 BlockRedFlower/BlockTallGrass 等少数方块,模组方块无法种植。

源码注释(IFlowerPottable.java:6-8):

Allow this block to be placed into vanilla Flower Pots. If your block is simple and all of its standard ItemBlock textures will work in a flower pot, you don’t need to override anything.

4 个方法全部是 default,简单方块只 implements 即可:

方法 默认返回 说明
isFlowerPottable(int meta) true 该 meta 是否可入盆;按 meta 区分时覆写
writeToFlowerPotNBT(NBTTagCompound, int meta) 空实现 向花盆 NBT 写入附加数据,供其余两个方法读取
renderFlowerPot(NBTTagCompound, IBlockAccess, Block, int, int, int, RenderBlocks) false 覆写花盆内渲染;返回 true 表示已接管
replaceFlowerPotDrop(NBTTagCompound) null 替换打碎花盆时的掉落;返回 null 走默认掉落

writeToFlowerPotNBT 写入的数据在 renderFlowerPot 与 replaceFlowerPotDrop 中通过同一个 NBTTagCompound 参数读回(见 IFlowerPottable.java:20-22 注释)。

数值

数值名 值
接口方法数 4
抽象方法数 0(全部有 default 实现)
需覆写的方法数 0(简单方块)

注入的 mixin 共 9 个,分属两个枚举条目:

枚举条目 阶段 mixin 数 依赖
MODDED_FLOWERS_IN_FLOWER_POT EARLY 3(MixinBlockFlowerPot、MixinTileEntityFlowerPot、MixinRenderBlocks_FlowerPot) 无
BIOMES_O_PLENTY_FLOWER_POT LATE 6(flowerpotcompat.MixinBOP*) Biomes O’ Plenty

Biomes O’ Plenty 那组在 TargetMods 中以 modid BiomesOPlenty 声明(mixins/TargetMods.java:13),Biomes O’ Plenty 未加载则整组不注入。

交互

方块实现接口后:

  • 玩家右键花盆时,非 isFlowerPottable(meta) 返回 true 的 meta 会被拒绝
  • 放置时调用 writeToFlowerPotNBT 把状态存入花盆 TileEntity
  • 渲染时 renderFlowerPot 返回 true 则接管,否则用标准 ItemBlock 贴图
  • 破坏时 replaceFlowerPotDrop 返回非 null 则用该掉落

enableMoreFlowerPottage 为 false 时两个枚举条目的 setApplyIf 均不成立,9 个 mixin 全部不注入,接口实现失效。

相关条目