mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-10-29 21:02:59 +00:00
Turn inspections up to 11
OK, so let's get this out of the way, there's some actual changes mixed in here too. I'm really sorry: - Turtles can now not be renamed with unnamed item tags (previously it would clear the name, this seemed a little unideal). - commands.getBlock(s)Data will also include NBT. Now, onto the horror story which is these inspection changes: - Make a lot of methods static - Typo fixes - Make utility classes final + private constructor - Lots of reformatting (ifs -> ternary, invert control flow, etc...) - ??? - Profit! I'm so going to regret this - can pretty much guarantee this is going to break something.
This commit is contained in:
@@ -26,7 +26,7 @@ public abstract class BlockGeneric extends Block implements ITileEntityProvider
|
||||
protected BlockGeneric( Material material )
|
||||
{
|
||||
super( material );
|
||||
this.hasTileEntity = true;
|
||||
hasTileEntity = true;
|
||||
}
|
||||
|
||||
protected abstract TileGeneric createTile( IBlockState state );
|
||||
@@ -108,11 +108,7 @@ public abstract class BlockGeneric extends Block implements ITileEntityProvider
|
||||
public boolean getBundledRedstoneConnectivity( World world, BlockPos pos, EnumFacing side )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile instanceof TileGeneric )
|
||||
{
|
||||
return ((TileGeneric) tile).getBundledRedstoneConnectivity( side );
|
||||
}
|
||||
return false;
|
||||
return tile instanceof TileGeneric && ((TileGeneric) tile).getBundledRedstoneConnectivity( side );
|
||||
}
|
||||
|
||||
public int getBundledRedstoneOutput( World world, BlockPos pos, EnumFacing side )
|
||||
|
||||
@@ -7,10 +7,41 @@
|
||||
package dan200.computercraft.shared.common;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public interface IColouredItem
|
||||
{
|
||||
int getColour( ItemStack stack );
|
||||
String NBT_COLOUR = "colour";
|
||||
|
||||
ItemStack withColour( ItemStack stack, int colour );
|
||||
default int getColour( ItemStack stack )
|
||||
{
|
||||
return getColourBasic( stack );
|
||||
}
|
||||
|
||||
default ItemStack withColour( ItemStack stack, int colour )
|
||||
{
|
||||
ItemStack copy = stack.copy();
|
||||
setColourBasic( copy, colour );
|
||||
return copy;
|
||||
}
|
||||
|
||||
static int getColourBasic( ItemStack stack )
|
||||
{
|
||||
NBTTagCompound tag = stack.getTagCompound();
|
||||
return tag != null && tag.hasKey( NBT_COLOUR ) ? tag.getInteger( NBT_COLOUR ) : -1;
|
||||
}
|
||||
|
||||
static void setColourBasic( ItemStack stack, int colour )
|
||||
{
|
||||
NBTTagCompound tag = stack.getTagCompound();
|
||||
if( colour == -1 )
|
||||
{
|
||||
if( tag != null ) tag.removeTag( NBT_COLOUR );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( tag == null ) stack.setTagCompound( tag = new NBTTagCompound() );
|
||||
tag.setInteger( NBT_COLOUR, colour );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public abstract class TileGeneric extends TileEntity
|
||||
@Nullable
|
||||
public BlockGeneric getBlock()
|
||||
{
|
||||
Block block = getWorld().getBlockState( getPos() ).getBlock();
|
||||
Block block = getBlockType();
|
||||
return block instanceof BlockGeneric ? (BlockGeneric) block : null;
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ public abstract class TileGeneric extends TileEntity
|
||||
double range = getInteractRange( player );
|
||||
BlockPos pos = getPos();
|
||||
return player.getEntityWorld() == getWorld() &&
|
||||
player.getDistanceSq( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ) <= (range * range);
|
||||
player.getDistanceSq( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ) <= range * range;
|
||||
}
|
||||
|
||||
protected void writeDescription( @Nonnull NBTTagCompound nbt )
|
||||
|
||||
Reference in New Issue
Block a user