Search in sources :

Example 21 with MaterialInstance

use of net.silentchaos512.gear.gear.material.MaterialInstance 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 22 with MaterialInstance

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

the class CompoundPartItem method getName.

@Override
public Component getName(ItemStack stack) {
    PartData part = PartData.from(stack);
    MaterialInstance material = getPrimaryMaterial(stack);
    if (part != null && material != null) {
        TranslatableComponent nameText = new TranslatableComponent(this.getDescriptionId() + ".nameProper", material.getDisplayName(partType, ItemStack.EMPTY));
        int nameColor = Color.blend(part.getColor(ItemStack.EMPTY), Color.VALUE_WHITE, 0.25f) & 0xFFFFFF;
        return TextUtil.withColor(nameText, nameColor);
    }
    return super.getName(stack);
}
Also used : TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) PartData(net.silentchaos512.gear.gear.part.PartData) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) LazyMaterialInstance(net.silentchaos512.gear.gear.material.LazyMaterialInstance)

Example 23 with MaterialInstance

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

the class TraitsCommand method getMaterialsWithTrait.

private static String getMaterialsWithTrait(ITrait trait) {
    StringBuilder str = new StringBuilder();
    boolean foundAny = false;
    for (IMaterial material : MaterialManager.getValues(false)) {
        MaterialInstance instance = MaterialInstance.of(material);
        Collection<PartType> typesWithTrait = new ArrayList<>();
        for (PartType partType : PartType.getValues()) {
            Collection<TraitInstance> traits = instance.getTraits(partType);
            for (TraitInstance inst : traits) {
                if (inst.getTrait().equals(trait) && material.isVisible(partType)) {
                    typesWithTrait.add(partType);
                    break;
                }
            }
        }
        if (!typesWithTrait.isEmpty()) {
            if (foundAny) {
                str.append(", ");
            }
            foundAny = true;
            str.append("**").append(instance.getDisplayName(PartType.MAIN).getString()).append("**").append(" _(").append(typesWithTrait.stream().map(pt -> pt.getDisplayName(0).getString()).collect(Collectors.joining(", "))).append(")_");
        }
    }
    return str.toString();
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) ResourceLocation(net.minecraft.resources.ResourceLocation) SilentGear(net.silentchaos512.gear.SilentGear) ModContainer(net.minecraftforge.fml.ModContainer) java.util(java.util) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) SharedSuggestionProvider(net.minecraft.commands.SharedSuggestionProvider) CommandSourceStack(net.minecraft.commands.CommandSourceStack) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) LocalDateTime(java.time.LocalDateTime) MaterialManager(net.silentchaos512.gear.gear.material.MaterialManager) NetworkDirection(net.minecraftforge.network.NetworkDirection) ResourceLocationArgument(net.minecraft.commands.arguments.ResourceLocationArgument) ServerPlayer(net.minecraft.server.level.ServerPlayer) PartData(net.silentchaos512.gear.gear.part.PartData) ITraitCondition(net.silentchaos512.gear.api.traits.ITraitCondition) ChatFormatting(net.minecraft.ChatFormatting) ITraitSerializer(net.silentchaos512.gear.api.traits.ITraitSerializer) PartManager(net.silentchaos512.gear.gear.part.PartManager) ClientOutputCommandPacket(net.silentchaos512.gear.network.ClientOutputCommandPacket) SuggestionProvider(com.mojang.brigadier.suggestion.SuggestionProvider) IGearPart(net.silentchaos512.gear.api.part.IGearPart) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Component(net.minecraft.network.chat.Component) TraitManager(net.silentchaos512.gear.gear.trait.TraitManager) CommandContext(com.mojang.brigadier.context.CommandContext) SimpleTrait(net.silentchaos512.gear.gear.trait.SimpleTrait) Commands(net.minecraft.commands.Commands) ModList(net.minecraftforge.fml.ModList) AndTraitCondition(net.silentchaos512.gear.gear.trait.condition.AndTraitCondition) IModInfo(net.minecraftforge.forgespi.language.IModInfo) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Player(net.minecraft.world.entity.player.Player) PartType(net.silentchaos512.gear.api.part.PartType) IMaterial(net.silentchaos512.gear.api.material.IMaterial) Util(net.minecraft.Util) TextComponent(net.minecraft.network.chat.TextComponent) ITrait(net.silentchaos512.gear.api.traits.ITrait) java.io(java.io) TraitInstance(net.silentchaos512.gear.api.traits.TraitInstance) DateTimeFormatter(java.time.format.DateTimeFormatter) TraitSerializers(net.silentchaos512.gear.gear.trait.TraitSerializers) Network(net.silentchaos512.gear.network.Network) ItemStack(net.minecraft.world.item.ItemStack) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) ClickEvent(net.minecraft.network.chat.ClickEvent) IMaterial(net.silentchaos512.gear.api.material.IMaterial) TraitInstance(net.silentchaos512.gear.api.traits.TraitInstance) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance)

