use of gregtech.api.unification.stack.UnificationEntry 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.UnificationEntry 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.UnificationEntry 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.UnificationEntry 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.UnificationEntry in project GregTech by GregTechCE.
the class ProcessingShaping method registerOre.
public void registerOre(UnificationEntry entry, String modName, SimpleItemStack simpleStack) {
ItemStack stack = simpleStack.asItemStack();
long materialMass = entry.material.getMass();
int amount = (int) (entry.orePrefix.materialAmount / M);
int voltageMultiplier;
if ((entry.material instanceof MetalMaterial) && ((MetalMaterial) entry.material).blastFurnaceTemperature >= 2800) {
voltageMultiplier = 64;
} else {
voltageMultiplier = 16;
}
if (!(amount > 0 && amount <= 64 && entry.orePrefix.materialAmount % M == 0L)) {
return;
}
if (entry.material instanceof MetalMaterial && !entry.material.hasFlag(NO_SMELTING)) {
if (entry.material.hasFlag(NO_SMASHING)) {
voltageMultiplier /= 4;
} else if (entry.orePrefix.name().startsWith(OrePrefix.dust.name())) {
return;
}
MetalMaterial smeltInto = ((MetalMaterial) entry.material).smeltInto;
if (!OrePrefix.block.isIgnored(smeltInto)) {
RecipeMap.EXTRUDER_RECIPES.recipeBuilder().inputs(GTUtility.copyAmount(9, stack)).notConsumable(MetaItems.SHAPE_EXTRUDER_BLOCK).outputs(OreDictUnifier.get(OrePrefix.block, smeltInto, amount)).duration(10 * amount).EUt(8 * voltageMultiplier).buildAndRegister();
RecipeMap.ALLOY_SMELTER_RECIPES.recipeBuilder().inputs(GTUtility.copyAmount(9, stack)).notConsumable(MetaItems.SHAPE_MOLD_BLOCK).outputs(OreDictUnifier.get(OrePrefix.block, smeltInto, amount)).duration(5 * amount).EUt(4 * voltageMultiplier).buildAndRegister();
}
if (entry.material != smeltInto) {
RecipeMap.EXTRUDER_RECIPES.recipeBuilder().inputs(GTUtility.copyAmount(1, stack)).notConsumable(MetaItems.SHAPE_EXTRUDER_INGOT).outputs(OreDictUnifier.get(OrePrefix.ingot, smeltInto, amount)).duration(10).EUt(4 * voltageMultiplier).buildAndRegister();
}
RecipeMap.EXTRUDER_RECIPES.recipeBuilder().inputs(GTUtility.copyAmount(1, stack)).notConsumable(MetaItems.SHAPE_EXTRUDER_PLATE).outputs(OreDictUnifier.get(OrePrefix.plate, smeltInto, amount)).duration((int) Math.max(materialMass * amount, amount)).EUt(8 * voltageMultiplier).buildAndRegister();
if (amount * 2 <= 64) {
RecipeMap.EXTRUDER_RECIPES.recipeBuilder().inputs(GTUtility.copyAmount(1, stack)).notConsumable(MetaItems.SHAPE_EXTRUDER_ROD).outputs(OreDictUnifier.get(OrePrefix.stick, smeltInto, amount * 2)).duration((int) Math.max(materialMass * 2L * amount, amount)).EUt(6 * voltageMultiplier).buildAndRegister();
}
if (amount * 2 <= 64) {
RecipeMap.EXTRUDER_RECIPES.recipeBuilder().inputs(GTUtility.copyAmount(1, stack)).notConsumable(MetaItems.SHAPE_EXTRUDER_WIRE).outputs(OreDictUnifier.get(OrePrefix.wireGt01, smeltInto, amount * 2)).duration((int) Math.max(materialMass * 2L * amount, amount)).EUt(6 * voltageMultiplier).buildAndRegister();
}
if (amount * 8 <= 64) {
RecipeMap.EXTRUDER_RECIPES.recipeBuilder().inputs(GTUtility.copyAmount(1, stack)).notConsumable(MetaItems.SHAPE_EXTRUDER_BOLT).outputs(OreDictUnifier.get(OrePrefix.bolt, smeltInto, amount * 8)).duration((int) Math.max(materialMass * 2L * amount, amount)).EUt(8 * voltageMultiplier).buildAndRegister();
}
if (amount * 4 <= 64) {
RecipeMap.EXTRUDER_RECIPES.recipeBuilder().inputs(GTUtility.copyAmount(1, stack)).notConsumable(MetaItems.SHAPE_EXTRUDER_RING).outputs(OreDictUnifier.get(OrePrefix.ring, smeltInto, amount * 4)).duration((int) Math.max(materialMass * 2L * amount, amount)).EUt(6 * voltageMultiplier).buildAndRegister();
if (!entry.material.hasFlag(NO_SMASHING)) {
ModHandler.addShapedRecipe("ring_" + entry.material, OreDictUnifier.get(OrePrefix.ring, entry.material), "h ", " X", 'X', new UnificationEntry(OrePrefix.stick, entry.material));
}
}
RecipeMap.EXTRUDER_RECIPES.recipeBuilder().inputs(GTUtility.copyAmount(2, stack)).notConsumable(MetaItems.SHAPE_EXTRUDER_SWORD).outputs(OreDictUnifier.get(OrePrefix.toolHeadSword, smeltInto, amount)).duration((int) Math.max(materialMass * 2L * amount, amount)).EUt(8 * voltageMultiplier).buildAndRegister();
RecipeMap.EXTRUDER_RECIPES.recipeBuilder().inputs(GTUtility.copyAmount(3, stack)).notConsumable(MetaItems.SHAPE_EXTRUDER_PICKAXE).outputs(OreDictUnifier.get(OrePrefix.toolHeadPickaxe, smeltInto, amount)).duration((int) Math.max(materialMass * 3L * amount, amount)).EUt(8 * voltageMultiplier).buildAndRegister();
RecipeMap.EXTRUDER_RECIPES.recipeBuilder().inputs(GTUtility.copyAmount(1, stack)).notConsumable(MetaItems.SHAPE_EXTRUDER_SHOVEL).outputs(OreDictUnifier.get(OrePrefix.toolHeadShovel, smeltInto, amount)).duration((int) Math.max(materialMass * amount, amount)).EUt(8 * voltageMultiplier).buildAndRegister();
RecipeMap.EXTRUDER_RECIPES.recipeBuilder().inputs(GTUtility.copyAmount(3, stack)).notConsumable(MetaItems.SHAPE_EXTRUDER_AXE).outputs(OreDictUnifier.get(OrePrefix.toolHeadAxe, smeltInto, amount)).duration((int) Math.max(materialMass * 3L * amount, amount)).EUt(8 * voltageMultiplier).buildAndRegister();
RecipeMap.EXTRUDER_RECIPES.recipeBuilder().inputs(GTUtility.copyAmount(2, stack)).notConsumable(MetaItems.SHAPE_EXTRUDER_HOE).outputs(OreDictUnifier.get(OrePrefix.toolHeadHoe, smeltInto, amount)).duration((int) Math.max(materialMass * 2L * amount, amount)).EUt(8 * voltageMultiplier).buildAndRegister();
RecipeMap.EXTRUDER_RECIPES.recipeBuilder().inputs(GTUtility.copyAmount(6, stack)).notConsumable(MetaItems.SHAPE_EXTRUDER_HAMMER).outputs(OreDictUnifier.get(OrePrefix.toolHeadHammer, smeltInto, amount)).duration((int) Math.max(materialMass * 6L * amount, amount)).EUt(8 * voltageMultiplier).buildAndRegister();
RecipeMap.EXTRUDER_RECIPES.recipeBuilder().inputs(GTUtility.copyAmount(2, stack)).notConsumable(MetaItems.SHAPE_EXTRUDER_FILE).outputs(OreDictUnifier.get(OrePrefix.toolHeadFile, smeltInto, amount)).duration((int) Math.max(materialMass * 2L * amount, amount)).EUt(8 * voltageMultiplier).buildAndRegister();
RecipeMap.EXTRUDER_RECIPES.recipeBuilder().inputs(GTUtility.copyAmount(2, stack)).notConsumable(MetaItems.SHAPE_EXTRUDER_SAW).outputs(OreDictUnifier.get(OrePrefix.toolHeadSaw, smeltInto, amount)).duration((int) Math.max(materialMass * 2L * amount, amount)).EUt(8 * voltageMultiplier).buildAndRegister();
RecipeMap.EXTRUDER_RECIPES.recipeBuilder().inputs(GTUtility.copyAmount(4, stack)).notConsumable(MetaItems.SHAPE_EXTRUDER_GEAR).outputs(OreDictUnifier.get(OrePrefix.gear, smeltInto, amount)).duration((int) Math.max(materialMass * 5L * amount, amount)).EUt(8 * voltageMultiplier).buildAndRegister();
RecipeMap.ALLOY_SMELTER_RECIPES.recipeBuilder().inputs(GTUtility.copyAmount(2, stack)).notConsumable(MetaItems.SHAPE_MOLD_PLATE).outputs(OreDictUnifier.get(OrePrefix.plate, smeltInto, amount)).duration((int) Math.max(materialMass * 2L * amount, amount)).EUt(2 * voltageMultiplier).buildAndRegister();
RecipeMap.ALLOY_SMELTER_RECIPES.recipeBuilder().inputs(GTUtility.copyAmount(8, stack)).notConsumable(MetaItems.SHAPE_MOLD_GEAR).outputs(OreDictUnifier.get(OrePrefix.gear, smeltInto, amount)).duration((int) Math.max(materialMass * 10L * amount, amount)).EUt(2 * voltageMultiplier).buildAndRegister();
if (entry.material == Materials.Steel) {
// if (amount * 2 <= 64) {
// RecipeMap.EXTRUDER_RECIPES.recipeBuilder()
// .inputs(GTUtility.copyAmount(1, stack))
// .notConsumable(MetaItems.SHAPE_EXTRUDER_CASING)
// .outputs(ModHandler.IC2.getIC2Item(ItemName.casing, CasingResourceType.steel, amount * 2))
// .duration(amount * 32)
// .EUt(3 * voltageMultiplier)
// .buildAndRegister();
// }
// if (amount * 2 <= 64) {
// RecipeMap.ALLOY_SMELTER_RECIPES.recipeBuilder()
// .inputs(GTUtility.copyAmount(2, stack))
// .notConsumable(MetaItems.SHAPE_MOLD_CASING)
// .outputs(ModHandler.IC2.getIC2Item(ItemName.casing, CasingResourceType.steel, amount * 3))
// .duration(amount * 128)
// .EUt(voltageMultiplier)
// .buildAndRegister();
// }
} else if (entry.material == Materials.Iron || entry.material == Materials.WroughtIron) {
// }
if (amount * 31 <= 64) {
RecipeMap.ALLOY_SMELTER_RECIPES.recipeBuilder().inputs(GTUtility.copyAmount(31, stack)).notConsumable(MetaItems.SHAPE_MOLD_ANVIL).outputs(new ItemStack(Blocks.ANVIL, 1, 0)).duration(amount * 512).EUt(4 * voltageMultiplier).buildAndRegister();
}
} else if (entry.material == Materials.Tin) {
// RecipeMap.EXTRUDER_RECIPES.recipeBuilder()
// .inputs(GTUtility.copyAmount(2, stack))
// .notConsumable(MetaItems.SHAPE_EXTRUDER_CELL)
// .outputs(ModHandler.IC2.getIC2Item(ItemName.fluid_cell, amount))
// .duration(amount * 128)
// .EUt(32)
// .buildAndRegister();
//
// if (amount * 2 <= 64) {
// RecipeMap.EXTRUDER_RECIPES.recipeBuilder()
// .inputs(GTUtility.copyAmount(1, stack))
// .notConsumable(MetaItems.SHAPE_EXTRUDER_CASING)
// .outputs(ModHandler.IC2.getIC2Item(ItemName.casing, CasingResourceType.tin, amount * 2))
// .duration(amount * 32)
// .EUt(3 * voltageMultiplier)
// .buildAndRegister();
//
// }
// if (amount * 2 <= 64) {
// RecipeMap.ALLOY_SMELTER_RECIPES.recipeBuilder()
// .inputs(GTUtility.copyAmount(2, stack))
// .notConsumable(MetaItems.SHAPE_MOLD_CASING)
// .outputs(ModHandler.IC2.getIC2Item(ItemName.casing, CasingResourceType.tin, amount * 3))
// .duration(amount * 128)
// .EUt(voltageMultiplier)
// .buildAndRegister();
// }
} else if (entry.material == Materials.Lead) {
// if (amount * 2 <= 64) {
// RecipeMap.EXTRUDER_RECIPES.recipeBuilder()
// .inputs(GTUtility.copyAmount(1, stack))
// .notConsumable(MetaItems.SHAPE_EXTRUDER_CASING)
// .outputs(ModHandler.IC2.getIC2Item(ItemName.casing, CasingResourceType.lead, amount * 2))
// .duration(amount * 32)
// .EUt(3 * voltageMultiplier)
// .buildAndRegister();
// }
// if (amount * 2 <= 64) {
// RecipeMap.ALLOY_SMELTER_RECIPES.recipeBuilder()
// .inputs(GTUtility.copyAmount(2, stack))
// .notConsumable(MetaItems.SHAPE_MOLD_CASING)
// .outputs(ModHandler.IC2.getIC2Item(ItemName.casing, CasingResourceType.lead, amount * 3))
// .duration(amount * 128)
// .EUt(voltageMultiplier)
// .buildAndRegister();
// }
} else if (entry.material == Materials.Copper || entry.material == Materials.AnnealedCopper) {
// if (amount * 2 <= 64) {
// RecipeMap.EXTRUDER_RECIPES.recipeBuilder()
// .inputs(GTUtility.copyAmount(1, stack))
// .notConsumable(MetaItems.SHAPE_EXTRUDER_CASING)
// .outputs(ModHandler.IC2.getIC2Item(ItemName.casing, CasingResourceType.copper, amount * 2))
// .duration(amount * 32)
// .EUt(3 * voltageMultiplier)
// .buildAndRegister();
// }
// if (amount * 2 <= 64) {
// RecipeMap.ALLOY_SMELTER_RECIPES.recipeBuilder()
// .inputs(GTUtility.copyAmount(2, stack))
// .notConsumable(MetaItems.SHAPE_MOLD_CASING)
// .outputs(ModHandler.IC2.getIC2Item(ItemName.casing, CasingResourceType.copper, amount * 3))
// .duration(amount * 128)
// .EUt(voltageMultiplier)
// .buildAndRegister();
// }
} else if (entry.material == Materials.Bronze) {
// if (amount * 2 <= 64) {
// RecipeMap.EXTRUDER_RECIPES.recipeBuilder()
// .inputs(GTUtility.copyAmount(1, stack))
// .notConsumable(MetaItems.SHAPE_EXTRUDER_CASING)
// .outputs(ModHandler.IC2.getIC2Item(ItemName.casing, CasingResourceType.bronze, amount * 2))
// .duration(amount * 32)
// .EUt(3 * voltageMultiplier)
// .buildAndRegister();
// }
// if (amount * 2 <= 64) {
// RecipeMap.ALLOY_SMELTER_RECIPES.recipeBuilder()
// .inputs(GTUtility.copyAmount(2, stack))
// .notConsumable(MetaItems.SHAPE_MOLD_CASING)
// .outputs(ModHandler.IC2.getIC2Item(ItemName.casing, CasingResourceType.bronze, amount * 3))
// .duration(amount * 128)
// .EUt(voltageMultiplier)
// .buildAndRegister();
// }
} else if (entry.material == Materials.Gold) {
// if (amount * 2 <= 64) {
// RecipeMap.EXTRUDER_RECIPES.recipeBuilder()
// .inputs(GTUtility.copyAmount(1, stack))
// .notConsumable(MetaItems.SHAPE_EXTRUDER_CASING)
// .outputs(ModHandler.IC2.getIC2Item(ItemName.casing, CasingResourceType.gold, amount * 2))
// .duration(amount * 32)
// .EUt(3 * voltageMultiplier)
// .buildAndRegister();
// }
// if (amount * 2 <= 64) {
// RecipeMap.ALLOY_SMELTER_RECIPES.recipeBuilder()
// .inputs(GTUtility.copyAmount(2, stack))
// .notConsumable(MetaItems.SHAPE_MOLD_CASING)
// .outputs(ModHandler.IC2.getIC2Item(ItemName.casing, CasingResourceType.gold, amount * 3))
// .duration(amount * 128)
// .EUt(voltageMultiplier)
// .buildAndRegister();
// }
}
} else if (entry.material == Materials.Glass) {
RecipeMap.EXTRUDER_RECIPES.recipeBuilder().inputs(GTUtility.copyAmount(1, stack)).notConsumable(MetaItems.SHAPE_EXTRUDER_PLATE).outputs(OreDictUnifier.get(OrePrefix.plate, entry.material, amount)).duration((int) Math.max(materialMass * amount, amount)).EUt(8 * voltageMultiplier).buildAndRegister();
RecipeMap.EXTRUDER_RECIPES.recipeBuilder().inputs(GTUtility.copyAmount(1, stack)).notConsumable(MetaItems.SHAPE_EXTRUDER_BOTTLE).outputs(new ItemStack(Items.GLASS_BOTTLE, 1)).duration(amount * 32).EUt(16).buildAndRegister();
RecipeMap.ALLOY_SMELTER_RECIPES.recipeBuilder().inputs(GTUtility.copyAmount(1, stack)).notConsumable(MetaItems.SHAPE_MOLD_BOTTLE).outputs(new ItemStack(Items.GLASS_BOTTLE, 1)).duration(amount * 64).EUt(4).buildAndRegister();
}
}
Aggregations