我的世界1.18.1自定义流体
时间: 2023-08-06 22:06:04 浏览: 131
在Minecraft 1.18.1中,自定义流体需要进行如下步骤:
1. 创建一个自定义的流体类(继承自FlowingFluid类),并在类中设置流体的属性,如密度、粘度、渲染材质等。
```java
public class MyFluid extends FlowingFluid {
public MyFluid() {
super(
() -> MyFluidBlock.STILL,
() -> MyFluidBlock.FLOWING,
FluidAttributes.builder(
new ResourceLocation("my_mod", "block/my_fluid_still"),
new ResourceLocation("my_mod", "block/my_fluid_flow"))
.density(800)
.viscosity(1500)
.temperature(1000)
.build());
}
}
```
2. 创建一个自定义的流体方块类(继承自FlowingFluidBlock类),并在类中设置流体方块的属性,如硬度、材质等。
```java
public class MyFluidBlock extends FlowingFluidBlock {
public static final FluidStateFlowing FLOWING = (FluidStateFlowing) MyFluid.INSTANCE.getDefaultState().getBlockState().getFluidState();
public static final FluidStateStill STILL = (FluidStateStill) MyFluid.INSTANCE.getDefaultState().getBlockState().getFluidState().getStillFluidState();
public MyFluidBlock() {
super(MyFluid::new, Block.Properties.create(Material.WATER)
.doesNotBlockMovement()
.hardnessAndResistance(100.0F)
.noDrops());
setRegistryName("my_mod", "my_fluid");
}
@Override
public FluidState getFluidState(BlockState state) {
return state.get(LEVEL) == 0 ? STILL : FLOWING;
}
}
```
在上面的代码中,我们创建了一个名为"MyFluidBlock"的流体方块类,并将其与自定义的流体类关联。
3. 注册自定义流体和流体方块。
```java
public class MyMod implements ModInitializer {
public static final MyFluid MY_FLUID = new MyFluid();
public static final MyFluidBlock MY_FLUID_BLOCK = new MyFluidBlock();
@Override
public void onInitialize() {
Registry.register(Registry.FLUID, new Identifier("my_mod", "my_fluid"), MY_FLUID);
Registry.register(Registry.BLOCK, new Identifier("my_mod", "my_fluid"), MY_FLUID_BLOCK);
Registry.register(Registry.ITEM, new Identifier("my_mod", "my_fluid_bucket"), new BucketItem(MY_FLUID, new Item.Settings().recipeRemainder(Items.BUCKET).maxCount(1).group(ItemGroup.MISC)).setUnlocalizedName("my_fluid_bucket"));
FluidBlockRegistry.getDefaultInstance().register(MY_FLUID_BLOCK, MY_FLUID_BLOCK);
}
}
```
在上面的代码中,我们注册了自定义流体、流体方块,并创建了一个桶(BucketItem),用于获取自定义流体。
希望这些信息能对你有所帮助!
阅读全文