Search in sources :

Example 26 with PartType

use of net.silentchaos512.gear.api.part.PartType in project Silent-Gear by SilentChaos512.

the class ModKitItem method appendHoverText.

@Override
public void appendHoverText(ItemStack stack, @Nullable Level worldIn, List<Component> tooltip, TooltipFlag flagIn) {
    PartType selected = getSelectedType(stack);
    tooltip.add(TextUtil.withColor(TextUtil.translate("item", "mod_kit.selected"), Color.SKYBLUE).append(selected.getDisplayName(0).withStyle(ChatFormatting.GRAY)));
    tooltip.add(TextUtil.translate("item", "mod_kit.keyHint", TextUtil.withColor(TextUtil.keyBinding(KeyTracker.CYCLE_BACK), Color.AQUAMARINE), TextUtil.withColor(TextUtil.keyBinding(KeyTracker.CYCLE_NEXT), Color.AQUAMARINE)));
    if (flagIn.isAdvanced()) {
        TextComponent text = new TextComponent("Removable types: " + getRemovableTypes().size());
        tooltip.add(TextUtil.withColor(text, ChatFormatting.DARK_GRAY));
    }
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) TextComponent(net.minecraft.network.chat.TextComponent)

Example 27 with PartType

use of net.silentchaos512.gear.api.part.PartType in project Silent-Gear by SilentChaos512.

the class GearBlueprintItem method appendSupportedTypesText.

private void appendSupportedTypesText(Collection<Component> list) {
    if (KeyTracker.isDisplayStatsDown()) {
        Optional<ICoreItem> itemOptional = this.gearType.getItem();
        if (itemOptional.isPresent()) {
            TextListBuilder builder = new TextListBuilder();
            ICoreItem item = itemOptional.get();
            ItemStack gear = new ItemStack(item);
            for (PartType type : PartType.getValues()) {
                if (type != PartType.MAIN) {
                    List<IGearPart> partsOfType = PartManager.getPartsOfType(type);
                    if (!partsOfType.isEmpty() && item.supportsPart(gear, PartData.of(partsOfType.get(0)))) {
                        builder.add(type.getDisplayName(0));
                    }
                }
            }
            List<Component> lines = builder.build();
            if (!lines.isEmpty()) {
                list.add(TextUtil.withColor(TextUtil.misc("supportedPartTypes"), Color.GOLD));
                list.addAll(lines);
            }
        }
    } else {
        list.add(TextUtil.withColor(TextUtil.misc("supportedPartTypes"), Color.GOLD).append(" ").append(TextUtil.withColor(TextUtil.keyBinding(KeyTracker.DISPLAY_STATS), ChatFormatting.GRAY)));
    }
}
Also used : TextListBuilder(net.silentchaos512.gear.client.util.TextListBuilder) PartType(net.silentchaos512.gear.api.part.PartType) IGearPart(net.silentchaos512.gear.api.part.IGearPart) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) ItemStack(net.minecraft.world.item.ItemStack) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Component(net.minecraft.network.chat.Component) TextComponent(net.minecraft.network.chat.TextComponent)

Example 28 with PartType

use of net.silentchaos512.gear.api.part.PartType 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 29 with PartType

use of net.silentchaos512.gear.api.part.PartType in project Silent-Gear by SilentChaos512.

the class ConversionRecipe method getParts.

private Collection<? extends IPartData> getParts() {
    PartDataList ret = PartDataList.of();
    // noinspection OverlyLongLambda
    this.resultMaterials.forEach((partType, list) -> {
        partType.getCompoundPartItem(item.getGearType()).ifPresent(partItem -> {
            PartData part = PartData.from(partItem.create(list));
            if (part != null) {
                ret.add(part);
            }
        });
    });
    return ret;
}
Also used : PartDataList(net.silentchaos512.gear.api.part.PartDataList) PartData(net.silentchaos512.gear.gear.part.PartData) IPartData(net.silentchaos512.gear.api.part.IPartData)

Example 30 with PartType

use of net.silentchaos512.gear.api.part.PartType in project Silent-Gear by SilentChaos512.

the class ConversionRecipe method deserializeMaterials.

private static void deserializeMaterials(JsonObject json, ConversionRecipe recipe) {
    JsonObject resultJson = json.getAsJsonObject("result");
    for (Map.Entry<String, JsonElement> entry : resultJson.getAsJsonObject("materials").entrySet()) {
        PartType partType = PartType.get(Objects.requireNonNull(SilentGear.getIdWithDefaultNamespace(entry.getKey())));
        JsonElement element = entry.getValue();
        if (element.isJsonArray()) {
            List<IMaterialInstance> list = new ArrayList<>();
            for (JsonElement e : element.getAsJsonArray()) {
                list.add(LazyMaterialInstance.deserialize(e.getAsJsonObject()));
            }
            recipe.resultMaterials.put(partType, list);
        } else {
            recipe.resultMaterials.put(partType, Collections.singletonList(LazyMaterialInstance.deserialize(element.getAsJsonObject())));
        }
    }
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject)

Aggregations

PartType (net.silentchaos512.gear.api.part.PartType)37 ItemStack (net.minecraft.world.item.ItemStack)14 PartData (net.silentchaos512.gear.gear.part.PartData)14 StatInstance (net.silentchaos512.gear.api.stats.StatInstance)13 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)10 ICoreItem (net.silentchaos512.gear.api.item.ICoreItem)10 TextComponent (net.minecraft.network.chat.TextComponent)9 ResourceLocation (net.minecraft.resources.ResourceLocation)9 GearType (net.silentchaos512.gear.api.item.GearType)9 PartDataList (net.silentchaos512.gear.api.part.PartDataList)9 ItemStat (net.silentchaos512.gear.api.stats.ItemStat)9 Component (net.minecraft.network.chat.Component)8 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)8 IPartData (net.silentchaos512.gear.api.part.IPartData)8 MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)8 TraitInstance (net.silentchaos512.gear.api.traits.TraitInstance)7 StatGearKey (net.silentchaos512.gear.api.util.StatGearKey)7 ArrayList (java.util.ArrayList)5 Collectors (java.util.stream.Collectors)5 MutableComponent (net.minecraft.network.chat.MutableComponent)5