首发于Enaium的个人博客
前言
本教程将会教你如何添加流体,什么是流体呢?就是像水、熔岩这样的东西,我们将会添加一种新的流体。
创建流体
在原版中流体都继承了net.minecraft.fluid.FlowableFluid
,所以我们也继承它。
首先创建一个抽象类AwesomeFluid
,然后继承FlowableFluid
,然后实现一些方法。
matchesType
:判断流体是否是我们的流体isInfinite
:是否是无限流体,就是像水一样,无限多beforeBreakingBlock
:当流体破坏方块时,会调用这个方法,我们在这里把方块掉落,比如火把被水破坏时,会掉落火把canBeReplacedWith
:是否可以被替换getFlowSpeed
:流体流动速度getLevelDecreasePerBlock
:水返回 1,熔岩在主世界时返回 2 并且在下界时返回 1getTickRate
:水返回 5,熔岩在主世界时返回 30 并且在下界时返回 10getBlastResistance
:爆炸抗性,水和熔岩都是 100
public abstract class AwesomeFluid extends FlowableFluid {
@Override
public boolean matchesType(Fluid fluid) {
return fluid == getStill() || fluid == getFlowing();
}
@Override
protected boolean isInfinite(World world) {
return true;
}
@Override
protected void beforeBreakingBlock(WorldAccess world, BlockPos pos, BlockState state) {
final BlockEntity blockEntity = state.hasBlockEntity() ? world.getBlockEntity(pos) : null;
Block.dropStacks(state, world, pos, blockEntity);
}
@Override
protected boolean canBeReplacedWith(FluidState state, BlockView world, BlockPos pos, Fluid fluid, Direction direction) {
return false;
}
@Override
protected int getFlowSpeed(WorldView world) {
return 4;
}
@Override
protected int getLevelDecreasePerBlock(WorldView world) {
return 1;
}
@Override
public int getTickRate(WorldView world) {
return 5;
}
@Override
protected float getBlastResistance(