1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-07-02 10:03:32 +00:00

Merge pull request #204 from SquidDev-CC/feature/some-deprecation

Use IBlockState instead of Block methods
This commit is contained in:
Daniel Ratcliffe 2017-05-06 21:41:54 +01:00 committed by GitHub
commit f4dab801e4
13 changed files with 57 additions and 66 deletions

View File

@ -412,7 +412,6 @@ private void processPacket( ComputerCraftPacket packet, EntityPlayer player )
private void registerForgeHandlers() private void registerForgeHandlers()
{ {
ForgeHandlers handlers = new ForgeHandlers(); ForgeHandlers handlers = new ForgeHandlers();
FMLCommonHandler.instance().bus().register( handlers );
MinecraftForge.EVENT_BUS.register( handlers ); MinecraftForge.EVENT_BUS.register( handlers );
} }

View File

@ -119,7 +119,7 @@ private Object getBlockInfo( World world, BlockPos pos )
table.put( "metadata", metadata ); table.put( "metadata", metadata );
Map<Object, Object> stateTable = new HashMap<Object, Object>(); Map<Object, Object> stateTable = new HashMap<Object, Object>();
for( Object o : block.getActualState( state, world, pos ).getProperties().entrySet() ) for( Object o : state.getActualState( world, pos ).getProperties().entrySet() )
{ {
ImmutableMap.Entry<IProperty, Object> entry = (ImmutableMap.Entry<IProperty, Object>)o; ImmutableMap.Entry<IProperty, Object> entry = (ImmutableMap.Entry<IProperty, Object>)o;
String propertyName = entry.getKey().getName(); String propertyName = entry.getKey().getName();

View File

@ -18,6 +18,7 @@
import dan200.computercraft.shared.computer.items.IComputerItem; import dan200.computercraft.shared.computer.items.IComputerItem;
import dan200.computercraft.shared.pocket.apis.PocketAPI; import dan200.computercraft.shared.pocket.apis.PocketAPI;
import dan200.computercraft.shared.pocket.peripherals.PocketModemPeripheral; import dan200.computercraft.shared.pocket.peripherals.PocketModemPeripheral;
import dan200.computercraft.shared.util.StringUtil;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
@ -30,7 +31,6 @@
import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundEvent; import net.minecraft.util.SoundEvent;
import net.minecraft.util.text.translation.I18n;
import net.minecraft.world.World; import net.minecraft.world.World;
import java.util.List; import java.util.List;
@ -200,14 +200,14 @@ public String getItemStackDisplayName( ItemStack stack )
boolean modem = getHasModem( stack ); boolean modem = getHasModem( stack );
if( modem ) if( modem )
{ {
return I18n.translateToLocalFormatted( return StringUtil.translateToLocalFormatted(
baseString + ".upgraded.name", baseString + ".upgraded.name",
I18n.translateToLocal( "upgrade.computercraft:wireless_modem.adjective" ) StringUtil.translateToLocal( "upgrade.computercraft:wireless_modem.adjective" )
); );
} }
else else
{ {
return I18n.translateToLocal( baseString + ".name" ); return StringUtil.translateToLocal( baseString + ".name" );
} }
} }

View File

@ -48,10 +48,7 @@
import dan200.computercraft.shared.pocket.recipes.PocketComputerUpgradeRecipe; import dan200.computercraft.shared.pocket.recipes.PocketComputerUpgradeRecipe;
import dan200.computercraft.shared.turtle.blocks.TileTurtle; import dan200.computercraft.shared.turtle.blocks.TileTurtle;
import dan200.computercraft.shared.turtle.inventory.ContainerTurtle; import dan200.computercraft.shared.turtle.inventory.ContainerTurtle;
import dan200.computercraft.shared.util.Colour; import dan200.computercraft.shared.util.*;
import dan200.computercraft.shared.util.CreativeTabMain;
import dan200.computercraft.shared.util.ImpostorRecipe;
import dan200.computercraft.shared.util.ImpostorShapelessRecipe;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
@ -68,7 +65,6 @@
import net.minecraft.util.IThreadListener; import net.minecraft.util.IThreadListener;
import net.minecraft.util.SoundEvent; import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.translation.I18n;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.event.world.WorldEvent;
@ -130,7 +126,7 @@ public String getRecordInfo( ItemStack recordStack )
{ {
ItemRecord record = (ItemRecord) item; ItemRecord record = (ItemRecord) item;
String key = ObfuscationReflectionHelper.getPrivateValue( ItemRecord.class, record, "field_185077_c" ); String key = ObfuscationReflectionHelper.getPrivateValue( ItemRecord.class, record, "field_185077_c" );
return I18n.translateToLocal( key ); return StringUtil.translateToLocal( key );
} }
return null; return null;
} }

View File

@ -57,7 +57,7 @@ public TurtleCommandResult execute( ITurtleAccess turtle )
table.put( "metadata", metadata ); table.put( "metadata", metadata );
Map<Object, Object> stateTable = new HashMap<Object, Object>(); 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; ImmutableMap.Entry<IProperty, Object> entry = (ImmutableMap.Entry<IProperty, Object>)o;
String propertyName = entry.getKey().getName(); String propertyName = entry.getKey().getName();

View File

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

View File

