use of net.silentchaos512.gear.api.material.IMaterialDisplay in project Silent-Gear by SilentChaos512.
the class GearDisplayManager method getMaterials.
public static Collection<IMaterialDisplay> getMaterials() {
synchronized (MATERIALS) {
Collection<IMaterialDisplay> ret = new ArrayList<>();
for (IMaterial material : MaterialManager.getValues()) {
MaterialInstance mat = MaterialInstance.of(material);
ret.add(mat.getDisplayProperties());
}
ret.addAll(MATERIALS.values());
return ret;
}
}
use of net.silentchaos512.gear.api.material.IMaterialDisplay in project Silent-Gear by SilentChaos512.
the class GearDisplayManager method reloadMaterials.
private static void reloadMaterials(ResourceManager resourceManager) {
Collection<ResourceLocation> resources = resourceManager.listResources(PATH_MATERIALS, s -> s.endsWith(".json"));
if (resources.isEmpty())
return;
synchronized (MATERIALS) {
SilentGear.LOGGER.info("Reloading material model files");
MATERIALS.clear();
String packName = "ERROR";
for (ResourceLocation id : resources) {
String path = id.getPath().substring(PATH_MATERIALS.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 material model {} as it's null or empty", name);
} else {
IMaterialDisplay model = MaterialDisplay.deserialize(name, json);
MATERIALS.put(name, model);
}
} catch (IllegalArgumentException | JsonParseException ex) {
SilentGear.LOGGER.error("Parsing error loading material model {}", name, ex);
ERROR_LIST.add(String.format("material:%s (%s)", name, packName));
} catch (IOException ex) {
SilentGear.LOGGER.error("Could not read material model {}", name, ex);
ERROR_LIST.add(String.format("material:%s (%s)", name, packName));
}
}
}
}
use of net.silentchaos512.gear.api.material.IMaterialDisplay in project Silent-Gear by SilentChaos512.
the class GearModelOverrideList method addWithBlendedColor.
private static void addWithBlendedColor(List<MaterialLayer> list, PartData part, MaterialInstance material, ItemStack stack) {
IMaterialDisplay model = material.getDisplayProperties();
GearType gearType = GearHelper.getType(stack);
List<MaterialLayer> layers = model.getLayerList(gearType, part, material).getLayers();
addColorBlendedLayers(list, part, stack, layers);
}
use of net.silentchaos512.gear.api.material.IMaterialDisplay in project Silent-Gear by SilentChaos512.
the class CompoundPartModel method buildFakeModel.
private void buildFakeModel(Function<Material, TextureAtlasSprite> spriteGetter, ImmutableList.Builder<BakedQuad> builder, Transformation rotation, IMaterial material) {
// This method will display an example item for items with no data (ie, for advancements)
MaterialInstance mat = MaterialInstance.of(material);
IMaterialDisplay model = mat.getDisplayProperties();
MaterialLayer exampleMain = model.getLayerList(this.gearType, this.partType, mat).getFirstLayer();
if (exampleMain != null) {
builder.addAll(getQuadsForSprite(0, spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, exampleMain.getTexture(this.texturePath, 0))), rotation, exampleMain.getColor()));
}
builder.addAll(getQuadsForSprite(0, spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, new StaticLayer(PART_MARKER_TEXTURE).getTexture(this.gearType, 0))), rotation, Color.VALUE_WHITE));
}
use of net.silentchaos512.gear.api.material.IMaterialDisplay in project Silent-Gear by SilentChaos512.
the class FragmentModel method buildFakeModel.
private void buildFakeModel(Function<Material, TextureAtlasSprite> spriteGetter, ImmutableList.Builder<BakedQuad> builder, Transformation rotation, IMaterial material) {
// This method will display an example item for items with no data (ie, for advancements)
MaterialInstance mat = MaterialInstance.of(material);
IMaterialDisplay model = mat.getDisplayProperties();
MaterialLayer exampleMain = model.getLayerList(GearType.FRAGMENT, PartType.MAIN, mat).getFirstLayer();
if (exampleMain != null) {
builder.addAll(getQuadsForSprite(0, spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, exampleMain.getTexture(GearType.FRAGMENT, 0))), rotation, exampleMain.getColor()));
}
}
Aggregations