Search in sources :

Example 11 with IMaterialInstance

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

the class CraftedMaterialItem method getColor.

@Override
public int getColor(ItemStack stack, int layer) {
    IMaterialInstance material = getMaterial(stack);
    IMaterialDisplay model = material.getDisplayProperties();
    return model.getLayerColor(GearType.ALL, PartType.MAIN, material, layer);
}
Also used : IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay)

Example 12 with IMaterialInstance

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

the class RepairKitItem method addMaterial.

public boolean addMaterial(ItemStack repairKit, ItemStack materialStack) {
    Tuple<IMaterialInstance, Float> tuple = getMaterialAndValue(materialStack);
    if (tuple != null) {
        IMaterialInstance mat = tuple.getA();
        float value = tuple.getB();
        if (getStoredMaterialAmount(repairKit) > getKitCapacity() - value) {
            // Repair kit is full
            return false;
        }
        String key = getShorthandKey(mat);
        CompoundTag storageTag = repairKit.getOrCreateTagElement(NBT_STORAGE);
        float current = storageTag.getFloat(key);
        storageTag.putFloat(key, current + value);
        return true;
    }
    return false;
}
Also used : IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 13 with IMaterialInstance

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

the class SynergyUtils method getSynergy.

public static float getSynergy(PartType partType, List<? extends IMaterialInstance> materials, Collection<TraitInstance> traits) {
    if (materials.isEmpty()) {
        return 1;
    }
    // First, we add a bonus for the number of unique materials
    double synergy = getBaseSynergy(materials);
    // Second, reduce synergy for differences in certain properties
    IMaterialInstance primary = materials.get(0);
    final double primaryRarity = primary.getStat(partType, ItemStats.RARITY);
    final double maxRarity = materials.stream().mapToDouble(m -> m.getStat(partType, ItemStats.RARITY)).max().orElse(0);
    final int maxTier = materials.stream().mapToInt(m -> m.getTier(partType)).max().orElse(0);
    for (IMaterialInstance material : getUniques(materials)) {
        if (maxRarity > 0) {
            float rarity = material.getStat(partType, ItemStats.RARITY);
            synergy -= 0.005 * Math.abs(primaryRarity - rarity);
        }
        if (maxTier > 0) {
            int tier = material.getTier(partType);
            synergy -= 0.08 * Math.abs(maxTier - tier);
        }
    }
    // Synergy traits
    for (TraitInstance trait : traits) {
        if (trait.getTrait() instanceof SynergyTrait) {
            synergy = ((SynergyTrait) trait.getTrait()).apply(synergy, trait.getLevel());
        }
    }
    return (float) Mth.clamp(synergy, MIN_VALUE, MAX_VALUE);
}
Also used : SynergyTrait(net.silentchaos512.gear.gear.trait.SynergyTrait) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) TraitInstance(net.silentchaos512.gear.api.traits.TraitInstance)

Example 14 with IMaterialInstance

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

the class SGearJeiPlugin method registerItemSubtypes.

