Skip to content

Commit

Permalink
Some further cleanup and 1.13 cherry-picks
Browse files Browse the repository at this point in the history
Are most of these changes small and petty? Yes. However, IMO they do
make the code more readable. Anyway, a summary of some of the more
interesting changes:

 - Expose Abstract*Upgrade classes in the API
 - Fix the spelling of Jonathan in the API docs (*shakes fist*)
 - Fix bug with printout not working in the offhand.
 - Rename any argments/variables accidentally named "m_*", and add an
   inspection to prevent it happening again.
 - Remove most of the Block*.Properties classes - just inline them in
   the parent class.
 - Return super.writeToNBT instead of reassigning at the top.
SquidDev committed Apr 2, 2019
1 parent 390575a commit 2965fb6
Showing 81 changed files with 597 additions and 892 deletions.
10 changes: 5 additions & 5 deletions codeInspectionSettings.xml
Original file line number Diff line number Diff line change
@@ -1290,12 +1290,12 @@
<option name="m_ignoreStaticMethods" value="true" />
</inspection_tool>
<inspection_tool class="LocalVariableName" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="LocalVariableNamingConvention" enabled="false" level="WARNING" enabled_by_default="false">
<inspection_tool class="LocalVariableNamingConvention" enabled="true" level="ERROR" enabled_by_default="true">
<option name="m_ignoreForLoopParameters" value="false" />
<option name="m_ignoreCatchParameters" value="false" />
<option name="m_regex" value="[a-z][A-Za-z\d]*" />
<option name="m_minLength" value="1" />
<option name="m_maxLength" value="20" />
<option name="m_maxLength" value="50" />
</inspection_tool>
<inspection_tool class="LocalVariableNamingConventionJS" enabled="false" level="WARNING" enabled_by_default="false">
<option name="m_regex" value="[a-z][A-Za-z]*" />
@@ -1490,7 +1490,7 @@
<inspection_tool class="NewExceptionWithoutArguments" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="NewGroovyClassNamingConvention" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="NewInstanceOfSingleton" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="NewMethodNamingConvention" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="NewMethodNamingConvention" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="NewObjectEquality" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="NewStringBufferWithCharArgument" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="NoButtonGroup" enabled="true" level="WARNING" enabled_by_default="true" />
@@ -1657,10 +1657,10 @@
<option name="m_ignoreSingleCharacterNames" value="false" />
<option name="m_ignoreOverridesOfLibraryMethods" value="false" />
</inspection_tool>
<inspection_tool class="ParameterNamingConvention" enabled="false" level="WARNING" enabled_by_default="false">
<inspection_tool class="ParameterNamingConvention" enabled="true" level="ERROR" enabled_by_default="true">
<option name="m_regex" value="[a-z][A-Za-z\d]*" />
<option name="m_minLength" value="1" />
<option name="m_maxLength" value="20" />
<option name="m_maxLength" value="50" />
</inspection_tool>
<inspection_tool class="ParameterNamingConventionJS" enabled="false" level="WARNING" enabled_by_default="false">
<option name="m_regex" value="[a-z][A-Za-z]*" />
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Mod properties
mod_version=1.81.1
mod_version=1.82.0

# Minecraft properties
mc_version=1.12.2
6 changes: 3 additions & 3 deletions src/main/java/dan200/computercraft/ComputerCraft.java
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
import dan200.computercraft.shared.pocket.peripherals.PocketModem;
import dan200.computercraft.shared.pocket.peripherals.PocketSpeaker;
import dan200.computercraft.shared.proxy.IComputerCraftProxy;
import dan200.computercraft.shared.proxy.ComputerCraftProxyCommon;
import dan200.computercraft.shared.turtle.blocks.BlockTurtle;
import dan200.computercraft.shared.turtle.items.ItemTurtleAdvanced;
import dan200.computercraft.shared.turtle.items.ItemTurtleLegacy;
@@ -248,7 +248,7 @@ public static final class Upgrades
clientSide = "dan200.computercraft.client.proxy.ComputerCraftProxyClient",
serverSide = "dan200.computercraft.shared.proxy.ComputerCraftProxyCommon"
)
private static IComputerCraftProxy proxy;
private static ComputerCraftProxyCommon proxy;

@Mod.EventHandler
public void preInit( FMLPreInitializationEvent event )
@@ -270,7 +270,7 @@ public void init( FMLInitializationEvent event )
@Mod.EventHandler
public void onServerStarting( FMLServerStartingEvent event )
{
proxy.initServer( event.getServer() );
ComputerCraftProxyCommon.initServer( event.getServer() );
}

