Skip to content

Commit

Permalink
Cached State Conversions and some other tweaks, fixes #193
Browse files Browse the repository at this point in the history
  • Loading branch information
AlgorithmX2 committed Dec 1, 2016
1 parent b956bf4 commit f9ef629
Show file tree
Hide file tree
Showing 29 changed files with 216 additions and 116 deletions.
4 changes: 2 additions & 2 deletions src/main/java/mod/chiselsandbits/bitbag/BagInventory.java
Expand Up @@ -10,9 +10,9 @@

import mod.chiselsandbits.core.ChiselsAndBits;
import mod.chiselsandbits.helpers.LocalStrings;
import mod.chiselsandbits.helpers.ModUtil;
import mod.chiselsandbits.items.ItemBitBag;
import mod.chiselsandbits.items.ItemChiseledBit;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
Expand Down Expand Up @@ -351,7 +351,7 @@ public List<String> listContents(
final ItemStack is = getStackInSlot( x );
if ( is != null )
{
final IBlockState state = Block.getStateById( ItemChiseledBit.getStackState( is ) );
final IBlockState state = ModUtil.getStateById( ItemChiseledBit.getStackState( is ) );
if ( state == null )
{
continue;
Expand Down
Expand Up @@ -5,7 +5,6 @@
import mod.chiselsandbits.helpers.DeprecationHelper;
import mod.chiselsandbits.helpers.ModUtil;
import mod.chiselsandbits.items.ItemChiseledBit;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -164,7 +163,7 @@ public ItemStack getFluidBitStack(
return null;
}

return ItemChiseledBit.createStack( Block.getStateId( liquid.getBlock().getDefaultState() ), amount, false );
return ItemChiseledBit.createStack( ModUtil.getStateId( liquid.getBlock().getDefaultState() ), amount, false );
}

@Override
Expand All @@ -176,7 +175,7 @@ public ItemStack insertItem(
if ( stack != null && stack.getItem() instanceof ItemChiseledBit )
{
final int state = ItemChiseledBit.getStackState( stack );
final IBlockState blk = Block.getStateById( state );
final IBlockState blk = ModUtil.getStateById( state );

Fluid f = null;
for ( final Fluid fl : FluidRegistry.getRegisteredFluids().values() )
Expand Down
Expand Up @@ -100,7 +100,7 @@ public static void addFluidBlock(
{
try
{
fluidStates.put( Block.getStateId( state ), fluid );
fluidStates.put( ModUtil.getStateId( state ), fluid );
}
catch ( final Throwable t )
{
Expand Down Expand Up @@ -328,7 +328,7 @@ public static BlockBitInfo createFromState(
reflectBlock.getExplosionResistance( null, null, null, null );
final boolean test_d = getDeclaringClass( blkClass, reflectBlock.MethodName, World.class, BlockPos.class, Entity.class, Explosion.class ) == Block.class;

final boolean isFluid = fluidStates.containsKey( Block.getStateId( state ) );
final boolean isFluid = fluidStates.containsKey( ModUtil.getStateId( state ) );

// is it perfect?
if ( test_a && test_b && test_c && test_d && !isFluid )
Expand Down
28 changes: 19 additions & 9 deletions src/main/java/mod/chiselsandbits/chiseledblock/BlockChiseled.java
Expand Up @@ -272,17 +272,27 @@ public boolean canRenderInLayer(
return true;
}

public TileEntityBlockChiseled getTileEntity(
static ExceptionNoTileEntity noTileEntity = new ExceptionNoTileEntity();

public static TileEntityBlockChiseled getTileEntity(
final TileEntity te ) throws ExceptionNoTileEntity
{
if ( te instanceof TileEntityBlockChiseled )
if ( te == null )
{
throw noTileEntity;
}

try
{
return (TileEntityBlockChiseled) te;
}
throw new ExceptionNoTileEntity();
catch ( final ClassCastException e )
{
throw noTileEntity;
}
}

public TileEntityBlockChiseled getTileEntity(
public static TileEntityBlockChiseled getTileEntity(
final IBlockAccess world,
final BlockPos pos ) throws ExceptionNoTileEntity
{
Expand Down Expand Up @@ -524,7 +534,7 @@ public boolean addLandingEffects(
try
{
final IBlockState texture = getTileEntity( worldObj, blockPosition ).getBlockState( Blocks.STONE );
worldObj.spawnParticle( EnumParticleTypes.BLOCK_DUST, entity.posX, entity.posY, entity.posZ, numberOfParticles, 0.0D, 0.0D, 0.0D, 0.15000000596046448D, new int[] { Block.getStateId( texture ) } );
worldObj.spawnParticle( EnumParticleTypes.BLOCK_DUST, entity.posX, entity.posY, entity.posZ, numberOfParticles, 0.0D, 0.0D, 0.0D, 0.15000000596046448D, new int[] { ModUtil.getStateId( texture ) } );
return true;
}
catch ( final ExceptionNoTileEntity e )
Expand Down Expand Up @@ -940,13 +950,13 @@ public static boolean replaceWithChisled(
{
BlockChiseled blk = ChiselsAndBits.getBlocks().getConversion( originalState );

int BlockID = Block.getStateId( actingState );
int BlockID = ModUtil.getStateId( actingState );

if ( isAir )
{
actingState = Block.getStateById( fragmentBlockStateID );
actingState = ModUtil.getStateById( fragmentBlockStateID );
target = actingState.getBlock();
BlockID = Block.getStateId( actingState );
BlockID = ModUtil.getStateId( actingState );
blk = ChiselsAndBits.getBlocks().getConversion( actingState );
// its still air tho..
actingState = Blocks.AIR.getDefaultState();
Expand Down Expand Up @@ -993,7 +1003,7 @@ public IBlockState getCommonState(
final VoxelBlob vb = data.getVoxelBlob();
if ( vb != null )
{
return Block.getStateById( vb.getVoxelStats().mostCommonState );
return ModUtil.getStateById( vb.getVoxelStats().mostCommonState );
}
}

Expand Down
Expand Up @@ -57,7 +57,7 @@ public int getPrimaryBlockStateID()

public IBlockState getPrimaryBlockState()
{
return Block.getStateById( primaryBlockState );
return ModUtil.getStateById( primaryBlockState );
}

public VoxelBlobStateReference getVoxelRef(
Expand Down Expand Up @@ -89,15 +89,15 @@ public NBTBlobConverter(
sideState = tile.sideState;
lightValue = tile.getLightValue();
isNormalCube = tile.isNormalCube;
primaryBlockState = Block.getStateId( tile.getBlockState( Blocks.COBBLESTONE ) );
primaryBlockState = ModUtil.getStateId( tile.getBlockState( Blocks.COBBLESTONE ) );
voxelBlobRef = tile.getBlobStateReference();
format = voxelBlobRef == null ? -1 : voxelBlobRef.getFormat();
}

public void fillWith(
final IBlockState state )
{
voxelBlobRef = new VoxelBlobStateReference( Block.getStateId( state ), 0 );
voxelBlobRef = new VoxelBlobStateReference( ModUtil.getStateId( state ), 0 );
updateFromBlob();
}

Expand Down Expand Up @@ -175,7 +175,7 @@ public final boolean readChisleData(
if ( primaryBlockState == 0 )
{
// if load fails default to cobble stone...
primaryBlockState = Block.getStateId( Blocks.COBBLESTONE.getDefaultState() );
primaryBlockState = ModUtil.getStateId( Blocks.COBBLESTONE.getDefaultState() );
}

voxelBlobRef = new VoxelBlobStateReference( v, 0 );
Expand Down
Expand Up @@ -231,7 +231,7 @@ public IBlockState getBlockState(

if ( stateID != null )
{
final IBlockState state = Block.getStateById( stateID );
final IBlockState state = ModUtil.getStateById( stateID );
if ( state != null )
{
return state;
Expand Down Expand Up @@ -432,14 +432,14 @@ public void func_189667_a(
public void fillWith(
final IBlockState blockType )
{
final int ref = Block.getStateId( blockType );
final int ref = ModUtil.getStateId( blockType );

sideState = 0xff;
lightlevel = DeprecationHelper.getLightValue( blockType );
isNormalCube = ModUtil.isNormalCube( blockType );

IExtendedBlockState state = getBasicState()
.withProperty( BlockChiseled.UProperty_VoxelBlob, new VoxelBlobStateReference( Block.getStateId( blockType ), getPositionRandom( pos ) ) );
.withProperty( BlockChiseled.UProperty_VoxelBlob, new VoxelBlobStateReference( ModUtil.getStateId( blockType ), getPositionRandom( pos ) ) );

final VoxelNeighborRenderTracker tracker = state.getValue( BlockChiseled.UProperty_VoxelNeighborState );

Expand Down Expand Up @@ -491,7 +491,7 @@ public VoxelBlob getBlob()
if ( vb == null )
{
vb = new VoxelBlob();
vb.fill( Block.getStateId( Blocks.COBBLESTONE.getDefaultState() ) );
vb.fill( ModUtil.getStateId( Blocks.COBBLESTONE.getDefaultState() ) );
}
}
else
Expand Down Expand Up @@ -632,7 +632,7 @@ public void setBlob(
setState( getBasicState()
.withProperty( BlockChiseled.UProperty_VoxelBlob, new VoxelBlobStateReference( common.mostCommonState, getPositionRandom( pos ) ) ) );

final IBlockState newState = Block.getStateById( common.mostCommonState );
final IBlockState newState = ModUtil.getStateById( common.mostCommonState );
if ( !MinecraftForge.EVENT_BUS.post( new EventFullBlockRestoration( worldObj, pos, newState ) ) )
{
worldObj.setBlockState( pos, newState, triggerUpdates ? 3 : 0 );
Expand Down
Expand Up @@ -87,6 +87,7 @@ public static synchronized void clearCache()
if ( FMLCommonHandler.instance().getSide() == Side.CLIENT )
{
updateCacheClient();
ModUtil.cacheFastStates();
}
}

Expand All @@ -108,7 +109,7 @@ private static void updateCacheClient()

for ( final IBlockState state : block.getBlockState().getValidStates() )
{
int id = Block.getStateId( state );
final int id = ModUtil.getStateId( state );
if ( state == null || state.getBlock() != block )
{
// reverse mapping is broken, so just skip over this state.
Expand Down Expand Up @@ -670,7 +671,7 @@ public BlobStats getVoxelStats()
cb.mostCommonStateTotal = quantity;
}

final IBlockState state = Block.getStateById( r );
final IBlockState state = ModUtil.getStateById( r );
if ( state != null && r != 0 )
{
nonAirBits += quantity;
Expand Down
Expand Up @@ -8,6 +8,7 @@

import mod.chiselsandbits.chiseledblock.data.VoxelBlob;
import mod.chiselsandbits.core.Log;
import mod.chiselsandbits.helpers.ModUtil;
import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
Expand Down Expand Up @@ -86,7 +87,7 @@ protected int readStateID(
}
}

return Block.getStateId( state );
return ModUtil.getStateId( state );
}

@SuppressWarnings( { "unchecked", "rawtypes" } )
Expand Down Expand Up @@ -119,7 +120,7 @@ protected void writeStateID(
final PacketBuffer buffer,
final int key )
{
final IBlockState state = Block.getStateById( key );
final IBlockState state = ModUtil.getStateById( key );
final Block blk = state.getBlock();

String sname = "air?";
Expand Down
Expand Up @@ -2,6 +2,7 @@

import mod.chiselsandbits.chiseledblock.data.VoxelBlob;
import mod.chiselsandbits.helpers.DeprecationHelper;
import mod.chiselsandbits.helpers.ModUtil;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.network.PacketBuffer;
Expand Down Expand Up @@ -42,15 +43,15 @@ protected int readStateID(
return 0;
}

return Block.getStateId( state );
return ModUtil.getStateId( state );
}

@Override
protected void writeStateID(
final PacketBuffer buffer,
final int key )
{
final IBlockState state = Block.getStateById( key );
final IBlockState state = ModUtil.getStateById( key );
final Block blk = state.getBlock();

final String name = Block.REGISTRY.getNameForObject( blk ).toString();
Expand Down
@@ -1,6 +1,6 @@
package mod.chiselsandbits.client;

import net.minecraft.block.Block;
import mod.chiselsandbits.helpers.ModUtil;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.color.IBlockColor;
Expand All @@ -17,7 +17,7 @@ public int colorMultiplier(
final BlockPos pos,
final int tint )
{
final IBlockState tstate = Block.getStateById( tint );
final IBlockState tstate = ModUtil.getStateById( tint );
return Minecraft.getMinecraft().getBlockColors().colorMultiplier( tstate, worldIn, pos, 0 );
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/mod/chiselsandbits/client/ItemColorBits.java
Expand Up @@ -2,6 +2,7 @@

import mod.chiselsandbits.chiseledblock.BlockBitInfo;
import mod.chiselsandbits.core.ClientSide;
import mod.chiselsandbits.helpers.ModUtil;
import mod.chiselsandbits.items.ItemChiseledBit;
import mod.chiselsandbits.render.helpers.ModelUtil;
import net.minecraft.block.Block;
Expand All @@ -20,7 +21,7 @@ public int getColorFromItemstack(
{
if ( ClientSide.instance.holdingShift() )
{
final IBlockState state = Block.getStateById( tint );
final IBlockState state = ModUtil.getStateById( tint );
final Block blk = state.getBlock();
final Item i = Item.getItemFromBlock( blk );

Expand All @@ -32,7 +33,7 @@ public int getColorFromItemstack(
return 0xffffff;
}

final IBlockState state = Block.getStateById( ItemChiseledBit.getStackState( stack ) );
final IBlockState state = ModUtil.getStateById( ItemChiseledBit.getStackState( stack ) );
return state == null ? 0xffffffff : BlockBitInfo.getColorFor( state, tint );
}

Expand Down
@@ -1,5 +1,6 @@
package mod.chiselsandbits.client;

import mod.chiselsandbits.helpers.ModUtil;
import mod.chiselsandbits.render.helpers.ModelUtil;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
Expand All @@ -15,7 +16,7 @@ public int getColorFromItemstack(
final ItemStack stack,
final int tint )
{
final IBlockState state = Block.getStateById( tint );
final IBlockState state = ModUtil.getStateById( tint );
final Block blk = state.getBlock();
final Item i = Item.getItemFromBlock( blk );

Expand Down
@@ -1,6 +1,7 @@
package mod.chiselsandbits.client;

import mod.chiselsandbits.core.ClientSide;
import mod.chiselsandbits.helpers.ModUtil;
import mod.chiselsandbits.render.helpers.ModelUtil;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
Expand All @@ -18,7 +19,7 @@ public int getColorFromItemstack(
{
if ( ClientSide.instance.holdingShift() )
{
final IBlockState state = Block.getStateById( tint );
final IBlockState state = ModUtil.getStateById( tint );
final Block blk = state.getBlock();
final Item i = Item.getItemFromBlock( blk );

Expand Down
@@ -1,6 +1,7 @@
package mod.chiselsandbits.client.culling;

import mod.chiselsandbits.chiseledblock.BlockBitInfo;
import mod.chiselsandbits.helpers.ModUtil;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Biomes;
import net.minecraft.init.Blocks;
Expand All @@ -22,7 +23,6 @@ public class MCCullTest implements ICullTest, IBlockAccess
private IBlockState a;
private IBlockState b;

@SuppressWarnings( "deprecation" )
@Override
public boolean isVisible(
final int mySpot,
Expand All @@ -33,12 +33,12 @@ public boolean isVisible(
return false;
}

a = net.minecraft.block.Block.BLOCK_STATE_IDS.getByValue( mySpot );
a = ModUtil.getStateById( mySpot );
if ( a == null )
{
a = Blocks.AIR.getDefaultState();
}
b = net.minecraft.block.Block.BLOCK_STATE_IDS.getByValue( secondSpot );
b = ModUtil.getStateById( secondSpot );
if ( b == null )
{
b = Blocks.AIR.getDefaultState();
Expand Down

0 comments on commit f9ef629

Please sign in to comment.