User Tools

Site Tools


zh_cn:tutorial:fluids

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
zh_cn:tutorial:fluids [2020/11/15 01:23] – [Rendering setup] solidblockzh_cn:tutorial:fluids [2023/05/04 11:22] – [创建抽象流体] solidblock
Line 3: Line 3:
 在这里,我们将介绍自定义流体的创建。如果计划创建多个流体,建议创建一个抽象的基本流体类,在其中设置必要的默认值,这些默认值将在其子类中共享。我们还将使其像湖泊一样在世界中生成。 在这里,我们将介绍自定义流体的创建。如果计划创建多个流体,建议创建一个抽象的基本流体类,在其中设置必要的默认值,这些默认值将在其子类中共享。我们还将使其像湖泊一样在世界中生成。
 ===== 创建抽象流体 ===== ===== 创建抽象流体 =====
-原版流体扩展了''net.minecraft.fluid.FlowableFluid'',我们也应如此。 +原版流体继承了 ''<yarn net.minecraft.class_3609>'',我们也应如此。 
-<code java [enable_line_numbers="true"]> +<yarncode java [enable_line_numbers="true"]> 
-public abstract class TutorialFluid extends FlowableFluid +public abstract class TutorialFluid extends class_3609 {
-{+
  /**  /**
- * @return is the given fluid an instance of this fluid?+ * @return 给定的流体是否为该流体的实例?
  */  */
  @Override  @Override
- public boolean matchesType(Fluid fluid) + public boolean method_15780(class_3611 fluid) {
- {+
  return fluid == getStill() || fluid == getFlowing();  return fluid == getStill() || fluid == getFlowing();
  }  }
   
  /**  /**
- * @return is the fluid infinite like water?+ * @return 流体是否可以像无限刷水的方法一样无限生成?在原版,这取决于游戏规则。
  */  */
  @Override  @Override
- protected boolean isInfinite() + protected boolean method_15737() {
- {+
  return false;  return false;
  }  }
   
  /**  /**
-Perform actions when fluid flows into a replaceable block. Water drops +流体流入一个可替换的方块时的行为。 
-the block's loot table. Lava plays the "block.lava.extinguish" sound.+水会掉落方块的战利品表。熔岩会播放“block.lava.extinguish”音效。
  */  */
  @Override  @Override
- protected void beforeBreakingBlock(WorldAccess world, BlockPos pos, BlockState state) + protected void method_15730(class_1936 world, class_2338 pos, class_2680 state) {
- {+
  final BlockEntity blockEntity = state.getBlock().hasBlockEntity() ? world.getBlockEntity(pos) : null;  final BlockEntity blockEntity = state.getBlock().hasBlockEntity() ? world.getBlockEntity(pos) : null;
  Block.dropStacks(state, world, pos, blockEntity);  Block.dropStacks(state, world, pos, blockEntity);
Line 37: Line 33:
   
  /**  /**
-Lava returns true if its FluidState is above a certain height and the +熔岩在其 FluidState 高于指定的高度且该流体为水时返回 true。
- * Fluid is Water.+
  
- * @return if the given Fluid can flow into this FluidState?+ * @return 给定的流体能否流入它的 FluidState
  */  */
  @Override  @Override
- protected boolean canBeReplacedWith(FluidState fluidState, BlockView blockView, BlockPos blockPos, Fluid fluid, Direction direction) + protected boolean method_15777(class_3610 fluidState, class_1922 blockView, class_2338 blockPos, class_3611 fluid, class_2350 direction) {
- {+
  return false;  return false;
  }  }
   
  /**  /**
-Possibly related to the distance checks for flowing into nearby holes? +或许与流入周围附近凹洞的距离检查有关? 
-Water returns 4. Lava returns in the Overworld and in the Nether.+水返回4。熔岩在主世界返回2,而在下界返回4
  */  */
  @Override  @Override
- protected int getFlowSpeed(WorldView worldView) + protected int method_15733(class_4538 worldView) {
- {+
  return 4;  return 4;
  }  }
   
  /**  /**
-Water returns 1. Lava returns in the Overworld and in the Nether.+返回每次流动一格,其等级减少的数值。水返回1,熔岩在主世界返回2,在下界返回1
  */  */
  @Override  @Override
- protected int getLevelDecreasePerBlock(WorldView worldView) + protected int method_15739(class_4538 worldView) {
- {+
  return 1;  return 1;
  }  }
   
  /**  /**
-Water returns 5. Lava returns 30 in the Overworld and 10 in the Nether.+返回每流一格需要花费的时间(按刻计算)。水返回5。熔岩在主世界返回30,在下界返回10
  */  */
  @Override  @Override
- public int getTickRate(WorldView worldView) + public int method_15789(class_4538 worldView) {
- {+
  return 5;  return 5;
  }  }
   
  /**  /**
-Water and Lava both return 100.0F.+返回爆炸抗性。水和熔岩都返回100.0F
  */  */
  @Override  @Override
- protected float getBlastResistance() + protected float method_15784() {
- {+
  return 100.0F;  return 100.0F;
  }  }
 } }
-</code>+</yarncode>
  
 ===== 进行 ===== ===== 进行 =====
Line 252: Line 242:
 </code> </code>
 ===== 渲染设置 ===== ===== 渲染设置 =====
-为了让流体拥有材质,或者与一个颜色绑定,你需要为其注册一个''FluidRenderHandler''。这里,我们重用水的材质,并仅仅改变用于其上的颜色。为确保材质渲染为半透明的,你可以使用Fabric的''BlockRenderLayerMap''+为了让流体拥有纹理,或者与一个颜色绑定,你需要为其注册一个''FluidRenderHandler''。这里,我们重用水的纹理,并仅仅改变用于其上的颜色。为确保纹理渲染为半透明的,你可以使用Fabric的''BlockRenderLayerMap''
  
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
Line 333: Line 323:
 </code> </code>
  
-如果你需要使用你自己的流体材质,你可以参考原版资源包((''assets/minecraft/blockstates/water.json''\\ ''assets/minecraft/models/block/water.json''\\ ''assets/minecraft/textures/block/water_still.png''\\ ''assets/minecraft/textures/block/water_still.png.mcmeta''\\ ''assets/minecraft/textures/block/water_flow.png''\\ ''assets/minecraft/textures/block/water_flow.png.mcmeta''))作为一个模板。+如果你需要使用你自己的流体纹理,你可以参考原版资源包((''assets/minecraft/blockstates/water.json''\\ ''assets/minecraft/models/block/water.json''\\ ''assets/minecraft/textures/block/water_still.png''\\ ''assets/minecraft/textures/block/water_still.png.mcmeta''\\ ''assets/minecraft/textures/block/water_flow.png''\\ ''assets/minecraft/textures/block/water_flow.png.mcmeta''))作为一个模板。
  
-===== Generation in a world =====+===== 在世界中生成 ===== 
 +为使得酸湖在世界中生成,你可以在你的''ModInitializer''中创建一个''net.minecraft.world.gen.feature.LakeFeature'',然后将其添加到你需要让它生成的生物群系中:
  
-要在世界上产生酸湖,可以使用在ModInitializer中创建的** net.minecraft.world.gen.feature.LakeFeature **: +<code java [enable_line_numbers="true"]
-<code java> +// ...
-         +
-        LakeFeature acidFeature = Registry.register(Registry.FEATURE, new Identifier(MODID,"acid_lake"), new LakeFeature(dynamic -> new LakeFeatureConfig(acid.getDefaultState())));+
  
 +public static LakeFeature ACID_LAKE;
 +
 +// ...
 +
 +@Override
 +public void onInitialize()
 +{
 + // ...
 +
 + ACID_LAKE = Registry.register(Registry.FEATURE, new Identifier(MOD_ID, "acid_lake"), new LakeFeature(SingleStateFeatureConfig::deserialize));
 +
 + // 在沼泽中生成,类似于水湖,但是概率为40(数字越高,生成几率越低)
 + Biomes.SWAMP.addFeature(
 + GenerationStep.Feature.LOCAL_MODIFICATIONS,
 + ACID_LAKE.configure(new SingleStateFeatureConfig(ACID.getDefaultState()))
 + .createDecoratedFeature(Decorator.WATER_LAKE.configure(new ChanceDecoratorConfig(40)))
 + );
 +
 + // ...
 +}
 +
 +// ...
 </code> </code>
-然后将其放入所需的生物群系中以生成: 
-<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): 
-        Biomes.FOREST.addFeature(GenerationStep.Feature.LOCAL_MODIFICATIONS, Biome.configureFeature(acidFeature, new LakeFeatureConfig(acid.getDefaultState()), Decorator.WATER_LAKE, new LakeDecoratorConfig(40))); 
-</code> 
-本教程到此结束。 
  
zh_cn/tutorial/fluids.txt · Last modified: 2023/05/04 11:31 by solidblock