use of net.silentchaos512.gear.api.material.IMaterialInstance in project Silent-Gear by SilentChaos512.
the class CustomMaterialItem method fillItemCategory.
@Override
public void fillItemCategory(CreativeModeTab group, NonNullList<ItemStack> items) {
if (allowdedIn(group)) {
items.add(create(LazyMaterialInstance.of(Const.Materials.EXAMPLE)));
for (IMaterial material : MaterialManager.getValues()) {
if (material instanceof CustomCompoundMaterial) {
IMaterialInstance mat = MaterialInstance.of(material);
ItemStack stack = create(mat);
if (mat.getIngredient().test(stack)) {
items.add(stack);
}
}
}
}
}
use of net.silentchaos512.gear.api.material.IMaterialInstance in project Silent-Gear by SilentChaos512.
the class FragmentItem method getMaterial.
@Nullable
public static IMaterialInstance getMaterial(ItemStack stack) {
if (stack.getOrCreateTag().contains(NBT_MATERIAL, Tag.TAG_COMPOUND)) {
return MaterialInstance.read(stack.getOrCreateTag().getCompound(NBT_MATERIAL));
}
// Old, pre-compound style
ResourceLocation id = ResourceLocation.tryParse(stack.getOrCreateTag().getString(NBT_MATERIAL));
IMaterial material = MaterialManager.get(id);
if (material != null) {
return MaterialInstance.of(material);
}
return null;
}
use of net.silentchaos512.gear.api.material.IMaterialInstance in project Silent-Gear by SilentChaos512.
the class CombineFragmentsRecipe method assemble.
@Override
public ItemStack assemble(CraftingContainer craftingInventory) {
StackList list = StackList.from(craftingInventory);
ItemStack stack = list.firstOfType(FragmentItem.class);
if (stack.isEmpty())
return ItemStack.EMPTY;
IMaterialInstance material = FragmentItem.getMaterial(stack);
if (material == null)
return ItemStack.EMPTY;
// Get the actual item the fragment came from (if present)
if (!material.getItem().isEmpty()) {
return material.getItem();
}
// Try to get an equivalent item from the material's ingredient
ItemStack[] matchingStacks = material.getIngredient().getItems();
if (matchingStacks.length < 1) {
if (material.getIngredient() instanceof ExclusionIngredient) {
// Get excluded ingredients if no others are available
ItemStack[] allMatches = ((ExclusionIngredient) material.getIngredient()).getMatchingStacksWithExclusions();
if (allMatches.length > 0) {
return allMatches[0];
}
}
return ItemStack.EMPTY;
}
return matchingStacks[0].copy();
}
use of net.silentchaos512.gear.api.material.IMaterialInstance in project Silent-Gear by SilentChaos512.
the class ConversionRecipe method readMaterials.
private static void readMaterials(FriendlyByteBuf buffer, ConversionRecipe recipe) {
int typeCount = buffer.readByte();
for (int i = 0; i < typeCount; ++i) {
PartType partType = PartType.get(buffer.readResourceLocation());
int matCount = buffer.readByte();
List<IMaterialInstance> list = new ArrayList<>(matCount);
for (int j = 0; j < matCount; ++j) {
list.add(LazyMaterialInstance.read(buffer));
}
recipe.resultMaterials.put(partType, list);
}
}
use of net.silentchaos512.gear.api.material.IMaterialInstance in project Silent-Gear by SilentChaos512.
the class SalvagingRecipe method salvage.
/**
* Salvages parts into their respective material items, or fragments if appropriate. This does
* not necessarily give back the original item used for the material, but an item that matches
* it.
*
* @param part The part
* @return The list of items to return
*/
public static List<ItemStack> salvage(PartData part) {
if (part.get() instanceof CompoundPart && part.getItem().getItem() instanceof CompoundPartItem) {
int craftedCount = ((CompoundPartItem) part.getItem().getItem()).getCraftedCount(part.getItem());
if (craftedCount < 1) {
SilentGear.LOGGER.warn("Compound part's crafted count is less than 1? {}", part.getItem());
return Collections.singletonList(part.getItem());
}
List<IMaterialInstance> materials = part.getMaterials();
Map<IMaterialInstance, Integer> fragments = new LinkedHashMap<>();
for (IMaterialInstance material : materials) {
int fragmentCount = 8 / craftedCount;
fragments.merge(material.onSalvage(), fragmentCount, Integer::sum);
}
List<ItemStack> ret = new ArrayList<>();
for (Map.Entry<IMaterialInstance, Integer> entry : fragments.entrySet()) {
IMaterialInstance material = entry.getKey();
int count = entry.getValue();
int fulls = count / 8;
int frags = count % 8;
if (fulls > 0) {
ret.add(material.getItem());
}
if (frags > 0) {
ret.add(ModItems.FRAGMENT.get().create(material, frags));
}
}
return ret;
}
return Collections.singletonList(part.getItem());
}
Aggregations