Add FlatteningMap and EntityFlatteningMap (#1635)

This commit is contained in:
Eclipse-Sol authored and GitHub committed 2026-04-18 09:20:24 -07:00
1 parent e5cd1372e7
commit 0db691db0b
5 files changed
+1469 -71

No files matched your search

@@ -6,7 +6,9 @@ import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
@@ -14,10 +16,16 @@ import java.util.Set;
public class BlockEntry {
private final NamespacedId id;
private final Set<Integer> metas;
private final Map<String, String> stateProperties;
public BlockEntry(NamespacedId id, Set<Integer> metas) {
public BlockEntry(NamespacedId id, Set<Integer> metas) {
this(id, metas, Collections.emptyMap());
}
public BlockEntry(NamespacedId id, Set<Integer> metas, Map<String, String> stateProperties) {
this.id = id;
this.metas = metas;
this.stateProperties = stateProperties;
}
/**
@@ -39,60 +47,66 @@ public class BlockEntry {
return new BlockEntry(new NamespacedId("minecraft", entry), Collections.emptySet());
}
// Examples of what we'll accept
// Examples of what we accept:
// stone
// stone:0
// minecraft:stone:0
// minecraft:stone:0,1,2 # Theoretically valid, but I haven't seen any examples in actual shaders
// minecraft:stone:0,1,2
// minecraft:furnace:lit=true (blockstate property)
// minecraft:oak_log:axis=y (blockstate property)
// Examples of what we don't (Yet?) accept - Seems to be from MC 1.8+
// minecraft:farmland:moisture=0
// minecraft:farmland:moisture=1
// minecraft:double_plant:half=lower
// minecraft:double_plant:half=upper
// minecraft:grass:snowy=true
// minecraft:unpowered_comparator:powered=false
// Less trivial case: no metas involved, just a namespace
//
// The first term MUST be a valid ResourceLocation component
// The second term, if it is not numeric, must be a valid ResourceLocation component.
if (splitStates.length == 2 && !StringUtils.isNumeric(splitStates[1].substring(0, 1))) {
// Less trivial case: no metas or state properties, just a namespace
if (splitStates.length == 2 && !StringUtils.isNumeric(splitStates[1].substring(0, 1))
&& !splitStates[1].contains("=")) {
return new BlockEntry(new NamespacedId(splitStates[0], splitStates[1]), Collections.emptySet());
}
// Complex case: One or more states involved...
// Complex case: metas and/or state properties
final int statesStart;
final NamespacedId id;
if (StringUtils.isNumeric(splitStates[1].substring(0, 1))) {
// We have an entry of the form "stone:0"
if (splitStates.length == 2) {
// "stone:0" or "stone:lit=true"
statesStart = 1;
id = new NamespacedId("minecraft", splitStates[0]);
} else if (StringUtils.isNumeric(splitStates[1].substring(0, 1)) || splitStates[1].contains("=")) {
// "stone:0:something" or "stone:lit=true:something" — unlikely but handle it
statesStart = 1;
id = new NamespacedId("minecraft", splitStates[0]);
} else {
// We have an entry of the form "minecraft:stone:0"
// "minecraft:stone:0" or "minecraft:furnace:lit=true"
statesStart = 2;
id = new NamespacedId(splitStates[0], splitStates[1]);
}
final Set<Integer> metas = new HashSet<>();
final Set<Integer> metas = new HashSet<>();
final Map<String, String> properties = new HashMap<>();
for (int index = statesStart; index < splitStates.length; index++) {
// Parse out one or more metadata ids
final String[] metaParts = splitStates[index].split(",");
String segment = splitStates[index];
for (String metaPart : metaParts) {
try {
metas.add(Integer.parseInt(metaPart));
} catch (NumberFormatException e) {
Iris.logger.warn("Warning: the block ID map entry \"" + entry + "\" could not be fully parsed:");
Iris.logger.warn("- Metadata ids must be a comma separated list of one or more integers, but "+ splitStates[index] + " is not of that form!");
}
}
if (segment.contains("=")) {
// Blockstate property: key=value
for (String prop : segment.split(",")) {
int eq = prop.indexOf('=');
if (eq > 0 && eq < prop.length() - 1) {
properties.put(prop.substring(0, eq), prop.substring(eq + 1));
}
}
} else {
// Metadata IDs: comma-separated integers
for (String metaPart : segment.split(",")) {
try {
metas.add(Integer.parseInt(metaPart));
} catch (NumberFormatException e) {
Iris.logger.warn("Warning: the block ID map entry \"" + entry + "\" could not be fully parsed:");
Iris.logger.warn("- Metadata ids must be a comma separated list of one or more integers, but " + segment + " is not of that form!");
}
}
}
}
return new BlockEntry(id, metas);
return new BlockEntry(id, metas, properties);
}
@Override
@@ -100,11 +114,11 @@ public class BlockEntry {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final BlockEntry that = (BlockEntry) o;
return Objects.equals(id, that.id) && Objects.equals(metas, that.metas);
return Objects.equals(id, that.id) && Objects.equals(metas, that.metas) && Objects.equals(stateProperties, that.stateProperties);
}
@Override
public int hashCode() {
return Objects.hash(id, metas);
return Objects.hash(id, metas, stateProperties);
}
}
@@ -0,0 +1,95 @@
package net.coderbot.iris.shaderpack.materialmap;
import java.util.HashMap;
import java.util.Map;
/**
* Maps modern entity names to their 1.7.10 equivalents.
*
* In 1.11+, entity IDs were changed to namespaced: "minecraft:cave_spider".
* In 1.7.10, entities are registered with names like "CaveSpider".
* Some entities were also renamed or split into multiple types.
*
* This map is used at lookup time: when a modern shader pack references an entity by its
* modern name, we resolve it to the 1.7.10 name that EntityList uses.
*/
public class EntityFlatteningMap {
/** Maps modern entity name -> 1.7.10 entity name. */
private static final Map<String, String> MODERN_TO_LEGACY = new HashMap<>();
static {
// Simple case changes
simple("Arrow", "arrow");
simple("Bat", "bat");
simple("Blaze", "blaze");
simple("Boat", "boat");
simple("Chicken", "chicken");
simple("Cow", "cow");
simple("Creeper", "creeper");
simple("Enderman", "enderman");
simple("Ghast", "ghast");
simple("Giant", "giant");
simple("Item", "item");
simple("Painting", "painting");
simple("Pig", "pig");
simple("Sheep", "sheep");
simple("Silverfish", "silverfish");
simple("Skeleton", "skeleton");
simple("Slime", "slime");
simple("Snowball", "snowball");
simple("Spider", "spider");
simple("Squid", "squid");
simple("Villager", "villager");
simple("Witch", "witch");
simple("Wolf", "wolf");
simple("Zombie", "zombie");
// Renamed entities
simple("CaveSpider", "cave_spider");
simple("EnderCrystal", "end_crystal");
simple("EnderDragon", "ender_dragon");
simple("EntityHorse", "horse");
simple("EyeOfEnderSignal", "eye_of_ender");
simple("FallingSand", "falling_block");
simple("Fireball", "fireball");
simple("FireworksRocketEntity", "firework_rocket");
simple("ItemFrame", "item_frame");
simple("LavaSlime", "magma_cube");
simple("LeashKnot", "leash_knot");
simple("MushroomCow", "mooshroom");
simple("Ozelot", "ocelot");
simple("PigZombie", "zombified_piglin");
simple("PrimedTnt", "tnt");
simple("SmallFireball", "small_fireball");
simple("SnowMan", "snow_golem");
simple("ThrownEnderpearl", "ender_pearl");
simple("ThrownExpBottle", "experience_bottle");
simple("ThrownPotion", "potion");
simple("VillagerGolem", "iron_golem");
simple("WitherBoss", "wither");
simple("WitherSkull", "wither_skull");
simple("XPOrb", "experience_orb");
// Minecarts
simple("MinecartRideable", "minecart");
simple("MinecartChest", "chest_minecart");
simple("MinecartCommandBlock", "command_block_minecart");
simple("MinecartFurnace", "furnace_minecart");
simple("MinecartHopper", "hopper_minecart");
simple("MinecartSpawner", "spawner_minecart");
simple("MinecartTNT", "tnt_minecart");
}
/**
* Returns the 1.7.10 entity name for a modern entity name, or null if no mapping exists.
* The input name should not include the "minecraft:" namespace prefix.
*/
public static String toLegacy(String modernName) {
return MODERN_TO_LEGACY.get(modernName);
}
private static void simple(String legacy, String modern) {
MODERN_TO_LEGACY.put(modern, legacy);
}
}
File diff suppressed because it is too large. Load diff