tutorial:fluids
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tutorial:fluids [2019/09/24 11:43] – lake generation alexiy | tutorial:fluids [2019/09/24 15:02] – code style alexiy | ||
---|---|---|---|
Line 53: | Line 53: | ||
// how much does the height of the fluid block decreases | // how much does the height of the fluid block decreases | ||
@Override | @Override | ||
- | protected int getLevelDecreasePerBlock(ViewableWorld | + | protected int getLevelDecreasePerBlock(ViewableWorld |
{ | { | ||
return 1; | return 1; | ||
Line 63: | Line 63: | ||
*/ | */ | ||
@Override | @Override | ||
- | public int getTickRate(ViewableWorld | + | public int getTickRate(ViewableWorld |
{ | { | ||
return 5; | return 5; | ||
Line 76: | Line 76: | ||
// this seems to determine fluid' | // this seems to determine fluid' | ||
@Override | @Override | ||
- | protected int method_15733(ViewableWorld | + | protected int method_15733(ViewableWorld |
{ | { | ||
return 4; | return 4; | ||
Line 83: | Line 83: | ||
// I don't know what this does, but it's present in the water fluid | // I don't know what this does, but it's present in the water fluid | ||
@Override | @Override | ||
- | protected void beforeBreakingBlock(IWorld | + | protected void beforeBreakingBlock(IWorld |
- | BlockEntity | + | BlockEntity |
- | Block.dropStacks(blockState_1, iWorld_1.getWorld(), | + | Block.dropStacks(blockState, world.getWorld(), |
} | } | ||
// also don't know what it does | // also don't know what it does | ||
- | public boolean method_15777(FluidState | + | public boolean method_15777(FluidState |
- | return | + | return |
} | } | ||
Line 98: | Line 98: | ||
*/ | */ | ||
@Override | @Override | ||
- | public abstract boolean matchesType(Fluid | + | public abstract boolean matchesType(Fluid |
- | /** | ||
- | * Required for entities to behave in this fluid like in water | ||
- | */ | ||
- | @Override | ||
- | public boolean matches(Tag< | ||
- | { | ||
- | return tag_1 == FluidTags.WATER; | ||
- | } | ||
} | } | ||
</ | </ | ||
Line 141: | Line 133: | ||
@Override | @Override | ||
- | public boolean matchesType(Fluid | + | public boolean matchesType(Fluid |
{ | { | ||
return false; | return false; | ||
Line 186: | Line 178: | ||
@Override | @Override | ||
- | protected void appendProperties(StateFactory.Builder< | + | protected void appendProperties(StateFactory.Builder< |
{ | { | ||
- | super.appendProperties(stateFactory$Builder_1); | + | super.appendProperties(stateFactoryBuilder); |
- | | + | |
} | } | ||
} | } | ||
Line 209: | Line 201: | ||
{ | { | ||
| | ||
- | stillAcid = Registry.register(Registry.FLUID, | + | stillAcid = Registry.register(Registry.FLUID, |
- | flowingAcid = Registry.register(Registry.FLUID, | + | flowingAcid = Registry.register(Registry.FLUID, |
| | ||
- | acidBucket=new BucketItem(stillAcid, | + | acidBucket = new BucketItem(stillAcid, |
- | Registry.register(Registry.ITEM, | + | Registry.register(Registry.ITEM, |
} | } | ||
+ | </ | ||
+ | |||
+ | To make the custom fluid behave like water or lava, you must add it to a corresponding fluid tag: make a file " | ||
+ | <code json> | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ] | ||
+ | } | ||
</ | </ | ||
Line 243: | Line 246: | ||
... | ... | ||
| | ||
- | acid=new BaseFluidBlock(stillAcid, | + | acid = new BaseFluidBlock(stillAcid, |
- | Registry.register(Registry.BLOCK, | + | Registry.register(Registry.BLOCK, |
} | } | ||
</ | </ | ||
Line 263: | Line 266: | ||
{ | { | ||
// | // | ||
- | return [ModInitializer].acid.getDefaultState().with(FluidBlock.LEVEL, | + | return [ModInitializer].acid.getDefaultState().with(FluidBlock.LEVEL, |
} | } | ||
Line 299: | Line 302: | ||
public void onInitializeClient() | public void onInitializeClient() | ||
{ | { | ||
- | Identifier stillSpriteLocation=new Identifier(" | + | Identifier stillSpriteLocation = new Identifier(" |
- | Identifier dynamicSpriteLocation=new Identifier(" | + | Identifier dynamicSpriteLocation = new Identifier(" |
// here I tell to use only 16x16 area of the water texture | // here I tell to use only 16x16 area of the water texture | ||
- | FabricSprite stillAcidSprite = new FabricSprite(stillSpriteLocation, | + | FabricSprite stillAcidSprite = new FabricSprite(stillSpriteLocation, |
// same, but 32 | // same, but 32 | ||
- | FabricSprite dynamicAcidSprite=new FabricSprite(dynamicSpriteLocation, | + | FabricSprite dynamicAcidSprite = new FabricSprite(dynamicSpriteLocation, |
| | ||
// adding the sprites to the block texture atlas | // adding the sprites to the block texture atlas | ||
Line 313: | Line 316: | ||
// this renderer is responsible for drawing fluids in a world | // this renderer is responsible for drawing fluids in a world | ||
- | FluidRenderHandler acidRenderHandler=new FluidRenderHandler() | + | FluidRenderHandler acidRenderHandler = new FluidRenderHandler() |
{ | { | ||
// return the sprites: still sprite goes first into the array, flowing/ | // return the sprites: still sprite goes first into the array, flowing/ | ||
Line 319: | Line 322: | ||
public Sprite[] getFluidSprites(ExtendedBlockView extendedBlockView, | public Sprite[] getFluidSprites(ExtendedBlockView extendedBlockView, | ||
{ | { | ||
- | return new Sprite[]{stillAcidSprite, | + | return new Sprite[]{stillAcidSprite, |
} | } | ||
Line 332: | Line 335: | ||
// registering the same renderer for both fluid variants is intentional | // registering the same renderer for both fluid variants is intentional | ||
- | FluidRenderHandlerRegistry.INSTANCE.register([ModInitializer].stillAcid, | + | FluidRenderHandlerRegistry.INSTANCE.register([ModInitializer].stillAcid, |
- | FluidRenderHandlerRegistry.INSTANCE.register([ModInitializer].flowingAcid, | + | FluidRenderHandlerRegistry.INSTANCE.register([ModInitializer].flowingAcid, |
</ | </ | ||
Line 343: | Line 346: | ||
<code java> | <code java> | ||
| | ||
- | LakeFeature acidFeature=Registry.register(Registry.FEATURE, | + | LakeFeature acidFeature = Registry.register(Registry.FEATURE, |
</ | </ | ||
Line 349: | Line 352: | ||
<code java> | <code java> | ||
// I tell it to generate like water lakes, with a rarity of 40 (the higher is the number, the lesser is the generation chance): | // I tell it to generate like water lakes, with a rarity of 40 (the higher is the number, the lesser is the generation chance): | ||
- | Biomes.FOREST.addFeature(GenerationStep.Feature.LOCAL_MODIFICATIONS, | + | Biomes.FOREST.addFeature(GenerationStep.Feature.LOCAL_MODIFICATIONS, |
</ | </ | ||
This is the end of the tutorial. | This is the end of the tutorial. | ||
tutorial/fluids.txt · Last modified: 2023/05/04 11:31 by solidblock