use of net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler in project Paradise-Lost by devs-immortal.
the class FluidRenderSetup method setupFluidRendering.
public static void setupFluidRendering(final Fluid still, final Fluid flowing, final Identifier textureFluidId, final int color) {
final Identifier stillSpriteId = new Identifier(textureFluidId.getNamespace(), "block/" + textureFluidId.getPath() + "_still");
final Identifier flowingSpriteId = new Identifier(textureFluidId.getNamespace(), "block/" + textureFluidId.getPath() + "_flow");
// If they're not already present, add the sprites to the block atlas
ClientSpriteRegistryCallback.event(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE).register((atlasTexture, registry) -> {
registry.register(stillSpriteId);
registry.register(flowingSpriteId);
});
final Identifier fluidId = Registry.FLUID.getId(still);
final Identifier listenerId = new Identifier(fluidId.getNamespace(), fluidId.getPath() + "_reload_listener");
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<Identifier, Sprite> atlas = MinecraftClient.getInstance().getSpriteAtlas(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE);
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, renderHandler);
FluidRenderHandlerRegistry.INSTANCE.register(flowing, renderHandler);
}
use of net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler in project fabric by FabricMC.
the class FluidRenderHandlerRegistryImpl method onFluidRendererReload.
public void onFluidRendererReload(Sprite[] waterSprites, Sprite[] lavaSprites) {
FluidRenderHandler waterHandler = new FluidRenderHandler() {
@Override
public Sprite[] getFluidSprites(ExtendedBlockView view, BlockPos pos, FluidState state) {
return waterSprites;
}
@Override
public int getFluidColor(ExtendedBlockView view, BlockPos pos, FluidState state) {
if (view != null && pos != null) {
return BiomeColors.getWaterColor(view, pos);
} else {
return Biomes.DEFAULT.getWaterColor();
}
}
};
// noinspection Convert2Lambda
FluidRenderHandler lavaHandler = new FluidRenderHandler() {
@Override
public Sprite[] getFluidSprites(ExtendedBlockView view, BlockPos pos, FluidState state) {
return lavaSprites;
}
};
register(Fluids.WATER, waterHandler);
register(Fluids.FLOWING_WATER, waterHandler);
register(Fluids.LAVA, lavaHandler);
register(Fluids.FLOWING_LAVA, lavaHandler);
handlers.putAll(modHandlers);
}
use of net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler in project Paradise-Lost by devs-immortal.
the class FluidRenderSetup method setupDenseAercloudRenderingBecauseItJustNeedsToBeASpecialSnowflakeWithOnlyAStillState.
public static void setupDenseAercloudRenderingBecauseItJustNeedsToBeASpecialSnowflakeWithOnlyAStillState(final Fluid still, final Identifier textureFluidId) {
final Identifier stillSpriteId = new Identifier(textureFluidId.getNamespace(), "block/" + textureFluidId.getPath() + "_still");
final Identifier flowingSpriteId = new Identifier(textureFluidId.getNamespace(), "block/" + textureFluidId.getPath() + "_flow");
// If they're not already present, add the sprites to the block atlas
ClientSpriteRegistryCallback.event(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE).register((atlasTexture, registry) -> {
registry.register(stillSpriteId);
registry.register(flowingSpriteId);
});
final Identifier fluidId = Registry.FLUID.getId(still);
final Identifier listenerId = new Identifier(fluidId.getNamespace(), fluidId.getPath() + "_reload_listener");
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<Identifier, Sprite> atlas = MinecraftClient.getInstance().getSpriteAtlas(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE);
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 0xFFFFFF;
}
};
FluidRenderHandlerRegistry.INSTANCE.register(still, renderHandler);
}
Aggregations