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";
}
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);
}
}
}
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();
}
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);
}
}
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);
}
Aggregations