mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-17 11:05:04 +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
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user