zh_cn:tutorial:fluids
                Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| zh_cn:tutorial:fluids [2023/05/04 11:27] – [制作一个流体方块] solidblock | zh_cn:tutorial:fluids [2023/05/04 11:31] (current) – [渲染设置] solidblock | ||
|---|---|---|---|
| Line 234: | Line 234: | ||
| </ | </ | ||
| ===== 渲染设置 ===== | ===== 渲染设置 ===== | ||
| - | 为了让流体拥有纹理,或者与一个颜色绑定,你需要为其注册一个'' | + | 为了让流体拥有纹理,或者与一个颜色绑定,你需要为其注册一个'' | 
| + | |||
| + | < | ||
| + | @Environment(EnvType.CLIENT) | ||
| + | public class TutorialModClient implements ClientModInitializer { | ||
| - | <code java [enable_line_numbers=" | ||
| - | public class TutorialModClient implements ClientModInitializer | ||
| - | { | ||
| - | // ... | ||
| - | |||
| @Override | @Override | ||
| - | public void onInitializeClient() | + | 	public void onInitializeClient()  | 
| - | { | + | 		FluidRenderHandlerRegistry.INSTANCE.register(TutorialMod.STILL_ACID, | 
| + | 				new class_2960(" | ||
| + | 				new class_2960(" | ||
| + | 0x4CC248 | ||
| + | )); | ||
| + | |||
| + | 		BlockRenderLayerMap.INSTANCE.putFluids(class_1921.method_23583(), | ||
| + | |||
| + | //if you want to use custom textures they needs to be registered. | ||
| + | //In this example this is unnecessary because the vanilla water textures are already registered. | ||
| + | //To register your custom textures use this method. | ||
| + | 		// | ||
| + | 		//    registry.register(new Identifier(" | ||
| + | 		//    registry.register(new Identifier(" | ||
| + | //}); | ||
| // ... | // ... | ||
| - | |||
| - | 		setupFluidRendering(TutorialMod.STILL_ACID, | ||
| - | 		BlockRenderLayerMap.INSTANCE.putFluids(RenderLayer.getTranslucent(), | ||
| - | |||
| - | // ... | ||
| - | } | ||
| - | |||
| - | // ... | ||
| - | |||
| - | 	public static void setupFluidRendering(final Fluid still, final Fluid flowing, final Identifier textureFluidId, | ||
| - | { | ||
| - | 		final Identifier stillSpriteId = new Identifier(textureFluidId.getNamespace(), | ||
| - | 		final Identifier flowingSpriteId = new Identifier(textureFluidId.getNamespace(), | ||
| - | |||
| - | 		// If they' | ||
| - | 		ClientSpriteRegistryCallback.event(SpriteAtlasTexture.BLOCK_ATLAS_TEX).register((atlasTexture, | ||
| - | { | ||
| - | 			registry.register(stillSpriteId); | ||
| - | 			registry.register(flowingSpriteId); | ||
| - | }); | ||
| - | |||
| - | 		final Identifier fluidId = Registry.FLUID.getId(still); | ||
| - | 		final Identifier listenerId = new Identifier(fluidId.getNamespace(), | ||
| - | |||
| - | final Sprite[] fluidSprites = { null, null }; | ||
| - | |||
| - | ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() | ||
| - | { | ||
| - | @Override | ||
| - | public Identifier getFabricId() | ||
| - | { | ||
| - | return listenerId; | ||
| - | } | ||
| - | |||
| - | /** | ||
| - | * Get the sprites from the block atlas when resources are reloaded | ||
| - | */ | ||
| - | @Override | ||
| - | public void apply(ResourceManager resourceManager) | ||
| - | { | ||
| - | 				final Function< | ||
| - | 				fluidSprites[0] = atlas.apply(stillSpriteId); | ||
| - | 				fluidSprites[1] = atlas.apply(flowingSpriteId); | ||
| - | } | ||
| - | }); | ||
| - | |||
| - | // The FluidRenderer gets the sprites and color from a FluidRenderHandler during rendering | ||
| - | final FluidRenderHandler renderHandler = new FluidRenderHandler() | ||
| - | { | ||
| - | @Override | ||
| - | public Sprite[] getFluidSprites(BlockRenderView view, BlockPos pos, FluidState state) | ||
| - | { | ||
| - | 				return fluidSprites; | ||
| - | } | ||
| - | |||
| - | @Override | ||
| - | public int getFluidColor(BlockRenderView view, BlockPos pos, FluidState state) | ||
| - | { | ||
| - | return color; | ||
| - | } | ||
| - | }; | ||
| - | |||
| - | 		FluidRenderHandlerRegistry.INSTANCE.register(still, | ||
| - | 		FluidRenderHandlerRegistry.INSTANCE.register(flowing, | ||
| } | } | ||
| - | |||
| - | // ... | ||
| } | } | ||
| - | </code> | + | </yarncode> | 
| 如果你需要使用你自己的流体纹理,你可以参考原版资源包(('' | 如果你需要使用你自己的流体纹理,你可以参考原版资源包(('' | ||
zh_cn/tutorial/fluids.1683199662.txt.gz · Last modified: 2023/05/04 11:27 by solidblock