Search in sources :

Example 26 with MaterialInstance

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

the class GearArmorItem method getArmorTexture.

// endregion
// region Client-side methods and rendering horrors
@Override
public String getArmorTexture(ItemStack stack, Entity entity, EquipmentSlot slot, String type) {
    // Empty texture if broken
    if (GearHelper.isBroken(stack))
        return SilentGear.MOD_ID + ":textures/models/armor/empty.png";
    int layer = slot == EquipmentSlot.LEGS ? 2 : 1;
    // Overlay - default to a blank texture
    if ("overlay".equals(type))
        return SilentGear.MOD_ID + ":textures/models/armor/all_layer_" + layer + "_overlay.png";
    // New material-based armor
    MaterialInstance material = GearData.getPrimaryArmorMaterial(stack);
    if (material != null) {
        IMaterialDisplay materialModel = material.getDisplayProperties();
        PartType partType = GearData.hasPartOfType(stack, PartType.COATING) ? PartType.COATING : PartType.MAIN;
        MaterialLayer materialLayer = materialModel.getLayerList(this.getGearType(), partType, material).getFirstLayer();
        if (materialLayer != null) {
            ResourceLocation tex = materialLayer.getTextureId();
            return tex.getNamespace() + ":textures/models/armor/" + tex.getPath() + "_layer_" + layer + (type != null ? "_" + type : "") + ".png";
        }
    }
    return "silentgear:textures/models/armor/main_generic_hc_layer_" + layer + (type != null ? "_" + type : "") + ".png";
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay) MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer) ResourceLocation(net.minecraft.resources.ResourceLocation) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance)

Example 27 with MaterialInstance

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

the class RepairKitItem method removeRepairMaterials.

public void removeRepairMaterials(ItemStack repairKit, Map<MaterialInstance, Float> toRemove) {
    CompoundTag nbt = repairKit.getOrCreateTagElement(NBT_STORAGE);
    for (Map.Entry<MaterialInstance, Float> entry : toRemove.entrySet()) {
        MaterialInstance mat = entry.getKey();
        Float amount = entry.getValue();
        String key = getShorthandKey(mat);
        float newValue = nbt.getFloat(key) - amount;
        if (newValue < 0.01f) {
            nbt.remove(key);
        } else {
            nbt.putFloat(key, newValue);
        }
    }
}
Also used : MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 28 with MaterialInstance

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

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

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

the class GearModelOverrideList method getOverrideModel.

private BakedModel getOverrideModel(CacheKey key, ItemStack stack, @Nullable ClientLevel worldIn, @Nullable LivingEntity entityIn, int animationFrame) {
    boolean broken = GearHelper.isBroken(stack);
    if (isDebugLoggingEnabled()) {
        SilentGear.LOGGER.info("getOverrideModel for {} ({})", stack.getHoverName().getString(), broken ? "broken" : "normal");
        SilentGear.LOGGER.info("- model key {}", key.data);
    }
    List<MaterialLayer> layers = new ArrayList<>();
    for (PartData part : getPartsInRenderOrder(stack)) {
        if (((ICoreItem) stack.getItem()).hasTexturesFor(part.getType())) {
            addSimplePartLayers(layers, part, stack);
            if (part.get() instanceof CompoundPart) {
                MaterialInstance mat = CompoundPart.getPrimaryMaterial(part);
                if (mat != null) {
                    addWithBlendedColor(layers, part, mat, stack);
                }
            }
        }
    }
    // TODO: Make this not a special case...
    if (stack.getItem() instanceof GearCrossbowItem) {
        getCrossbowCharge(stack, worldIn, entityIn).ifPresent(layers::add);
    }
    return model.bake(stack, layers, animationFrame, "test", owner, bakery, spriteGetter, modelTransform, this, modelLocation);
}
Also used : MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer) ArrayList(java.util.ArrayList) PartData(net.silentchaos512.gear.gear.part.PartData) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) CompoundPart(net.silentchaos512.gear.gear.part.CompoundPart) GearCrossbowItem(net.silentchaos512.gear.item.gear.GearCrossbowItem) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance)

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