@Mod.EventHandler
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
* Send enquiries to dratcliffe@gmail.com
*/

package dan200.computercraft.shared.turtle.upgrades;
package dan200.computercraft.api;

import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleUpgradeType;
@@ -15,6 +15,11 @@

import javax.annotation.Nonnull;

/**
* A base class for {@link ITurtleUpgrade}s.
*
* One does not have to use this, but it does provide a convenient template.
*/
public abstract class AbstractTurtleUpgrade implements ITurtleUpgrade
{
private final ResourceLocation id;
@@ -23,7 +28,7 @@ public abstract class AbstractTurtleUpgrade implements ITurtleUpgrade
private final String adjective;
private final ItemStack stack;

public AbstractTurtleUpgrade( ResourceLocation id, int legacyId, TurtleUpgradeType type, String adjective, ItemStack stack )
protected AbstractTurtleUpgrade( ResourceLocation id, int legacyId, TurtleUpgradeType type, String adjective, ItemStack stack )
{
this.id = id;
this.legacyId = legacyId;
@@ -32,27 +37,27 @@ public AbstractTurtleUpgrade( ResourceLocation id, int legacyId, TurtleUpgradeTy
this.stack = stack;
}

public AbstractTurtleUpgrade( ResourceLocation id, int legacyId, TurtleUpgradeType type, String adjective, Item item )
protected AbstractTurtleUpgrade( ResourceLocation id, int legacyId, TurtleUpgradeType type, String adjective, Item item )
{
this( id, legacyId, type, adjective, new ItemStack( item ) );
}

public AbstractTurtleUpgrade( ResourceLocation id, int legacyId, TurtleUpgradeType type, String adjective, Block block )
protected AbstractTurtleUpgrade( ResourceLocation id, int legacyId, TurtleUpgradeType type, String adjective, Block block )
{
this( id, legacyId, type, adjective, new ItemStack( block ) );
}

public AbstractTurtleUpgrade( ResourceLocation id, int legacyId, TurtleUpgradeType type, ItemStack stack )
protected AbstractTurtleUpgrade( ResourceLocation id, int legacyId, TurtleUpgradeType type, ItemStack stack )
{
this( id, legacyId, type, "upgrade." + id + ".adjective", stack );
}

public AbstractTurtleUpgrade( ResourceLocation id, int legacyId, TurtleUpgradeType type, Item item )
protected AbstractTurtleUpgrade( ResourceLocation id, int legacyId, TurtleUpgradeType type, Item item )
{
this( id, legacyId, type, new ItemStack( item ) );
}

public AbstractTurtleUpgrade( ResourceLocation id, int legacyId, TurtleUpgradeType type, Block block )
protected AbstractTurtleUpgrade( ResourceLocation id, int legacyId, TurtleUpgradeType type, Block block )
{
this( id, legacyId, type, new ItemStack( block ) );
}
2 changes: 1 addition & 1 deletion src/main/java/dan200/computercraft/api/media/IMedia.java
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ default boolean setLabel( @Nonnull ItemStack stack, @Nullable String label )

/**
* If this disk represents an item with audio (like a record), get the readable name of the audio track. ie:
* "Jonathon Coulton - Still Alive"
* "Jonathan Coulton - Still Alive"
*
* @param stack The {@link ItemStack} to modify.
* @return The name, or null if this item does not represent an item with audio.
Original file line number Diff line number Diff line change
@@ -4,14 +4,18 @@
* Send enquiries to dratcliffe@gmail.com
*/

package dan200.computercraft.shared.pocket.peripherals;
package dan200.computercraft.api.pocket;

import dan200.computercraft.api.pocket.IPocketUpgrade;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;

import javax.annotation.Nonnull;

/**
* A base class for {@link IPocketUpgrade}s.
*
* One does not have to use this, but it does provide a convenient template.
*/
public abstract class AbstractPocketUpgrade implements IPocketUpgrade
{
private final ResourceLocation id;
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.items.IItemHandler;

import javax.annotation.Nonnull;
@@ -21,7 +20,6 @@
/**
* Fired when a turtle attempts to interact with an inventory.
*/
@Cancelable
public abstract class TurtleInventoryEvent extends TurtleBlockEvent
{
private final IItemHandler handler;
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
import dan200.computercraft.shared.media.items.ItemDiskLegacy;
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
import dan200.computercraft.shared.turtle.items.ItemTurtleBase;
import dan200.computercraft.shared.util.Colour;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.client.renderer.block.model.IBakedModel;
@@ -132,7 +133,10 @@ public static void onItemColours( ColorHandlerEvent.Item event )
case 1: // Frame colour
return ComputerCraft.Items.pocketComputer.getColour( stack );
case 2: // Light colour
return ItemPocketComputer.getLightState( stack );
{
int light = ItemPocketComputer.getLightState( stack );
return light == -1 ? Colour.Black.getHex() : light;
}
}
}, ComputerCraft.Items.pocketComputer );

Original file line number Diff line number Diff line change
@@ -61,11 +61,11 @@ public void render( @Nonnull TileCable te, double x, double y, double z, float p
state = state.getActualState( world, pos );
if( te.getPeripheralType() != PeripheralType.Cable && WorldUtil.isVecInsideInclusive( CableBounds.getModemBounds( state ), hit.hitVec.subtract( pos.getX(), pos.getY(), pos.getZ() ) ) )
{
state = block.getDefaultState().withProperty( BlockCable.Properties.MODEM, state.getValue( BlockCable.Properties.MODEM ) );
state = block.getDefaultState().withProperty( BlockCable.MODEM, state.getValue( BlockCable.MODEM ) );
}
else
{
state = state.withProperty( BlockCable.Properties.MODEM, BlockCableModemVariant.None );
state = state.withProperty( BlockCable.MODEM, BlockCableModemVariant.None );
}

IBakedModel model = mc.getBlockRendererDispatcher().getModelForState( state );
Original file line number Diff line number Diff line change
@@ -25,17 +25,17 @@ public abstract class ComputerAccess implements IComputerAccess
private final IAPIEnvironment m_environment;
private final Set<String> m_mounts = new HashSet<>();

protected ComputerAccess( IAPIEnvironment m_environment )
protected ComputerAccess( IAPIEnvironment environment )
{
this.m_environment = m_environment;
this.m_environment = environment;
}

public void unmountAll()
{
FileSystem fileSystem = m_environment.getFileSystem();
for( String m_mount : m_mounts )
for( String mount : m_mounts )
{
fileSystem.unmount( m_mount );
fileSystem.unmount( mount );
}
m_mounts.clear();
}
4 changes: 2 additions & 2 deletions src/main/java/dan200/computercraft/core/apis/FSAPI.java
Original file line number Diff line number Diff line change
@@ -34,9 +34,9 @@ public class FSAPI implements ILuaAPI
private IAPIEnvironment m_env;
private FileSystem m_fileSystem;

public FSAPI( IAPIEnvironment _env )
public FSAPI( IAPIEnvironment env )
{
m_env = _env;
m_env = env;
m_fileSystem = null;
}

Original file line number Diff line number Diff line change
@@ -228,9 +228,9 @@ public IPeripheral getAvailablePeripheral( @Nonnull String name )
private final PeripheralWrapper[] m_peripherals;
private boolean m_running;

public PeripheralAPI( IAPIEnvironment _environment )
public PeripheralAPI( IAPIEnvironment environment )
{
m_environment = _environment;
m_environment = environment;
m_environment.setPeripheralChangeListener( this );

m_peripherals = new PeripheralWrapper[6];
6 changes: 3 additions & 3 deletions src/main/java/dan200/computercraft/core/apis/TermAPI.java
Original file line number Diff line number Diff line change
@@ -24,10 +24,10 @@ public class TermAPI implements ILuaAPI
private final Terminal m_terminal;
private final IComputerEnvironment m_environment;

public TermAPI( IAPIEnvironment _environment )
public TermAPI( IAPIEnvironment environment )
{
m_terminal = _environment.getTerminal();
m_environment = _environment.getComputerEnvironment();
m_terminal = environment.getTerminal();
m_environment = environment.getComputerEnvironment();
}

@Override
Original file line number Diff line number Diff line change
@@ -28,10 +28,10 @@ public class ComputerSystem extends ComputerAccess implements IComputerSystem
{
private final IAPIEnvironment m_environment;

ComputerSystem( IAPIEnvironment m_environment )
ComputerSystem( IAPIEnvironment environment )
{
super( m_environment );
this.m_environment = m_environment;
super( environment );
this.m_environment = environment;
}

@Nonnull
Original file line number Diff line number Diff line change
@@ -26,8 +26,8 @@
* the executor goes through three stages:
*
* When {@link State#COOL}, the computer is allocated {@link ComputerCraft#maxMainComputerTime}ns to execute any work
* this tick. At the beginning of the tick, we execute as many {@link MainThread} tasks as possible, until our timeframe
* or the global time frame has expired.
* this tick. At the beginning of the tick, we execute as many {@link MainThread} tasks as possible, until our
* time-frame or the global time frame has expired.
*
* Then, when other objects (such as {@link TileEntity}) are ticked, we update how much time we've used using
* {@link IWorkMonitor#trackWork(long, TimeUnit)}.
Original file line number Diff line number Diff line change
@@ -23,9 +23,9 @@ public class FileSystemWrapperMount implements IFileSystem
{
private final FileSystem m_filesystem;

public FileSystemWrapperMount( FileSystem m_filesystem )
public FileSystemWrapperMount( FileSystem filesystem )
{
this.m_filesystem = m_filesystem;
this.m_filesystem = filesystem;
}

@Override
Original file line number Diff line number Diff line change
@@ -22,6 +22,8 @@ public final class BundledRedstone
{
private static final Set<IBundledRedstoneProvider> providers = new LinkedHashSet<>();

private BundledRedstone() {}

public static void register( @Nonnull IBundledRedstoneProvider provider )
{
Preconditions.checkNotNull( provider, "provider cannot be null" );
16 changes: 4 additions & 12 deletions src/main/java/dan200/computercraft/shared/common/BlockGeneric.java
Original file line number Diff line number Diff line change
@@ -52,10 +52,10 @@ public final boolean onBlockActivated( World world, BlockPos pos, IBlockState st
@Override
@Deprecated
@SuppressWarnings( "deprecation" )
public final void neighborChanged( IBlockState state, World world, BlockPos pos, Block block, BlockPos neighbour )
public final void neighborChanged( IBlockState state, World world, BlockPos pos, Block neighbourBlock, BlockPos neighbourPos )
{
TileEntity tile = world.getTileEntity( pos );
if( tile instanceof TileGeneric ) ((TileGeneric) tile).onNeighbourChange( neighbour );
if( tile instanceof TileGeneric ) ((TileGeneric) tile).onNeighbourChange( neighbourPos );
}

@Override
@@ -91,11 +91,7 @@ public final boolean canConnectRedstone( IBlockState state, IBlockAccess world,
public final int getStrongPower( IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing oppositeSide )
{
TileEntity tile = world.getTileEntity( pos );
if( tile instanceof TileGeneric && tile.hasWorld() )
{
return ((TileGeneric) tile).getRedstoneOutput( oppositeSide.getOpposite() );
}
return 0;
return tile instanceof TileGeneric && tile.hasWorld() ? ((TileGeneric) tile).getRedstoneOutput( oppositeSide.getOpposite() ) : 0;
}

@Override
@@ -114,11 +110,7 @@ public boolean getBundledRedstoneConnectivity( World world, BlockPos pos, EnumFa
public int getBundledRedstoneOutput( World world, BlockPos pos, EnumFacing side )
{
TileEntity tile = world.getTileEntity( pos );
if( tile instanceof TileGeneric && tile.hasWorld() )
{
return ((TileGeneric) tile).getBundledRedstoneOutput( side );
}
return 0;
return tile instanceof TileGeneric && tile.hasWorld() ? ((TileGeneric) tile).getBundledRedstoneOutput( side ) : 0;
}

@Nonnull
Original file line number Diff line number Diff line change
@@ -78,11 +78,7 @@ public ItemStack getCraftingResult( @Nonnull InventoryCrafting inv )
}
}

if( colourable.isEmpty() )
{
return ItemStack.EMPTY;
}

if( colourable.isEmpty() ) return ItemStack.EMPTY;
return ((IColouredItem) colourable.getItem()).withColour( colourable, tracker.getColour() );
}

Original file line number Diff line number Diff line change
@@ -130,7 +130,6 @@ public boolean shouldRefresh( World world, BlockPos pos, @Nonnull IBlockState ol
@Override
public final SPacketUpdateTileEntity getUpdatePacket()
{
// Communicate properties
NBTTagCompound nbt = new NBTTagCompound();
writeDescription( nbt );
return new SPacketUpdateTileEntity( getPos(), 0, nbt );
Loading

0 comments on commit 2965fb6

Please sign in to comment.