Add Various Features (#1209) (#1277)

Co-authored-by: Eclipse-Sol <[email protected]>
This commit is contained in:
Jason MitchellandEclipse-Sol authored and GitHub committed 2026-01-19 13:03:56 -08:00
1 parent ea4a3cdf0b
commit 362724610c
22 files changed
+785 -96

No files matched your search

+6 -4
View File
@@ -9,7 +9,9 @@ import com.gtnewhorizons.angelica.config.AngelicaConfig;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
import lombok.Getter;
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
import com.gtnewhorizons.angelica.config.AngelicaConfig;
@@ -860,14 +862,14 @@ public class Iris {
private static int getShaderMaterialOverrideId(Block block, int meta) {
if (contextHolder == null) {
final Object2IntMap<Block> blockMatches = BlockRenderingSettings.INSTANCE.getBlockMatches();
if (blockMatches == null) {
final Reference2ObjectMap<Block, Int2IntMap> blockMetaMatches = BlockRenderingSettings.INSTANCE.getBlockMetaMatches();
if (blockMetaMatches == null) {
return -1;
}
contextHolder = new BlockContextHolder(blockMatches);
contextHolder = new BlockContextHolder(blockMetaMatches);
}
contextHolder.set(block, (short) block.getRenderType());
contextHolder.set(block, meta, (short) block.getRenderType());
return contextHolder.blockId;
}
@@ -1,19 +1,39 @@
package net.coderbot.iris.block_context;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
import net.minecraft.block.Block;
/**
* Holds block context for shader material ID lookups.
*/
public class BlockContextHolder {
private final Object2IntMap<Block> blockMatches;
private final Reference2ObjectMap<Block, Int2IntMap> blockMetaMatches;
public int blockId;
public short renderType;
public BlockContextHolder(Object2IntMap<Block> blockMatches) {
this.blockMatches = blockMatches;
public BlockContextHolder(Reference2ObjectMap<Block, Int2IntMap> blockMetaMatches) {
this.blockMetaMatches = blockMetaMatches;
this.blockId = -1;
this.renderType = -1;
}
public void set(Block block, short renderType) {
/**
* Set the material ID for a block.
* @param block The block
* @param meta The block metadata
* @param renderType The render type
*/
public void set(Block block, int meta, short renderType) {
Int2IntMap metaMap = this.blockMetaMatches != null ? this.blockMetaMatches.get(block) : null;
int id = metaMap != null ? metaMap.get(meta) : -1;
this.blockId = id;
this.renderType = renderType;
this.blockId = blockMatches.getOrDefault(block, -1);
}
public void reset() {
this.blockId = -1;
this.renderType = -1;
}
}
@@ -1,9 +1,12 @@
package net.coderbot.iris.block_rendering;
import com.gtnewhorizons.angelica.compat.toremove.RenderLayer;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap;
import net.coderbot.iris.shaderpack.materialmap.BlockEntry;
import net.coderbot.iris.shaderpack.materialmap.BlockRenderType;
@@ -14,14 +17,19 @@ import net.minecraft.util.ResourceLocation;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class BlockMaterialMapping {
public static Object2IntMap<Block> createBlockStateIdMap(Int2ObjectMap<List<BlockEntry>> blockPropertiesMap) {
Object2IntMap<Block> blockMatches = new Object2IntOpenHashMap<>();
/**
* Creates a two-level map structure for block material IDs.
* Based on Iris's BlockState mapping approach adapted for 1.7.10's metadata system.
*/
public static Reference2ObjectMap<Block, Int2IntMap> createBlockMetaIdMap(Int2ObjectMap<List<BlockEntry>> blockPropertiesMap) {
Reference2ObjectMap<Block, Int2IntMap> blockMatches = new Reference2ObjectOpenHashMap<>();
blockPropertiesMap.forEach((intId, entries) -> {
for (BlockEntry entry : entries) {
addBlock(entry, blockMatches, intId);
addBlockMetas(entry, blockMatches, intId);
}
});
@@ -57,7 +65,11 @@ public class BlockMaterialMapping {
};
}
private static void addBlock(BlockEntry entry, Object2IntMap<Block> idMap, int intId) {
/**
* Adds block+metadata combinations to the material ID map.
* Based on Iris's addBlockStates method, adapted for 1.7.10 metadata system.
*/
private static void addBlockMetas(BlockEntry entry, Reference2ObjectMap<Block, Int2IntMap> idMap, int intId) {
final NamespacedId id = entry.getId();
final ResourceLocation resourceLocation = new ResourceLocation(id.getNamespace(), id.getName());
@@ -69,40 +81,25 @@ public class BlockMaterialMapping {
return;
}
idMap.put(block, intId);
Set<Integer> metas = entry.getMetas();
// Set<Integer> metas = entry.getMetas();
// // All metas match
// if (metas.isEmpty()) {
// idMap.putIfAbsent(new BlockMatch(block, null), intId);
// return;
// }
//
// // A subset of metas match
// for(int meta : metas) {
// idMap.putIfAbsent(new BlockMatch(block, meta), intId);
// }
Int2IntMap metaMap = idMap.get(block);
if (metaMap == null) {
metaMap = new Int2IntOpenHashMap();
metaMap.defaultReturnValue(-1);
idMap.put(block, metaMap);
}
if (metas.isEmpty()) {
// Add all metadata values (0-15) if there aren't any specific ones
for (int meta = 0; meta < 16; meta++) {
metaMap.putIfAbsent(meta, intId);
}
} else {
// Add only specific metadata values
for (int meta : metas) {
metaMap.putIfAbsent(meta, intId);
}
}
}
// We ignore generics here, the actual types don't matter because we just convert
// them to strings anyways, and the compiler checks just get in the way.
//
// If you're able to rewrite this function without SuppressWarnings, feel free.
// But otherwise it works fine.
// TODO: BlockStateIdMap
// @SuppressWarnings({"rawtypes", "unchecked"})
// private static boolean checkState(BlockState state, Map<Property<?>, String> expectedValues) {
// for (Map.Entry<Property<?>, String> condition : expectedValues.entrySet()) {
// Property property = condition.getKey();
// String expectedValue = condition.getValue();
//
// String actualValue = property.getName(state.getValue(property));
//
// if (!expectedValue.equals(actualValue)) {
// return false;
// }
// }
//
// return true;
// }
}
@@ -1,8 +1,9 @@
package net.coderbot.iris.block_rendering;
import com.gtnewhorizons.angelica.compat.toremove.RenderLayer;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntFunction;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
import lombok.Getter;
import net.coderbot.iris.shaderpack.materialmap.NamespacedId;
import net.minecraft.block.Block;
@@ -16,9 +17,10 @@ public class BlockRenderingSettings {
@Getter
private boolean reloadRequired;
private Object2IntMap<Block> blockMatches;
private Reference2ObjectMap<Block, Int2IntMap> blockMetaMatches;
private Map<Block, RenderLayer> blockTypeIds;
private Object2IntFunction<NamespacedId> entityIds;
private Object2IntFunction<NamespacedId> itemIds;
private float ambientOcclusionLevel;
private boolean disableDirectionalShading;
private boolean useSeparateAo;
@@ -26,7 +28,7 @@ public class BlockRenderingSettings {
public BlockRenderingSettings() {
reloadRequired = false;
blockMatches = null;
blockMetaMatches = null;
blockTypeIds = null;
ambientOcclusionLevel = 1.0F;
disableDirectionalShading = false;
@@ -48,8 +50,8 @@ public class BlockRenderingSettings {
}
@Nullable
public Object2IntMap<Block> getBlockMatches() {
return blockMatches;
public Reference2ObjectMap<Block, Int2IntMap> getBlockMetaMatches() {
return blockMetaMatches;
}
@Nullable
@@ -62,13 +64,14 @@ public class BlockRenderingSettings {
return entityIds;
}
public void setBlockMatches(Object2IntMap<Block> blockIds) {
if (this.blockMatches != null && this.blockMatches.equals(blockIds)) {
return;
}
@Nullable
public Object2IntFunction<NamespacedId> getItemIds() {
return itemIds;
}
public void setBlockMetaMatches(Reference2ObjectMap<Block, Int2IntMap> blockMetaIds) {
this.reloadRequired = true;
this.blockMatches = blockIds;
this.blockMetaMatches = blockMetaIds;
}
public void setBlockTypeIds(Map<Block, RenderLayer> blockTypeIds) {
@@ -85,6 +88,11 @@ public class BlockRenderingSettings {
this.entityIds = entityIds;
}
public void setItemIds(Object2IntFunction<NamespacedId> itemIds) {
// note: no reload needed, items are rendered every frame.
this.itemIds = itemIds;
}
public float getAmbientOcclusionLevel() {
return ambientOcclusionLevel;
}
@@ -2,7 +2,6 @@ package net.coderbot.iris.celeritas;
import com.gtnewhorizons.angelica.rendering.celeritas.api.IrisShaderProvider;
import com.gtnewhorizons.angelica.rendering.celeritas.iris.IrisExtendedChunkVertexType;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import net.coderbot.iris.Iris;
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
import net.coderbot.iris.shadows.ShadowRenderingState;
@@ -66,12 +65,6 @@ public class IrisCeleritasShaderProvider implements IrisShaderProvider {
return BlockRenderingSettings.INSTANCE.getBlockTypeIds();
}
@Override
@Nullable
public Object2IntMap<Block> getBlockMatches() {
return BlockRenderingSettings.INSTANCE.getBlockMatches();
}
public void deleteShaders() {
overrides.deleteShaders();
}
@@ -59,6 +59,7 @@ import net.coderbot.iris.texture.pbr.PBRTextureManager;
import net.coderbot.iris.texture.pbr.PBRType;
import net.coderbot.iris.uniforms.CommonUniforms;
import net.coderbot.iris.uniforms.FrameUpdateNotifier;
import net.coderbot.iris.uniforms.ItemMaterialHelper;
import net.coderbot.iris.uniforms.custom.CustomUniforms;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.EntityRenderer;
@@ -230,11 +231,13 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
holder -> CommonUniforms.addNonDynamicUniforms(holder, programs.getPack().getIdMap(), programs.getPackDirectives(), this.updateNotifier)
);
// TODO: BlockStateIdMap
BlockRenderingSettings.INSTANCE.setBlockMatches(BlockMaterialMapping.createBlockStateIdMap(programs.getPack().getIdMap().getBlockProperties()));
BlockRenderingSettings.INSTANCE.setBlockMetaMatches(BlockMaterialMapping.createBlockMetaIdMap(programs.getPack().getIdMap().getBlockProperties()));
BlockRenderingSettings.INSTANCE.setBlockTypeIds(BlockMaterialMapping.createBlockTypeMap(programs.getPack().getIdMap().getBlockRenderTypeMap()));
BlockRenderingSettings.INSTANCE.setEntityIds(programs.getPack().getIdMap().getEntityIdMap());
ItemMaterialHelper.clearCache();
BlockRenderingSettings.INSTANCE.setItemIds(programs.getPack().getIdMap().getItemIdMap());
BlockRenderingSettings.INSTANCE.setAmbientOcclusionLevel(programs.getPackDirectives().getAmbientOcclusionLevel());
BlockRenderingSettings.INSTANCE.setDisableDirectionalShading(shouldDisableDirectionalShading());
BlockRenderingSettings.INSTANCE.setUseSeparateAo(programs.getPackDirectives().shouldUseSeparateAo());
@@ -132,6 +132,82 @@ public class IdMap {
return parseIdMap(properties, "entity.", "entity.properties");
}
/**
* Parses a space-delimited list of identifiers.
* Identifiers with spaces or special characters can be enclosed in double quotes.
* Use backslash to escape quotes or backslashes within quoted strings.
*
* Examples (input -> parsed result):
* minecraft:stone natura:berry
* -> minecraft:stone, natura:berry
*
* minecraft:stone "Natura:N Crops"
* -> minecraft:stone, Natura:N Crops
*
* "SomeDumbMod:Foo\\ \"Bar\":3"
* -> SomeDumbMod:Foo\ "Bar":3
*
* @param value The space-delimited string to parse
* @param fileName The name of the properties file (for error messages)
* @param key The property key being parsed (for error messages)
* @return List of parsed identifiers
*/
private static List<String> parseIdentifierList(String value, String fileName, String key) {
if (value.indexOf('"') == -1) {
String[] parts = value.split("\\s+");
List<String> result = new ArrayList<>(parts.length);
for (String part : parts) {
if (!part.isEmpty()) {
result.add(part);
}
}
return result;
}
// Found quote, start of a dumb block ID
List<String> result = new ArrayList<>();
StringBuilder current = new StringBuilder();
boolean inQuotes = false;
boolean escaped = false;
for (int i = 0; i < value.length(); i++) {
char c = value.charAt(i);
if (escaped) {
current.append(c);
escaped = false;
} else if (c == '\\') {
escaped = true;
} else if (c == '"') {
inQuotes = !inQuotes;
} else if (Character.isWhitespace(c) && !inQuotes) {
if (current.length() > 0) {
result.add(current.toString());
current.setLength(0);
}
} else {
current.append(c);
}
}
// Didn't close a quote, warn
if (inQuotes) {
Iris.logger.warn(fileName + " [" + key + "]: Unclosed quote");
}
// Trailing backslash, warn
if (escaped) {
Iris.logger.warn(fileName + " [" + key + "]: Trailing backslash");
}
// Add final token
if (current.length() > 0) {
result.add(current.toString());
}
return result;
}
/**
* Parses a NamespacedId map in OptiFine format
*/
@@ -158,8 +234,8 @@ public class IdMap {
return;
}
// Split on any whitespace
for (String part : value.split("\\s+")) {
// Parse identifiers
for (String part : parseIdentifierList(value, fileName, key)) {
if (part.contains("=")) {
// Avoid tons of logspam for now
Iris.logger.warn("Failed to parse an ResourceLocation in " + fileName + " for the key " + key + ": state properties are currently not supported: " + part);
@@ -209,8 +285,8 @@ public class IdMap {
}
}
// Split on whitespace groups, not just single spaces
for (String part : value.toString().split("\\s+")) {
// Parse identifiers
for (String part : parseIdentifierList(value.toString(), fileName, key)) {
if (part.isEmpty()) {
continue;
}
@@ -255,7 +331,7 @@ public class IdMap {
return;
}
for (String part : value.split("\\s+")) {
for (String part : parseIdentifierList(value, fileName, key)) {
// Note: NamespacedId performs no validation on the content. That will need to be done by whatever is
// converting these things to ResourceLocations.
overrides.put(new NamespacedId(part), renderType);
@@ -34,7 +34,9 @@ public enum ProgramId {
Entities(ProgramGroup.Gbuffers, "entities", TexturedLit),
EntitiesTrans(ProgramGroup.Gbuffers, "entities_translucent", Entities),
EntitiesGlowing(ProgramGroup.Gbuffers, "entities_glowing", Entities),
ArmorGlint(ProgramGroup.Gbuffers, "armor_glint", Textured),
ArmorGlint(ProgramGroup.Gbuffers, "armor_glint", Textured,
new BlendModeOverride(new BlendState(BlendModeFunction.SRC_COLOR.getGlId(), BlendModeFunction.ONE.getGlId(), BlendModeFunction.ONE.getGlId(), BlendModeFunction.ZERO.getGlId()))),
// TODO: Figure out why this is needed in 2.x, this worked properly before without needing an override
SpiderEyes(ProgramGroup.Gbuffers, "spidereyes", Textured,
new BlendModeOverride(new BlendState(BlendModeFunction.SRC_ALPHA.getGlId(), BlendModeFunction.ONE.getGlId(), BlendModeFunction.ZERO.getGlId(), BlendModeFunction.ONE.getGlId()))),
@@ -18,6 +18,10 @@ public class CapturedRenderingState {
private int currentRenderedEntity = -1;
private Runnable entityIdListener = null;
@Getter
private int currentRenderedItem = -1;
private Runnable itemIdListener = null;
@Getter
private final Vector4f currentEntityColor = new Vector4f();
private Runnable entityColorListener = null;
@@ -53,6 +57,18 @@ public class CapturedRenderingState {
}
}
public void setCurrentRenderedItem(int item) {
if (this.currentRenderedItem == item) {
return;
}
this.currentRenderedItem = item;
if (this.itemIdListener != null) {
this.itemIdListener.run();
}
}
public ValueUpdateNotifier getEntityIdNotifier() {
return listener -> this.entityIdListener = listener;
}
@@ -61,5 +77,9 @@ public class CapturedRenderingState {
return listener -> this.blockEntityIdListener = listener;
}
public ValueUpdateNotifier getItemIdNotifier() {
return listener -> this.itemIdListener = listener;
}
public ValueUpdateNotifier getEntityColorNotifier() { return listener -> this.entityColorListener = listener; }
}
@@ -44,6 +44,9 @@ public final class IdMapUniforms {
uniforms.uniform1i("blockEntityId", CapturedRenderingState.INSTANCE::getCurrentRenderedBlockEntity,
CapturedRenderingState.INSTANCE.getBlockEntityIdNotifier());
uniforms.uniform1i("currentRenderedItemId", CapturedRenderingState.INSTANCE::getCurrentRenderedItem,
CapturedRenderingState.INSTANCE.getItemIdNotifier());
}
/**
@@ -0,0 +1,126 @@
package net.coderbot.iris.uniforms;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet;
import it.unimi.dsi.fastutil.objects.Object2IntFunction;
import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
import net.coderbot.iris.shaderpack.materialmap.NamespacedId;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
/**
* Helper class for resolving material IDs for items.
* Checks both item.properties and block.properties.
*/
public class ItemMaterialHelper {
private static final Reference2ObjectMap<Item, Int2IntMap> MATERIAL_CACHE = new Reference2ObjectOpenHashMap<>();
private static final int CACHE_MISS_SENTINEL = Integer.MIN_VALUE;
public static final IntSet WARNED_UNKNOWN_ARMOR_INDICES = new IntOpenHashSet();
/**
* Get the material ID for an ItemStack.
* Checks item.properties first, then block.properties if the item is an ItemBlock.
*
* @param itemStack The item stack to get material ID for
* @return The material ID, or -1 if not found in either map
*/
public static int getMaterialId(ItemStack itemStack) {
if (itemStack == null || itemStack.getItem() == null) {
return -1;
}
return getMaterialId(itemStack.getItem(), itemStack.getItemDamage());
}
public static int getMaterialId(Item item, int metadata) {
if (item == null) {
return -1;
}
// Check cache first
Int2IntMap metadataCache = MATERIAL_CACHE.get(item);
if (metadataCache != null) {
int cached = metadataCache.getOrDefault(metadata, CACHE_MISS_SENTINEL);
if (cached != CACHE_MISS_SENTINEL) {
return cached;
}
}
// Cache miss
int materialId = lookupMaterialId(item, metadata);
if (metadataCache == null) {
metadataCache = new Int2IntOpenHashMap();
metadataCache.defaultReturnValue(CACHE_MISS_SENTINEL);
MATERIAL_CACHE.put(item, metadataCache);
}
metadataCache.put(metadata, materialId);
return materialId;
}
/**
* Perform the actual material ID lookup without caching.
*/
private static int lookupMaterialId(Item item, int metadata) {
String itemIdString = (String) Item.itemRegistry.getNameForObject(item);
if (itemIdString == null) {
return -1;
}
ResourceLocation itemId = new ResourceLocation(itemIdString);
NamespacedId namespacedId = new NamespacedId(itemId.getResourceDomain(), itemId.getResourcePath());
// First, check item.properties
Object2IntFunction<NamespacedId> itemIds = BlockRenderingSettings.INSTANCE.getItemIds();
if (itemIds != null) {
int id = itemIds.applyAsInt(namespacedId);
if (id != -1) {
return id;
}
}
// Second, check block.properties if this is an ItemBlock
if (item instanceof ItemBlock) {
ItemBlock itemBlock = (ItemBlock) item;
Block block = itemBlock.field_150939_a; // The block this item places
if (block == null) {
return -1;
}
// Convert item damage to block metadata
int blockMeta = itemBlock.getMetadata(metadata);
Reference2ObjectMap<Block, Int2IntMap> blockMetaMatches = BlockRenderingSettings.INSTANCE.getBlockMetaMatches();
if (blockMetaMatches != null) {
Int2IntMap metaMap = blockMetaMatches.get(block);
if (metaMap != null) {
int id = metaMap.get(blockMeta);
if (id != -1) {
return id;
}
}
}
}
// Not found in either map
return -1;
}
/**
* Clear the material ID cache.
* Should be called when shader packs are reloaded
*/
public static void clearCache() {
MATERIAL_CACHE.clear();
WARNED_UNKNOWN_ARMOR_INDICES.clear();
}
}