Fixes #2376: Implemented coloring on color applicator.
This commit is contained in:
@@ -36,12 +36,7 @@ import appeng.client.render.cablebus.CubeBuilder;
|
||||
import appeng.core.AELog;
|
||||
|
||||
|
||||
/**
|
||||
* @author Sebastian
|
||||
* @version rv3 - 10.10.2016
|
||||
* @since rv3 10.10.2016
|
||||
*/
|
||||
public class BiometricCardBakedModel implements IPerspectiveAwareModel
|
||||
class BiometricCardBakedModel implements IPerspectiveAwareModel
|
||||
{
|
||||
|
||||
private final VertexFormat format;
|
||||
@@ -58,12 +53,12 @@ public class BiometricCardBakedModel implements IPerspectiveAwareModel
|
||||
|
||||
private final ImmutableList<BakedQuad> generalQuads;
|
||||
|
||||
public BiometricCardBakedModel( VertexFormat format, IBakedModel baseModel, TextureAtlasSprite texture, ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms )
|
||||
BiometricCardBakedModel( VertexFormat format, IBakedModel baseModel, TextureAtlasSprite texture, ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms )
|
||||
{
|
||||
this( format, baseModel, texture, 0, transforms );
|
||||
}
|
||||
|
||||
public BiometricCardBakedModel( VertexFormat format, IBakedModel baseModel, TextureAtlasSprite texture, int hash, ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms )
|
||||
BiometricCardBakedModel( VertexFormat format, IBakedModel baseModel, TextureAtlasSprite texture, int hash, ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms )
|
||||
{
|
||||
this.format = format;
|
||||
this.baseModel = baseModel;
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
package appeng.client.render.model;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.vecmath.Matrix4f;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
|
||||
import net.minecraft.client.renderer.block.model.ItemOverrideList;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.client.model.IPerspectiveAwareModel;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
|
||||
|
||||
class ColorApplicatorBakedModel implements IPerspectiveAwareModel
|
||||
{
|
||||
|
||||
private final IBakedModel baseModel;
|
||||
|
||||
private final ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms;
|
||||
|
||||
private final EnumMap<EnumFacing, List<BakedQuad>> quadsBySide;
|
||||
|
||||
private final List<BakedQuad> generalQuads;
|
||||
|
||||
ColorApplicatorBakedModel( IBakedModel baseModel, ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> map,
|
||||
TextureAtlasSprite texDark, TextureAtlasSprite texMedium, TextureAtlasSprite texBright )
|
||||
{
|
||||
this.baseModel = baseModel;
|
||||
this.transforms = map;
|
||||
|
||||
// Put the tint indices in... Since this is an item model, we are ignoring rand
|
||||
this.generalQuads = fixQuadTint( null, texDark, texMedium, texBright );
|
||||
this.quadsBySide = new EnumMap<>( EnumFacing.class );
|
||||
for( EnumFacing facing : EnumFacing.values() )
|
||||
{
|
||||
this.quadsBySide.put( facing, fixQuadTint( facing, texDark, texMedium, texBright ) );
|
||||
}
|
||||
}
|
||||
|
||||
private List<BakedQuad> fixQuadTint( EnumFacing facing, TextureAtlasSprite texDark, TextureAtlasSprite texMedium, TextureAtlasSprite texBright )
|
||||
{
|
||||
List<BakedQuad> quads = baseModel.getQuads( null, facing, 0 );
|
||||
List<BakedQuad> result = new ArrayList<>( quads.size() );
|
||||
for( BakedQuad quad : quads )
|
||||
{
|
||||
int tint;
|
||||
|
||||
if( quad.getSprite() == texDark )
|
||||
{
|
||||
tint = 1;
|
||||
}
|
||||
else if( quad.getSprite() == texMedium )
|
||||
{
|
||||
tint = 2;
|
||||
}
|
||||
else if( quad.getSprite() == texBright )
|
||||
{
|
||||
tint = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.add( quad );
|
||||
continue;
|
||||
}
|
||||
|
||||
BakedQuad newQuad = new BakedQuad(
|
||||
quad.getVertexData(),
|
||||
tint,
|
||||
quad.getFace(),
|
||||
quad.getSprite(),
|
||||
quad.shouldApplyDiffuseLighting(),
|
||||
quad.getFormat()
|
||||
);
|
||||
result.add( newQuad );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads( @Nullable IBlockState state, @Nullable EnumFacing side, long rand )
|
||||
{
|
||||
if( side == null )
|
||||
{
|
||||
return generalQuads;
|
||||
}
|
||||
return this.quadsBySide.get( side );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAmbientOcclusion()
|
||||
{
|
||||
return baseModel.isAmbientOcclusion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGui3d()
|
||||
{
|
||||
return baseModel.isGui3d();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltInRenderer()
|
||||
{
|
||||
return baseModel.isBuiltInRenderer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getParticleTexture()
|
||||
{
|
||||
return baseModel.getParticleTexture();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemCameraTransforms getItemCameraTransforms()
|
||||
{
|
||||
return baseModel.getItemCameraTransforms();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemOverrideList getOverrides()
|
||||
{
|
||||
return baseModel.getOverrides();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<? extends IBakedModel, Matrix4f> handlePerspective( ItemCameraTransforms.TransformType type )
|
||||
{
|
||||
return MapWrapper.handlePerspective( this, transforms, type );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package appeng.client.render.model;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.client.model.IPerspectiveAwareModel;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
|
||||
import appeng.core.AppEng;
|
||||
|
||||
|
||||
/**
|
||||
* A color applicator uses the base model, and extends it with additional layers that are colored according to the selected color of the applicator.
|
||||
*/
|
||||
public class ColorApplicatorModel implements IModel
|
||||
{
|
||||
|
||||
private static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "item/color_applicator_colored" );
|
||||
|
||||
private static final ResourceLocation TEXTURE_DARK = new ResourceLocation( AppEng.MOD_ID, "items/color_applicator_tip_dark" );
|
||||
private static final ResourceLocation TEXTURE_MEDIUM = new ResourceLocation( AppEng.MOD_ID, "items/color_applicator_tip_medium" );
|
||||
private static final ResourceLocation TEXTURE_BRIGHT = new ResourceLocation( AppEng.MOD_ID, "items/color_applicator_tip_bright" );
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getDependencies()
|
||||
{
|
||||
return Collections.singletonList( MODEL_BASE );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getTextures()
|
||||
{
|
||||
return ImmutableList.of(
|
||||
TEXTURE_DARK,
|
||||
TEXTURE_MEDIUM,
|
||||
TEXTURE_BRIGHT
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel bake( IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter )
|
||||
{
|
||||
IBakedModel baseModel = getBaseModel( state, format, bakedTextureGetter );
|
||||
|
||||
TextureAtlasSprite texDark = bakedTextureGetter.apply( TEXTURE_DARK );
|
||||
TextureAtlasSprite texMedium = bakedTextureGetter.apply( TEXTURE_MEDIUM );
|
||||
TextureAtlasSprite texBright = bakedTextureGetter.apply( TEXTURE_BRIGHT );
|
||||
|
||||
ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> map = IPerspectiveAwareModel.MapWrapper.getTransforms( state );
|
||||
|
||||
return new ColorApplicatorBakedModel( baseModel, map, texDark, texMedium, texBright );
|
||||
}
|
||||
|
||||
private IBakedModel getBaseModel( IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter )
|
||||
{
|
||||
// Load the base model
|
||||
try
|
||||
{
|
||||
return ModelLoaderRegistry.getModel( MODEL_BASE ).bake( state, format, bakedTextureGetter );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
throw new RuntimeException( e );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModelState getDefaultState()
|
||||
{
|
||||
return TRSRTransformation.identity();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user