Search in sources :

Example 26 with IMaterialInstance

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);
                }
            }
        }
    }
}
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 27 with IMaterialInstance

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

Example 28 with IMaterialInstance

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();
}
Also used : ExclusionIngredient(net.silentchaos512.lib.crafting.ingredient.ExclusionIngredient) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) StackList(net.silentchaos512.lib.collection.StackList) ItemStack(net.minecraft.world.item.ItemStack)

Example 29 with IMaterialInstance

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);
    }
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance)

Example 30 with IMaterialInstance

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

Aggregations

IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)24 ItemStack (net.minecraft.world.item.ItemStack)10 PartType (net.silentchaos512.gear.api.part.PartType)6 TraitInstance (net.silentchaos512.gear.api.traits.TraitInstance)6 ResourceLocation (net.minecraft.resources.ResourceLocation)5 IMaterial (net.silentchaos512.gear.api.material.IMaterial)5 IMaterialDisplay (net.silentchaos512.gear.api.material.IMaterialDisplay)5 Nullable (javax.annotation.Nullable)4 StatGearKey (net.silentchaos512.gear.api.util.StatGearKey)4 ArrayList (java.util.ArrayList)3 Collectors (java.util.stream.Collectors)3 Component (net.minecraft.network.chat.Component)3 SilentGear (net.silentchaos512.gear.SilentGear)3 StatInstance (net.silentchaos512.gear.api.stats.StatInstance)3 JsonObject (com.google.gson.JsonObject)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 FriendlyByteBuf (net.minecraft.network.FriendlyByteBuf)2 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)2