use of net.silentchaos512.gear.api.material.MaterialLayer 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.material.MaterialLayer in project Silent-Gear by SilentChaos512.
the class GearModelOverrideList method getCrossbowCharge.
private static Optional<MaterialLayer> getCrossbowCharge(ItemStack stack, @Nullable ClientLevel world, @Nullable LivingEntity entity) {
// TODO: Maybe should add an ICoreItem method to get additional layers?
ItemPropertyFunction chargedProperty = ItemProperties.getProperty(stack.getItem(), new ResourceLocation("charged"));
ItemPropertyFunction fireworkProperty = ItemProperties.getProperty(stack.getItem(), new ResourceLocation("firework"));
if (chargedProperty != null && fireworkProperty != null) {
boolean charged = chargedProperty.call(stack, world, entity, 0) > 0;
boolean firework = fireworkProperty.call(stack, world, entity, 0) > 0;
if (charged) {
if (firework) {
return Optional.of(new MaterialLayer(PartTextures.CHARGED_FIREWORK, Color.VALUE_WHITE));
}
return Optional.of(new MaterialLayer(PartTextures.CHARGED_ARROW, Color.VALUE_WHITE));
}
}
return Optional.empty();
}
use of net.silentchaos512.gear.api.material.MaterialLayer 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);
}
use of net.silentchaos512.gear.api.material.MaterialLayer 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.MaterialLayer in project Silent-Gear by SilentChaos512.
the class CompoundPartModel method bake.
@SuppressWarnings("MethodWithTooManyParameters")
public BakedModel bake(List<MaterialLayer> layers, String transformVariant, IModelConfiguration owner, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelTransform, ItemOverrides overrideList, 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(this.texturePath, 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, Color.VALUE_WHITE));
}
}
// Extras
for (int i = 0; i < this.extraLayers.size(); i++) {
ResourceLocation texture = this.extraLayers.get(i);
builder.addAll(getQuadsForSprite(layers.size() + i, spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, new StaticLayer(texture).getTexture())), rotation, Color.VALUE_WHITE));
}
builder.addAll(getQuadsForSprite(layers.size(), spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, new StaticLayer(PART_MARKER_TEXTURE).getTexture())), rotation, Color.LIGHTSKYBLUE.getColor()));
TextureAtlasSprite particle = spriteGetter.apply(owner.resolveTexture("particle"));
return new BakedPerspectiveModel(builder.build(), particle, transforms, overrideList, rotation.isIdentity(), owner.isSideLit(), getCameraTransforms(transformVariant));
}
Aggregations