Piston API

Piston API

添加可推动的方块实体,并让玩家和模组开发者能够处理活塞交互!

游戏机制

一个让模组和整合包处理活塞交互的小型模组!


API 功能:

为自定义方块提供高级活塞交互

活塞 API 为方块提供了一种方式,使其能够与活塞进行位置和世界敏感的交互!主要是方块的推动性和粘性。

IPushableBehavior:

  • 此接口添加了一个方法 getPushReaction(接收方块源和活塞信息,返回 EnumPushReaction)。如果方块具有高级推动反应逻辑,则应实现此接口。此接口覆盖原版的 getPushReaction(IBlockState) 方法,未实现该接口的方块会回退到原版方法。对于整合包开发者: 每个方块的推动反应可以通过在 postInit 期间使用 Groovyscript 调用 PushReactionHanlder.overridePushReaction 来覆盖(模组开发者不应这样做!)
  • Groovyscript 示例:
import static git.jbredwards.piston_api.mod.asm.PushReactionHandler.overridePushReaction
import net.minecraft.block.material.EnumPushReaction

//makes dirt be destroyed by pistons when pushed (like grass or leaves)
overridePushReaction(block('minecraft:dirt'), EnumPushReaction.DESTROY)

//makes orange wool not pushable by pistons, while leaving the rest pushable
def orangeWool = blockstate('minecraft:wool', 1)
overridePushReaction(block('minecraft:wool'), {source, pistonInfo -> orangeWool == source.getBlockState() ? EnumPushReaction.BLOCK : EnumPushReaction.NORMAL})

IStickyBehavior:

  • 此接口添加了两个方法:getStickReaction(接收方块源、要测试的相邻方块和活塞信息,返回 EnumStickReaction),以及 hasStickySide(接收方块源和活塞信息,返回该方块是否有任何可能粘性的面)。如果方块具有高级粘性逻辑,则应实现此接口。此接口覆盖 Forge 的 isStickyBlock(IBlockState) 方法,未实现该接口的方块会回退到 Forge 方法。对于整合包开发者: 每个方块的粘性结果可以通过在 postInit 期间使用 Groovyscript 调用 StickReactionHanlder.overrideStickReaction 来覆盖(模组开发者不应这样做!)
  • Groovyscript 示例:

import static git.jbredwards.piston_api.mod.asm.StickReactionHandler.overrideStickReaction
import git.jbredwards.piston_api.api.piston.EnumStickReaction

//makes slime blocks not sticky
overrideStickReaction(block('minecraft:slime'), EnumStickReaction.PASS)

//makes crafting tables sticky
overrideStickReaction(block('minecraft:crafting_table'), EnumStickReaction.STICK)

//makes bookshelves never stick to anything
overrideStickReaction(block('minecraft:bookshelf'), EnumStickReaction.NEVER)

//makes stained glass sticky, but only to the same color
overrideStickReaction(block('minecraft:stained_glass'), {source, other, pistonInfo -> source.getBlockState() == other.getBlockState() ? EnumStickReaction.STICK : EnumStickReaction.PASS})

//a more complicated example, makes the open part of logs sticky
import static git.jbredwards.piston_api.api.block.IStickyBehavior.getConnectingSide
import net.minecraft.block.BlockLog
overrideStickReaction([block('minecraft:log'), block('minecraft:log2')], {source, other, pistonInfo ->
    def connectingAxis = BlockLog.EnumAxis.fromFacingAxis(getConnectingSide(source, other).getAxis())
    def logAxis = source.getBlockState().getValue(BlockLog.LOG_AXIS)

    connectingAxis == logAxis ? EnumStickReaction.STICK : EnumStickReaction.PASS
})

主要功能:

  • 可配置的活塞推动限制
  • 活塞可以移动方块实体
  • 活塞不会破坏流体状态(在安装了 Fluidlogged API 时)
  • Quark 模组兼容性

小型功能:

  • 覆盖现有的活塞交互
  • 被推动时箱子会相互粘住
  • 当方块被活塞破坏时播放方块破坏音效和粒子

此模组将不会移植