Generalize non-terrain block's material ID setting (#1981)

This commit is contained in:
Eclipse-Sol authored and GitHub committed 2026-08-02 13:10:38 -07:00
1 parent 6c5eedb7c1
commit b5dd1c04ce
13 files changed
+514 -40

No files matched your search

@@ -293,8 +293,12 @@ public enum Mixins implements IMixins {
, "shaders.MixinLocale"
, "shaders.MixinRender"
, "shaders.MixinRenderBiped"
, "shaders.MixinRenderBlocks_FaceNormals"
, "shaders.MixinRenderBlocks_FallingShading"
, "shaders.MixinRenderBlocks_ItemId"
, "shaders.MixinRenderDragon"
, "shaders.MixinRenderEntityFlame"
, "shaders.MixinRenderFallingBlock"
, "shaders.MixinRendererLivingEntity"
, "shaders.MixinRenderGlobal"
, "shaders.AccessorEntityHorse"
@@ -0,0 +1,83 @@
package com.gtnewhorizons.angelica.rendering;
import net.minecraft.block.Block;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.util.ForgeDirection;
public final class FallingBlockMetaAccess implements IBlockAccess {
private IBlockAccess delegate;
private int x;
private int y;
private int z;
private int metadata;
public FallingBlockMetaAccess set(IBlockAccess delegate, int x, int y, int z, int metadata) {
this.delegate = delegate;
this.x = x;
this.y = y;
this.z = z;
this.metadata = metadata;
return this;
}
public void clear() {
this.delegate = null;
}
@Override
public int getBlockMetadata(int x, int y, int z) {
if (x == this.x && y == this.y && z == this.z) {
return this.metadata;
}
return delegate.getBlockMetadata(x, y, z);
}
@Override
public Block getBlock(int x, int y, int z) {
return delegate.getBlock(x, y, z);
}
@Override
public TileEntity getTileEntity(int x, int y, int z) {
return delegate.getTileEntity(x, y, z);
}
@Override
public int getLightBrightnessForSkyBlocks(int x, int y, int z, int lightValue) {
return delegate.getLightBrightnessForSkyBlocks(x, y, z, lightValue);
}
@Override
public int isBlockProvidingPowerTo(int x, int y, int z, int direction) {
return delegate.isBlockProvidingPowerTo(x, y, z, direction);
}
@Override
public boolean isAirBlock(int x, int y, int z) {
return delegate.isAirBlock(x, y, z);
}
@Override
public BiomeGenBase getBiomeGenForCoords(int x, int z) {
return delegate.getBiomeGenForCoords(x, z);
}
@Override
public int getHeight() {
return delegate.getHeight();
}
@Override
public boolean extendedLevelsInChunkCache() {
return delegate.extendedLevelsInChunkCache();
}
@Override
public boolean isSideSolid(int x, int y, int z, ForgeDirection side, boolean _default) {
return delegate.isSideSolid(x, y, z, side, _default);
}
}
@@ -0,0 +1,56 @@
package com.gtnewhorizons.angelica.rendering;
import com.gtnewhorizon.gtnhlib.client.renderer.TessellatorManager;
import com.gtnewhorizons.angelica.glsm.GLStateManager;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
import net.coderbot.iris.block_rendering.BlockMaterialMapping;
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
import net.coderbot.iris.gl.shader.ProgramCreator;
import net.irisshaders.iris.api.v0.IrisApi;
import net.minecraft.block.Block;
import net.minecraft.world.IBlockAccess;
public final class FallingBlockRendering {
public static boolean active;
private static final FallingBlockMetaAccess META_ACCESS = new FallingBlockMetaAccess();
private FallingBlockRendering() {
}
public static FallingBlockMetaAccess metaAccess(IBlockAccess world, int x, int y, int z, int metadata) {
return META_ACCESS.set(world, x, y, z, metadata);
}
public static void setEntityAttribute(Block block, int metadata) {
if (!shadersActive()) return;
GLStateManager.glVertexAttrib2s(ProgramCreator.MC_ENTITY, (short) blockMaterialId(block, metadata), (short) 0);
}
public static void resetEntityAttribute() {
if (!shadersActive()) return;
GLStateManager.glVertexAttrib2s(ProgramCreator.MC_ENTITY, (short) -1, (short) -1);
}
private static int blockMaterialId(Block block, int metadata) {
final Reference2ObjectMap<Block, Int2IntMap> blockMetaMatches = BlockRenderingSettings.INSTANCE.getBlockMetaMatches();
if (blockMetaMatches == null) return -1;
final Int2IntMap metaMap = blockMetaMatches.get(block);
return metaMap != null ? BlockMaterialMapping.resolveId(metaMap, metadata) : -1;
}
public static boolean isActive() {
return active && shadersActive();
}
private static boolean shadersActive() {
return TessellatorManager.isOnMainThread() && IrisApi.getInstance().isShaderPackInUse();
}
public static boolean skipDirectionalShading() {
return isActive() && BlockRenderingSettings.INSTANCE.shouldDisableDirectionalShading();
}
}
@@ -781,7 +781,11 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
}
public boolean shouldOverrideShaders() {
return isRenderingWorld && !isRenderingFullScreenPass && !isPostChain && isMainBound;
return isRenderingLevelGeometry() && isMainBound;
}
public boolean isRenderingLevelGeometry() {
return isRenderingWorld && !isRenderingFullScreenPass && !isPostChain;
}
public Pass getActivePassProgram() {
@@ -1,5 +1,9 @@
package net.coderbot.iris.uniforms;
import net.coderbot.iris.Iris;
import net.coderbot.iris.pipeline.DeferredWorldRenderingPipeline;
import net.coderbot.iris.pipeline.WorldRenderingPipeline;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
/**
@@ -23,6 +27,13 @@ public class ItemIdManager {
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(id);
}
/**
* Set the item ID for a Block rendered outside of terrain.
*/
public static void setBlockId(Block block, int metadata) {
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(Math.max(0, ItemMaterialHelper.getMaterialId(block, metadata)));
}
/**
* Reset the item ID to 0.
* Used when entering/exiting render sections or before glint rendering.
@@ -30,4 +41,28 @@ public class ItemIdManager {
public static void resetItemId() {
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(0);
}
/**
* The currently bound item ID.
*/
public static int getItemId() {
return CapturedRenderingState.INSTANCE.getCurrentRenderedItem();
}
/**
* Set an already-resolved item ID without performing a lookup.
*/
public static void setItemIdRaw(int id) {
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(id);
}
/**
* Honestly I don't know why there's comments on a lot of these.
* Guess I thought documentation is good but man if you can't figure this out
* you're in trouble.
*/
public static boolean isWorldRenderActive() {
final WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable();
return pipeline instanceof DeferredWorldRenderingPipeline drp && drp.isRenderingLevelGeometry();
}
}
@@ -23,6 +23,8 @@ public class ItemMaterialHelper {
private static final Reference2ObjectMap<Item, Int2IntMap> MATERIAL_CACHE = new Reference2ObjectOpenHashMap<>();
private static final int CACHE_MISS_SENTINEL = Integer.MIN_VALUE;
private static final Reference2ObjectMap<Item, NamespacedId> ITEM_NAME_CACHE = new Reference2ObjectOpenHashMap<>();
private static final Reference2ObjectMap<Block, Int2IntMap> BLOCK_MATERIAL_CACHE = new Reference2ObjectOpenHashMap<>();
/**
* Get the material ID for an ItemStack.
* For ItemBlock: checks block.properties first, then item.properties.
@@ -79,6 +81,52 @@ public class ItemMaterialHelper {
return materialId;
}
/**
* Get the material ID for a Block rendered outside of terrain.
*
* @return The material ID, or -1 if not found
*/
public static int getMaterialId(Block block, int metadata) {
if (block == null) {
return -1;
}
Int2IntMap metadataCache = BLOCK_MATERIAL_CACHE.get(block);
if (metadataCache != null) {
int cached = metadataCache.getOrDefault(metadata, CACHE_MISS_SENTINEL);
if (cached != CACHE_MISS_SENTINEL) {
return cached;
}
}
int materialId = lookupBlockMaterialId(block, metadata);
if (metadataCache == null) {
metadataCache = new Int2IntOpenHashMap();
metadataCache.defaultReturnValue(CACHE_MISS_SENTINEL);
BLOCK_MATERIAL_CACHE.put(block, metadataCache);
}
metadataCache.put(metadata, materialId);
return materialId;
}
private static int lookupBlockMaterialId(Block block, int metadata) {
Reference2ObjectMap<Block, Int2IntMap> blockMetaMatches = BlockRenderingSettings.INSTANCE.getBlockMetaMatches();
if (blockMetaMatches != null) {
Int2IntMap metaMap = blockMetaMatches.get(block);
if (metaMap != null) {
int id = BlockMaterialMapping.resolveId(metaMap, metadata);
if (id != -1) {
return id;
}
}
}
final Item item = Item.getItemFromBlock(block);
return item != null ? lookupItemPropertiesId(item) : -1;
}
/**
* Perform the actual material ID lookup without caching.
*
@@ -107,16 +155,17 @@ public class ItemMaterialHelper {
}
// Fall back to item.properties
Object2IntFunction<NamespacedId> itemIds = BlockRenderingSettings.INSTANCE.getItemIds();
if (itemIds != null) {
String itemIdString = Item.itemRegistry.getNameForObject(item);
if (itemIdString != null) {
ResourceLocation itemId = new ResourceLocation(itemIdString);
return itemIds.applyAsInt(new NamespacedId(itemId.getResourceDomain(), itemId.getResourcePath()));
}
return lookupItemPropertiesId(item);
}
private static int lookupItemPropertiesId(Item item) {
final Object2IntFunction<NamespacedId> itemIds = BlockRenderingSettings.INSTANCE.getItemIds();
if (itemIds == null) {
return -1;
}
return -1;
final NamespacedId name = getCachedItemName(item);
return name == null ? -1 : itemIds.applyAsInt(name);
}
/**
@@ -126,6 +175,7 @@ public class ItemMaterialHelper {
public static void clearCache() {
MATERIAL_CACHE.clear();
ITEM_NAME_CACHE.clear();
BLOCK_MATERIAL_CACHE.clear();
}
private static NamespacedId getCachedItemName(Item item) {