Skip to content

Commit

Permalink
Trigger updates related to full blocks properly for C&B Tiles.
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/mod/chiselsandbits/chiseledblock/data/VoxelNeighborRenderTracker.java
#	src/main/java/mod/chiselsandbits/core/ChiselsAndBits.java
  • Loading branch information
AlgorithmX2 committed Jan 15, 2017
1 parent 2445093 commit 4147928
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 13 deletions.
Expand Up @@ -8,10 +8,11 @@
import java.util.WeakHashMap;

import mod.chiselsandbits.chiseledblock.BoxType;
import mod.chiselsandbits.helpers.IStateRef;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraftforge.fml.common.FMLCommonHandler;

public final class VoxelBlobStateReference implements Comparable<VoxelBlobStateReference>
public final class VoxelBlobStateReference implements Comparable<VoxelBlobStateReference>, IStateRef
{

private static Map<VoxelBlobStateInstance, WeakReference<VoxelBlobStateInstance>> serverRefs = Collections.synchronizedMap( new WeakHashMap<VoxelBlobStateInstance, WeakReference<VoxelBlobStateInstance>>() );
Expand Down Expand Up @@ -98,6 +99,7 @@ public byte[] getByteArray()
return data.voxelBytes;
}

@Override
public VoxelBlob getVoxelBlob()
{
return data.getBlob();
Expand Down
Expand Up @@ -5,7 +5,9 @@
import mod.chiselsandbits.chiseledblock.BlockChiseled;
import mod.chiselsandbits.chiseledblock.TileEntityBlockChiseled;
import mod.chiselsandbits.core.ChiselsAndBits;
import mod.chiselsandbits.helpers.IStateRef;
import mod.chiselsandbits.helpers.ModUtil;
import mod.chiselsandbits.render.chiseledblock.BlockStateRef;
import mod.chiselsandbits.render.chiseledblock.ModelRenderState;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
Expand Down Expand Up @@ -111,25 +113,35 @@ public void update(

for ( final EnumFacing f : EnumFacing.VALUES )
{
assert f != null;
final BlockPos oPos = pos.offset( f );

final TileEntityBlockChiseled tebc = ModUtil.getChiseledTileEntity( access, pos.offset( f ) );
final TileEntityBlockChiseled tebc = ModUtil.getChiseledTileEntity( access, oPos );
assert f != null;
if ( tebc != null )
{
update( f, tebc.getBasicState().getValue( BlockChiseled.UProperty_VoxelBlob ) );
}
else
{
update( f, null );
final int stateid = ModUtil.getStateId( access.getBlockState( oPos ) );

if ( stateid == 0 )
{
update( f, null );
}
else
{
update( f, new BlockStateRef( stateid ) );
}
}
}
}

private void update(
final EnumFacing f,
final VoxelBlobStateReference value )
final IStateRef value )
{
if ( sides.get( f ) == value )
if ( sameValue( sides.get( f ), value ) )
{
return;
}
Expand All @@ -138,9 +150,27 @@ private void update(
{
sides.put( f, value );
lrs = null;
triggerUpdate();
}
}

private boolean sameValue(
final IStateRef iStateRef,
final IStateRef value )
{
if ( iStateRef == value )
{
return true;
}

if ( iStateRef == null || value == null )
{
return false;
}

return value.equals( iStateRef );
}

public ModelRenderState getRenderState(
final VoxelBlobStateReference data )
{
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/mod/chiselsandbits/helpers/IStateRef.java
@@ -0,0 +1,10 @@
package mod.chiselsandbits.helpers;

import mod.chiselsandbits.chiseledblock.data.VoxelBlob;

public interface IStateRef
{

VoxelBlob getVoxelBlob();

}
@@ -0,0 +1,36 @@
package mod.chiselsandbits.render.chiseledblock;

import mod.chiselsandbits.chiseledblock.data.VoxelBlob;
import mod.chiselsandbits.helpers.IStateRef;

public class BlockStateRef implements IStateRef
{
final int stateID;

public BlockStateRef(
final int sid )
{
stateID = sid;
}

@Override
public boolean equals(
final Object obj )
{
if ( obj instanceof BlockStateRef )
{
return stateID == ( (BlockStateRef) obj ).stateID;
}

return false;
}

@Override
public VoxelBlob getVoxelBlob()
{
final VoxelBlob b = new VoxelBlob();
b.fill( stateID );
return b;
}

};
Expand Up @@ -13,6 +13,7 @@
import mod.chiselsandbits.client.culling.ICullTest;
import mod.chiselsandbits.core.ChiselsAndBits;
import mod.chiselsandbits.core.ClientSide;
import mod.chiselsandbits.helpers.IStateRef;
import mod.chiselsandbits.helpers.ModUtil;
import mod.chiselsandbits.render.BaseBakedBlockModel;
import mod.chiselsandbits.render.helpers.ModelQuadLayer;
Expand Down Expand Up @@ -392,7 +393,7 @@ private void processXFaces(

for ( final EnumFacing myFace : X_Faces )
{
final VoxelBlobStateReference nextToState = mrs != null && myLayer != ChiselLayer.SOLID ? mrs.get( myFace ) : null;
final IStateRef nextToState = mrs != null && myLayer != ChiselLayer.SOLID ? mrs.get( myFace ) : null;
VoxelBlob nextTo = nextToState == null ? null : nextToState.getVoxelBlob();

if ( !myLayer.filter( nextTo ) )
Expand Down Expand Up @@ -454,7 +455,7 @@ private void processYFaces(

for ( final EnumFacing myFace : Y_Faces )
{
final VoxelBlobStateReference nextToState = mrs != null && myLayer != ChiselLayer.SOLID ? mrs.get( myFace ) : null;
final IStateRef nextToState = mrs != null && myLayer != ChiselLayer.SOLID ? mrs.get( myFace ) : null;
VoxelBlob nextTo = nextToState == null ? null : nextToState.getVoxelBlob();

if ( !myLayer.filter( nextTo ) )
Expand Down Expand Up @@ -516,7 +517,7 @@ private void processZFaces(

for ( final EnumFacing myFace : Z_Faces )
{
final VoxelBlobStateReference nextToState = mrs != null && myLayer != ChiselLayer.SOLID ? mrs.get( myFace ) : null;
final IStateRef nextToState = mrs != null && myLayer != ChiselLayer.SOLID ? mrs.get( myFace ) : null;
VoxelBlob nextTo = nextToState == null ? null : nextToState.getVoxelBlob();

if ( !myLayer.filter( nextTo ) )
Expand Down
@@ -1,14 +1,15 @@
package mod.chiselsandbits.render.chiseledblock;

import mod.chiselsandbits.chiseledblock.data.VoxelBlobStateReference;
import mod.chiselsandbits.helpers.IStateRef;
import net.minecraft.util.EnumFacing;

public class ModelRenderState
{

// less objects/garbage to clean up, and less memory usage.
private VoxelBlobStateReference north, south, east, west, up, down;
private IStateRef north, south, east, west, up, down;

public VoxelBlobStateReference get(
public IStateRef get(
final EnumFacing side )
{
switch ( side )
Expand All @@ -33,7 +34,7 @@ public VoxelBlobStateReference get(

public void put(
final EnumFacing side,
final VoxelBlobStateReference value )
final IStateRef value )
{
switch ( side )
{
Expand Down

0 comments on commit 4147928

Please sign in to comment.