use of net.silentchaos512.gear.api.material.IMaterialDisplay 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.api.material.IMaterialDisplay in project Silent-Gear by SilentChaos512.
the class ColorUtils method getBlendedColor.
public static int getBlendedColor(CompoundPartItem item, Collection<? extends IMaterialInstance> materials, int layer) {
int[] componentSums = new int[3];
int maxColorSum = 0;
int colorCount = 0;
int i = 0;
for (IMaterialInstance mat : materials) {
IMaterialDisplay model = mat.getDisplayProperties();
List<MaterialLayer> layers = model.getLayerList(item.getGearType(), item.getPartType(), mat).getLayers();
if (layers.size() > layer) {
int color = model.getLayerColor(item.getGearType(), item.getPartType(), mat, layer);
int r = (color >> 16) & 0xFF;
int g = (color >> 8) & 0xFF;
int b = color & 0xFF;
int colorWeight = item.getColorWeight(i, materials.size());
for (int j = 0; j < colorWeight; ++j) {
maxColorSum += Math.max(r, Math.max(g, b));
componentSums[0] += r;
componentSums[1] += g;
componentSums[2] += b;
++colorCount;
}
++i;
}
}
return blendColors(componentSums, maxColorSum, colorCount);
}
use of net.silentchaos512.gear.api.material.IMaterialDisplay in project Silent-Gear by SilentChaos512.
the class CompoundPartModel method getTextures.
@Override
public Collection<Material> getTextures(IModelConfiguration owner, Function<ResourceLocation, UnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
Set<Material> ret = new HashSet<>();
if (this.gearType == GearType.SHIELD) {
// Unobtainable part items, no need for textures
return ret;
}
// Generic built-in textures
for (PartTextures tex : PartTextures.getTextures(this.gearType)) {
ret.add(getTexture(tex.getTexture()));
}
// Custom textures
for (IMaterialDisplay materialDisplay : GearDisplayManager.getMaterials()) {
for (MaterialLayer layer : materialDisplay.getLayerList(this.gearType, this.partType, LazyMaterialInstance.of(materialDisplay.getMaterialId()))) {
ret.add(getTexture(layer));
}
}
for (ResourceLocation texture : this.extraLayers) {
ret.add(getTexture(new StaticLayer(texture)));
}
ret.add(getTexture(new StaticLayer(PART_MARKER_TEXTURE)));
ret.add(new Material(InventoryMenu.BLOCK_ATLAS, SilentGear.getId("item/error")));
if (CompoundPartModelOverrideList.isDebugLoggingEnabled()) {
SilentGear.LOGGER.info("Textures for compound part model '{}'", PartGearKey.of(this.gearType, this.partType));
for (Material mat : ret) {
SilentGear.LOGGER.info("- {}", mat.texture());
}
}
return ret;
}
use of net.silentchaos512.gear.api.material.IMaterialDisplay in project Silent-Gear by SilentChaos512.
the class CompoundPartModelOverrideList method addWithBlendedColor.
@SuppressWarnings("TypeMayBeWeakened")
private void addWithBlendedColor(List<MaterialLayer> list, PartData part, MaterialInstance material, ItemStack stack) {
IMaterialDisplay materialModel = material.getDisplayProperties();
List<MaterialLayer> layers = materialModel.getLayerList(this.model.gearType, part, material).getLayers();
for (int i = 0; i < layers.size(); i++) {
MaterialLayer layer = layers.get(i);
if ((layer.getColor() & 0xFFFFFF) < 0xFFFFFF) {
int blendedColor = part.getColor(stack, i, 0);
list.add(new MaterialLayer(layer.getTextureId(), part.getType(), blendedColor, false));
} else {
list.add(layer);
}
}
}
use of net.silentchaos512.gear.api.material.IMaterialDisplay in project Silent-Gear by SilentChaos512.
the class FragmentModelOverrideList method getOverrideModel.
private BakedModel getOverrideModel(ItemStack stack, @Nullable ClientLevel worldIn, @Nullable LivingEntity entityIn) {
List<MaterialLayer> layers = new ArrayList<>();
IMaterialInstance material = FragmentItem.getMaterial(stack);
if (material != null) {
IMaterialDisplay model = material.getDisplayProperties();
int layerLevel = 0;
for (MaterialLayer layer : model.getLayerList(GearType.FRAGMENT, PartType.MAIN, material)) {
int blendedColor = model.getLayerColor(GearType.FRAGMENT, PartType.MAIN, material, layerLevel);
layers.add(new MaterialLayer(layer.getTextureId(), blendedColor));
++layerLevel;
}
}
return model.bake(layers, owner, bakery, spriteGetter, modelTransform, this, modelLocation);
}
Aggregations