Search in sources :

Example 16 with IMaterial

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

the class MaterialManager method handleSyncPacket.

public static void handleSyncPacket(SyncMaterialsPacket msg, Supplier<NetworkEvent.Context> ctx) {
    synchronized (MATERIALS) {
        Map<ResourceLocation, IMaterial> oldMaterials = ImmutableMap.copyOf(MATERIALS);
        MATERIALS.clear();
        for (IMaterial mat : msg.getMaterials()) {
            mat.retainData(oldMaterials.get(mat.getId()));
            MATERIALS.put(mat.getId(), mat);
        }
        SilentGear.LOGGER.info("Read {} materials from server", MATERIALS.size());
    }
    ctx.get().setPacketHandled(true);
}
Also used : IMaterial(net.silentchaos512.gear.api.material.IMaterial) ResourceLocation(net.minecraft.resources.ResourceLocation)

Example 17 with IMaterial

use of net.silentchaos512.gear.api.material.IMaterial 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 18 with IMaterial

use of net.silentchaos512.gear.api.material.IMaterial 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 19 with IMaterial

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

the class GearModel method buildFakeModel.

private void buildFakeModel(Function<Material, TextureAtlasSprite> spriteGetter, ImmutableList.Builder<BakedQuad> builder, Transformation rotation, IMaterial material) {
    // This method will display an example tool for items with no data (ie, for advancements)
    MaterialInstance mat = MaterialInstance.of(material);
    IMaterialDisplay model = mat.getDisplayProperties();
    if (!gearType.isArmor()) {
        MaterialLayer exampleRod = model.getLayerList(this.gearType, PartType.ROD, mat).getFirstLayer();
        if (exampleRod != null) {
            builder.addAll(getQuadsForSprite(0, spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, exampleRod.getTexture(gearType, 0))), rotation, exampleRod.getColor()));
        }
    }
    MaterialLayer exampleMain = model.getLayerList(this.gearType, PartType.MAIN, mat).getFirstLayer();
    if (exampleMain != null) {
        builder.addAll(getQuadsForSprite(0, spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, exampleMain.getTexture(gearType, 0))), rotation, exampleMain.getColor()));
    }
    if (gearType.matches(GearType.RANGED_WEAPON)) {
        MaterialLayer exampleBowstring = model.getLayerList(this.gearType, PartType.CORD, mat).getFirstLayer();
        if (exampleBowstring != null) {
            builder.addAll(getQuadsForSprite(0, spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, exampleBowstring.getTexture(gearType, 0))), rotation, exampleBowstring.getColor()));
        }
    }
}
Also used : IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay) MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer) IMaterial(net.silentchaos512.gear.api.material.IMaterial) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) LazyMaterialInstance(net.silentchaos512.gear.gear.material.LazyMaterialInstance)

Aggregations

IMaterial (net.silentchaos512.gear.api.material.IMaterial)17 MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)9 ResourceLocation (net.minecraft.resources.ResourceLocation)8 ItemStack (net.minecraft.world.item.ItemStack)6 Nullable (javax.annotation.Nullable)5 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)5 IMaterialDisplay (net.silentchaos512.gear.api.material.IMaterialDisplay)4 Component (net.minecraft.network.chat.Component)3 MaterialLayer (net.silentchaos512.gear.api.material.MaterialLayer)3 PartType (net.silentchaos512.gear.api.part.PartType)3 LazyMaterialInstance (net.silentchaos512.gear.gear.material.LazyMaterialInstance)3 ArrayList (java.util.ArrayList)2 Collectors (java.util.stream.Collectors)2 ListTag (net.minecraft.nbt.ListTag)2 Tag (net.minecraft.nbt.Tag)2 ClickEvent (net.minecraft.network.chat.ClickEvent)2 TextComponent (net.minecraft.network.chat.TextComponent)2 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)2 ServerPlayer (net.minecraft.server.level.ServerPlayer)2 Player (net.minecraft.world.entity.player.Player)2