Implemented translucent facades.

This commit is contained in:
Sebastian Hartte 2016-10-15 13:40:41 +02:00
parent 9c69352f9a
commit ea8c02b591
3 changed files with 53 additions and 43 deletions

View File

@ -66,9 +66,7 @@ import appeng.block.AEBaseTileBlock;
import appeng.client.UnlistedProperty;
import appeng.client.render.cablebus.CableBusBakedModel;
import appeng.client.render.cablebus.CableBusRenderState;
import appeng.core.AEConfig;
import appeng.core.Api;
import appeng.core.features.AEFeature;
import appeng.helpers.AEGlassMaterial;
import appeng.integration.IntegrationRegistry;
import appeng.integration.IntegrationType;
@ -226,17 +224,6 @@ public class BlockCableBus extends AEBaseTileBlock
return this.cb( w, pos ).canConnectRedstone( EnumSet.of( side ) );
}
@Override
public boolean canRenderInLayer( final BlockRenderLayer layer )
{
if( AEConfig.instance.isFeatureEnabled( AEFeature.AlphaPass ) )
{
return layer == BlockRenderLayer.CUTOUT || layer == BlockRenderLayer.TRANSLUCENT;
}
return layer == BlockRenderLayer.CUTOUT;
}
@Override
public ItemStack getPickBlock( final IBlockState state, final RayTraceResult target, final World world, final BlockPos pos, final EntityPlayer player )
{
@ -423,7 +410,7 @@ public class BlockCableBus extends AEBaseTileBlock
{
if( AEApi.instance().partHelper().getCableRenderMode().transparentFacades )
{
return layer == BlockRenderLayer.TRANSLUCENT;
return layer == BlockRenderLayer.CUTOUT || layer == BlockRenderLayer.TRANSLUCENT;
}
else
{

View File

@ -34,8 +34,10 @@ 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.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.common.property.IExtendedBlockState;
import appeng.api.util.AECableType;
@ -72,38 +74,47 @@ public class CableBusBakedModel implements IBakedModel
return Collections.emptyList();
}
// First, handle the cable at the center of the cable bus
BlockRenderLayer layer = MinecraftForgeClient.getRenderLayer();
List<BakedQuad> quads = new ArrayList<>();
addCableQuads( renderState, quads );
for( EnumFacing facing : EnumFacing.values() )
// The core parts of the cable will only be rendered in the CUTOUT layer. TRANSLUCENT is used only for translucent facades further down below.
if ( layer == BlockRenderLayer.CUTOUT )
{
List<ResourceLocation> models = renderState.getAttachments().get( facing );
if( models == null )
{
continue;
}
// First, handle the cable at the center of the cable bus
addCableQuads( renderState, quads );
for( ResourceLocation model : models )
// Then handle attachments
for( EnumFacing facing : EnumFacing.values() )
{
IBakedModel bakedModel = partModels.get( model );
if( bakedModel == null )
List<ResourceLocation> models = renderState.getAttachments().get( facing );
if( models == null )
{
throw new IllegalStateException( "Trying to use an unregistered part model: " + model );
continue;
}
List<BakedQuad> partQuads = bakedModel.getQuads( state, null, rand );
for( ResourceLocation model : models )
{
IBakedModel bakedModel = partModels.get( model );
// Rotate quads accordingly
QuadRotator rotator = new QuadRotator();
partQuads = rotator.rotateQuads( partQuads, facing, EnumFacing.UP );
if( bakedModel == null )
{
throw new IllegalStateException( "Trying to use an unregistered part model: " + model );
}
quads.addAll( partQuads );
List<BakedQuad> partQuads = bakedModel.getQuads( state, null, rand );
// Rotate quads accordingly
QuadRotator rotator = new QuadRotator();
partQuads = rotator.rotateQuads( partQuads, facing, EnumFacing.UP );
quads.addAll( partQuads );
}
}
}
facadeBuilder.addFacades(
layer,
renderState.getFacades(),
renderState.getBoundingBoxes(),
renderState.getAttachments().keySet(),

View File

@ -38,6 +38,7 @@ 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;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
@ -54,7 +55,7 @@ import appeng.core.AppEng;
public class FacadeBuilder
{
static final ResourceLocation TEXTURE_FACADE = new ResourceLocation( AppEng.MOD_ID, "parts/cable_anchor" );
private static final ResourceLocation TEXTURE_FACADE = new ResourceLocation( AppEng.MOD_ID, "parts/cable_anchor" );
private final BlockColors blockColors = Minecraft.getMinecraft().getBlockColors();
@ -74,7 +75,7 @@ public class FacadeBuilder
return Collections.singletonList( TEXTURE_FACADE );
}
void addFacades( Map<EnumFacing, FacadeRenderState> facadesState, List<AxisAlignedBB> partBoxes, Set<EnumFacing> sidesWithParts, long rand, List<BakedQuad> quads )
void addFacades( BlockRenderLayer layer, Map<EnumFacing, FacadeRenderState> facadesState, List<AxisAlignedBB> partBoxes, Set<EnumFacing> sidesWithParts, long rand, List<BakedQuad> quads )
{
boolean thinFacades = isUseThinFacades( partBoxes );
@ -88,7 +89,7 @@ public class FacadeBuilder
try
{
addFacade( facadesState, side, cutOutBox, thinFacades, renderStilt, rand, builder );
addFacade( layer, facadesState, side, cutOutBox, thinFacades, renderStilt, rand, builder );
}
catch( Throwable t )
{
@ -119,7 +120,7 @@ public class FacadeBuilder
return firstFound;
}
private void addFacade( Map<EnumFacing, FacadeRenderState> facades, EnumFacing side, AEAxisAlignedBB busBounds, boolean thinFacades, boolean renderStilt, long rand, CubeBuilder builder )
private void addFacade( BlockRenderLayer layer, Map<EnumFacing, FacadeRenderState> facades, EnumFacing side, AEAxisAlignedBB busBounds, boolean thinFacades, boolean renderStilt, long rand, CubeBuilder builder )
{
FacadeRenderState facadeState = facades.get( side );
@ -128,7 +129,7 @@ public class FacadeBuilder
builder.setDrawFaces( EnumSet.allOf( EnumFacing.class ) );
// We only render the stilt if we don't intersect with any part directly, and if there's no part on our side
if( renderStilt && busBounds == null )
if( renderStilt && busBounds == null && layer == BlockRenderLayer.CUTOUT )
{
builder.setTexture( facadeTexture );
switch( side )
@ -154,15 +155,17 @@ public class FacadeBuilder
}
}
// Do not add the translucent facade in any other layer than translucent
boolean translucent = AEApi.instance().partHelper().getCableRenderMode().transparentFacades;
if( translucent && layer != BlockRenderLayer.TRANSLUCENT )
{
return;
}
final float thickness = thinFacades ? 1 : 2;
IBakedModel blockModel = blockRendererDispatcher.getModelForState( blockState );
if( AEApi.instance().partHelper().getCableRenderMode().transparentFacades )
{
// TODO rbw.setOpacity( 0.3f );
}
int color = 0xffffff;
try
{
@ -172,7 +175,16 @@ public class FacadeBuilder
{
}
builder.setColorRGB( color );
if( translucent )
{
color &= 0xFFFFFF;
color |= 0x4C000000;
builder.setColor( color );
}
else
{
builder.setColorRGB( color );
}
// TODO: Cache this
for( EnumFacing facing : facadeState.getOpenFaces() )