use of org.spongepowered.api.item.ItemTypes in project core by CubeEngine.
the class MaterialMatcher method buildVariantMap.
private Map<BlockType, Map<String, BlockState>> buildVariantMap() {
Map<BlockType, Map<String, BlockState>> blockStateItemsByType = new HashMap<>();
for (Entry<String, BlockState> entry : blockStateItems.entrySet()) {
BlockType itemType = entry.getValue().getType();
Map<String, BlockState> itemTypes = blockStateItemsByType.computeIfAbsent(itemType, k -> new HashMap<>());
itemTypes.put(entry.getKey(), entry.getValue());
}
Map<BlockType, Map<String, BlockState>> variants = new HashMap<>();
blockStateItemsByType.entrySet().stream().filter(e -> e.getValue().size() != 1).forEach(e -> {
Map<String, Set<String>> variantNames = new HashMap<>();
Map<List<String>, BlockState> fullVariant = new HashMap<>();
for (Entry<String, BlockState> entry : e.getValue().entrySet()) {
String variant = entry.getKey();
variant = variant.substring(variant.indexOf("[") + 1, variant.indexOf("]"));
// multiple variants
String[] split = variant.split(",");
fullVariant.put(Arrays.asList(split), entry.getValue());
for (String variantEntry : split) {
String[] variantEntryPart = variantEntry.split("=");
Set<String> variantValues = variantNames.computeIfAbsent(variantEntryPart[0], k -> new HashSet<>());
variantValues.add(variantEntryPart[1]);
}
}
for (Entry<String, Set<String>> entry : variantNames.entrySet()) {
if (entry.getKey().equals("axis") || entry.getKey().equals("facing") || entry.getKey().equals("half") || entry.getKey().equals("shape") || entry.getKey().equals("open") || entry.getKey().equals("powered") || entry.getKey().equals("stage") || entry.getKey().equals("decayable")) {
Map<List<String>, BlockState> filtered = new HashMap<>();
for (Entry<List<String>, BlockState> offender : fullVariant.entrySet()) {
List<String> key = new ArrayList<>(offender.getKey());
for (String fv : entry.getValue()) {
key.remove(entry.getKey() + "=" + fv);
}
if (!key.isEmpty()) {
filtered.put(key, offender.getValue());
}
}
fullVariant = filtered;
}
if (entry.getValue().size() == 1) {
String singleVariant = entry.getKey() + "=" + entry.getValue().iterator().next();
fullVariant = fullVariant.entrySet().stream().collect(Collectors.toMap(fv -> {
List<String> split = new ArrayList<>(fv.getKey());
split.remove(singleVariant);
return split;
}, Entry::getValue));
}
}
for (Entry<List<String>, BlockState> variant : fullVariant.entrySet()) {
if (variant.getKey().size() > 1) {
System.out.print(e.getKey().getName() + " Has multiple Variants:");
for (String s : variant.getKey()) {
System.out.print(" " + s);
}
System.out.print("\n");
}
}
variants.put(e.getKey(), fullVariant.entrySet().stream().collect(Collectors.toMap(en -> String.join(" ", en.getKey().stream().map(s -> s.split("=")[1]).collect(toList())), Entry::getValue)));
});
/*
for (Entry<ItemType, Map<String, ItemStack>> variant : variants.entrySet())
{
System.out.print(variant.getKey().getName() + ":\n");
for (Entry<String, ItemStack> entry : variant.getValue().entrySet())
{
System.out.print(" " + entry.getKey() + ": " + entry.getValue().getTranslation().get() + "\n");
}
}
*/
return variants;
}
Aggregations