Merge origin/main into fix/2087-pot-top
Item quads keep both flags: the PR's cull_back (entitySolid back-face culling) and main's translucent (the translucent item sheet). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -48,6 +48,9 @@ pub struct ItemQuad {
|
||||
pub light_emission: u8,
|
||||
/// The render type culls back faces (`entitySolid`): world drawing discards them.
|
||||
pub cull_back: bool,
|
||||
/// The quad's sprite has translucent pixels (`MaterialInfo.itemRenderType`
|
||||
/// is a translucent sheet): drawn with the translucent entities.
|
||||
pub translucent: bool,
|
||||
}
|
||||
/// Which glint render type a quad uses.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
@@ -161,7 +164,7 @@ impl ItemRenderState {
|
||||
let m = pose * layer.matrix;
|
||||
match &layer.geometry {
|
||||
LayerGeometry::Quads(baked) => {
|
||||
submit_quads(baked, layer, self.display, m, sprites, sink);
|
||||
submit_quads(renderer, baked, layer, self.display, m, sprites, sink);
|
||||
}
|
||||
LayerGeometry::Special { model, argument } => special::submit(
|
||||
renderer,
|
||||
@@ -205,6 +208,7 @@ pub fn argb(color: i32) -> u32 {
|
||||
|
||||
/// `ItemFeatureRenderer.prepareMainSubmit` for one cuboid layer.
|
||||
fn submit_quads(
|
||||
renderer: &ItemRenderer,
|
||||
baked: &BakedItemModel,
|
||||
layer: &LayerRender,
|
||||
display: DisplayContext,
|
||||
@@ -218,6 +222,8 @@ fn submit_quads(
|
||||
FoilType::Special => Foil::Special,
|
||||
};
|
||||
let _ = display;
|
||||
// Quads of one layer mostly share a sprite: look its translucency up once.
|
||||
let mut last: Option<(&str, bool)> = None;
|
||||
for q in &baked.quads {
|
||||
let Some(r) = sprites
|
||||
.get(sprite_name(&q.material.sprite))
|
||||
@@ -241,6 +247,16 @@ fn submit_quads(
|
||||
let pos = q.positions.map(|p| m.transform_point3(Vec3::from(p)));
|
||||
let uv =
|
||||
q.uv.map(|[u, v]| [r.u0 + (r.u1 - r.u0) * u, r.v0 + (r.v1 - r.v0) * v]);
|
||||
let translucent = match last {
|
||||
Some((sprite, translucent)) if sprite == q.material.sprite => translucent,
|
||||
_ => {
|
||||
let translucent = renderer
|
||||
.sprites
|
||||
.translucent(sprite_name(&q.material.sprite));
|
||||
last = Some((&q.material.sprite, translucent));
|
||||
translucent
|
||||
}
|
||||
};
|
||||
sink.quad(ItemQuad {
|
||||
pos,
|
||||
uv,
|
||||
@@ -249,6 +265,7 @@ fn submit_quads(
|
||||
foil,
|
||||
light_emission: q.light_emission,
|
||||
cull_back: false,
|
||||
translucent: translucent || q.material.force_translucent,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -263,6 +280,9 @@ struct FileSprites {
|
||||
root: PathBuf,
|
||||
permutations: Vec<PalettedPermutations>,
|
||||
cache: Mutex<HashMap<String, Option<SpriteMask>>>,
|
||||
/// Sprites with a pixel that is neither fully transparent nor opaque
|
||||
/// (`Transparency.hasTranslucent`), filled in as sprites load.
|
||||
translucent: Mutex<HashMap<String, bool>>,
|
||||
}
|
||||
impl SpriteLookup for FileSprites {
|
||||
fn mask(&self, sprite: &str) -> Option<SpriteMask> {
|
||||
@@ -286,6 +306,13 @@ fn argb_pixels(rgba: &[u8]) -> Vec<u32> {
|
||||
.collect()
|
||||
}
|
||||
impl FileSprites {
|
||||
fn translucent(&self, sprite: &str) -> bool {
|
||||
let known = |this: &Self| this.translucent.lock().ok()?.get(sprite).copied();
|
||||
known(self).unwrap_or_else(|| {
|
||||
self.mask(sprite);
|
||||
known(self).unwrap_or(false)
|
||||
})
|
||||
}
|
||||
fn png(&self, sprite: &str, directory: &str) -> PathBuf {
|
||||
crate::atlas_sources::texture_path(&self.root, sprite, directory)
|
||||
}
|
||||
@@ -306,6 +333,10 @@ impl FileSprites {
|
||||
(w, h, pixels)
|
||||
}
|
||||
};
|
||||
let translucent = argb.iter().any(|p| matches!(p >> 24, 1..=254));
|
||||
if let Ok(mut cache) = self.translucent.lock() {
|
||||
cache.insert(sprite.to_owned(), translucent);
|
||||
}
|
||||
let alpha: Vec<u8> = argb.iter().map(|p| (p >> 24) as u8).collect();
|
||||
let animation = fs::read_to_string(png.with_extension("png.mcmeta"))
|
||||
.ok()
|
||||
@@ -366,6 +397,9 @@ pub struct ItemRenderer {
|
||||
sprites: FileSprites,
|
||||
baked: Mutex<HashMap<String, Arc<BakedItemModel>>>,
|
||||
extents: Mutex<HashMap<String, Arc<Vec<Vec3>>>>,
|
||||
/// GUI items already drawn: the HUD vertices of a static item at a GUI position
|
||||
/// (`gui::draw`), which are the same every frame it stays there.
|
||||
pub(crate) gui_drawn: Mutex<HashMap<gui::DrawnKey, Arc<[crate::hud::HudVertex]>>>,
|
||||
/// Entity model layers of the special renderers.
|
||||
parts: HashMap<String, ModelPart>,
|
||||
/// `colormap/grass.png` as ARGB.
|
||||
@@ -452,9 +486,11 @@ impl ItemRenderer {
|
||||
root: root.to_path_buf(),
|
||||
permutations,
|
||||
cache: Mutex::default(),
|
||||
translucent: Mutex::default(),
|
||||
},
|
||||
baked: Mutex::default(),
|
||||
extents: Mutex::default(),
|
||||
gui_drawn: Mutex::default(),
|
||||
parts,
|
||||
grass,
|
||||
})
|
||||
@@ -652,6 +688,7 @@ pub fn tag_json(tag: &Tag) -> Value {
|
||||
/// The resolver's view of a client stack: its item, count and component patch.
|
||||
pub fn stack_view(stack: &crate::items::ItemStack) -> StackView {
|
||||
let mut view = StackView::new(&stack.item, stack.count as i32);
|
||||
view.bundle_selected = stack.data().map_or(-1, |d| d.bundle_selected.0);
|
||||
if let Some(Tag::Compound(c)) = crate::item_data::components_tag(stack.damage, stack.data()) {
|
||||
for (k, v) in &c {
|
||||
let key = k.to_string_lossy();
|
||||
@@ -692,7 +729,12 @@ impl ItemSink for WorldSink<'_> {
|
||||
} else {
|
||||
self.light
|
||||
};
|
||||
let overlay = if q.foil == Foil::None { 0 } else { 7 };
|
||||
let overlay = match (q.foil, q.translucent) {
|
||||
(Foil::None, true) => crate::gfx::TRANSLUCENT_ITEM_OVERLAY,
|
||||
(Foil::None, false) => 0,
|
||||
(_, true) => crate::gfx::TRANSLUCENT_GLINT_ITEM_OVERLAY,
|
||||
(_, false) => 7,
|
||||
};
|
||||
for (p, uv) in q.pos.iter().zip(q.uv) {
|
||||
self.out.push(Vertex {
|
||||
normal: if q.cull_back { CULL_BACK } else { [0; 4] },
|
||||
|
||||
Reference in New Issue
Block a user