@ -34,8 +34,7 @@ protected boolean canBreakBlock( World world, BlockPos pos )
if( super.canBreakBlock( world, pos ) ) if( super.canBreakBlock( world, pos ) )
{ {
IBlockState state = world.getBlockState( pos ); IBlockState state = world.getBlockState( pos );
Block block = state.getBlock(); Material material = state.getMaterial( );
Material material = block.getMaterial( state );
return return
material == Material.PLANTS || material == Material.PLANTS ||
material == Material.CACTUS || material == Material.CACTUS ||

View File

@ -26,8 +26,7 @@ protected boolean canBreakBlock( World world, BlockPos pos )
if( super.canBreakBlock( world, pos ) ) if( super.canBreakBlock( world, pos ) )
{ {
IBlockState state = world.getBlockState( pos ); IBlockState state = world.getBlockState( pos );
Block block = state.getBlock(); Material material = state.getMaterial( );
Material material = block.getMaterial( state );
return return
material == Material.GROUND || material == Material.GROUND ||
material == Material.SAND || material == Material.SAND ||

View File

@ -26,8 +26,7 @@ protected boolean canBreakBlock( World world, BlockPos pos )
if( super.canBreakBlock( world, pos ) ) if( super.canBreakBlock( world, pos ) )
{ {
IBlockState state = world.getBlockState( pos ); IBlockState state = world.getBlockState( pos );
Block block = state.getBlock(); Material material = state.getMaterial( );
Material material = block.getMaterial( state );
return return
material == Material.PLANTS || material == Material.PLANTS ||
material == Material.LEAVES || material == Material.LEAVES ||

View File

@ -136,7 +136,7 @@ protected boolean canBreakBlock( World world, BlockPos pos )
{ {
IBlockState state = world.getBlockState( pos ); IBlockState state = world.getBlockState( pos );
Block block = state.getBlock(); 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; return false;
} }

View File

@ -11,43 +11,33 @@
import net.minecraft.block.BlockRedstoneWire; import net.minecraft.block.BlockRedstoneWire;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.world.IBlockAccess; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
public class RedstoneUtil 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 ) public static int getRedstoneOutput( World world, BlockPos pos, EnumFacing side )
{ {
int power = 0; int power = 0;
Block block = getBlock( world, pos );
if( block != null && block != Blocks.AIR )
{
IBlockState state = world.getBlockState( pos ); IBlockState state = world.getBlockState( pos );
Block block = state.getBlock();
if( block != Blocks.AIR )
{
if( block == Blocks.REDSTONE_WIRE ) if( block == Blocks.REDSTONE_WIRE )
{ {
if( side != EnumFacing.UP ) if( side != EnumFacing.UP )
{ {
power = ((Integer)state.getValue( BlockRedstoneWire.POWER )).intValue(); power = state.getValue( BlockRedstoneWire.POWER );
} }
else else
{ {
power = 0; 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 ) ) if( block.isNormalCube( state, world, pos ) )
{ {
@ -56,10 +46,10 @@ else if( block.canProvidePower( state ) )
if( testSide != side ) if( testSide != side )
{ {
BlockPos testPos = pos.offset( testSide ); BlockPos testPos = pos.offset( testSide );
Block neighbour = getBlock( world, testPos ); IBlockState neighbour = world.getBlockState( testPos );
if( neighbour != null && neighbour.canProvidePower( state ) ) 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 static int getBundledRedstoneOutput( World world, BlockPos pos, EnumFacin
public static void propogateRedstoneOutput( World world, BlockPos pos, EnumFacing side ) public static void propogateRedstoneOutput( World world, BlockPos pos, EnumFacing side )
{ {
// Propogate ordinary output // Propogate ordinary output
Block block = getBlock( world, pos ); IBlockState block = world.getBlockState( pos );
BlockPos neighbourPos = pos.offset( side ); BlockPos neighbourPos = pos.offset( side );
Block neighbour = getBlock( world, neighbourPos ); IBlockState neighbour = world.getBlockState( neighbourPos );
if( neighbour != null && neighbour != Blocks.AIR ) if( neighbour.getBlock() != Blocks.AIR )
{ {
world.notifyBlockOfStateChange( neighbourPos, block ); world.notifyBlockOfStateChange( neighbourPos, block.getBlock() );
if( neighbour.isNormalCube( world.getBlockState( neighbourPos ), world, neighbourPos ) ) if( neighbour.getBlock().isNormalCube( neighbour, world, neighbourPos ) )
{ {
world.notifyNeighborsOfStateExcept( neighbourPos, neighbour, side.getOpposite() ); world.notifyNeighborsOfStateExcept( neighbourPos, neighbour.getBlock(), side.getOpposite() );
} }
} }
} }

View File

@ -23,4 +23,22 @@ public static String normaliseLabel( String label )
return builder.toString(); 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 );
}
} }

View File

@ -27,16 +27,7 @@ public static boolean isBlockInWorld( World world, BlockPos pos )
public static boolean isLiquidBlock( World world, BlockPos pos ) public static boolean isLiquidBlock( World world, BlockPos pos )
{ {
if( isBlockInWorld( world, pos ) ) return isBlockInWorld( world, pos ) && world.getBlockState( pos ).getMaterial().isLiquid();
{
IBlockState state = world.getBlockState( pos );
Block block = state.getBlock();
if( block != null )
{
return block.getMaterial( state ).isLiquid();
}
}
return false;
} }
public static BlockPos moveCoords( BlockPos pos, EnumFacing dir ) public static BlockPos moveCoords( BlockPos pos, EnumFacing dir )