Example 24 with MaterialInstance

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

the class PartMaterialIngredient method test.

@Override
public boolean test(@Nullable ItemStack stack) {
    if (stack == null || stack.isEmpty())
        return false;
    MaterialInstance material = MaterialInstance.from(stack);
    if (material == null)
        return false;
    int tier = material.getTier(this.partType);
    return material.get().isCraftingAllowed(material, partType, gearType) && (categories.isEmpty() || material.hasAnyCategory(categories)) && tierMatches(tier);
}
Also used : MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance)

Example 25 with MaterialInstance

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

the class CoatingSmithingRecipe method applyUpgrade.

@Override
protected ItemStack applyUpgrade(ItemStack gear, ItemStack upgradeItem) {
    MaterialInstance material = MaterialInstance.from(upgradeItem);
    if (material != null) {
        GearType gearType = GearHelper.getType(gear);
        if (gearType.isGear()) {
            ItemStack result = gear.copy();
            PartType.COATING.getCompoundPartItem(gearType).ifPresent(cpi -> {
                ItemStack partItem = cpi.create(material, 1);
                // Unfortunately this deletes the old part; can't get a player here
                GearData.addOrReplacePart(result, Objects.requireNonNull(PartData.from(partItem)));
            });
            result.setDamageValue(0);
            GearData.removeExcessParts(result, PartType.COATING);
            // Crafting player is always null?
            GearData.recalculateStats(result, ForgeHooks.getCraftingPlayer());
            return result;
        }
    }
    return ItemStack.EMPTY;
}
Also used : GearType(net.silentchaos512.gear.api.item.GearType) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) ItemStack(net.minecraft.world.item.ItemStack)

Aggregations

MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)25 ItemStack (net.minecraft.world.item.ItemStack)12 IMaterial (net.silentchaos512.gear.api.material.IMaterial)10 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)10 PartType (net.silentchaos512.gear.api.part.PartType)9 MaterialLayer (net.silentchaos512.gear.api.material.MaterialLayer)8 PartData (net.silentchaos512.gear.gear.part.PartData)8 Component (net.minecraft.network.chat.Component)7 IMaterialDisplay (net.silentchaos512.gear.api.material.IMaterialDisplay)7 TextComponent (net.minecraft.network.chat.TextComponent)6 ResourceLocation (net.minecraft.resources.ResourceLocation)6 TraitInstance (net.silentchaos512.gear.api.traits.TraitInstance)6 Collectors (java.util.stream.Collectors)5 Nullable (javax.annotation.Nullable)5 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)5 GearType (net.silentchaos512.gear.api.item.GearType)5 ItemStat (net.silentchaos512.gear.api.stats.ItemStat)5 LazyMaterialInstance (net.silentchaos512.gear.gear.material.LazyMaterialInstance)5 java.util (java.util)4 ArrayList (java.util.ArrayList)4