use of net.silentchaos512.gear.api.material.MaterialLayer in project Silent-Gear by SilentChaos512.
the class CompoundPartModelOverrideList method getOverrideModel.
private BakedModel getOverrideModel(ItemStack stack, @Nullable ClientLevel worldIn, @Nullable LivingEntity entityIn) {
List<MaterialLayer> layers = new ArrayList<>();
PartData part = PartData.from(stack);
MaterialInstance primaryMaterial = CompoundPartItem.getPrimaryMaterial(stack);
if (part != null && primaryMaterial != null) {
addWithBlendedColor(layers, part, primaryMaterial, stack);
}
return model.bake(layers, "test", owner, bakery, spriteGetter, modelTransform, this, modelLocation);
}
use of net.silentchaos512.gear.api.material.MaterialLayer 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()));
}
}
use of net.silentchaos512.gear.api.material.MaterialLayer in project Silent-Gear by SilentChaos512.
the class FragmentModel method bake.
@SuppressWarnings("MethodWithTooManyParameters")
public BakedModel bake(List<MaterialLayer> layers, IModelConfiguration owner, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelTransform, FragmentModelOverrideList fragmentModelOverrideList, ResourceLocation modelLocation) {
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
Transformation rotation = modelTransform.getRotation();
ImmutableMap<ItemTransforms.TransformType, Transformation> transforms = PerspectiveMapWrapper.getTransforms(modelTransform);
for (int i = 0; i < layers.size(); i++) {
MaterialLayer layer = layers.get(i);
TextureAtlasSprite texture = spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, layer.getTexture(GearType.FRAGMENT, 0)));
builder.addAll(getQuadsForSprite(i, texture, rotation, layer.getColor()));
}
// No layers?
if (layers.isEmpty()) {
if (Const.Materials.EXAMPLE.isPresent()) {
buildFakeModel(spriteGetter, builder, rotation, Const.Materials.EXAMPLE.get());
} else {
// Shouldn't happen, but...
SilentGear.LOGGER.error("Example material is missing?");
TextureAtlasSprite texture = spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, SilentGear.getId("item/error")));
builder.addAll(getQuadsForSprite(0, texture, rotation, 0xFFFFFF));
}
}
TextureAtlasSprite particle = spriteGetter.apply(owner.resolveTexture("particle"));
return new BakedPerspectiveModel(builder.build(), particle, transforms, overrideList, rotation.isIdentity(), owner.isSideLit(), cameraTransforms);
}
use of net.silentchaos512.gear.api.material.MaterialLayer in project Silent-Gear by SilentChaos512.
the class FragmentModel method getTextures.
@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
ret.add(getTexture(PartTextures.CLOTH.getTexture()));
ret.add(getTexture(PartTextures.METAL.getTexture()));
ret.add(getTexture(PartTextures.WOOD.getTexture()));
// Custom textures
for (IMaterialDisplay materialDisplay : GearDisplayManager.getMaterials()) {
for (MaterialLayer layer : materialDisplay.getLayerList(GearType.FRAGMENT, PartType.MAIN, LazyMaterialInstance.of(materialDisplay.getMaterialId()))) {
ret.add(getTexture(layer));
}
}
SilentGear.LOGGER.info("Textures for fragment model");
for (Material mat : ret) {
SilentGear.LOGGER.info("- {}", mat.texture());
}
return ret;
}
use of net.silentchaos512.gear.api.material.MaterialLayer 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;
}
Aggregations