use of gregtech.api.unification.stack.SimpleItemStack in project GregTech by GregTechCE.
the class OreDictUnifier method onItemRegistration.
@SubscribeEvent
public static void onItemRegistration(OreDictionary.OreRegisterEvent event) {
SimpleItemStack simpleItemStack = new SimpleItemStack(event.getOre());
String oreName = event.getName();
// cache this registration by name
stackOreDictName.computeIfAbsent(simpleItemStack, k -> new HashSet<>()).add(oreName);
// and try to transform registration name into OrePrefix + Material pair
OrePrefix orePrefix = OrePrefix.getPrefix(oreName);
Material material = null;
if (orePrefix == null) {
// split ore dict name to parts
// oreBasalticMineralSand -> ore, Basaltic, Mineral, Sand
ArrayList<String> splits = new ArrayList<>();
StringBuilder builder = new StringBuilder();
for (char character : oreName.toCharArray()) {
if (Character.isUpperCase(character)) {
if (builder.length() > 0) {
splits.add(builder.toString());
builder = new StringBuilder().append(character);
} else
splits.add(Character.toString(character));
} else
builder.append(character);
}
if (builder.length() > 0) {
splits.add(builder.toString());
}
// try to combine in different manners
// oreBasaltic MineralSand , ore BasalticMineralSand
StringBuilder buffer = new StringBuilder();
for (int i = 0; i < splits.size(); i++) {
buffer.append(splits.get(i));
// ore -> OrePrefix.ore
OrePrefix maybePrefix = OrePrefix.getPrefix(buffer.toString());
// BasalticMineralSand
String possibleMaterialName = Joiner.on("").join(splits.subList(i + 1, splits.size()));
// basaltic_mineral_sand
String underscoreName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, possibleMaterialName);
// Materials.BasalticSand
Material possibleMaterial = Material.MATERIAL_REGISTRY.getObject(underscoreName);
if (maybePrefix != null && possibleMaterial != null) {
orePrefix = maybePrefix;
material = possibleMaterial;
break;
}
}
}
// finally register item
if (orePrefix != null && (material != null || orePrefix.isSelfReferencing)) {
UnificationEntry unificationEntry = new UnificationEntry(orePrefix, material);
stackUnificationInfo.put(simpleItemStack, unificationEntry);
stackUnificationItems.computeIfAbsent(unificationEntry, p -> new ArrayList<>()).add(simpleItemStack);
orePrefix.processOreRegistration(material);
}
}
use of gregtech.api.unification.stack.SimpleItemStack in project GregTech by GregTechCE.
the class OreDictUnifier method getByProducts.
@Nullable
public static ImmutableList<MaterialStack> getByProducts(ItemStack itemStack) {
if (itemStack.isEmpty())
return null;
SimpleItemStack simpleItemStack = new SimpleItemStack(itemStack);
UnificationEntry entry = stackUnificationInfo.get(simpleItemStack);
if (entry != null && entry.material != null)
return ImmutableList.of(new MaterialStack(entry.material, entry.orePrefix.materialAmount), entry.orePrefix.secondaryMaterial);
ItemMaterialInfo info = materialUnificationInfo.get(simpleItemStack);
return info == null ? null : info.byProducts;
}
use of gregtech.api.unification.stack.SimpleItemStack in project GregTech by GregTechCE.
the class OreDictUnifier method get.
public static ItemStack get(OrePrefix orePrefix, Material material, int stackSize) {
UnificationEntry unificationEntry = new UnificationEntry(orePrefix, material);
if (!stackUnificationItems.containsKey(unificationEntry) || !unificationEntry.orePrefix.isUnificationEnabled)
return ItemStack.EMPTY;
ArrayList<SimpleItemStack> keys = stackUnificationItems.get(unificationEntry);
keys.sort(Comparator.comparing(a -> a.item.delegate.name().getResourceDomain()));
return keys.size() > 0 ? keys.get(0).asItemStack(stackSize) : ItemStack.EMPTY;
}
use of gregtech.api.unification.stack.SimpleItemStack in project GregTech by GregTechCE.
the class OreDictUnifier method getPrefix.
@Nullable
public static OrePrefix getPrefix(ItemStack itemStack) {
if (itemStack.isEmpty())
return null;
SimpleItemStack simpleItemStack = new SimpleItemStack(itemStack);
UnificationEntry entry = stackUnificationInfo.get(simpleItemStack);
if (entry != null)
return entry.orePrefix;
return null;
}
use of gregtech.api.unification.stack.SimpleItemStack in project GregTech by GregTechCE.
the class OreDictUnifier method getMaterial.
@Nullable
public static MaterialStack getMaterial(ItemStack itemStack) {
if (itemStack.isEmpty())
return null;
SimpleItemStack simpleItemStack = new SimpleItemStack(itemStack);
UnificationEntry entry = stackUnificationInfo.get(simpleItemStack);
if (entry != null && entry.material != null)
return new MaterialStack(entry.material, entry.orePrefix.materialAmount);
ItemMaterialInfo info = materialUnificationInfo.get(simpleItemStack);
return info == null ? null : info.material.copy();
}
Aggregations