Fixes #2577: Use the item stacks color handler to color tinted quads of the block model.

This commit is contained in:
Sebastian Hartte 2016-11-06 03:35:56 +01:00
parent efa0ab7e4e
commit fbb0c05c7f
5 changed files with 88 additions and 35 deletions

View file

@ -108,8 +108,9 @@ public class FacadeDispatcherBakedModel implements IBakedModel
ItemFacade itemFacade = (ItemFacade) stack.getItem();
IBlockState state = itemFacade.getTextureBlockState( stack );
ItemStack textureItem = itemFacade.getTextureItem( stack );
return new FacadeWithBlockBakedModel( baseModel, state, format );
return new FacadeWithBlockBakedModel( baseModel, state, textureItem, format );
}
};
}

View file

@ -32,6 +32,7 @@ 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.client.renderer.vertex.VertexFormat;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import appeng.client.render.cablebus.CubeBuilder;
@ -53,10 +54,13 @@ public class FacadeWithBlockBakedModel implements IBakedModel
private final VertexFormat format;
public FacadeWithBlockBakedModel( IBakedModel baseModel, IBlockState blockState, VertexFormat format )
private final ItemStack textureItem;
public FacadeWithBlockBakedModel( IBakedModel baseModel, IBlockState blockState, ItemStack textureItem, VertexFormat format )
{
this.baseModel = baseModel;
this.blockState = blockState;
this.textureItem = textureItem;
this.textureModel = Minecraft.getMinecraft().getBlockRendererDispatcher().getModelForState( blockState );
this.format = format;
}
@ -69,10 +73,14 @@ public class FacadeWithBlockBakedModel implements IBakedModel
{
List<BakedQuad> quads = new ArrayList<>( 1 );
CubeBuilder builder = new CubeBuilder( format, quads );
TextureAtlasSprite sprite = FacadeBuilder.getSprite( textureModel, blockState, side, rand );
if ( sprite != null )
FacadeBuilder.TextureAtlasAndTint sprite = FacadeBuilder.getSprite( textureModel, blockState, side, rand );
if ( sprite != null && sprite.getSprite() != null )
{
builder.setTexture( sprite );
if( sprite.getTint() != -1 )
{
builder.setColor( Minecraft.getMinecraft().getItemColors().getColorFromItemstack( textureItem, sprite.getTint() ) );
}
builder.setTexture( sprite.getSprite() );
builder.setDrawFaces( EnumSet.of( EnumFacing.NORTH ) );
builder.addCube( 0, 0, 0, 16, 16, 16 );
return quads;

View file

@ -36,7 +36,6 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockRendererDispatcher;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.color.BlockColors;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.util.BlockRenderLayer;
@ -60,8 +59,6 @@ public class FacadeBuilder
private static final ResourceLocation TEXTURE_FACADE = new ResourceLocation( AppEng.MOD_ID, "parts/cable_anchor" );
private final BlockColors blockColors = Minecraft.getMinecraft().getBlockColors();
private final VertexFormat format;
private final TextureAtlasSprite facadeTexture;
@ -87,7 +84,7 @@ public class FacadeBuilder
CubeBuilder builder = new CubeBuilder( format, quads );
facadesState.forEach( ( side, textureItem ) ->
facadesState.forEach( ( side, state ) ->
{
AxisAlignedBB facadeBox = getFacadeBox( side, thinFacades );
AEAxisAlignedBB cutOutBox = getCutOutBox( facadeBox, partBoxes );
@ -104,10 +101,10 @@ public class FacadeBuilder
} );
}
public static TextureAtlasSprite getSprite( IBakedModel blockModel, IBlockState state, EnumFacing facing, long rand)
public static TextureAtlasAndTint getSprite( IBakedModel blockModel, IBlockState state, EnumFacing facing, long rand)
{
TextureAtlasSprite firstFound = null;
TextureAtlasAndTint firstFound = null;
BlockRenderLayer orgLayer = MinecraftForgeClient.getRenderLayer();
try
@ -120,18 +117,18 @@ public class FacadeBuilder
for( BakedQuad bakedQuad : blockModel.getQuads( state, facing, rand ) )
{
return bakedQuad.getSprite();
return new TextureAtlasAndTint( bakedQuad );
}
for( BakedQuad bakedQuad : blockModel.getQuads( state, null, rand ) )
{
if( firstFound == null )
{
firstFound = bakedQuad.getSprite();
firstFound = new TextureAtlasAndTint( bakedQuad );
}
if( bakedQuad.getFace() == facing )
{
return bakedQuad.getSprite();
return new TextureAtlasAndTint( bakedQuad );
}
}
}
@ -154,7 +151,7 @@ public class FacadeBuilder
{
try
{
return blockModel.getParticleTexture();
return new TextureAtlasAndTint( blockModel.getParticleTexture(), -1 );
}
catch( Exception e )
{
@ -215,36 +212,42 @@ public class FacadeBuilder
IBakedModel blockModel = blockRendererDispatcher.getModelForState( blockState );
int color = 0xffffff;
try
{
blockColors.getColor( blockState );
}
catch( final Throwable ignored )
{
}
final int color;
if( translucent )
{
color &= 0xFFFFFF;
color |= 0x4C000000;
builder.setColor( color );
color = 0x4CFFFFFF;
}
else
{
builder.setColorRGB( color );
color = 0xFFFFFFFF;
}
// TODO: Cache this
for( EnumFacing facing : facadeState.getOpenFaces() )
{
TextureAtlasSprite sprite = getSprite( blockModel, blockState, facing, rand );
if( sprite != null )
TextureAtlasAndTint spriteAndTint = getSprite( blockModel, blockState, facing, rand );
if( spriteAndTint != null && spriteAndTint.sprite != null )
{
builder.setTexture( facing, sprite );
// Use the tint color from the item stack here, which is based upon the assumption that the
// model used for the block will use the same meaning for tint indices as the item model does
if( spriteAndTint.tint != -1 )
{
int tintColor = facadeState.resolveTintColor( spriteAndTint.tint );
// Still apply the transparency color
tintColor &= 0xFFFFFF;
tintColor |= color & 0xFF000000;
builder.setColor( tintColor );
}
else
{
builder.setColor( color );
}
builder.setTexture( facing, spriteAndTint.sprite );
}
else
{
builder.setColor( color );
builder.setTexture( facing, facadeTexture );
}
}
@ -460,4 +463,34 @@ public class FacadeBuilder
throw new IllegalArgumentException( "Unsupported face: " + side );
}
}
public static class TextureAtlasAndTint
{
private final TextureAtlasSprite sprite;
private final int tint;
private TextureAtlasAndTint( BakedQuad quad )
{
this.sprite = quad.getSprite();
this.tint = quad.getTintIndex();
}
private TextureAtlasAndTint( TextureAtlasSprite sprite, int tint )
{
this.sprite = sprite;
this.tint = tint;
}
public TextureAtlasSprite getSprite()
{
return sprite;
}
public int getTint()
{
return tint;
}
}
}

View file

@ -4,6 +4,8 @@ package appeng.client.render.cablebus;
import java.util.EnumSet;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
@ -19,10 +21,14 @@ public class FacadeRenderState
// Which faces of the cube should be rendered for this particular facade
private final EnumSet<EnumFacing> openFaces;
public FacadeRenderState( IBlockState sourceBlock, EnumSet<EnumFacing> openFaces )
// For resolving the tint indices of a facade
private final ItemStack textureItem;
public FacadeRenderState( IBlockState sourceBlock, EnumSet<EnumFacing> openFaces, ItemStack textureItem )
{
this.sourceBlock = sourceBlock;
this.openFaces = openFaces;
this.textureItem = textureItem;
}
public IBlockState getSourceBlock()
@ -35,4 +41,9 @@ public class FacadeRenderState
return openFaces;
}
public int resolveTintColor( int tintIndex )
{
return Minecraft.getMinecraft().getItemColors().getColorFromItemstack( textureItem, tintIndex );
}
}

View file

@ -1261,12 +1261,12 @@ public class CableBusContainer extends CableBusStorage implements AEMultiTile, I
IFacadePart facade = getFacade( side.ordinal() );
if( facade != null )
{
ItemStack textureItem = facade.getTextureItem();
IBlockState blockState = facade.getBlockState();
if( blockState != null )
if( blockState != null && textureItem != null )
{
EnumSet<EnumFacing> openFaces = calculateFaceOpenFaces( side );
return new FacadeRenderState( blockState, openFaces );
return new FacadeRenderState( blockState, openFaces, textureItem );
}
}