1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-11-05 16:13:03 +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:
SquidDev
2017-05-06 15:31:06 +01:00
parent 06b63980eb
commit c7f5d039b2
13 changed files with 57 additions and 66 deletions

View File

@@ -57,7 +57,7 @@ public class TurtleInspectCommand implements ITurtleCommand
table.put( "metadata", metadata );
Map<Object, Object> stateTable = new HashMap<Object, Object>();
for( Object o : block.getActualState( state, world, newPosition ).getProperties().entrySet() )
for( Object o : state.getActualState( world, newPosition ).getProperties().entrySet() )
{
ImmutableMap.Entry<IProperty, Object> entry = (ImmutableMap.Entry<IProperty, Object>)o;
String propertyName = entry.getKey().getName();

View File

@@ -14,6 +14,7 @@ import dan200.computercraft.shared.computer.items.ItemComputerBase;
import dan200.computercraft.shared.turtle.blocks.ITurtleTile;
import dan200.computercraft.shared.turtle.core.TurtleBrain;
import dan200.computercraft.shared.util.Colour;
import dan200.computercraft.shared.util.StringUtil;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
@@ -21,10 +22,9 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.translation.I18n;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import java.util.ArrayList;
@@ -142,29 +142,29 @@ public abstract class ItemTurtleBase extends ItemComputerBase implements ITurtle
ITurtleUpgrade right = getUpgrade( stack, TurtleSide.Right );
if( left != null && right != null )
{
return I18n.translateToLocalFormatted(
return StringUtil.translateToLocalFormatted(
baseString + ".upgraded_twice.name",
I18n.translateToLocal( right.getUnlocalisedAdjective() ),
I18n.translateToLocal( left.getUnlocalisedAdjective() )
StringUtil.translateToLocal( right.getUnlocalisedAdjective() ),
StringUtil.translateToLocal( left.getUnlocalisedAdjective() )
);
}
else if( left != null )
{
return I18n.translateToLocalFormatted(
return StringUtil.translateToLocalFormatted(
baseString + ".upgraded.name",
I18n.translateToLocal( left.getUnlocalisedAdjective() )
StringUtil.translateToLocal( left.getUnlocalisedAdjective() )
);
}
else if( right != null )
{
return I18n.translateToLocalFormatted(
return StringUtil.translateToLocalFormatted(
baseString + ".upgraded.name",
I18n.translateToLocal( right.getUnlocalisedAdjective() )
StringUtil.translateToLocal( right.getUnlocalisedAdjective() )
);
}
else
{
return I18n.translateToLocal( baseString + ".name" );
return StringUtil.translateToLocal( baseString + ".name" );
}
}

View File

@@ -34,8 +34,7 @@ public class TurtleHoe extends TurtleTool
if( super.canBreakBlock( world, pos ) )
{
IBlockState state = world.getBlockState( pos );
Block block = state.getBlock();
Material material = block.getMaterial( state );
Material material = state.getMaterial( );
return
material == Material.PLANTS ||
material == Material.CACTUS ||

View File

@@ -26,8 +26,7 @@ public class TurtleShovel extends TurtleTool
if( super.canBreakBlock( world, pos ) )
{
IBlockState state = world.getBlockState( pos );
Block block = state.getBlock();
Material material = block.getMaterial( state );
Material material = state.getMaterial( );
return
material == Material.GROUND ||
material == Material.SAND ||

View File

@@ -26,8 +26,7 @@ public class TurtleSword extends TurtleTool
if( super.canBreakBlock( world, pos ) )
{
IBlockState state = world.getBlockState( pos );
Block block = state.getBlock();
Material material = block.getMaterial( state );
Material material = state.getMaterial( );
return
material == Material.PLANTS ||
material == Material.LEAVES ||

View File

@@ -136,7 +136,7 @@ public class TurtleTool implements ITurtleUpgrade
{
IBlockState state = world.getBlockState( pos );
Block block = state.getBlock();
if( block.isAir( state, world, pos ) || block == Blocks.BEDROCK || block.getBlockHardness( state, world, pos ) <= -1.0F )
if( block.isAir( state, world, pos ) || block == Blocks.BEDROCK || state.getBlockHardness( world, pos ) <= -1.0F )
{
return false;
}