Search in sources :

Example 11 with IMaterial

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;
}
Also used : IMaterial(net.silentchaos512.gear.api.material.IMaterial) ItemStack(net.minecraft.world.item.ItemStack) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) LazyMaterialInstance(net.silentchaos512.gear.gear.material.LazyMaterialInstance)

Example 12 with IMaterial

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;
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) MaterialGrade(net.silentchaos512.gear.api.part.MaterialGrade) Nullable(javax.annotation.Nullable)

Example 13 with IMaterial

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;
}
Also used : IMaterial(net.silentchaos512.gear.api.material.IMaterial) MaterialList(net.silentchaos512.gear.api.material.MaterialList) Tag(net.minecraft.nbt.Tag) ListTag(net.minecraft.nbt.ListTag) ListTag(net.minecraft.nbt.ListTag)

Example 14 with IMaterial

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);
                }
            }
        }
    }
}
Also used : IMaterial(net.silentchaos512.gear.api.material.IMaterial) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) CustomCompoundMaterial(net.silentchaos512.gear.gear.material.CustomCompoundMaterial) ItemStack(net.minecraft.world.item.ItemStack)

Example 15 with IMaterial

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;
}
Also used : IMaterial(net.silentchaos512.gear.api.material.IMaterial) ResourceLocation(net.minecraft.resources.ResourceLocation) Nullable(javax.annotation.Nullable)

Aggregations

IMaterial (net.silentchaos512.gear.api.material.IMaterial)17 MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)9 ResourceLocation (net.minecraft.resources.ResourceLocation)8 ItemStack (net.minecraft.world.item.ItemStack)6 Nullable (javax.annotation.Nullable)5 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)5 IMaterialDisplay (net.silentchaos512.gear.api.material.IMaterialDisplay)4 Component (net.minecraft.network.chat.Component)3 MaterialLayer (net.silentchaos512.gear.api.material.MaterialLayer)3 PartType (net.silentchaos512.gear.api.part.PartType)3 LazyMaterialInstance (net.silentchaos512.gear.gear.material.LazyMaterialInstance)3 ArrayList (java.util.ArrayList)2 Collectors (java.util.stream.Collectors)2 ListTag (net.minecraft.nbt.ListTag)2 Tag (net.minecraft.nbt.Tag)2 ClickEvent (net.minecraft.network.chat.ClickEvent)2 TextComponent (net.minecraft.network.chat.TextComponent)2 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)2 ServerPlayer (net.minecraft.server.level.ServerPlayer)2 Player (net.minecraft.world.entity.player.Player)2