描述
Liquid Lab 是一个流体 API,旨在简化 Fabric 平台上自定义流体的创建过程,因为几乎所有流体属性都是硬编码的。该 API 包含的功能包括设置雾效颜色、数据驱动的混合行为以及会向上流动的自定义气态流体。此 API 的存在是为了制作高质量的流体,而不仅仅是换皮的“水”或“熔岩”。
功能
基础流体更改
向基础 Fluid 类添加了许多实用方法。
实体溅射效果
- 通过
onEntityEntry 实现
- 当实体首次接触流体时调用
- 参数:
- 实体所在的 World(世界)
- 接触流体的 Entity(实体)
实体交互
- 通过
onEntityCollision 实现
- 当实体位于流体内部时调用
- 参数:
- 实体所在的 World(世界)
- 流体的 Block Position(方块位置)
- 位于流体内的 Entity(实体)
实体粘度
- 通过
getFluidMotion 实现
- 用于控制流体的推力及粘度
- 参数:
- 返回一个
FluidMotion 对象,存储以下信息:
- 实体的 XYZ 速度乘数
- 流体的推力
- 实体主动移动时的移动速度
物品粘度
- 通过
getItemMotion 实现
- 用于控制物品实体的浮力和粘度
- 参数:
- 返回一个
FluidMotion 对象,存储以下信息:
- 物品的 XYZ 速度乘数
- 物品的最大垂直速度
- 物品在流体中上升的速度
雾效
- 通过
getFogProperties 实现
- 允许流体拥有特殊的雾效
- 参数:
- 实体所在的 World(世界)
- Camera(相机/玩家视角)的位置
- 正在观察雾效的 Entity(实体)
- 返回一个
FogProperties 对象,存储以下信息:
- 雾效起始距离(以方块为单位)
- 雾效结束距离(以方块为单位)
- 雾效的 RGB 颜色
雨滴粒子
- 通过
getRainParticle 实现
- 当雨水落在流体上时,为流体提供独特的溅射粒子效果
- 返回:
桶的声音
- 通过
getBucketEmptySound 实现
- 不仅允许流体拥有自定义的填充声音,还允许拥有自定义的倒出声音
- 返回:
寻路
- 通过
canPathfindThrough 实现
- 允许流体直接判断是否有实体尝试在其内部进行寻路
- 参数:
- 返回:
流体标签
API 添加了 7 个流体标签:
liquid_lab:enhanced_mobility
liquid_lab:swimmable
liquid_lab:drowns
liquid_lab:evaporates
liquid_lab:fall_damage_reducing
liquid_lab:fall_damage_resetting
liquid_lab:gaseous
气态流体
此外,API 还添加了反向流动(向上流动)的流体。气态流体的注册方式与普通流体相同,但方块形式需使用 GasFluidBlock 创建,流体形式需通过继承 FlowableGasFluid 创建。在渲染方面,请在客户端初始化器中使用 SimpleGasFluidRenderHandler,而不是 SimpleFluidRenderHandler。
流体混合
提供了一个简单而灵活的系统,用于创建数据驱动的流体混合,以实现模组间的兼容性。
文件夹结构
要添加流体混合配方,首先在命名空间文件夹中创建一个名为 fluid_mixing 的文件夹。此处的文件应为 JSON 格式,文件名需为该命名空间下的有效流体标签,以便正常运行。
文件结构
replace 可选。表示此文件是否替换该流体的所有规则
rules 该流体需遵循的规则列表
type 定义规则适用的时机。可以是 on_update(当流体被邻近方块更新时应用规则)或 on_flow(当另一种流体流入此流体时应用规则)。
is_still 可选。表示该流体必须是静态源还是流动方块。如果未定义,则接受任何形式的流体
smoke 可选。表示此交互是否会产生烟雾粒子
predicate 必须通过的方块谓词,交互才能成功
transform 用于放置交互结果方块的方块状态提供者
方块谓词
- 添加了
liquid_lab:touching_fluids
- 当相邻流体匹配
fluids 参数,且该流体可以流入该方块时判定通过
- 添加了
liquid_lab:adjacent_blocks
- 当相邻方块匹配谓词的
blocks 参数时判定通过
工具类
API 添加了一些简单的实用方法,以使实现某些流体相关功能更加简单。
流体工具 (Fluid Utils)
包含与流体交互相关的方法,例如 splashEntity,可用于 onEntityEntry 中以轻松实现自定义溅射效果。
粒子工具 (Particle Utils)
包含与注册方块泄漏粒子相关的方法。该类允许独立或一次性地为流体和气体注册滴水、下落和着陆粒子。
Description
Liquid Lab is a fluid API to streamline the creation of custom fluids on fabric, because nearly every fluid attribute is hardcoded. Some features include setting fog color, data driven mixing behavior, and custom gaseous fluids that flow upwards. This API exists to make high quality fluids and not just reskinned water or lava.
Features
Base Fluid Changes
Lots of utility methods added to the base Fluid class
Entity Splashing
- Done through
onEntityEntry
- Called when an entity first touches the fluid
- Params:
- World the entity is in
- Entity that touched the fluid
Entity Interactions
- Done through
onEntityCollision
- Called while an entity is within the fluid
- Params:
- World the entity is in
- Block Position of the fluid
- Entity that is within the fluid
Entity Viscosity
- Done through
getFluidMotion
- Used for the fluid's push force and viscosity
- Params:
- Returns a
FluidMotion object storing:
- XYZ velocity multiplier for an entity
- Push force of the fluid
- Movement speed for an entity actively moving
Item Viscosity
- Done through
getItemMotion
- Used for an item entity's buoyancy and viscosity
- Params:
- Returns a
FluidMotion object storing:
- XYZ velocity multiplier for an item
- Maximum vertical velocity of an item
- How fast an item rises in the fluid
Fog
- Done through
getFogProperties
- Enables the fluid to have special fog
- Params:
- World the entity is in
- Position of the cameara
- Entity that is viewing the fog
- Returns a
FogProperties object storing:
- Fog start in blocks
- Fog End in Blocks
- RGB color of the fog
Rain Particles
- Done through
getRainParticle
- Gives the fluid unique splash particles when rain falls onto it
- Returns:
- The particle to use when the fluid is rained on
Bucket Sounds
- Done through
getBucketEmptySound
- Enables the fluid to not only have a custom filling sound, but also a custom emptying sound
- Returns:
- The sound to make when a bucket is emptied
Pathfinding
- Done through
canPathfindThrough
- Allows a fluid to directly identify weather something should try to pathfind through it
- Params:
- The type of navigation an entity has
- Returns:
- If it is valid to pathfind through this fluid
Fluid Tags
7 fluid tags are added by the API:
liquid_lab:enhanced_mobility
- Defines that this fluid is swimmable and has sprint swimming
liquid_lab:swimmable
- Defines if this fluid can be swum in
liquid_lab:drowns
- Defines if this fluid will drown entities submerged within it
liquid_lab:evaporates
- Defines if the fluid cannot be placed in the nether
liquid_lab:fall_damage_reducing
- Makes the fluid affect fall damage the same way lava does
liquid_lab:fall_damage_resetting
- Makes the fluid affect fall damage in the same way as water
liquid_lab:gaseous
- Simply marks the fluid as a gas, does not have any other functionality
Gaseous Fluids
Additionally, the API also adds reversed fluids that flow upwards. Gaseous fluids are registered in the same way as regular fluids, except the block form is created with GasFluidBlock and the fluid form is created by extending FlowableGasFluid. For rendering, use SimpleGasFluidRenderHandler, rather than SimpleFluidRenderHandler in your client initializer.
Fluid Mixing
A simple yet flexable system is provided for creating data driven fluid mixing to allow for compatibility between mods.
Folder Structure
To add a fluid mix, first create a folder named fluid_mixing in the namespace folder. Files here should be JSON files named as a valid fluid tag for that namespace to fuction properly.
File Structure
replace Optional. Weather or not this file replaces all of the rules for this fluid
rules A list of rules for this fluid to follow
type Defines when the rule applies. Can be either on_update, which applies the rule when the fluid is updated by nearby blocks or on_flow, which applies the rule when another fluid flows into this fluid.
is_still Optional. Weather this fluid must be a source or flowing block. If not defined, any form of the fluid is accepted
smoke Optional. Weather or not this interaction creates smoke particles
predicate Block predicate that must pass for the interaction to succeed
transform A block state provider to place the resulting block of the interaction
Block Predicates
- Added
liquid_lab:touching_fluids
- Passes when an adjacent fluid matches the
fluids parameter and if it that fluid could flow into the block
- Added
liquid_lab:adjacent_blocks
- Passes when an adjacent block matches the predicate's
blocks paramenter
Utility
Some simple utility methods are added by the API to make implementing certain aspects of fluids simpler.
Fluid Utils
Contains methods related to fluid interactions, such as splashEntity for use in onEntityEntry to make custom splashing effects with ease.
Particle Utils
Contains methods related to registering block leak particles. The class allows for registering dripping, falling, and landing particles independently or all at once for fluids and gasses.
评论 0
登录后参与评分
还没有评论,来抢沙发吧