-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partially implement custom fluids for Fabric 1.20.1
- Loading branch information
1 parent
838f8c8
commit f66cdf3
Showing
11 changed files
with
259 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
@: fluid | ||
fluid: SimpleFluid | ||
contentid: | ||
title: | ||
texture: | ||
|
||
# block to copy properties from | ||
copyblock: Blocks.WATER | ||
|
||
# update speed of the fluid? | ||
# probably measured in ticks | ||
tickrate: 5 | ||
|
||
# fluid level decrease per block spread | ||
decreaseperblock: 1 | ||
|
||
# flow speed of the fluid. | ||
# probably measured in ticks | ||
flowspeed: 4 | ||
|
||
# Whether the fluid creates source blocks like water | ||
isinfinite: false | ||
|
||
# Hex color of fluid. | ||
# 2 digits for each Red, Green, Blue, Alpha | ||
color: 0x808080D0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package ${mod.package}; | ||
|
||
import net.fabricmc.api.ClientModInitializer; | ||
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; | ||
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry; | ||
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry; | ||
import net.fabricmc.fabric.api.client.render.fluid.v1.SimpleFluidRenderHandler; | ||
import ${mod.package}.registry.ModBlocks; | ||
import ${mod.package}.registry.ModFluids; | ||
import net.minecraft.client.render.RenderLayer; | ||
|
||
public class ${mod.class}Client implements ClientModInitializer { | ||
@Override | ||
public void onInitializeClient() { | ||
|
||
---iter mod.registry.fluid.names | ||
FluidRenderHandlerRegistry.INSTANCE.register(ModFluids.STILL_${mod.fluid.$%v^upper}, ModFluids.FLOWING_${mod.fluid.$%v^upper}, | ||
SimpleFluidRenderHandler.coloredWater(${mod.fluid.$%v.color})); | ||
BlockRenderLayerMap.INSTANCE.putFluids(RenderLayer.getTranslucent(), | ||
ModFluids.STILL_${mod.fluid.$%v^upper}, ModFluids.FLOWING_${mod.fluid.$%v^upper}); | ||
---end | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package ${mod.package}.fluids; | ||
|
||
import ${mod.package}.registry.ModFluids; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.fluid.FlowableFluid; | ||
import net.minecraft.fluid.Fluid; | ||
import net.minecraft.fluid.FluidState; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.state.StateManager; | ||
import net.minecraft.state.property.Properties; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.world.BlockView; | ||
import net.minecraft.world.World; | ||
import net.minecraft.world.WorldAccess; | ||
import net.minecraft.world.WorldView; | ||
|
||
public abstract class ${mod.fluid.${%v}^class}Fluid extends FlowableFluid { | ||
@Override | ||
public Fluid getFlowing() { | ||
return ModFluids.FLOWING_${mod.fluid.${%v}^upper}; | ||
} | ||
|
||
@Override | ||
public Fluid getStill() { | ||
return ModFluids.STILL_${mod.fluid.${%v}^upper}; | ||
} | ||
|
||
@Override | ||
protected boolean isInfinite(World world) { | ||
return ${mod.fluid.${%v}.isinfinite^bool}; | ||
} | ||
|
||
@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 int getFlowSpeed(WorldView world) { | ||
return ${mod.fluid.${%v}.flowspeed^int}; | ||
} | ||
|
||
@Override | ||
protected int getLevelDecreasePerBlock(WorldView world) { | ||
return ${mod.fluid.${%v}.decreaseperblock^int}; | ||
} | ||
|
||
@Override | ||
public Item getBucketItem() { | ||
return ModFluids.${mod.fluid.${%v}^upper}_BUCKET; | ||
} | ||
|
||
@Override | ||
protected boolean canBeReplacedWith(FluidState state, BlockView world, BlockPos pos, Fluid fluid, Direction direction) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public int getTickRate(WorldView world) { | ||
return ${mod.fluid.${%v}.tickrate}; | ||
} | ||
|
||
@Override | ||
protected float getBlastResistance() { | ||
return 100f; | ||
} | ||
|
||
@Override | ||
public boolean matchesType(Fluid fluid) { | ||
return fluid == getStill() || fluid == getFlowing(); | ||
} | ||
|
||
@Override | ||
protected BlockState toBlockState(FluidState state) { | ||
return ModFluids.${mod.fluid.${%v}^upper}_FLUID_BLOCK.getDefaultState().with(Properties.LEVEL_15, getBlockStateLevel(state)); | ||
} | ||
|
||
@Override | ||
public boolean isStill(FluidState state) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public int getLevel(FluidState state) { | ||
return 0; | ||
} | ||
|
||
public static class Flowing extends ${mod.fluid.${%v}^class}Fluid { | ||
@Override | ||
protected void appendProperties(StateManager.Builder<Fluid, FluidState> builder) { | ||
super.appendProperties(builder); | ||
builder.add(LEVEL); | ||
} | ||
|
||
@Override | ||
public int getLevel(FluidState state) { | ||
return state.get(LEVEL); | ||
} | ||
|
||
@Override | ||
public boolean isStill(FluidState state) { | ||
return false; | ||
} | ||
} | ||
|
||
public static class Still extends ${mod.fluid.${%v}^class}Fluid { | ||
@Override | ||
public int getLevel(FluidState state) { | ||
return 8; | ||
} | ||
|
||
@Override | ||
public boolean isStill(FluidState state) { | ||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package ${mod.package}.registry; | ||
|
||
import ${mod.package}.${mod.class}; | ||
import ${mod.package}.fluids.*; | ||
import net.fabricmc.fabric.api.block.v1.FabricBlock; | ||
import net.fabricmc.fabric.api.item.v1.FabricItemSettings; | ||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.Blocks; | ||
import net.minecraft.block.FluidBlock; | ||
import net.minecraft.fluid.FlowableFluid; | ||
import net.minecraft.item.BucketItem; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.registry.Registries; | ||
import net.minecraft.registry.Registry; | ||
import net.minecraft.util.Identifier; | ||
|
||
public class ModFluids { | ||
---iter mod.registry.fluid.names | ||
public static final FlowableFluid STILL_${mod.fluid.$%v^upper} = Registry.register(Registries.FLUID, | ||
new Identifier(TestRubyMod.MOD_ID, "${mod.fluid.$%v}"), | ||
new ${mod.fluid.$%v^class}Fluid.Still()); | ||
public static final FlowableFluid FLOWING_${mod.fluid.$%v^upper} = Registry.register(Registries.FLUID, | ||
new Identifier(TestRubyMod.MOD_ID, "flowing_${mod.fluid.$%v}"), | ||
new ${mod.fluid.$%v^class}Fluid.Flowing()); | ||
public static final Block ${mod.fluid.$%v^upper}_FLUID_BLOCK = Registry.register(Registries.BLOCK, | ||
new Identifier(TestRubyMod.MOD_ID, "${mod.fluid.$%v}_block"), | ||
new FluidBlock(ModFluids.STILL_${mod.fluid.$%v^upper}, FabricBlockSettings.copyOf(${mod.fluid.$%v.copyblock}))); | ||
public static final Item ${mod.fluid.$%v^upper}_BUCKET = Registry.register(Registries.ITEM, | ||
new Identifier(TestRubyMod.MOD_ID, "${mod.fluid.$%v}_bucket"), | ||
new BucketItem(ModFluids.STILL_${mod.fluid.$%v^upper}, new FabricItemSettings().recipeRemainder(Items.BUCKET).maxCount(1))); | ||
---end | ||
|
||
public static void RegisterFluids() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
@: fluid | ||
fluid: SimpleFluid | ||
contentid: molten_ruby | ||
title: Molten Ruby | ||
texture: molten_ruby.png | ||
|
||
# block to copy properties from | ||
copyblock: Blocks.LAVA | ||
|
||
# update speed of the fluid? | ||
# probably measured in ticks | ||
tickrate: 5 | ||
|
||
# fluid level decrease per block spread | ||
decreaseperblock: 1 | ||
|
||
# flow speed of the fluid. | ||
# probably measured in ticks | ||
flowspeed: 4 | ||
|
||
# Whether the fluid creates source blocks like water | ||
isinfinite: false | ||
|
||
# Hex color of fluid. | ||
# 2 digits for each Red, Green, Blue, Alpha | ||
color: 0xE02020D0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.