mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-26 01:44:48 +00:00
Use IBlockState instead of Block methods
There was a crash in RedstoneUtil when redstone state was changing next to a full block due to the incorrect state being passed. By using IBlockState methods we ensure that this cannot happen again. The old IBlockState methods were also deprecated, so this reduces the warning count a little. I've also moved string translation into StringUtils, to reduce the number of deprecation warnings from there.
This commit is contained in:
@@ -11,43 +11,33 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockRedstoneWire;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class RedstoneUtil
|
||||
{
|
||||
private static Block getBlock( IBlockAccess world, BlockPos pos )
|
||||
{
|
||||
if( pos.getY() >= 0 )
|
||||
{
|
||||
return world.getBlockState( pos ).getBlock();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int getRedstoneOutput( World world, BlockPos pos, EnumFacing side )
|
||||
{
|
||||
int power = 0;
|
||||
Block block = getBlock( world, pos );
|
||||
if( block != null && block != Blocks.AIR )
|
||||
IBlockState state = world.getBlockState( pos );
|
||||
Block block = state.getBlock();
|
||||
if( block != Blocks.AIR )
|
||||
{
|
||||
IBlockState state = world.getBlockState( pos );
|
||||
if( block == Blocks.REDSTONE_WIRE )
|
||||
{
|
||||
if( side != EnumFacing.UP )
|
||||
{
|
||||
power = ((Integer)state.getValue( BlockRedstoneWire.POWER )).intValue();
|
||||
power = state.getValue( BlockRedstoneWire.POWER );
|
||||
}
|
||||
else
|
||||
{
|
||||
power = 0;
|
||||
}
|
||||
}
|
||||
else if( block.canProvidePower( state ) )
|
||||
else if( state.canProvidePower( ) )
|
||||
{
|
||||
power = block.getWeakPower( state, world, pos, side.getOpposite() );
|
||||
power = state.getWeakPower( world, pos, side.getOpposite() );
|
||||
}
|
||||
if( block.isNormalCube( state, world, pos ) )
|
||||
{
|
||||
@@ -56,10 +46,10 @@ public class RedstoneUtil
|
||||
if( testSide != side )
|
||||
{
|
||||
BlockPos testPos = pos.offset( testSide );
|
||||
Block neighbour = getBlock( world, testPos );
|
||||
if( neighbour != null && neighbour.canProvidePower( state ) )
|
||||
IBlockState neighbour = world.getBlockState( testPos );
|
||||
if( neighbour.canProvidePower( ) )
|
||||
{
|
||||
power = Math.max( power, neighbour.getStrongPower( state, world, testPos, testSide.getOpposite() ) );
|
||||
power = Math.max( power, neighbour.getStrongPower( world, testPos, testSide.getOpposite() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,15 +71,15 @@ public class RedstoneUtil
|
||||
public static void propogateRedstoneOutput( World world, BlockPos pos, EnumFacing side )
|
||||
{
|
||||
// Propogate ordinary output
|
||||
Block block = getBlock( world, pos );
|
||||
IBlockState block = world.getBlockState( pos );
|
||||
BlockPos neighbourPos = pos.offset( side );
|
||||
Block neighbour = getBlock( world, neighbourPos );
|
||||
if( neighbour != null && neighbour != Blocks.AIR )
|
||||
IBlockState neighbour = world.getBlockState( neighbourPos );
|
||||
if( neighbour.getBlock() != Blocks.AIR )
|
||||
{
|
||||
world.notifyBlockOfStateChange( neighbourPos, block );
|
||||
if( neighbour.isNormalCube( world.getBlockState( neighbourPos ), world, neighbourPos ) )
|
||||
world.notifyBlockOfStateChange( neighbourPos, block.getBlock() );
|
||||
if( neighbour.getBlock().isNormalCube( neighbour, world, neighbourPos ) )
|
||||
{
|
||||
world.notifyNeighborsOfStateExcept( neighbourPos, neighbour, side.getOpposite() );
|
||||
world.notifyNeighborsOfStateExcept( neighbourPos, neighbour.getBlock(), side.getOpposite() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,4 +23,22 @@ public class StringUtil
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a Stat name
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public static String translateToLocal( String key )
|
||||
{
|
||||
return net.minecraft.util.text.translation.I18n.translateToLocal( key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a Stat name with format args
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public static String translateToLocalFormatted( String key, Object... format )
|
||||
{
|
||||
return net.minecraft.util.text.translation.I18n.translateToLocalFormatted( key, format );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,16 +27,7 @@ public class WorldUtil
|
||||
|
||||
public static boolean isLiquidBlock( World world, BlockPos pos )
|
||||
{
|
||||
if( isBlockInWorld( world, pos ) )
|
||||
{
|
||||
IBlockState state = world.getBlockState( pos );
|
||||
Block block = state.getBlock();
|
||||
if( block != null )
|
||||
{
|
||||
return block.getMaterial( state ).isLiquid();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return isBlockInWorld( world, pos ) && world.getBlockState( pos ).getMaterial().isLiquid();
|
||||
}
|
||||
|
||||
public static BlockPos moveCoords( BlockPos pos, EnumFacing dir )
|
||||
|
||||
Reference in New Issue
Block a user