use of net.silentchaos512.gear.api.material.IMaterial in project Silent-Gear by SilentChaos512.
the class ShapelessCompoundPartRecipe method matches.
@Override
public boolean matches(CraftingContainer inv, Level worldIn) {
if (!this.getBaseRecipe().matches(inv, worldIn))
return false;
IMaterial first = null;
for (int i = 0; i < inv.getContainerSize(); ++i) {
ItemStack stack = inv.getItem(i);
MaterialInstance mat = MaterialInstance.from(stack);
if (mat != null) {
if (!mat.get().isCraftingAllowed(mat, item.getPartType(), this.getGearType(), inv)) {
return false;
}
// If classic mixing is disabled, all materials must be the same
if (first == null) {
first = mat.get();
} else if (!Config.Common.allowLegacyMaterialMixing.get() && first != mat.get()) {
return false;
}
}
}
return true;
}
use of net.silentchaos512.gear.api.material.IMaterial in project Silent-Gear by SilentChaos512.
the class MaterialInstance method readShorthand.
@Nullable
public static MaterialInstance readShorthand(String str) {
if (str.contains("#")) {
String[] parts = str.split("#");
ResourceLocation id = SilentGear.getIdWithDefaultNamespace(parts[0]);
IMaterial material = MaterialManager.get(id);
if (material != null) {
MaterialGrade grade = MaterialGrade.fromString(parts[1]);
return new MaterialInstance(material, grade);
}
return null;
}
ResourceLocation id = SilentGear.getIdWithDefaultNamespace(str);
IMaterial material = MaterialManager.get(id);
if (material != null) {
return new MaterialInstance(material);
}
return null;
}
use of net.silentchaos512.gear.api.material.IMaterial in project Silent-Gear by SilentChaos512.
the class CompoundMaterialItem method getSubMaterials.
public static MaterialList getSubMaterials(ItemStack stack) {
MaterialList ret = MaterialList.empty();
ListTag listNbt = stack.getOrCreateTag().getList(NBT_MATERIALS, Tag.TAG_STRING);
if (!listNbt.isEmpty()) {
for (Tag nbt : listNbt) {
IMaterial mat = MaterialManager.get(SilentGear.getIdWithDefaultNamespace(nbt.getAsString()));
if (mat != null) {
ret.add(MaterialInstance.of(mat));
}
}
} else {
ListTag list = stack.getOrCreateTag().getList(NBT_MATERIALS, Tag.TAG_COMPOUND);
return MaterialList.deserializeNbt(list);
}
return ret;
}
use of net.silentchaos512.gear.api.material.IMaterial 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.IMaterial 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;
}
Aggregations