Copy fluid and lava still textures to Item atlas for DynamicFluidContainerModel. Fixes #10809

This commit is contained in:
LexManos committed 2026-04-12 12:53:34 -07:00
1 parent 77cb0c5c4e
commit 7846d25606
11 files changed
+176 -11

No files matched your search

@@ -0,0 +1,49 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.client;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import net.minecraft.client.data.AtlasProvider;
import net.minecraft.client.renderer.texture.atlas.SpriteSource;
import net.minecraft.client.renderer.texture.atlas.sources.SingleFile;
import net.minecraft.data.AtlasIds;
import net.minecraft.data.CachedOutput;
import net.minecraft.data.PackOutput;
import net.minecraft.resources.Identifier;
public class ForgeAtlasProvider extends AtlasProvider {
public ForgeAtlasProvider(PackOutput output) {
super(output);
}
@Override
public CompletableFuture<?> run(final CachedOutput cache) {
return CompletableFuture.allOf(
this.storeAtlas(cache, AtlasIds.BLOCKS, List.of(
single("white")
)),
this.storeAtlas(cache, AtlasIds.ITEMS, List.of(
fromBlock("block/lava_still"),
fromBlock("block/water_still")
))
);
}
private static SpriteSource single(String path) {
return new SingleFile(Identifier.fromNamespaceAndPath("forge", path));
}
private static SpriteSource fromBlock(String name) {
var resource = Identifier.withDefaultNamespace(name);
var id = resource;
if (resource.getPath().startsWith("block/"))
id = resource.withPath(path -> "item/" + path.substring(6));
return new SingleFile(resource, Optional.of(id));
}
}
@@ -8,7 +8,6 @@ package net.minecraftforge.client.model;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import com.mojang.math.Transformation;
import net.minecraft.client.renderer.block.dispatch.ModelState;
import net.minecraft.client.renderer.chunk.ChunkSectionLayer;
import net.minecraft.client.resources.model.ModelBaker;
@@ -31,6 +30,7 @@ import net.minecraftforge.client.model.geometry.IGeometryLoader;
import net.minecraftforge.client.model.geometry.StandaloneGeometryBakingContext;
import net.minecraftforge.client.model.geometry.UnbakedGeometryHelper;
import net.minecraftforge.registries.ForgeRegistries;
import org.joml.Quaternionf;
import org.joml.Vector3f;
@@ -81,17 +81,26 @@ public class DynamicFluidContainerModel implements UnbakedGeometry {
@Override
public QuadCollection bake(TextureSlots textures, ModelBaker baker, ModelState state, ModelDebugName name, IGeometryBakingContext context) {
Material fluidMaskLocation = textures.getMaterial("fluid");
Material coverLocation = textures.getMaterial("cover");
Material stillMaterial = null;
if (fluid != Fluids.EMPTY) {
var stillTexture = IClientFluidTypeExtensions.of(fluid).getStillTexture();
stillMaterial = new Material(stillTexture);
if (stillTexture != null) {
// Models can no longer have textures across atlases, so redirect to the item model of the same name.
// Modders may need to make clones of their textures in the item atlas, or provide a custom atlas alias
if (stillTexture.getPath().startsWith("block/"))
stillTexture = stillTexture.withPath(path -> "item/" + path.substring(6));
stillMaterial = new Material(stillTexture);
}
}
var materials = baker.materials();
var baseMaterial = materials.resolveSlot(textures, "base", name);
var fluidMaterial = stillMaterial == null ? null : materials.get(stillMaterial, name);
var coverMaterial = materials.resolveSlot(textures, "cover", name);
var coverMaterial = coverLocation == null ? null : materials.get(coverLocation, name);
/*
var particleSprite = sprites.resolveSlot(textures, "particle", name);
@@ -117,7 +126,7 @@ public class DynamicFluidContainerModel implements UnbakedGeometry {
var templateMaterial = materials.get(fluidMaskLocation, name);
if (templateMaterial != null) {
var transformedState = new SimpleModelState(transformation.compose(FLUID_TRANSFORM));
UnbakedGeometryHelper.bakeMaskedSprite(buf, baker.interner(), transformedState, info(baker, templateMaterial, 1), info(baker, fluidMaterial, 1));
UnbakedGeometryHelper.bakeMaskedSprite(buf, baker.interner(), transformedState, info(baker, fluidMaterial, 1), info(baker, templateMaterial, 1));
}
}
@@ -11,6 +11,7 @@ import net.minecraft.client.renderer.block.dispatch.ModelState;
import net.minecraft.client.renderer.texture.MissingTextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.resources.model.ModelBaker;
import net.minecraft.client.resources.model.cuboid.CuboidFace;
import net.minecraft.client.resources.model.cuboid.FaceBakery;
import net.minecraft.client.resources.model.cuboid.ItemModelGenerator;
import net.minecraft.client.resources.model.geometry.BakedQuad;
@@ -91,15 +92,16 @@ public class UnbakedGeometryHelper {
final BakedQuad.MaterialInfo texture,
final BakedQuad.MaterialInfo template
) {
var spriteContents = template.sprite().contents();
int width = spriteContents.width(), height = spriteContents.height();
var sprite = template.sprite().contents();
int width = sprite.width();
int height = sprite.height();
var bits = new BitSet(width * height);
// For every frame in the texture, mark all the opaque pixels (this is what vanilla does too)
spriteContents.getUniqueFrames().forEach(frame -> {
sprite.getUniqueFrames().forEach(frame -> {
for (int x = 0; x < width; x++)
for (int y = 0; y < height; y++)
if (!spriteContents.isTransparent(frame, x, y))
if (!sprite.isTransparent(frame, x, y))
bits.set(x + y * width);
});
@@ -132,8 +134,10 @@ public class UnbakedGeometryHelper {
var to = new Vector3f(16 * x / (float) width, 16 - 16 * y / (float) height, 8.5F);
// Create element
builder.addUnculledFace(FaceBakery.bakeQuad(interner, from, to, ItemModelGenerator.SOUTH_FACE_UVS, Quadrant.R0, texture, Direction.SOUTH, state, null));
builder.addUnculledFace(FaceBakery.bakeQuad(interner, from, to, ItemModelGenerator.NORTH_FACE_UVS, Quadrant.R0, texture, Direction.NORTH, state, null));
var southUvs = new CuboidFace.UVs(from.x, from.y, to.x, to.y);
var northUvs = new CuboidFace.UVs(to.x, from.y, from.x, to.y);
builder.addUnculledFace(FaceBakery.bakeQuad(interner, from, to, southUvs, Quadrant.R0, texture, Direction.SOUTH, state, null));
builder.addUnculledFace(FaceBakery.bakeQuad(interner, from, to, northUvs, Quadrant.R0, texture, Direction.NORTH, state, null));
// Reset xStart
xStart = -1;
@@ -37,6 +37,8 @@ import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.pathfinder.PathType;
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.ForgeAtlasProvider;
import net.minecraftforge.client.extensions.common.IClientFluidTypeExtensions;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.common.data.ForgeBiomeTagsProvider;
@@ -69,6 +71,7 @@ import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.config.ModConfigEvent;
import net.minecraftforge.fml.event.lifecycle.*;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLLoader;
import net.minecraftforge.registries.*;
import net.minecraftforge.registries.holdersets.AndHolderSet;
import net.minecraftforge.registries.holdersets.AnyHolderSet;
@@ -444,8 +447,11 @@ public class ForgeMod {
gen.addProvider(event.includeServer(), new ForgeBiomeTagsProvider(packOutput, lookupProvider, existingFileHelper));
gen.addProvider(event.includeServer(), new ForgeStructureTagsProvider(packOutput, lookupProvider, existingFileHelper));
gen.addProvider(event.includeClient(), new ForgeSpriteSourceProvider(packOutput, existingFileHelper));
gen.addProvider(event.includeClient(), new VanillaSoundDefinitionsProvider(packOutput, existingFileHelper));
// The provider uses Client only classes, so put a side guard on it.
if (FMLLoader.getDist() == Dist.CLIENT) {
gen.addProvider(event.includeClient(), new ForgeAtlasProvider(packOutput));
}
}
// done in an event instead of deferred to only enable if a mod requests it
@@ -11,6 +11,10 @@ import net.minecraft.resources.Identifier;
import java.util.Optional;
/**
* @deprecated Use Vanilla's {@link net.minecraft.client.data.AtlasProvider AtlasProvider}
*/
@Deprecated(forRemoval = true, since = "26.1.2")
public class ForgeSpriteSourceProvider extends SpriteSourceProvider
{
public ForgeSpriteSourceProvider(PackOutput output, ExistingFileHelper fileHelper)
@@ -24,7 +24,10 @@ import java.util.function.BiConsumer;
* allows adding additional textures to the atlas by adding {@link SpriteSource}s to the configuration.</p>
* <p>See {@link SpriteSources} for the available sources and the constants in this class for the
* atlases used in vanilla Minecraft</p>
*
* @deprecated Use Vanilla's {@link net.minecraft.client.data.AtlasProvider AtlasProvider}
*/
@Deprecated(forRemoval = true, since = "26.1.2")
public abstract class SpriteSourceProvider extends JsonCodecProvider<List<SpriteSource>>
{
protected static final Identifier BLOCKS_ATLAS = Identifier.withDefaultNamespace("blocks");