mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-15 17:55:08 +00:00
Add FlatteningMap and EntityFlatteningMap (#1635)
This commit is contained in:
1 parent
e5cd1372e7
commit
0db691db0b
5 files changed
+1469
-71
No files matched your search
@@ -7,8 +7,10 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
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.Iris;
|
||||
import net.coderbot.iris.shaderpack.materialmap.BlockEntry;
|
||||
import net.coderbot.iris.shaderpack.materialmap.BlockRenderType;
|
||||
import net.coderbot.iris.shaderpack.materialmap.FlatteningMap;
|
||||
import net.coderbot.iris.shaderpack.materialmap.NamespacedId;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
@@ -39,8 +41,16 @@ public class BlockMaterialMapping {
|
||||
Map<Block, BlockRenderLayer> blockTypeIds = new Reference2ReferenceOpenHashMap<>();
|
||||
|
||||
blockPropertiesMap.forEach((id, blockType) -> {
|
||||
final ResourceLocation resourceLocation = new ResourceLocation(id.getNamespace(), id.getName());
|
||||
final Block block = Block.getBlockFromName(resourceLocation.toString());
|
||||
Block block = resolveBlock(id);
|
||||
|
||||
// Try flattening map for modern names
|
||||
if ((block == null || block == Blocks.air) && "minecraft".equals(id.getNamespace())) {
|
||||
List<BlockEntry> legacyEntries = FlatteningMap.toLegacy(id.getName(), Map.of());
|
||||
if (legacyEntries != null) {
|
||||
// Use the first entry for render type (render type applies per-block)
|
||||
block = resolveBlock(legacyEntries.getFirst().getId());
|
||||
}
|
||||
}
|
||||
|
||||
if (block == null || block == Blocks.air) {
|
||||
return;
|
||||
@@ -73,19 +83,32 @@ public class BlockMaterialMapping {
|
||||
* 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());
|
||||
NamespacedId id = entry.getId();
|
||||
String name = id.getName();
|
||||
boolean hasStateProps = !entry.getStateProperties().isEmpty();
|
||||
boolean hasExplicitMetas = !entry.getMetas().isEmpty();
|
||||
|
||||
final Block block = (Block) Block.blockRegistry.getObject(resourceLocation.toString());
|
||||
if ("minecraft".equals(id.getNamespace()) && (hasStateProps || !hasExplicitMetas)) {
|
||||
List<BlockEntry> legacyEntries = FlatteningMap.toLegacy(name, entry.getStateProperties());
|
||||
if (legacyEntries != null) {
|
||||
for (BlockEntry legacy : legacyEntries) {
|
||||
applyMetas(resolveBlock(legacy.getId()), legacy.getMetas(), idMap, intId);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If the block doesn't exist, by default the registry will return AIR. That probably isn't what we want.
|
||||
// TODO: Assuming that Registry.BLOCK.getDefaultId() == "minecraft:air" here
|
||||
// Fall back to registry with the entry's own metas
|
||||
Block block = resolveBlock(id);
|
||||
applyMetas(block, entry.getMetas(), idMap, intId);
|
||||
}
|
||||
// If the block doesn't exist, by default the registry will return AIR. That probably isn't what we want.
|
||||
// TODO: Assuming that Registry.BLOCK.getDefaultId() == "minecraft:air" here
|
||||
private static void applyMetas(Block block, Set<Integer> metas, Reference2ObjectMap<Block, Int2IntMap> idMap, int intId) {
|
||||
if (block == null || block == Blocks.air) {
|
||||
return;
|
||||
}
|
||||
|
||||
Set<Integer> metas = entry.getMetas();
|
||||
|
||||
Int2IntMap metaMap = idMap.get(block);
|
||||
if (metaMap == null) {
|
||||
metaMap = new Int2IntOpenHashMap();
|
||||
@@ -94,15 +117,18 @@ public class BlockMaterialMapping {
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Block resolveBlock(NamespacedId id) {
|
||||
final ResourceLocation resourceLocation = new ResourceLocation(id.getNamespace(), id.getName());
|
||||
return (Block) Block.blockRegistry.getObject(resourceLocation.toString());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user