use of net.silentchaos512.gear.api.part.IPartDisplay in project Silent-Gear by SilentChaos512.
the class GearModel method getTextures.
@SuppressWarnings("OverlyComplexMethod")
@Override
public Collection<Material> getTextures(IModelConfiguration owner, Function<ResourceLocation, UnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
Set<Material> ret = new HashSet<>();
ret.add(new Material(InventoryMenu.BLOCK_ATLAS, SilentGear.getId("item/error")));
// Generic built-in textures
for (PartTextures tex : PartTextures.getTextures(this.gearType)) {
int animationFrames = tex.isAnimated() ? item.getAnimationFrames() : 1;
for (int i = 0; i < animationFrames; ++i) {
MaterialLayer layer = new MaterialLayer(tex, Color.VALUE_WHITE);
ret.add(getTexture(layer, i, false));
ret.add(getTexture(layer, 0, true));
}
}
// Custom textures
for (IMaterialDisplay materialDisplay : GearDisplayManager.getMaterials()) {
for (PartType partType : PartType.getValues()) {
if (item.hasTexturesFor(partType)) {
for (MaterialLayer layer : materialDisplay.getLayerList(gearType, partType, LazyMaterialInstance.of(materialDisplay.getMaterialId()))) {
int animationFrames = layer.isAnimated() ? item.getAnimationFrames() : 1;
ret.addAll(this.getTexturesForAllFrames(layer, animationFrames, false));
ret.addAll(this.getTexturesForAllFrames(layer, 1, true));
}
}
}
}
for (IPartDisplay partDisplay : GearDisplayManager.getParts()) {
for (MaterialLayer layer : partDisplay.getLayers(gearType, FakePartData.of(PartType.NONE))) {
int animationFrames = layer.isAnimated() ? item.getAnimationFrames() : 1;
ret.addAll(this.getTexturesForAllFrames(layer, animationFrames, false));
ret.addAll(this.getTexturesForAllFrames(layer, animationFrames, true));
}
}
if (GearModelOverrideList.isDebugLoggingEnabled()) {
SilentGear.LOGGER.info("Textures for gear model '{}' ({})", getTexturePath(false), this.gearType.getName());
for (Material mat : ret) {
SilentGear.LOGGER.info("- {}", mat.texture());
}
}
return ret;
}
use of net.silentchaos512.gear.api.part.IPartDisplay in project Silent-Gear by SilentChaos512.
the class GearModelOverrideList method addSimplePartLayers.
private static void addSimplePartLayers(List<MaterialLayer> list, PartData part, ItemStack stack) {
IPartDisplay model = GearDisplayManager.get(part.get());
if (model != null) {
GearType gearType = GearHelper.getType(stack);
List<MaterialLayer> layers = model.getLayers(gearType, part).getLayers();
addColorBlendedLayers(list, part, stack, layers);
}
}
use of net.silentchaos512.gear.api.part.IPartDisplay in project Silent-Gear by SilentChaos512.
the class GearDisplayManager method reloadParts.
private static void reloadParts(ResourceManager resourceManager) {
Collection<ResourceLocation> resources = resourceManager.listResources(PATH_PARTS, s -> s.endsWith(".json"));
if (resources.isEmpty())
return;
synchronized (PARTS) {
SilentGear.LOGGER.info("Reloading part model files");
PARTS.clear();
String packName = "ERROR";
for (ResourceLocation id : resources) {
String path = id.getPath().substring(PATH_PARTS.length() + 1, id.getPath().length() - ".json".length());
ResourceLocation name = new ResourceLocation(id.getNamespace(), path);
try (Resource iresource = resourceManager.getResource(id)) {
packName = iresource.getSourceName();
JsonObject json = GsonHelper.fromJson(GSON, IOUtils.toString(iresource.getInputStream(), StandardCharsets.UTF_8), JsonObject.class);
if (json == null) {
SilentGear.LOGGER.error("Could not load part model {} as it's null or empty", name);
} else {
IPartDisplay model = PartDisplay.deserialize(name, json);
PARTS.put(name, model);
}
} catch (IllegalArgumentException | JsonParseException ex) {
SilentGear.LOGGER.error("Parsing error loading part model {}", name, ex);
ERROR_LIST.add(String.format("part:%s (%s)", name, packName));
} catch (IOException ex) {
SilentGear.LOGGER.error("Could not read part model {}", name, ex);
ERROR_LIST.add(String.format("part:%s (%s)", name, packName));
}
}
}
}
Aggregations