com.parzivail.util.client.model.AbstractModel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pswg Show documentation
Show all versions of pswg Show documentation
Explore the galaxy with Galaxies: Parzi's Star Wars Mod!
/*******************************************************************************
* Copyright 2019 grondag
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.parzivail.util.client.model;
import com.parzivail.pswg.Galaxies;
import com.parzivail.util.client.model.compat.FrapiCompat;
import com.parzivail.util.client.model.compat.IndiumCompat;
import net.fabricmc.fabric.api.renderer.v1.Renderer;
import net.fabricmc.fabric.api.renderer.v1.RendererAccess;
import net.fabricmc.fabric.api.renderer.v1.material.BlendMode;
import net.fabricmc.fabric.api.renderer.v1.material.MaterialFinder;
import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial;
import net.fabricmc.fabric.api.renderer.v1.mesh.MeshBuilder;
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
import net.fabricmc.fabric.api.util.TriState;
import net.minecraft.class_1058;
import net.minecraft.class_1087;
import net.minecraft.class_809;
import java.util.Optional;
public abstract class AbstractModel implements class_1087, FabricBakedModel
{
private static MaterialFinder MATERIAL_FINDER;
public static RenderMaterial MAT_DIFFUSE_OPAQUE;
public static RenderMaterial MAT_DIFFUSE_CUTOUT;
public static RenderMaterial MAT_DIFFUSE_TRANSLUCENT;
public static RenderMaterial MAT_EMISSIVE;
protected final class_1058 modelSprite;
protected final class_809 transformation;
protected AbstractModel(class_1058 sprite, class_809 transformation)
{
modelSprite = sprite;
this.transformation = transformation;
if (MATERIAL_FINDER == null)
{
MATERIAL_FINDER = createMaterialFinder();
MAT_DIFFUSE_OPAQUE = MATERIAL_FINDER.find();
MAT_DIFFUSE_CUTOUT = MATERIAL_FINDER.blendMode(BlendMode.CUTOUT_MIPPED).find();
MAT_DIFFUSE_TRANSLUCENT = MATERIAL_FINDER.blendMode(BlendMode.TRANSLUCENT).find();
MAT_EMISSIVE = MATERIAL_FINDER.emissive(true).ambientOcclusion(TriState.FALSE).disableDiffuse(true).find();
}
}
protected static MaterialFinder createMaterialFinder()
{
return Optional
.ofNullable(RendererAccess.INSTANCE.getRenderer()).map(Renderer::materialFinder)
.or(IndiumCompat::getMaterialFinder)
.or(() -> {
Galaxies.LOG.warn("No MaterialFinder found in Fabric API or Indium!");
return FrapiCompat.getMaterialFinder82();
})
.orElseThrow(() -> new RuntimeException("No MaterialFinder found in Fabric API, Indium, or Fabric (impl)!"));
}
protected static MeshBuilder createMeshBuilder()
{
return Optional
.ofNullable(RendererAccess.INSTANCE.getRenderer()).map(Renderer::meshBuilder)
.or(IndiumCompat::getMeshBuilder)
.or(() -> {
Galaxies.LOG.warn("No MeshBuilder found in Fabric API or Indium!");
return FrapiCompat.getMeshBuilder();
})
.orElseThrow(() -> new RuntimeException("No MeshBuilder found in Fabric API, Indium, or Fabric (impl)!"));
}
@Override
public boolean method_4708()
{
return true;
}
@Override
public boolean method_4713()
{
return false;
}
@Override
public class_1058 method_4711()
{
return modelSprite;
}
@Override
public class_809 method_4709()
{
return transformation;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy