A wee bit of a cleanup of the API

- Move some method over to defaulted methods
 - Use Objects rather than Preconditions
This commit is contained in:
SquidDev 2018-12-17 21:33:49 +00:00
parent 3537f49ced
commit 741ee447ca
38 changed files with 184 additions and 260 deletions

View File

@ -5,9 +5,7 @@ indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
# Sadly too many files have whitespace errors, so we leave this as is for
# now and just make sure we don't introduce any more.
# trim_trailing_whitespace = true
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]

View File

@ -268,7 +268,9 @@ public static void registerMediaProvider( @Nonnull IMediaProvider handler )
*
* @param handler The turtle permission provider to register.
* @see dan200.computercraft.api.permissions.ITurtlePermissionProvider
* @deprecated Prefer using {@link dan200.computercraft.api.turtle.event.TurtleBlockEvent} or the standard Forge events.
*/
@Deprecated
public static void registerPermissionProvider( @Nonnull ITurtlePermissionProvider handler )
{
findCC();
@ -382,7 +384,7 @@ public static IWiredElement getWiredElementAt( @Nonnull IBlockAccess world, @Non
{
}
}
return null;
}

View File

@ -90,7 +90,7 @@ public interface IMount
* @throws IOException If the file does not exist, or could not be opened.
*/
@Nonnull
@SuppressWarnings("deprecation")
@SuppressWarnings( "deprecation" )
default ReadableByteChannel openChannelForRead( @Nonnull String path ) throws IOException
{
return Channels.newChannel( openForRead( path ) );

View File

@ -67,7 +67,7 @@ public interface IWritableMount extends IMount
* @throws IOException If the file could not be opened for writing.
*/
@Nonnull
@SuppressWarnings("deprecation")
@SuppressWarnings( "deprecation" )
default WritableByteChannel openChannelForWrite( @Nonnull String path ) throws IOException
{
return Channels.newChannel( openForWrite( path ) );
@ -94,7 +94,7 @@ default WritableByteChannel openChannelForWrite( @Nonnull String path ) throws I
* @throws IOException If the file could not be opened for writing.
*/
@Nonnull
@SuppressWarnings("deprecation")
@SuppressWarnings( "deprecation" )
default WritableByteChannel openChannelForAppend( @Nonnull String path ) throws IOException
{
return Channels.newChannel( openForAppend( path ) );

View File

@ -4,7 +4,7 @@
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
@API( owner="ComputerCraft", provides="ComputerCraft|API|FileSystem", apiVersion="${version}" )
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|FileSystem", apiVersion = "${version}" )
package dan200.computercraft.api.filesystem;
import net.minecraftforge.fml.common.API;

View File

@ -31,17 +31,23 @@ public interface ILuaAPI extends ILuaObject
*
* One should only interact with the file system.
*/
default void startup() { }
default void startup()
{
}
/**
* Called every time the computer is ticked. This can be used to process various.
*/
default void update() { }
default void update()
{
}
/**
* Called when the computer is turned off or unloaded.
*
* This should reset the state of the object, disposing any remaining file handles, or other resources.
*/
default void shutdown() { }
default void shutdown()
{
}
}

View File

@ -14,7 +14,7 @@
public class LuaException extends Exception
{
private static final long serialVersionUID = -6136063076818512651L;
private final int m_level;
private final int level;
public LuaException()
{
@ -29,7 +29,7 @@ public LuaException( @Nullable String message )
public LuaException( @Nullable String message, int level )
{
super( message );
m_level = level;
this.level = level;
}
/**
@ -40,6 +40,6 @@ public LuaException( @Nullable String message, int level )
*/
public int getLevel()
{
return m_level;
return level;
}
}

View File

@ -4,7 +4,7 @@
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
@API( owner="ComputerCraft", provides="ComputerCraft|API|Lua", apiVersion="${version}" )
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Lua", apiVersion = "${version}" )
package dan200.computercraft.api.lua;
import net.minecraftforge.fml.common.API;

View File

@ -23,7 +23,7 @@ public interface IMedia
/**
* Get a string representing the label of this item. Will be called via {@code disk.getLabel()} in lua.
*
* @param stack The itemstack to inspect.
* @param stack The {@link ItemStack} to inspect.
* @return The label. ie: "Dan's Programs".
*/
@Nullable
@ -32,36 +32,45 @@ public interface IMedia
/**
* Set a string representing the label of this item. Will be called vi {@code disk.setLabel()} in lua.
*
* @param stack The itemstack to modify.
* @param stack The {@link ItemStack} to modify.
* @param label The string to set the label to.
* @return true if the label was updated, false if the label may not be modified.
*/
boolean setLabel( @Nonnull ItemStack stack, @Nullable String label );
default boolean setLabel( @Nonnull ItemStack stack, @Nullable String label )
{
return false;
}
/**
* If this disk represents an item with audio (like a record), get the readable name of the audio track. ie:
* "Jonathon Coulton - Still Alive"
*
* @param stack The itemstack to inspect.
* @param stack The {@link ItemStack} to modify.
* @return The name, or null if this item does not represent an item with audio.
*/
@Nullable
String getAudioTitle( @Nonnull ItemStack stack );
default String getAudioTitle( @Nonnull ItemStack stack )
{
return null;
}
/**
* If this disk represents an item with audio (like a record), get the resource name of the audio track to play.
*
* @param stack The itemstack to inspect.
* @param stack The {@link ItemStack} to modify.
* @return The name, or null if this item does not represent an item with audio.
*/
@Nullable
SoundEvent getAudio( @Nonnull ItemStack stack );
default SoundEvent getAudio( @Nonnull ItemStack stack )
{
return null;
}
/**
* If this disk represents an item with data (like a floppy disk), get a mount representing it's contents. This will
* be mounted onto the filesystem of the computer while the media is in the disk drive.
*
* @param stack The itemstack to inspect.
* @param stack The {@link ItemStack} to modify.
* @param world The world in which the item and disk drive reside.
* @return The mount, or null if this item does not represent an item with data. If the mount returned also
* implements {@link dan200.computercraft.api.filesystem.IWritableMount}, it will mounted using mountWritable()
@ -71,5 +80,8 @@ public interface IMedia
* @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(Class, String, String)
*/
@Nullable
IMount createDataMount( @Nonnull ItemStack stack, @Nonnull World world );
default IMount createDataMount( @Nonnull ItemStack stack, @Nonnull World world )
{
return null;
}
}

View File

@ -4,7 +4,7 @@
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
@API( owner="ComputerCraft", provides="ComputerCraft|API|Media", apiVersion="${version}" )
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Media", apiVersion = "${version}" )
package dan200.computercraft.api.media;
import net.minecraftforge.fml.common.API;

View File

@ -53,7 +53,7 @@ public interface IPacketReceiver
* @return Whether this receiver receives packets from other dimensions.
* @see #getRange()
* @see #receiveDifferentDimension(Packet)
* @see IPacketNetwork#transmitInterdimensional(Packet)
* @see IPacketNetwork#transmitInterdimensional(Packet)
*/
boolean isInterdimensional();

View File

@ -5,10 +5,9 @@
*/
package dan200.computercraft.api.network;
import com.google.common.base.Preconditions;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Objects;
/**
* Represents a packet which may be sent across a {@link IPacketNetwork}.
@ -21,11 +20,11 @@
*/
public class Packet
{
private final int m_channel;
private final int m_replyChannel;
private final Object m_payload;
private final int channel;
private final int replyChannel;
private final Object payload;
private final IPacketSender m_sender;
private final IPacketSender sender;
/**
* Create a new packet, ready for transmitting across the network.
@ -39,12 +38,12 @@ public class Packet
*/
public Packet( int channel, int replyChannel, @Nullable Object payload, @Nonnull IPacketSender sender )
{
Preconditions.checkNotNull( sender, "sender cannot be null" );
Objects.requireNonNull( sender, "sender cannot be null" );
m_channel = channel;
m_replyChannel = replyChannel;
m_payload = payload;
m_sender = sender;
this.channel = channel;
this.replyChannel = replyChannel;
this.payload = payload;
this.sender = sender;
}
/**
@ -55,7 +54,7 @@ public Packet( int channel, int replyChannel, @Nullable Object payload, @Nonnull
*/
public int getChannel()
{
return m_channel;
return channel;
}
/**
@ -65,7 +64,7 @@ public int getChannel()
*/
public int getReplyChannel()
{
return m_replyChannel;
return replyChannel;
}
/**
@ -77,7 +76,7 @@ public int getReplyChannel()
@Nullable
public Object getPayload()
{
return m_payload;
return payload;
}
/**
@ -88,7 +87,7 @@ public Object getPayload()
@Nonnull
public IPacketSender getSender()
{
return m_sender;
return sender;
}
@Override
@ -99,20 +98,20 @@ public boolean equals( Object o )
Packet packet = (Packet) o;
if( m_channel != packet.m_channel ) return false;
if( m_replyChannel != packet.m_replyChannel ) return false;
if( m_payload != null ? !m_payload.equals( packet.m_payload ) : packet.m_payload != null ) return false;
return m_sender.equals( packet.m_sender );
if( channel != packet.channel ) return false;
if( replyChannel != packet.replyChannel ) return false;
if( !Objects.equals( payload, packet.payload ) ) return false;
return sender.equals( packet.sender );
}
@Override
public int hashCode()
{
int result;
result = m_channel;
result = 31 * result + m_replyChannel;
result = 31 * result + (m_payload != null ? m_payload.hashCode() : 0);
result = 31 * result + m_sender.hashCode();
result = channel;
result = 31 * result + replyChannel;
result = 31 * result + (payload != null ? payload.hashCode() : 0);
result = 31 * result + sender.hashCode();
return result;
}
}

View File

@ -4,7 +4,7 @@
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
@API( owner="ComputerCraft", provides="ComputerCraft|API|Network", apiVersion="${version}" )
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Network", apiVersion = "${version}" )
package dan200.computercraft.api.network;
import net.minecraftforge.fml.common.API;

View File

@ -4,7 +4,7 @@
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
@API( owner="ComputerCraft", provides="ComputerCraft|API|Network|Wired", apiVersion="${version}" )
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Network|Wired", apiVersion = "${version}" )
package dan200.computercraft.api.network.wired;
import net.minecraftforge.fml.common.API;

View File

@ -4,7 +4,7 @@
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
@API( owner="ComputerCraft", provides="ComputerCraft|API", apiVersion="${version}" )
@API( owner = "ComputerCraft", provides = "ComputerCraft|API", apiVersion = "${version}" )
package dan200.computercraft.api;
import net.minecraftforge.fml.common.API;

View File

@ -4,7 +4,7 @@
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
@API( owner="ComputerCraft", provides="ComputerCraft|API|Peripheral", apiVersion="${version}" )
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Peripheral", apiVersion = "${version}" )
package dan200.computercraft.api.peripheral;
import net.minecraftforge.fml.common.API;

View File

@ -4,7 +4,7 @@
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
@API( owner="ComputerCraft", provides="ComputerCraft|API|Permissions", apiVersion="${version}" )
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Permissions", apiVersion = "${version}" )
package dan200.computercraft.api.permissions;
import net.minecraftforge.fml.common.API;

View File

@ -4,7 +4,7 @@
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
@API( owner="ComputerCraft", provides="ComputerCraft|API|Redstone", apiVersion="${version}" )
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Redstone", apiVersion = "${version}" )
package dan200.computercraft.api.redstone;
import net.minecraftforge.fml.common.API;

View File

@ -25,7 +25,6 @@
import javax.annotation.Nullable;
import javax.vecmath.Matrix4f;
/**
* The primary interface for defining an update for Turtles. A turtle update
* can either be a new tool, or a new peripheral.
@ -98,7 +97,10 @@ public interface ITurtleUpgrade
* and this method is not expected to be called.
*/
@Nullable
IPeripheral createPeripheral( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side );
default IPeripheral createPeripheral( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side )
{
return null;
}
/**
* Will only be called for Tool turtle. Called when turtle.dig() or turtle.attack() is called
@ -119,7 +121,10 @@ public interface ITurtleUpgrade
* to be called.
*/
@Nonnull
TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull EnumFacing direction );
default TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull EnumFacing direction )
{
return TurtleCommandResult.failure();
}
/**
* Called to obtain the model to be used when rendering a turtle peripheral.
@ -133,8 +138,8 @@ public interface ITurtleUpgrade
* @return The model that you wish to be used to render your upgrade, and a transformation to apply to it. Returning
* a transformation of {@code null} has the same effect as the identify matrix.
*/
@SideOnly(Side.CLIENT)
@Nonnull
@SideOnly( Side.CLIENT )
Pair<IBakedModel, Matrix4f> getModel( @Nullable ITurtleAccess turtle, @Nonnull TurtleSide side );
/**

View File

@ -19,8 +19,8 @@
*/
public final class TurtleCommandResult
{
private static final TurtleCommandResult s_success = new TurtleCommandResult( true, null, null );
private static final TurtleCommandResult s_emptyFailure = new TurtleCommandResult( false, null, null );
private static final TurtleCommandResult EMPTY_SUCCESS = new TurtleCommandResult( true, null, null );
private static final TurtleCommandResult EMPTY_FAILURE = new TurtleCommandResult( false, null, null );
/**
* Create a successful command result with no result.
@ -30,7 +30,7 @@ public final class TurtleCommandResult
@Nonnull
public static TurtleCommandResult success()
{
return success( null );
return EMPTY_SUCCESS;
}
/**
@ -42,14 +42,8 @@ public static TurtleCommandResult success()
@Nonnull
public static TurtleCommandResult success( @Nullable Object[] results )
{
if( results == null || results.length == 0 )
{
return s_success;
}
else
{
return new TurtleCommandResult( true, null, results );
}
if( results == null || results.length == 0 ) return EMPTY_SUCCESS;
return new TurtleCommandResult( true, null, results );
}
/**
@ -60,7 +54,7 @@ public static TurtleCommandResult success( @Nullable Object[] results )
@Nonnull
public static TurtleCommandResult failure()
{
return failure( null );
return EMPTY_FAILURE;
}
/**
@ -72,25 +66,19 @@ public static TurtleCommandResult failure()
@Nonnull
public static TurtleCommandResult failure( @Nullable String errorMessage )
{
if( errorMessage == null )
{
return s_emptyFailure;
}
else
{
return new TurtleCommandResult( false, errorMessage, null );
}
if( errorMessage == null ) return EMPTY_FAILURE;
return new TurtleCommandResult( false, errorMessage, null );
}
private final boolean m_success;
private final String m_errorMessage;
private final Object[] m_results;
private final boolean success;
private final String errorMessage;
private final Object[] results;
private TurtleCommandResult( boolean success, String errorMessage, Object[] results )
{
m_success = success;
m_errorMessage = errorMessage;
m_results = results;
this.success = success;
this.errorMessage = errorMessage;
this.results = results;
}
/**
@ -100,7 +88,7 @@ private TurtleCommandResult( boolean success, String errorMessage, Object[] resu
*/
public boolean isSuccess()
{
return m_success;
return success;
}
/**
@ -111,7 +99,7 @@ public boolean isSuccess()
@Nullable
public String getErrorMessage()
{
return m_errorMessage;
return errorMessage;
}
/**
@ -122,6 +110,6 @@ public String getErrorMessage()
@Nullable
public Object[] getResults()
{
return m_results;
return results;
}
}

View File

@ -30,7 +30,7 @@ public enum TurtleUpgradeType
* your upgrade to also provide methods. For example, a pickaxe could provide methods
* determining whether it can break the given block or not.
*/
Both,;
Both;
public boolean isTool()
{

View File

@ -1,12 +1,12 @@
package dan200.computercraft.api.turtle.event;
import com.google.common.base.Preconditions;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.TurtleCommandResult;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Objects;
/**
* An event fired when a turtle is performing a known action.
@ -21,7 +21,7 @@ public TurtleActionEvent( @Nonnull ITurtleAccess turtle, @Nonnull TurtleAction a
{
super( turtle );
Preconditions.checkNotNull( action, "action cannot be null" );
Objects.requireNonNull( action, "action cannot be null" );
this.action = action;
}

View File

@ -6,7 +6,6 @@
package dan200.computercraft.api.turtle.event;
import com.google.common.base.Preconditions;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleSide;
@ -17,6 +16,7 @@
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import javax.annotation.Nonnull;
import java.util.Objects;
/**
* Fired when a turtle attempts to attack an entity.
@ -37,9 +37,9 @@ public class TurtleAttackEvent extends TurtlePlayerEvent
public TurtleAttackEvent( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull Entity target, @Nonnull ITurtleUpgrade upgrade, @Nonnull TurtleSide side )
{
super( turtle, TurtleAction.ATTACK, player );
Preconditions.checkNotNull( target, "target cannot be null" );
Preconditions.checkNotNull( upgrade, "upgrade cannot be null" );
Preconditions.checkNotNull( side, "side cannot be null" );
Objects.requireNonNull( target, "target cannot be null" );
Objects.requireNonNull( upgrade, "upgrade cannot be null" );
Objects.requireNonNull( side, "side cannot be null" );
this.target = target;
this.upgrade = upgrade;
this.side = side;

View File

@ -6,7 +6,6 @@
package dan200.computercraft.api.turtle.event;
import com.google.common.base.Preconditions;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.turtle.ITurtleAccess;
@ -24,6 +23,7 @@
import javax.annotation.Nonnull;
import java.util.Map;
import java.util.Objects;
/**
* A general event for when a turtle interacts with a block or region.
@ -47,8 +47,8 @@ protected TurtleBlockEvent( @Nonnull ITurtleAccess turtle, @Nonnull TurtleAction
{
super( turtle, action, player );
Preconditions.checkNotNull( world, "world cannot be null" );
Preconditions.checkNotNull( pos, "pos cannot be null" );
Objects.requireNonNull( world, "world cannot be null" );
Objects.requireNonNull( pos, "pos cannot be null" );
this.world = world;
this.pos = pos;
}
@ -95,9 +95,9 @@ public Dig( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull
{
super( turtle, TurtleAction.DIG, player, world, pos );
Preconditions.checkNotNull( block, "block cannot be null" );
Preconditions.checkNotNull( upgrade, "upgrade cannot be null" );
Preconditions.checkNotNull( side, "side cannot be null" );
Objects.requireNonNull( block, "block cannot be null" );
Objects.requireNonNull( upgrade, "upgrade cannot be null" );
Objects.requireNonNull( side, "side cannot be null" );
this.block = block;
this.upgrade = upgrade;
this.side = side;
@ -165,7 +165,7 @@ public Place( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnul
{
super( turtle, TurtleAction.PLACE, player, world, pos );
Preconditions.checkNotNull( stack, "stack cannot be null" );
Objects.requireNonNull( stack, "stack cannot be null" );
this.stack = stack;
}
@ -198,8 +198,8 @@ public Inspect( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonn
{
super( turtle, TurtleAction.INSPECT, player, world, pos );
Preconditions.checkNotNull( state, "state cannot be null" );
Preconditions.checkNotNull( data, "data cannot be null" );
Objects.requireNonNull( state, "state cannot be null" );
Objects.requireNonNull( data, "data cannot be null" );
this.data = data;
this.state = state;
}
@ -234,7 +234,7 @@ public Map<String, Object> getData()
*/
public void addData( @Nonnull Map<String, ?> newData )
{
Preconditions.checkNotNull( newData, "newData cannot be null" );
Objects.requireNonNull( newData, "newData cannot be null" );
data.putAll( newData );
}
}

View File

@ -6,11 +6,11 @@
package dan200.computercraft.api.turtle.event;
import com.google.common.base.Preconditions;
import dan200.computercraft.api.turtle.ITurtleAccess;
import net.minecraftforge.fml.common.eventhandler.Event;
import javax.annotation.Nonnull;
import java.util.Objects;
/**
* A base class for all events concerning a turtle. This will only ever constructed and fired on the server side,
@ -26,7 +26,7 @@ public abstract class TurtleEvent extends Event
protected TurtleEvent( @Nonnull ITurtleAccess turtle )
{
Preconditions.checkNotNull( turtle, "turtle cannot be null" );
Objects.requireNonNull( turtle, "turtle cannot be null" );
this.turtle = turtle;
}

View File

@ -1,6 +1,5 @@
package dan200.computercraft.api.turtle.event;
import com.google.common.base.Preconditions;
import dan200.computercraft.api.turtle.ITurtleAccess;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
@ -11,6 +10,7 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Objects;
/**
* Fired when a turtle attempts to interact with an inventory.
@ -65,7 +65,7 @@ public Drop( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull
{
super( turtle, TurtleAction.DROP, player, world, pos, handler );
Preconditions.checkNotNull( stack, "stack cannot be null" );
Objects.requireNonNull( stack, "stack cannot be null" );
this.stack = stack;
}

View File

@ -6,11 +6,11 @@
package dan200.computercraft.api.turtle.event;
import com.google.common.base.Preconditions;
import dan200.computercraft.api.turtle.ITurtleAccess;
import net.minecraftforge.common.util.FakePlayer;
import javax.annotation.Nonnull;
import java.util.Objects;
/**
* An action done by a turtle which is normally done by a player.
@ -25,7 +25,7 @@ protected TurtlePlayerEvent( @Nonnull ITurtleAccess turtle, @Nonnull TurtleActio
{
super( turtle, action );
Preconditions.checkNotNull( player, "player cannot be null" );
Objects.requireNonNull( player, "player cannot be null" );
this.player = player;
}

View File

@ -4,7 +4,7 @@
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
@API(owner = "ComputerCraft", provides = "ComputerCraft|API|Turtle|Event", apiVersion = "${version}")
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Turtle|Event", apiVersion = "${version}" )
package dan200.computercraft.api.turtle.event;
import net.minecraftforge.fml.common.API;

View File

@ -4,7 +4,7 @@
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
@API( owner="ComputerCraft", provides="ComputerCraft|API|Turtle", apiVersion="${version}" )
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Turtle", apiVersion = "${version}" )
package dan200.computercraft.api.turtle;
import net.minecraftforge.fml.common.API;

View File

@ -87,18 +87,6 @@ public boolean setLabel( @Nonnull ItemStack stack, String label )
return true;
}
@Override
public String getAudioTitle( @Nonnull ItemStack stack )
{
return null;
}
@Override
public SoundEvent getAudio( @Nonnull ItemStack stack )
{
return null;
}
@Override
public IMount createDataMount( @Nonnull ItemStack stack, @Nonnull World world )
{

View File

@ -11,22 +11,12 @@
public class DefaultMediaProvider implements IMediaProvider
{
public DefaultMediaProvider()
{
}
@Override
public IMedia getMedia( @Nonnull ItemStack stack )
{
Item item = stack.getItem();
if( item instanceof IMedia )
{
return (IMedia)item;
}
else if( item instanceof ItemRecord )
{
return new RecordMedia();
}
if( item instanceof IMedia ) return (IMedia) item;
if( item instanceof ItemRecord ) return RecordMedia.INSTANCE;
return null;
}
}

View File

@ -18,7 +18,6 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
@ -34,16 +33,16 @@ public ItemDiskLegacy()
setMaxStackSize( 1 );
setHasSubtypes( true );
setTranslationKey( "computercraft:disk" );
setCreativeTab( ComputerCraft.mainCreativeTab );
setCreativeTab( ComputerCraft.mainCreativeTab );
}
@Override
public void getSubItems( @Nonnull CreativeTabs tabs, @Nonnull NonNullList<ItemStack> list )
{
if( !isInCreativeTab( tabs ) ) return;
for( int colour=0; colour<16; ++colour )
for( int colour = 0; colour < 16; ++colour )
{
ItemStack stack = createFromIDAndColour( -1, null, Colour.values()[ colour ].getHex() );
ItemStack stack = createFromIDAndColour( -1, null, Colour.values()[colour].getHex() );
if( stack.getItem() == this )
{
list.add( stack );
@ -56,7 +55,7 @@ public static ItemStack createFromIDAndColour( int id, String label, int colour
{
return ItemDiskExpanded.createFromIDAndColour( id, label, colour );
}
public int getDiskID( @Nonnull ItemStack stack )
{
int damage = stack.getItemDamage();
@ -69,9 +68,12 @@ public int getDiskID( @Nonnull ItemStack stack )
protected void setDiskID( @Nonnull ItemStack stack, int id )
{
if( id > 0 ) {
if( id > 0 )
{
stack.setItemDamage( id );
} else {
}
else
{
stack.setItemDamage( 0 );
}
}
@ -100,7 +102,7 @@ public String getLabel( @Nonnull ItemStack stack )
}
return null;
}
@Override
public boolean setLabel( @Nonnull ItemStack stack, String label )
{
@ -114,19 +116,7 @@ public boolean setLabel( @Nonnull ItemStack stack, String label )
}
return true;
}
@Override
public String getAudioTitle( @Nonnull ItemStack stack )
{
return null;
}
@Override
public SoundEvent getAudio( @Nonnull ItemStack stack )
{
return null;
}
@Override
public IMount createDataMount( @Nonnull ItemStack stack, @Nonnull World world )
{

View File

@ -18,7 +18,6 @@
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.NonNullList;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
@ -29,19 +28,19 @@
public class ItemTreasureDisk extends Item
implements IMedia
{
{
public ItemTreasureDisk()
{
setMaxStackSize( 1 );
setHasSubtypes( true );
setTranslationKey( "computercraft:treasure_disk" );
}
@Override
public void getSubItems( @Nonnull CreativeTabs tabs, @Nonnull NonNullList<ItemStack> list )
{
}
@Override
public void addInformation( @Nonnull ItemStack stack, World world, List<String> list, ITooltipFlag flag )
{
@ -57,7 +56,7 @@ public boolean doesSneakBypassUse( @Nonnull ItemStack stack, IBlockAccess world,
{
return true;
}
// IMedia implementation
@Override
@ -65,25 +64,7 @@ public String getLabel( @Nonnull ItemStack stack )
{
return getTitle( stack );
}
@Override
public boolean setLabel( @Nonnull ItemStack stack, String label )
{
return false;
}
@Override
public String getAudioTitle( @Nonnull ItemStack stack )
{
return null;
}
@Override
public SoundEvent getAudio( @Nonnull ItemStack stack )
{
return null;
}
@Override
public IMount createDataMount( @Nonnull ItemStack stack, @Nonnull World world )
{
@ -109,12 +90,12 @@ else if( rootTreasure.exists( "deprecated/" + subPath ) )
return null;
}
}
public static ItemStack create( String subPath, int colourIndex )
{
{
NBTTagCompound nbt = new NBTTagCompound();
nbt.setString( "subPath", subPath );
int slash = subPath.indexOf( "/" );
if( slash >= 0 )
{
@ -126,8 +107,8 @@ public static ItemStack create( String subPath, int colourIndex )
{
nbt.setString( "title", "untitled" );
}
nbt.setInteger( "colour", Colour.values()[ colourIndex ].getHex() );
nbt.setInteger( "colour", Colour.values()[colourIndex].getHex() );
ItemStack result = new ItemStack( ComputerCraft.Items.treasureDisk, 1, 0 );
result.setTagCompound( nbt );
return result;
@ -139,7 +120,7 @@ private static IMount getTreasureMount()
}
// private stuff
public String getTitle( @Nonnull ItemStack stack )
{
NBTTagCompound nbt = stack.getTagCompound();
@ -149,7 +130,7 @@ public String getTitle( @Nonnull ItemStack stack )
}
return "'alongtimeago' by dan200";
}
public String getSubPath( @Nonnull ItemStack stack )
{
NBTTagCompound nbt = stack.getTagCompound();
@ -159,7 +140,7 @@ public String getSubPath( @Nonnull ItemStack stack )
}
return "dan200/alongtimeago";
}
public int getColour( @Nonnull ItemStack stack )
{
NBTTagCompound nbt = stack.getTagCompound();

View File

@ -7,50 +7,40 @@
package dan200.computercraft.shared.media.items;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.filesystem.IMount;
import dan200.computercraft.api.media.IMedia;
import net.minecraft.item.ItemRecord;
import net.minecraft.item.ItemStack;
import net.minecraft.util.SoundEvent;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
// An implementation of IMedia for ItemRecord's
/**
* An implementation of IMedia for ItemRecord's
*/
public class RecordMedia implements IMedia
{
public RecordMedia()
public static final RecordMedia INSTANCE = new RecordMedia();
private RecordMedia()
{
}
@Override
public String getLabel( @Nonnull ItemStack stack )
{
return getAudioTitle( stack );
}
@Override
public boolean setLabel( @Nonnull ItemStack stack, String label )
{
return false;
}
@Override
public String getAudioTitle( @Nonnull ItemStack stack )
{
return ComputerCraft.getRecordInfo( stack );
}
@Override
public SoundEvent getAudio( @Nonnull ItemStack stack )
{
ItemRecord itemRecord = (ItemRecord)stack.getItem();
ItemRecord itemRecord = (ItemRecord) stack.getItem();
return itemRecord.sound;
}
@Override
public IMount createDataMount( @Nonnull ItemStack stack, @Nonnull World world )
{
return null;
}
}

View File

@ -28,7 +28,10 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.*;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.fml.relauncher.Side;
@ -82,7 +85,7 @@ public ItemStack create( int id, String label, int colour, ComputerFamily family
if( tag == null ) result.setTagCompound( tag = new NBTTagCompound() );
tag.setInteger( "colour", colour );
}
return result;
}
@ -374,7 +377,7 @@ public ComputerFamily getFamily( @Nonnull ItemStack stack )
@Override
public ItemStack withFamily( @Nonnull ItemStack stack, @Nonnull ComputerFamily family )
{
return PocketComputerItemFactory.create(
return PocketComputerItemFactory.create(
getComputerID( stack ), getLabel( stack ), getColour( stack ),
family, getUpgrade( stack )
);
@ -396,18 +399,6 @@ public boolean setLabel( @Nonnull ItemStack stack, String label )
return true;
}
@Override
public String getAudioTitle( @Nonnull ItemStack stack )
{
return null;
}
@Override
public SoundEvent getAudio( @Nonnull ItemStack stack )
{
return null;
}
@Override
public IMount createDataMount( @Nonnull ItemStack stack, @Nonnull World world )
{
@ -457,7 +448,7 @@ private void setSessionID( @Nonnull ItemStack stack, int sessionID )
stack.getTagCompound().setInteger( "sessionID", sessionID );
}
@SideOnly(Side.CLIENT)
@SideOnly( Side.CLIENT )
public ComputerState getState( @Nonnull ItemStack stack )
{
ClientComputer computer = getClientComputer( stack );
@ -468,7 +459,7 @@ public ComputerState getState( @Nonnull ItemStack stack )
return ComputerState.Off;
}
@SideOnly(Side.CLIENT)
@SideOnly( Side.CLIENT )
public int getLightState( @Nonnull ItemStack stack )
{
ClientComputer computer = getClientComputer( stack );

View File

@ -7,14 +7,16 @@
package dan200.computercraft.shared.turtle.upgrades;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.turtle.*;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.api.turtle.TurtleUpgradeType;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ModelManager;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@ -61,14 +63,14 @@ public String getUnlocalisedAdjective()
{
return "upgrade.minecraft:crafting_table.adjective";
}
@Nonnull
@Override
public TurtleUpgradeType getType()
{
return TurtleUpgradeType.Peripheral;
}
@Nonnull
@Override
public ItemStack getCraftingItem()
@ -82,13 +84,6 @@ public IPeripheral createPeripheral( @Nonnull ITurtleAccess turtle, @Nonnull Tur
return new CraftingTablePeripheral( turtle );
}
@Nonnull
@Override
public TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull EnumFacing dir )
{
return TurtleCommandResult.failure();
}
@SideOnly( Side.CLIENT )
private void loadModelLocations()
{

View File

@ -8,7 +8,10 @@
package dan200.computercraft.shared.turtle.upgrades;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.turtle.*;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.api.turtle.TurtleUpgradeType;
import dan200.computercraft.shared.peripheral.PeripheralType;
import dan200.computercraft.shared.peripheral.common.PeripheralItemFactory;
import dan200.computercraft.shared.peripheral.speaker.SpeakerPeripheral;
@ -17,13 +20,13 @@
import net.minecraft.client.renderer.block.model.ModelManager;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.lang3.tuple.Pair;
import javax.annotation.Nonnull;
import javax.vecmath.Matrix4f;
@ -34,7 +37,7 @@ private static class Peripheral extends SpeakerPeripheral
// Members
ITurtleAccess m_turtle;
public Peripheral(ITurtleAccess turtle)
public Peripheral( ITurtleAccess turtle )
{
super();
m_turtle = turtle;
@ -59,9 +62,9 @@ public BlockPos getPos()
}
@Override
public boolean equals(IPeripheral other)
public boolean equals( IPeripheral other )
{
if (other instanceof Peripheral)
if( other instanceof Peripheral )
{
Peripheral otherPeripheral = (Peripheral) other;
return otherPeripheral.m_turtle == m_turtle;
@ -124,14 +127,7 @@ public ItemStack getCraftingItem()
@Override
public IPeripheral createPeripheral( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side )
{
return new TurtleSpeaker.Peripheral(turtle);
}
@Nonnull
@Override
public TurtleCommandResult useTool( @Nonnull ITurtleAccess turtleAccess, @Nonnull TurtleSide turtleSide, @Nonnull TurtleVerb verb, @Nonnull EnumFacing direction )
{
return TurtleCommandResult.failure();
return new TurtleSpeaker.Peripheral( turtle );
}
@SideOnly( Side.CLIENT )
@ -166,7 +162,7 @@ public Pair<IBakedModel, Matrix4f> getModel( ITurtleAccess turtle, @Nonnull Turt
public void update( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide turtleSide )
{
IPeripheral turtlePeripheral = turtle.getPeripheral( turtleSide );
if ( turtlePeripheral instanceof Peripheral )
if( turtlePeripheral instanceof Peripheral )
{
Peripheral peripheral = (Peripheral) turtlePeripheral;
peripheral.update();

View File

@ -7,7 +7,6 @@
package dan200.computercraft.shared.turtle.upgrades;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.turtle.*;
import dan200.computercraft.api.turtle.event.TurtleAttackEvent;
import dan200.computercraft.api.turtle.event.TurtleBlockEvent;
@ -94,12 +93,6 @@ public ItemStack getCraftingItem()
return m_item.copy();
}
@Override
public IPeripheral createPeripheral( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side )
{
return null;
}
@Nonnull
@Override
@SideOnly( Side.CLIENT )