Skip to content

Commit

Permalink
Enable Shadow Rendering for full blocks, Adds #253
Browse files Browse the repository at this point in the history
  • Loading branch information
AlgorithmX2 committed Mar 25, 2017
1 parent eff36b7 commit ab733a6
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/main/java/mod/chiselsandbits/chiseledblock/BlockChiseled.java
Expand Up @@ -27,6 +27,7 @@
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.particle.ParticleManager;
Expand Down Expand Up @@ -69,6 +70,7 @@ public class BlockChiseled extends Block implements ITileEntityProvider, IMultiS
public static final IUnlistedProperty<VoxelNeighborRenderTracker> UProperty_VoxelNeighborState = new UnlistedVoxelNeighborState();
public static final IUnlistedProperty<VoxelBlobStateReference> UProperty_VoxelBlob = new UnlistedVoxelBlob();
public static final IUnlistedProperty<Integer> UProperty_Primary_BlockState = new UnlistedBlockStateID();
public static final PropertyBool LProperty_FullBlock = PropertyBool.create( "full_block" );

public final String name;

Expand Down Expand Up @@ -226,6 +228,8 @@ public BlockChiseled(
setHardness( 1 );
setHarvestLevel( "pickaxe", 0 );
name = BlockName;

setDefaultState( getDefaultState().withProperty( LProperty_FullBlock, false ) );
}

private void configureSound(
Expand Down Expand Up @@ -265,6 +269,20 @@ else if ( mat == Material.GLASS )
}
}

@Override
public int getMetaFromState(
IBlockState state )
{
return state.getValue( LProperty_FullBlock ) ? 1 : 0;
}

@Override
public IBlockState getStateFromMeta(
int meta )
{
return getDefaultState().withProperty( LProperty_FullBlock, meta == 1 );
}

@Override
public boolean canRenderInLayer(
final BlockRenderLayer layer )
Expand Down Expand Up @@ -310,14 +328,14 @@ public float getAmbientOcclusionLightValue(
public boolean isOpaqueCube(
final IBlockState state )
{
return false;
return state.getValue( LProperty_FullBlock );
}

@Override
public boolean isFullCube(
final IBlockState state )
{
return false;
return state.getValue( LProperty_FullBlock );
}

@Override
Expand Down Expand Up @@ -488,7 +506,7 @@ public ItemStack getPickBlock(
@Override
protected BlockStateContainer createBlockState()
{
return new ExtendedBlockState( this, new IProperty[0], new IUnlistedProperty[] { UProperty_VoxelBlob, UProperty_Primary_BlockState, UProperty_VoxelNeighborState } );
return new ExtendedBlockState( this, new IProperty[] { LProperty_FullBlock }, new IUnlistedProperty[] { UProperty_VoxelBlob, UProperty_Primary_BlockState, UProperty_VoxelNeighborState } );
}

@Override
Expand Down
Expand Up @@ -583,6 +583,11 @@ public boolean updateBlob(
if ( oldLV != getLightValue() || oldNC != isNormalCube() )
{
worldObj.checkLight( pos );

// update block state to reflect lighting characteristics
IBlockState state = worldObj.getBlockState( pos );
if ( state.isFullCube() != isNormalCube && state.getBlock() instanceof BlockChiseled )
worldObj.setBlockState( pos, state.withProperty( BlockChiseled.LProperty_FullBlock, isNormalCube ) );
}

if ( oldSides != sideState )
Expand Down Expand Up @@ -685,6 +690,11 @@ else if ( common.mostCommonState != 0 )
if ( olv != lv || oldNC != nc )
{
worldObj.checkLight( pos );

// update block state to reflect lighting characteristics
IBlockState state = worldObj.getBlockState( pos );
if ( state.isFullCube() != isNormalCube && state.getBlock() instanceof BlockChiseled )
worldObj.setBlockState( pos, state.withProperty( BlockChiseled.LProperty_FullBlock, isNormalCube ) );
}
}

Expand Down
26 changes: 26 additions & 0 deletions src/main/java/mod/chiselsandbits/core/ClientSide.java
Expand Up @@ -3,6 +3,7 @@
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -81,6 +82,7 @@
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ModelBakery;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.block.statemap.IStateMapper;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.texture.TextureUtil;
Expand Down Expand Up @@ -328,6 +330,7 @@ public ModelResourceLocation getModelLocation(
{
final Item item = Item.getItemFromBlock( blk );
registerMesh( item, 0, new ModelResourceLocation( new ResourceLocation( modId, "block_chiseled" ), "inventory" ) );
registerMesh( blk, new ModelResourceLocation( new ResourceLocation( modId, "block_chiseled" ), "" ) );
}

final BlockBitTank bitTank = ChiselsAndBits.getBlocks().blockBitTank;
Expand All @@ -348,6 +351,29 @@ private void registerMesh(
}
}

private void registerMesh(
final Block blk,
final ModelResourceLocation loctaion )
{
if ( blk != null )
{
ModelLoader.setCustomStateMapper( blk, new IStateMapper() {

@Override
public Map<IBlockState, ModelResourceLocation> putStateModelLocations(
Block blockIn )
{
Map<IBlockState,ModelResourceLocation> map = new HashMap<IBlockState,ModelResourceLocation>();

for ( IBlockState o : blk.getBlockState().getValidStates() )
map.put( o, loctaion );

return map;
}
});
}
}

public static TextureAtlasSprite undoIcon;
public static TextureAtlasSprite redoIcon;
public static TextureAtlasSprite trashIcon;
Expand Down

0 comments on commit ab733a6

Please sign in to comment.