mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-20 20:32:14 +00:00
Generalize non-terrain block's material ID setting (#1981)
This commit is contained in:
1 parent
6c5eedb7c1
commit
b5dd1c04ce
13 files changed
+514
-40
No files matched your search
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user