use of gregtech.api.unification.material.Material in project GregTech by GregTechCEu.
the class ModHandler method getRecyclingIngredients.
public static ItemMaterialInfo getRecyclingIngredients(int outputCount, Object... recipe) {
Map<Character, Integer> inputCountMap = new HashMap<>();
Map<Material, Long> materialStacksExploded = new HashMap<>();
int itr = 0;
while (recipe[itr] instanceof String) {
String s = (String) recipe[itr];
for (char c : s.toCharArray()) {
// skip tools
if (getToolNameByCharacter(c) != null)
continue;
int count = inputCountMap.getOrDefault(c, 0);
inputCountMap.put(c, count + 1);
}
itr++;
}
char lastChar = ' ';
for (int i = itr; i < recipe.length; i++) {
Object ingredient = recipe[i];
// Track the current working ingredient symbol
if (ingredient instanceof Character) {
lastChar = (char) ingredient;
continue;
}
// by an earlier method call parsing the recipe.
if (lastChar == ' ')
return null;
ItemStack stack;
if (ingredient instanceof MetaItem.MetaValueItem) {
stack = ((MetaItem<?>.MetaValueItem) ingredient).getStackForm();
} else if (ingredient instanceof UnificationEntry) {
stack = OreDictUnifier.get((UnificationEntry) ingredient);
} else if (ingredient instanceof ItemStack) {
stack = (ItemStack) ingredient;
} else if (ingredient instanceof Item) {
stack = new ItemStack((Item) ingredient, 1);
} else if (ingredient instanceof Block) {
stack = new ItemStack((Block) ingredient, 1);
} else if (ingredient instanceof String) {
stack = OreDictUnifier.get((String) ingredient);
} else
// throw out bad entries
continue;
BiConsumer<MaterialStack, Character> func = (ms, c) -> {
long amount = materialStacksExploded.getOrDefault(ms.material, 0L);
materialStacksExploded.put(ms.material, (ms.amount * inputCountMap.get(c)) + amount);
};
// First try to get ItemMaterialInfo
ItemMaterialInfo info = OreDictUnifier.getMaterialInfo(stack);
if (info != null) {
for (MaterialStack ms : info.getMaterials()) {
if (!(ms.material instanceof MarkerMaterial))
func.accept(ms, lastChar);
}
continue;
}
// Then try to get a single Material (UnificationEntry needs this, for example)
MaterialStack materialStack = OreDictUnifier.getMaterial(stack);
if (materialStack != null && !(materialStack.material instanceof MarkerMaterial))
func.accept(materialStack, lastChar);
// Gather any secondary materials if this item has an OrePrefix
OrePrefix prefix = OreDictUnifier.getPrefix(stack);
if (prefix != null && !prefix.secondaryMaterials.isEmpty()) {
for (MaterialStack ms : prefix.secondaryMaterials) {
func.accept(ms, lastChar);
}
}
}
return new ItemMaterialInfo(materialStacksExploded.entrySet().stream().map(e -> new MaterialStack(e.getKey(), e.getValue() / outputCount)).sorted(Comparator.comparingLong(m -> -m.amount)).collect(Collectors.toList()));
}
use of gregtech.api.unification.material.Material in project GregTech by GregTechCEu.
the class ItemBlockMaterialPipe method getItemStackDisplayName.
@Nonnull
@SuppressWarnings("unchecked")
@Override
public String getItemStackDisplayName(@Nonnull ItemStack stack) {
PipeType pipeType = blockPipe.getItemPipeType(stack);
Material material = ((BlockMaterialPipe<PipeType, NodeDataType, ?>) blockPipe).getItemMaterial(stack);
return material == null ? " " : pipeType.getOrePrefix().getLocalNameForItem(material);
}
use of gregtech.api.unification.material.Material in project GregTech by GregTechCEu.
the class OreDictUnifier method getMaterial.
@Nullable
public static MaterialStack getMaterial(ItemStack itemStack) {
if (itemStack.isEmpty())
return null;
ItemAndMetadata simpleItemStack = new ItemAndMetadata(itemStack);
UnificationEntry entry = stackUnificationInfo.get(simpleItemStack);
if (entry != null) {
Material entryMaterial = entry.material;
if (entryMaterial == null) {
entryMaterial = entry.orePrefix.materialType;
}
if (entryMaterial != null) {
return new MaterialStack(entryMaterial, entry.orePrefix.getMaterialAmount(entryMaterial));
}
}
ItemMaterialInfo info = materialUnificationInfo.get(simpleItemStack);
return info == null ? null : info.getMaterial().copy();
}
use of gregtech.api.unification.material.Material in project GregTech by GregTechCEu.
the class OrePrefix method runGeneratedMaterialHandlers.
private void runGeneratedMaterialHandlers() {
currentProcessingPrefix.set(this);
for (Material registeredMaterial : generatedMaterials) {
currentMaterial.set(registeredMaterial);
for (IOreRegistrationHandler registrationHandler : oreProcessingHandlers) {
registrationHandler.processMaterial(this, registeredMaterial);
}
currentMaterial.set(null);
}
// clear generated materials for next pass
generatedMaterials.clear();
currentProcessingPrefix.set(null);
}
use of gregtech.api.unification.material.Material in project GregTech by GregTechCEu.
the class FrameBakedModel method getQuads.
@Override
@Nonnull
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
List<BakedQuad> quads = new ArrayList<>();
if (side == null)
return quads;
if (state != null) {
Material material = state.getValue(((BlockFrame) state.getBlock()).variantProperty);
Map<EnumFacing, BakedQuad> materialFace = materialFaces.get(material.getMaterialIconSet());
if (materialFace == null) {
materialFaces.put(material.getMaterialIconSet(), materialFace = new Object2ObjectOpenHashMap<>());
}
BakedQuad materialFaceQuad = materialFace.get(side);
if (materialFaceQuad == null) {
materialFace.put(side, materialFaceQuad = ModelFactory.getBakery().makeBakedQuad(new Vector3f(0F, 0F, 0F), new Vector3f(16F, 16F, 16F), new BlockPartFace(side, 1, "", new BlockFaceUV(new float[] { 0.0F, 0.0F, 16.0F, 16.0F, 0.0F, 0.0F, 16.0F, 16.0F }, 0)), ModelLoader.defaultTextureGetter().apply(MaterialIconType.frameGt.getBlockPath(material.getMaterialIconSet())), side, ModelRotation.X0_Y0, null, true, true));
}
quads.add(materialFaceQuad);
particle.set(materialFaceQuad.getSprite());
} else {
ItemStack stack = FrameModelItemOverride.INSTANCE.stack.get();
if (!stack.isEmpty()) {
BlockFrame frame = (BlockFrame) ((ItemBlock) stack.getItem()).getBlock();
IBlockState frameState = frame.getDefaultState().withProperty(frame.variantProperty, frame.variantProperty.getAllowedValues().get(stack.getMetadata()));
for (EnumFacing face : EnumFacing.VALUES) {
quads.addAll(getQuads(frameState, face, rand));
}
}
}
return quads;
}
Aggregations