Search in sources :

Example 56 with PartType

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

the class GearElytraItem method supportsPart.

@Override
public boolean supportsPart(ItemStack gear, PartData part) {
    PartType type = part.getType();
    boolean canAdd = part.get().canAddToGear(gear, part);
    boolean supported = (requiresPartOfType(part.getType()) && canAdd) || canAdd;
    return (type == PartType.MAIN && supported) || type == PartType.LINING || supported;
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType)

Example 57 with PartType

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

the class SyncMaterialCraftingItemsPacket method encode.

public void encode(FriendlyByteBuf buffer) {
    buffer.writeVarInt(this.craftingItems.size());
    this.craftingItems.forEach((id, ingredient) -> {
        buffer.writeResourceLocation(id);
        ingredient.toNetwork(buffer);
    });
    buffer.writeVarInt(this.partSubs.size());
    for (ResourceLocation id : this.partSubs.keySet()) {
        Map<PartType, Ingredient> map = this.partSubs.get(id);
        buffer.writeResourceLocation(id);
        buffer.writeByte(map.size());
        map.forEach((type, ingredient) -> {
            buffer.writeResourceLocation(type.getName());
            ingredient.toNetwork(buffer);
        });
    }
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) Ingredient(net.minecraft.world.item.crafting.Ingredient) ResourceLocation(net.minecraft.resources.ResourceLocation)

Example 58 with PartType

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

the class MaterialsCommand method makeTsvLine.

private static String makeTsvLine(MaterialInstance material, PartType partType) {
    StringBuilder builder = new StringBuilder();
    appendTsv(builder, material.get().getPackName());
    appendTsv(builder, material.getDisplayName(partType).getString());
    int tier = material.getTier(partType);
    // appendTsv(builder, partType.getDisplayName(tier).getFormattedText());
    appendTsv(builder, partType.getDisplayName(0).getString());
    appendTsv(builder, material.getId().toString());
    appendTsv(builder, getParentId(material.get()));
    // Traits
    appendTsv(builder, material.getTraits(partType).stream().map(t -> t.getTrait().getDisplayName(t.getLevel()).getString()).collect(Collectors.joining(", ")));
    appendTsv(builder, tier);
    // Stats
    for (ItemStat stat : ItemStats.allStatsOrdered()) {
        Collection<StatInstance> statModifiers = material.getStatModifiers(partType, StatGearKey.of(stat, GearType.ALL));
        appendTsv(builder, FORMAT_CODES.matcher(StatModifierMap.formatText(statModifiers, stat, 5).getString()).replaceAll(""));
    }
    return builder.toString();
}
Also used : StatInstance(net.silentchaos512.gear.api.stats.StatInstance) ItemStat(net.silentchaos512.gear.api.stats.ItemStat)

Example 59 with PartType

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

the class MaterialsCommand method runDumpClient.

public static void runDumpClient(boolean includeChildren) {
    Player player = SilentGear.PROXY.getClientPlayer();
    if (player == null) {
        SilentGear.LOGGER.error("MaterialsCommand#runDumpClient: player is null?");
        return;
    }
    String fileName = "material_export.tsv";
    String dirPath = "output/silentgear";
    File output = new File(dirPath, fileName);
    File directory = output.getParentFile();
    if (!directory.exists() && !directory.mkdirs()) {
        player.sendMessage(new TextComponent("Could not create directory: " + output.getParent()), Util.NIL_UUID);
        return;
    }
    try (Writer writer = new OutputStreamWriter(new FileOutputStream(output), StandardCharsets.UTF_8)) {
        StringBuilder builder = new StringBuilder("Pack\tName\tType\tID\tParent\tTraits\tTier\t");
        ItemStats.allStatsOrdered().forEach(s -> builder.append(s.getDisplayName().getString()).append("\t"));
        writer.write(builder + "\n");
        List<PartType> partTypes = new ArrayList<>(PartType.getValues());
        partTypes.sort((o1, o2) -> Comparator.comparing(o -> ((PartType) o).getDisplayName(0).getString()).compare(o1, o2));
        for (PartType partType : partTypes) {
            for (IMaterial material : MaterialManager.getValues()) {
                if (includeChildren || getParentId(material).isEmpty()) {
                    MaterialInstance inst = MaterialInstance.of(material);
                    if (material.allowedInPart(inst, partType)) {
                        writer.write(makeTsvLine(inst, partType) + "\n");
                    }
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        Component fileNameText = (new TextComponent(output.getAbsolutePath())).withStyle(ChatFormatting.UNDERLINE).withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, output.getAbsolutePath())));
        player.sendMessage(new TextComponent("Wrote materials info to ").append(fileNameText), Util.NIL_UUID);
    }
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) PartType(net.silentchaos512.gear.api.part.PartType) IMaterial(net.silentchaos512.gear.api.material.IMaterial) ServerPlayer(net.minecraft.server.level.ServerPlayer) Player(net.minecraft.world.entity.player.Player) ClickEvent(net.minecraft.network.chat.ClickEvent) ArrayList(java.util.ArrayList) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Component(net.minecraft.network.chat.Component) TextComponent(net.minecraft.network.chat.TextComponent)

Example 60 with PartType

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

the class PartsCommand method runList.

private static int runList(CommandContext<CommandSourceStack> context) {
    String listStr = PartManager.getValues().stream().map(part -> part.getId().toString()).collect(Collectors.joining(", "));
    context.getSource().sendSuccess(new TextComponent(listStr), true);
    for (PartType type : PartType.getValues()) {
        int count = PartManager.getPartsOfType(type).size();
        String str = String.format("%s: %d", type.getName(), count);
        context.getSource().sendSuccess(new TextComponent(str), true);
    }
    return 1;
}
Also used : GearData(net.silentchaos512.gear.util.GearData) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) SharedSuggestionProvider(net.minecraft.commands.SharedSuggestionProvider) PartDataList(net.silentchaos512.gear.api.part.PartDataList) CommandSourceStack(net.minecraft.commands.CommandSourceStack) StatModifierMap(net.silentchaos512.gear.api.stats.StatModifierMap) ServerPlayer(net.minecraft.server.level.ServerPlayer) PartData(net.silentchaos512.gear.gear.part.PartData) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) PartManager(net.silentchaos512.gear.gear.part.PartManager) SuggestionProvider(com.mojang.brigadier.suggestion.SuggestionProvider) IGearPart(net.silentchaos512.gear.api.part.IGearPart) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) StatInstance(net.silentchaos512.gear.api.stats.StatInstance) ItemStat(net.silentchaos512.gear.api.stats.ItemStat) ItemStats(net.silentchaos512.gear.api.stats.ItemStats) Component(net.minecraft.network.chat.Component) StatGearKey(net.silentchaos512.gear.api.util.StatGearKey) CommandContext(com.mojang.brigadier.context.CommandContext) Commands(net.minecraft.commands.Commands) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) StandardCharsets(java.nio.charset.StandardCharsets) PartType(net.silentchaos512.gear.api.part.PartType) GearType(net.silentchaos512.gear.api.item.GearType) TextComponent(net.minecraft.network.chat.TextComponent) java.io(java.io) ItemStack(net.minecraft.world.item.ItemStack) Pattern(java.util.regex.Pattern) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) TextComponent(net.minecraft.network.chat.TextComponent) PartType(net.silentchaos512.gear.api.part.PartType)

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