Search in sources :

Example 6 with IMaterial

use of net.silentchaos512.gear.api.material.IMaterial in project Silent-Gear by SilentChaos512.

the class FragmentModel method buildFakeModel.

private void buildFakeModel(Function<Material, TextureAtlasSprite> spriteGetter, ImmutableList.Builder<BakedQuad> builder, Transformation rotation, IMaterial material) {
    // This method will display an example item for items with no data (ie, for advancements)
    MaterialInstance mat = MaterialInstance.of(material);
    IMaterialDisplay model = mat.getDisplayProperties();
    MaterialLayer exampleMain = model.getLayerList(GearType.FRAGMENT, PartType.MAIN, mat).getFirstLayer();
    if (exampleMain != null) {
        builder.addAll(getQuadsForSprite(0, spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, exampleMain.getTexture(GearType.FRAGMENT, 0))), rotation, exampleMain.getColor()));
    }
}
Also used : IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay) MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer) IMaterial(net.silentchaos512.gear.api.material.IMaterial) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) LazyMaterialInstance(net.silentchaos512.gear.gear.material.LazyMaterialInstance)

Example 7 with IMaterial

use of net.silentchaos512.gear.api.material.IMaterial in project Silent-Gear by SilentChaos512.

the class CompoundMaterialItem method getPrimaryMaterial.

@Nullable
private static IMaterialInstance getPrimaryMaterial(ItemStack stack) {
    IMaterialInstance first = MaterialList.deserializeFirst(stack.getOrCreateTag().getList(NBT_MATERIALS, Tag.TAG_COMPOUND));
    if (first != null) {
        return first;
    }
    // Read old style
    ListTag listNbt = stack.getOrCreateTag().getList(NBT_MATERIALS, Tag.TAG_STRING);
    if (!listNbt.isEmpty()) {
        Tag nbt = listNbt.get(0);
        ResourceLocation id = ResourceLocation.tryParse(nbt.getAsString());
        if (id != null) {
            IMaterial material = MaterialManager.get(id);
            if (material != null) {
                return MaterialInstance.of(material);
            }
        }
    }
    return null;
}
Also used : IMaterial(net.silentchaos512.gear.api.material.IMaterial) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) ResourceLocation(net.minecraft.resources.ResourceLocation) Tag(net.minecraft.nbt.Tag) ListTag(net.minecraft.nbt.ListTag) ListTag(net.minecraft.nbt.ListTag) Nullable(javax.annotation.Nullable)

Example 8 with IMaterial

use of net.silentchaos512.gear.api.material.IMaterial in project Silent-Gear by SilentChaos512.

the class CustomMaterialItem method getMaterial.

@Nullable
public static MaterialInstance getMaterial(ItemStack stack) {
    String str = stack.getOrCreateTag().getString(NBT_MATERIAL);
    ResourceLocation id = SilentGear.getIdWithDefaultNamespace(str);
    if (id != null) {
        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)

Example 9 with IMaterial

use of net.silentchaos512.gear.api.material.IMaterial in project Silent-Gear by SilentChaos512.

the class FillRepairKitRecipe method isRepairMaterial.

private static boolean isRepairMaterial(IMaterialInstance material) {
    float durability = material.getStat(PartType.MAIN, ItemStats.DURABILITY);
    float armorDurability = material.getStat(PartType.MAIN, ItemStats.ARMOR_DURABILITY);
    IMaterial mat = material.get();
    return mat != null && mat.allowedInPart(material, PartType.MAIN) && (durability > 0 || armorDurability > 0);
}
Also used : IMaterial(net.silentchaos512.gear.api.material.IMaterial)

Example 10 with IMaterial

use of net.silentchaos512.gear.api.material.IMaterial in project Silent-Gear by SilentChaos512.

the class IGearRecipe method getParts.

default Collection<PartData> getParts(Container inv) {
    List<MaterialInstance> materials = new ArrayList<>();
    IMaterial first = null;
    List<PartData> parts = new ArrayList<>();
    for (int i = 0; i < inv.getContainerSize(); ++i) {
        ItemStack stack = inv.getItem(i);
        if (!stack.isEmpty()) {
            MaterialInstance mat = MaterialInstance.from(stack);
            if (mat != null) {
                // 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 Collections.emptyList();
                }
                materials.add(mat);
            } else {
                PartData part = PartData.from(stack);
                if (part != null) {
                    parts.add(part);
                }
            }
        }
    }
    if (!materials.isEmpty()) {
        // Construct a tool head
        createToolHead(this.getOutputItem().getGearType(), materials).ifPresent(part -> parts.add(0, part));
    }
    return parts;
}
Also used : IMaterial(net.silentchaos512.gear.api.material.IMaterial) PartData(net.silentchaos512.gear.gear.part.PartData) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) ItemStack(net.minecraft.world.item.ItemStack)

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