@Override
public void registerItemSubtypes(ISubtypeRegistration reg) {
    reg.registerSubtypeInterpreter(ModItems.FRAGMENT.get(), (stack, context) -> {
        IMaterialInstance material = FragmentItem.getMaterial(stack);
        return material != null ? material.getId().toString() : "";
    });
    IIngredientSubtypeInterpreter<ItemStack> customMaterials = (stack, context) -> {
        IMaterialInstance material = CustomMaterialItem.getMaterial(stack);
        return material != null ? material.getId().toString() : "";
    };
    reg.registerSubtypeInterpreter(ModItems.CUSTOM_GEM.get(), customMaterials);
    reg.registerSubtypeInterpreter(ModItems.CUSTOM_INGOT.get(), customMaterials);
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) SilentGear(net.silentchaos512.gear.SilentGear) ModItems(net.silentchaos512.gear.init.ModItems) CraftingItems(net.silentchaos512.gear.item.CraftingItems) MetalCompoundingRecipe(net.silentchaos512.gear.crafting.recipe.compounder.MetalCompoundingRecipe) RepairKitItem(net.silentchaos512.gear.item.RepairKitItem) Item(net.minecraft.world.item.Item) SalvagerScreen(net.silentchaos512.gear.block.salvager.SalvagerScreen) IGuiHelper(mezz.jei.api.helpers.IGuiHelper) RecrystallizerScreen(net.silentchaos512.gear.block.compounder.RecrystallizerScreen) IModPlugin(mezz.jei.api.IModPlugin) ICoreTool(net.silentchaos512.gear.api.item.ICoreTool) Const(net.silentchaos512.gear.util.Const) Registration(net.silentchaos512.gear.init.Registration) JeiPlugin(mezz.jei.api.JeiPlugin) RefabricatorScreen(net.silentchaos512.gear.block.compounder.RefabricatorScreen) Minecraft(net.minecraft.client.Minecraft) ItemLike(net.minecraft.world.level.ItemLike) net.minecraft.world.item.crafting(net.minecraft.world.item.crafting) NonNullList(net.minecraft.core.NonNullList) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) FragmentItem(net.silentchaos512.gear.item.FragmentItem) GemCompoundingRecipe(net.silentchaos512.gear.crafting.recipe.compounder.GemCompoundingRecipe) NameUtils(net.silentchaos512.lib.util.NameUtils) ModBlocks(net.silentchaos512.gear.init.ModBlocks) VanillaRecipeCategoryUid(mezz.jei.api.constants.VanillaRecipeCategoryUid) Collection(java.util.Collection) CompoundingRecipe(net.silentchaos512.gear.crafting.recipe.compounder.CompoundingRecipe) PartMaterialIngredient(net.silentchaos512.gear.crafting.ingredient.PartMaterialIngredient) mezz.jei.api.registration(mezz.jei.api.registration) Collectors(java.util.stream.Collectors) Blocks(net.minecraft.world.level.block.Blocks) PartType(net.silentchaos512.gear.api.part.PartType) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) IIngredientSubtypeInterpreter(mezz.jei.api.ingredients.subtypes.IIngredientSubtypeInterpreter) SalvagingRecipe(net.silentchaos512.gear.crafting.recipe.salvage.SalvagingRecipe) CustomMaterialItem(net.silentchaos512.gear.item.CustomMaterialItem) ModRecipes(net.silentchaos512.gear.init.ModRecipes) ItemStack(net.minecraft.world.item.ItemStack) GraderScreen(net.silentchaos512.gear.block.grader.GraderScreen) VanillaTypes(mezz.jei.api.constants.VanillaTypes) Collections(java.util.Collections) MetalAlloyerScreen(net.silentchaos512.gear.block.compounder.MetalAlloyerScreen) FabricCompoundingRecipe(net.silentchaos512.gear.crafting.recipe.compounder.FabricCompoundingRecipe) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) ItemStack(net.minecraft.world.item.ItemStack)

Example 15 with IMaterialInstance

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

the class CombineFragmentsRecipe method matches.

@Override
public boolean matches(CraftingContainer craftingInventory, Level world) {
    // First, count the fragments. We want to fail fast.
    int fragmentCount = 0;
    for (int i = 0; i < craftingInventory.getContainerSize(); ++i) {
        ItemStack stack = craftingInventory.getItem(i);
        if (!stack.isEmpty()) {
            if (stack.getItem() == ModItems.FRAGMENT.get()) {
                ++fragmentCount;
            } else {
                return false;
            }
        }
    }
    if (fragmentCount != 8) {
        return false;
    }
    // Now, check that the fragments are all the same material.
    IMaterialInstance first = null;
    for (ItemStack stack : StackList.from(craftingInventory)) {
        IMaterialInstance material = FragmentItem.getMaterial(stack);
        if (material == null) {
            return false;
        }
        if (first == null) {
            first = material;
        } else if (!InventoryUtils.canItemsStack(material.getItem(), first.getItem())) {
            return false;
        }
    }
    return first != null;
}
Also used : 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