1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-01-05 15:00:29 +00:00

Some further cleanup and 1.13 cherry-picks

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.
This commit is contained in:
SquidDev 2019-04-02 11:50:13 +01:00
parent 390575ab4d
commit 2965fb666f
81 changed files with 601 additions and 896 deletions

View File

@ -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]*" />

View File

@ -1,5 +1,5 @@
# Mod properties
mod_version=1.81.1
mod_version=1.82.0
# Minecraft properties
mc_version=1.12.2

View File

@ -51,7 +51,7 @@ import dan200.computercraft.shared.peripheral.modem.wireless.WirelessNetwork;
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 class ComputerCraft
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 class ComputerCraft
@Mod.EventHandler
public void onServerStarting( FMLServerStartingEvent event )
{
proxy.initServer( event.getServer() );
ComputerCraftProxyCommon.initServer( event.getServer() );
}
@Mod.EventHandler

View File

@ -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 net.minecraft.util.ResourceLocation;
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 abstract class AbstractTurtleUpgrade implements ITurtleUpgrade
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 ) );
}

View File

@ -46,7 +46,7 @@ public interface IMedia
/**
* 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.

View File

@ -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;

View File

@ -11,7 +11,6 @@ import net.minecraft.item.ItemStack;
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 @@ import java.util.Objects;
/**
* Fired when a turtle attempts to interact with an inventory.
*/
@Cancelable
public abstract class TurtleInventoryEvent extends TurtleBlockEvent
{
private final IItemHandler handler;

View File

@ -11,6 +11,7 @@ import dan200.computercraft.client.render.TurtleModelLoader;
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 final class ClientRegistry
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 );

View File

@ -61,11 +61,11 @@ public class TileEntityCableRenderer extends TileEntitySpecialRenderer<TileCable
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 );

View File

@ -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();
}

View File

@ -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;
}

View File

@ -228,9 +228,9 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
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];

View File

@ -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

View File

@ -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

View File

@ -26,8 +26,8 @@ import java.util.concurrent.TimeUnit;
* 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)}.

View File

@ -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

View File

@ -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" );

View File

@ -52,10 +52,10 @@ public abstract class BlockGeneric extends Block implements ITileEntityProvider
@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 abstract class BlockGeneric extends Block implements ITileEntityProvider
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 abstract class BlockGeneric extends Block implements ITileEntityProvider
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

View File

@ -78,11 +78,7 @@ public class ColourableRecipe extends IForgeRegistryEntry.Impl<IRecipe> implemen
}
}
if( colourable.isEmpty() )
{
return ItemStack.EMPTY;
}
if( colourable.isEmpty() ) return ItemStack.EMPTY;
return ((IColouredItem) colourable.getItem()).withColour( colourable, tracker.getColour() );
}

View File

@ -130,7 +130,6 @@ public abstract class TileGeneric extends TileEntity
@Override
public final SPacketUpdateTileEntity getUpdatePacket()
{
// Communicate properties
NBTTagCompound nbt = new NBTTagCompound();
writeDescription( nbt );
return new SPacketUpdateTileEntity( getPos(), 0, nbt );

View File

@ -26,6 +26,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@ -67,38 +68,30 @@ public class CommandAPI implements ILuaAPI
private static Map<Object, Object> createOutput( String output )
{
Map<Object, Object> result = new HashMap<>( 1 );
result.put( 1, output );
return result;
return Collections.singletonMap( 1, output );
}
private Object[] doCommand( String command )
{
MinecraftServer server = m_computer.getWorld().getMinecraftServer();
if( server != null && server.isCommandBlockEnabled() )
{
ICommandManager commandManager = server.getCommandManager();
try
{
TileCommandComputer.CommandSender sender = m_computer.getCommandSender();
sender.clearOutput();
int result = commandManager.executeCommand( sender, command );
return new Object[] { result > 0, sender.copyOutput() };
}
catch( Throwable t )
{
if( ComputerCraft.logPeripheralErrors )
{
ComputerCraft.log.error( "Error running command.", t );
}
return new Object[] { false, createOutput( "Java Exception Thrown: " + t ) };
}
}
else
if( server == null || !server.isCommandBlockEnabled() )
{
return new Object[] { false, createOutput( "Command blocks disabled by server" ) };
}
ICommandManager commandManager = server.getCommandManager();
TileCommandComputer.CommandSender sender = m_computer.getCommandSender();
try
{
sender.clearOutput();
int result = commandManager.executeCommand( sender, command );
return new Object[] { result > 0, sender.copyOutput() };
}
catch( Throwable t )
{
if( ComputerCraft.logPeripheralErrors ) ComputerCraft.log.error( "Error running command.", t );
return new Object[] { false, createOutput( "Java Exception Thrown: " + t ) };
}
}
private static Object getBlockInfo( World world, BlockPos pos )
@ -120,7 +113,7 @@ public class CommandAPI implements ILuaAPI
table.put( "state", stateTable );
TileEntity tile = world.getTileEntity( pos );
if( tile != null ) table.put( "nbt", NBTUtil.toLua( tile.writeToNBT( new NBTTagCompound() ).copy() ) );
if( tile != null ) table.put( "nbt", NBTUtil.toLua( tile.writeToNBT( new NBTTagCompound() ) ) );
return table;
}

View File

@ -9,6 +9,7 @@ package dan200.computercraft.shared.computer.blocks;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.items.ComputerItemFactory;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.properties.PropertyEnum;
@ -28,7 +29,7 @@ public class BlockCommandComputer extends BlockComputerBase
public static final class Properties
{
public static final PropertyDirection FACING = PropertyDirection.create( "facing", EnumFacing.Plane.HORIZONTAL );
public static final PropertyDirection FACING = BlockHorizontal.FACING;
public static final PropertyEnum<ComputerState> STATE = PropertyEnum.create( "state", ComputerState.class );
}

View File

@ -9,6 +9,7 @@ package dan200.computercraft.shared.computer.blocks;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.items.ComputerItemFactory;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyDirection;
@ -28,7 +29,7 @@ public class BlockComputer extends BlockComputerBase
// Statics
public static final class Properties
{
public static final PropertyDirection FACING = PropertyDirection.create( "facing", EnumFacing.Plane.HORIZONTAL );
public static final PropertyDirection FACING = BlockHorizontal.FACING;
public static final PropertyBool ADVANCED = PropertyBool.create( "advanced" );
public static final PropertyEnum<ComputerState> STATE = PropertyEnum.create( "state", ComputerState.class );
}

View File

@ -82,14 +82,10 @@ public abstract class BlockComputerBase extends BlockDirectional
return getFamily( world.getBlockState( pos ) );
}
protected void updateInput( IBlockAccess world, BlockPos pos )
private static void updateInput( IBlockAccess world, BlockPos pos )
{
TileEntity tile = world.getTileEntity( pos );
if( tile instanceof TileComputerBase )
{
TileComputerBase computer = (TileComputerBase) tile;
computer.updateInput();
}
if( tile instanceof TileComputerBase ) ((TileComputerBase) tile).updateInput();
}
@Override

View File

@ -65,14 +65,14 @@ public class TileComputer extends TileComputerBase
}
@Override
public void writeDescription( @Nonnull NBTTagCompound nbt )
protected void writeDescription( @Nonnull NBTTagCompound nbt )
{
super.writeDescription( nbt );
nbt.setInteger( TAG_STATE, state.ordinal() );
}
@Override
public final void readDescription( @Nonnull NBTTagCompound nbt )
protected final void readDescription( @Nonnull NBTTagCompound nbt )
{
super.readDescription( nbt );
state = ComputerState.valueOf( nbt.getInteger( TAG_STATE ) );

View File

@ -19,6 +19,7 @@ import dan200.computercraft.shared.computer.core.IComputer;
import dan200.computercraft.shared.computer.core.ServerComputer;
import dan200.computercraft.shared.util.DirectionUtil;
import dan200.computercraft.shared.util.RedstoneUtil;
import joptsimple.internal.Strings;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
@ -57,10 +58,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
{
if( m_instanceID >= 0 )
{
if( !getWorld().isRemote )
{
ComputerCraft.serverComputerRegistry.remove( m_instanceID );
}
if( !getWorld().isRemote ) ComputerCraft.serverComputerRegistry.remove( m_instanceID );
m_instanceID = -1;
}
}
@ -193,11 +191,13 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
m_startOn = false;
}
computer.keepAlive();
if( computer.hasOutputChanged() ) updateOutput();
m_fresh = false;
m_computerID = computer.getID();
m_label = computer.getLabel();
m_on = computer.isOn();
if( computer.hasOutputChanged() ) updateOutput();
}
}
else
@ -211,8 +211,6 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
@Override
public NBTTagCompound writeToNBT( NBTTagCompound nbt )
{
nbt = super.writeToNBT( nbt );
// Save ID, label and power state
if( m_computerID >= 0 )
{
@ -223,7 +221,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
nbt.setString( "label", m_label );
}
nbt.setBoolean( "on", m_on );
return nbt;
return super.writeToNBT( nbt );
}
@Override
@ -297,13 +295,12 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
// Update redstone and peripherals
ServerComputer computer = getServerComputer();
if( computer != null )
if( computer == null ) return;
BlockPos pos = computer.getPosition();
for( EnumFacing dir : EnumFacing.VALUES )
{
BlockPos pos = computer.getPosition();
for( EnumFacing dir : EnumFacing.VALUES )
{
updateSideInput( computer, dir, pos.offset( dir ) );
}
updateSideInput( computer, dir, pos.offset( dir ) );
}
}
@ -344,19 +341,19 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
// IComputerTile
@Override
public int getComputerID()
public final int getComputerID()
{
return m_computerID;
}
@Override
public String getLabel()
public final String getLabel()
{
return m_label;
}
@Override
public void setComputerID( int id )
public final void setComputerID( int id )
{
if( getWorld().isRemote || m_computerID == id ) return;
@ -367,7 +364,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
}
@Override
public void setLabel( String label )
public final void setLabel( String label )
{
if( getWorld().isRemote || Objects.equals( m_label, label ) ) return;
@ -381,11 +378,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
public ComputerFamily getFamily()
{
BlockComputerBase block = getBlock();
if( block != null )
{
return block.getFamily( getWorld(), getPos() );
}
return ComputerFamily.Normal;
return block != null ? block.getFamily( getWorld(), getPos() ) : ComputerFamily.Normal;
}
@Override
@ -429,11 +422,12 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
{
if( !getWorld().isRemote || m_instanceID < 0 ) return null;
if( !ComputerCraft.clientComputerRegistry.contains( m_instanceID ) )
ClientComputer computer = ComputerCraft.clientComputerRegistry.get( m_instanceID );
if( computer == null )
{
ComputerCraft.clientComputerRegistry.add( m_instanceID, new ClientComputer( m_instanceID ) );
ComputerCraft.clientComputerRegistry.add( m_instanceID, computer = new ClientComputer( m_instanceID ) );
}
return ComputerCraft.clientComputerRegistry.get( m_instanceID );
return computer;
}
public ClientComputer getClientComputer()
@ -444,7 +438,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
// Networking stuff
@Override
public void writeDescription( @Nonnull NBTTagCompound nbt )
protected void writeDescription( @Nonnull NBTTagCompound nbt )
{
super.writeDescription( nbt );
nbt.setInteger( "instanceID", createServerComputer().getInstanceID() );
@ -453,7 +447,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
}
@Override
public void readDescription( @Nonnull NBTTagCompound nbt )
protected void readDescription( @Nonnull NBTTagCompound nbt )
{
super.readDescription( nbt );
m_instanceID = nbt.getInteger( "instanceID" );
@ -487,14 +481,13 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
@Override
public String getName()
{
String label = getLabel();
return label != null && !label.isEmpty() ? label : getBlockType().getTranslationKey();
return hasCustomName() ? m_label : getBlockType().getTranslationKey();
}
@Override
public boolean hasCustomName()
{
return getLabel() != null;
return !Strings.isNullOrEmpty( m_label );
}
@Nonnull

View File

@ -47,26 +47,16 @@ public abstract class ItemComputerBase extends ItemBlock implements IComputerIte
}
}
// IComputerItem implementation
@Override
public abstract int getComputerID( @Nonnull ItemStack stack );
@Override
public String getLabel( @Nonnull ItemStack stack )
{
if( stack.hasDisplayName() )
{
return stack.getDisplayName();
}
return null;
return IComputerItem.super.getLabel( stack );
}
@Override
public final ComputerFamily getFamily( @Nonnull ItemStack stack )
{
int damage = stack.getItemDamage();
return getFamily( damage );
return getFamily( stack.getItemDamage() );
}
// IMedia implementation

View File

@ -9,7 +9,6 @@ package dan200.computercraft.shared.computer.recipe;
import dan200.computercraft.shared.computer.items.IComputerItem;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.world.World;
import net.minecraftforge.common.crafting.CraftingHelper;
@ -27,47 +26,30 @@ public abstract class ComputerConvertRecipe extends ShapedRecipes
}
@Nonnull
protected abstract ItemStack convert( IComputerItem item, @Nonnull ItemStack stack );
protected abstract ItemStack convert( @Nonnull IComputerItem item, @Nonnull ItemStack stack );
@Override
public boolean matches( @Nonnull InventoryCrafting inventory, @Nonnull World world )
{
// See if we match the recipe, and extract the input computercraft ID
ItemStack computerStack = null;
for( int y = 0; y < 3; y++ )
if( !super.matches( inventory, world ) ) return false;
for( int i = 0; i < inventory.getSizeInventory(); i++ )
{
for( int x = 0; x < 3; x++ )
{
ItemStack stack = inventory.getStackInRowAndColumn( x, y );
Ingredient target = getIngredients().get( x + y * 3 );
// First verify we match the ingredient
if( !target.apply( stack ) ) return false;
// We want to ensure we have a computer item somewhere in the recipe
if( stack.getItem() instanceof IComputerItem ) computerStack = stack;
}
if( inventory.getStackInSlot( i ).getItem() instanceof IComputerItem ) return true;
}
return computerStack != null;
return false;
}
@Nonnull
@Override
public ItemStack getCraftingResult( @Nonnull InventoryCrafting inventory )
{
for( int y = 0; y < 3; y++ )
// Find our computer item and convert it.
for( int i = 0; i < inventory.getSizeInventory(); i++ )
{
for( int x = 0; x < 3; x++ )
{
ItemStack stack = inventory.getStackInRowAndColumn( x, y );
// If we're a computer, convert!
if( stack.getItem() instanceof IComputerItem )
{
return convert( (IComputerItem) stack.getItem(), stack );
}
}
ItemStack stack = inventory.getStackInSlot( i );
if( stack.getItem() instanceof IComputerItem ) return convert( (IComputerItem) stack.getItem(), stack );
}
return ItemStack.EMPTY;

View File

@ -31,7 +31,7 @@ public class ComputerFamilyRecipe extends ComputerConvertRecipe
@Nonnull
@Override
protected ItemStack convert( IComputerItem item, @Nonnull ItemStack stack )
protected ItemStack convert( @Nonnull IComputerItem item, @Nonnull ItemStack stack )
{
return item.withFamily( stack, family );
}

View File

@ -24,13 +24,13 @@ public class PartAdvancedModem implements IMultipart
@Override
public IPartSlot getSlotForPlacement( World world, BlockPos pos, IBlockState state, EnumFacing facing, float hitX, float hitY, float hitZ, EntityLivingBase placer )
{
return EnumFaceSlot.fromFace( state.getValue( BlockAdvancedModem.Properties.FACING ) );
return EnumFaceSlot.fromFace( state.getValue( BlockAdvancedModem.FACING ) );
}
@Override
public IPartSlot getSlotFromWorld( IBlockAccess world, BlockPos pos, IBlockState state )
{
return EnumFaceSlot.fromFace( state.getValue( BlockAdvancedModem.Properties.FACING ) );
return EnumFaceSlot.fromFace( state.getValue( BlockAdvancedModem.FACING ) );
}
@Override

View File

@ -36,7 +36,7 @@ public class PartNormalModem implements IMultipart
private EnumFacing getFacing( IBlockState state )
{
BlockPeripheralVariant type = state.getValue( BlockPeripheral.Properties.VARIANT );
BlockPeripheralVariant type = state.getValue( BlockPeripheral.VARIANT );
if( type == BlockPeripheralVariant.WirelessModemUpOn || type == BlockPeripheralVariant.WirelessModemUpOff )
{
return EnumFacing.UP;
@ -47,7 +47,7 @@ public class PartNormalModem implements IMultipart
}
else
{
return state.getValue( BlockPeripheral.Properties.FACING );
return state.getValue( BlockPeripheral.FACING );
}
}

View File

@ -34,7 +34,7 @@ public class ContainerHeldItem extends Container
@Override
public boolean canInteractWith( @Nonnull EntityPlayer player )
{
if( player == null || !player.isEntityAlive() ) return false;
if( !player.isEntityAlive() ) return false;
ItemStack stack = player.getHeldItem( m_hand );
return stack == m_stack || !stack.isEmpty() && !m_stack.isEmpty() && stack.getItem() == m_stack.getItem();

View File

@ -46,9 +46,9 @@ public class PrintoutRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements
}
@Override
public boolean matches( @Nonnull InventoryCrafting _inventory, @Nonnull World world )
public boolean matches( @Nonnull InventoryCrafting inventory, @Nonnull World world )
{
return !getCraftingResult( _inventory ).isEmpty();
return !getCraftingResult( inventory ).isEmpty();
}
@Nonnull

View File

@ -149,7 +149,7 @@ public final class Containers implements IGuiHandler
break;
}
case PRINTOUT:
return new ContainerHeldItem( player, x == 0 ? EnumHand.MAIN_HAND : EnumHand.MAIN_HAND );
return new ContainerHeldItem( player, x == 0 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND );
case POCKET_COMPUTER:
return new ContainerPocketComputer( player, x == 0 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND );
case VIEW_COMPUTER:

View File

@ -17,6 +17,7 @@ import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
import dan200.computercraft.shared.peripheral.printer.TilePrinter;
import dan200.computercraft.shared.peripheral.speaker.TileSpeaker;
import dan200.computercraft.shared.util.DirectionUtil;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.properties.PropertyEnum;
@ -42,11 +43,8 @@ import javax.annotation.Nonnull;
public class BlockPeripheral extends BlockGeneric
{
public static final class Properties
{
public static final PropertyDirection FACING = PropertyDirection.create( "facing", EnumFacing.Plane.HORIZONTAL );
public static final PropertyEnum<BlockPeripheralVariant> VARIANT = PropertyEnum.create( "variant", BlockPeripheralVariant.class );
}
public static final PropertyDirection FACING = BlockHorizontal.FACING;
public static final PropertyEnum<BlockPeripheralVariant> VARIANT = PropertyEnum.create( "variant", BlockPeripheralVariant.class );
public BlockPeripheral()
{
@ -55,8 +53,8 @@ public class BlockPeripheral extends BlockGeneric
setTranslationKey( "computercraft:peripheral" );
setCreativeTab( ComputerCraft.mainCreativeTab );
setDefaultState( blockState.getBaseState()
.withProperty( Properties.FACING, EnumFacing.NORTH )
.withProperty( Properties.VARIANT, BlockPeripheralVariant.DiskDriveEmpty )
.withProperty( FACING, EnumFacing.NORTH )
.withProperty( VARIANT, BlockPeripheralVariant.DiskDriveEmpty )
);
}
@ -72,7 +70,7 @@ public class BlockPeripheral extends BlockGeneric
@Override
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer( this, Properties.FACING, Properties.VARIANT );
return new BlockStateContainer( this, FACING, VARIANT );
}
@Nonnull
@ -83,42 +81,42 @@ public class BlockPeripheral extends BlockGeneric
IBlockState state = getDefaultState();
if( meta >= 2 && meta <= 5 )
{
state = state.withProperty( Properties.VARIANT, BlockPeripheralVariant.DiskDriveEmpty );
state = state.withProperty( Properties.FACING, EnumFacing.byIndex( meta ) );
state = state.withProperty( VARIANT, BlockPeripheralVariant.DiskDriveEmpty );
state = state.withProperty( FACING, EnumFacing.byIndex( meta ) );
}
else if( meta <= 9 )
{
if( meta == 0 )
{
state = state.withProperty( Properties.VARIANT, BlockPeripheralVariant.WirelessModemDownOff );
state = state.withProperty( Properties.FACING, EnumFacing.NORTH );
state = state.withProperty( VARIANT, BlockPeripheralVariant.WirelessModemDownOff );
state = state.withProperty( FACING, EnumFacing.NORTH );
}
else if( meta == 1 )
{
state = state.withProperty( Properties.VARIANT, BlockPeripheralVariant.WirelessModemUpOff );
state = state.withProperty( Properties.FACING, EnumFacing.NORTH );
state = state.withProperty( VARIANT, BlockPeripheralVariant.WirelessModemUpOff );
state = state.withProperty( FACING, EnumFacing.NORTH );
}
else
{
state = state.withProperty( Properties.VARIANT, BlockPeripheralVariant.WirelessModemOff );
state = state.withProperty( Properties.FACING, EnumFacing.byIndex( meta - 4 ) );
state = state.withProperty( VARIANT, BlockPeripheralVariant.WirelessModemOff );
state = state.withProperty( FACING, EnumFacing.byIndex( meta - 4 ) );
}
}
else if( meta == 10 )
{
state = state.withProperty( Properties.VARIANT, BlockPeripheralVariant.Monitor );
state = state.withProperty( VARIANT, BlockPeripheralVariant.Monitor );
}
else if( meta == 11 )
{
state = state.withProperty( Properties.VARIANT, BlockPeripheralVariant.PrinterEmpty );
state = state.withProperty( VARIANT, BlockPeripheralVariant.PrinterEmpty );
}
else if( meta == 12 )
{
state = state.withProperty( Properties.VARIANT, BlockPeripheralVariant.AdvancedMonitor );
state = state.withProperty( VARIANT, BlockPeripheralVariant.AdvancedMonitor );
}
else if( meta == 13 )
{
state = state.withProperty( Properties.VARIANT, BlockPeripheralVariant.Speaker );
state = state.withProperty( VARIANT, BlockPeripheralVariant.Speaker );
}
return state;
}
@ -127,12 +125,12 @@ public class BlockPeripheral extends BlockGeneric
public int getMetaFromState( IBlockState state )
{
int meta = 0;
BlockPeripheralVariant variant = state.getValue( Properties.VARIANT );
BlockPeripheralVariant variant = state.getValue( VARIANT );
switch( variant.getPeripheralType() )
{
case DiskDrive:
{
EnumFacing dir = state.getValue( Properties.FACING );
EnumFacing dir = state.getValue( FACING );
if( dir.getAxis() == EnumFacing.Axis.Y )
{
dir = EnumFacing.NORTH;
@ -153,7 +151,7 @@ public class BlockPeripheral extends BlockGeneric
break;
default:
{
EnumFacing dir = state.getValue( Properties.FACING );
EnumFacing dir = state.getValue( FACING );
meta = dir.getIndex() + 4;
break;
}
@ -189,16 +187,16 @@ public class BlockPeripheral extends BlockGeneric
if( !(tile instanceof TileDiskDrive) ) return state;
TileDiskDrive drive = (TileDiskDrive) tile;
state = state.withProperty( Properties.FACING, drive.getDirection() );
state = state.withProperty( FACING, drive.getDirection() );
switch( drive.getAnim() )
{
default:
case 0:
return state.withProperty( Properties.VARIANT, BlockPeripheralVariant.DiskDriveEmpty );
return state.withProperty( VARIANT, BlockPeripheralVariant.DiskDriveEmpty );
case 1:
return state.withProperty( Properties.VARIANT, BlockPeripheralVariant.DiskDriveInvalid );
return state.withProperty( VARIANT, BlockPeripheralVariant.DiskDriveInvalid );
case 2:
return state.withProperty( Properties.VARIANT, BlockPeripheralVariant.DiskDriveFull );
return state.withProperty( VARIANT, BlockPeripheralVariant.DiskDriveFull );
}
}
case Printer:
@ -206,18 +204,18 @@ public class BlockPeripheral extends BlockGeneric
if( !(tile instanceof TilePrinter) ) return state;
TilePrinter printer = (TilePrinter) tile;
state = state.withProperty( Properties.FACING, printer.getDirection() );
state = state.withProperty( FACING, printer.getDirection() );
switch( printer.getAnim() )
{
default:
case 0:
return state.withProperty( Properties.VARIANT, BlockPeripheralVariant.PrinterEmpty );
return state.withProperty( VARIANT, BlockPeripheralVariant.PrinterEmpty );
case 1:
return state.withProperty( Properties.VARIANT, BlockPeripheralVariant.PrinterTopFull );
return state.withProperty( VARIANT, BlockPeripheralVariant.PrinterTopFull );
case 2:
return state.withProperty( Properties.VARIANT, BlockPeripheralVariant.PrinterBottomFull );
return state.withProperty( VARIANT, BlockPeripheralVariant.PrinterBottomFull );
case 3:
return state.withProperty( Properties.VARIANT, BlockPeripheralVariant.PrinterBothFull );
return state.withProperty( VARIANT, BlockPeripheralVariant.PrinterBothFull );
}
}
case WirelessModem:
@ -230,19 +228,19 @@ public class BlockPeripheral extends BlockGeneric
{
case UP:
return state
.withProperty( Properties.FACING, EnumFacing.NORTH )
.withProperty( Properties.VARIANT,
.withProperty( FACING, EnumFacing.NORTH )
.withProperty( VARIANT,
modem.isOn() ? BlockPeripheralVariant.WirelessModemUpOn : BlockPeripheralVariant.WirelessModemUpOff );
case DOWN:
return state
.withProperty( Properties.FACING, EnumFacing.NORTH )
.withProperty( Properties.VARIANT,
.withProperty( FACING, EnumFacing.NORTH )
.withProperty( VARIANT,
modem.isOn() ? BlockPeripheralVariant.WirelessModemDownOn : BlockPeripheralVariant.WirelessModemDownOff );
default:
{
return state
.withProperty( Properties.FACING, direction )
.withProperty( Properties.VARIANT,
.withProperty( FACING, direction )
.withProperty( VARIANT,
modem.isOn() ? BlockPeripheralVariant.WirelessModemOn : BlockPeripheralVariant.WirelessModemOff );
}
}
@ -250,7 +248,7 @@ public class BlockPeripheral extends BlockGeneric
case Speaker:
{
if( !(tile instanceof TileSpeaker) ) return state;
return state.withProperty( Properties.FACING, ((TileSpeaker) tile).getDirection() );
return state.withProperty( FACING, ((TileSpeaker) tile).getDirection() );
}
case Monitor:
case AdvancedMonitor:
@ -345,8 +343,8 @@ public class BlockPeripheral extends BlockGeneric
}
return state
.withProperty( Properties.FACING, dir )
.withProperty( Properties.VARIANT, BlockPeripheralVariant.values()[baseVariant.ordinal() + subType] );
.withProperty( FACING, dir )
.withProperty( VARIANT, BlockPeripheralVariant.values()[baseVariant.ordinal() + subType] );
}
default:
return state;
@ -363,38 +361,38 @@ public class BlockPeripheral extends BlockGeneric
case DiskDrive:
default:
return getDefaultState()
.withProperty( Properties.VARIANT, BlockPeripheralVariant.DiskDriveEmpty )
.withProperty( Properties.FACING, placedSide.getAxis() == EnumFacing.Axis.Y ? EnumFacing.NORTH : placedSide );
.withProperty( VARIANT, BlockPeripheralVariant.DiskDriveEmpty )
.withProperty( FACING, placedSide.getAxis() == EnumFacing.Axis.Y ? EnumFacing.NORTH : placedSide );
case WirelessModem:
{
EnumFacing dir = placedSide.getOpposite();
if( dir == EnumFacing.DOWN )
{
return getDefaultState()
.withProperty( Properties.VARIANT, BlockPeripheralVariant.WirelessModemDownOff )
.withProperty( Properties.FACING, EnumFacing.NORTH );
.withProperty( VARIANT, BlockPeripheralVariant.WirelessModemDownOff )
.withProperty( FACING, EnumFacing.NORTH );
}
else if( dir == EnumFacing.UP )
{
return getDefaultState()
.withProperty( Properties.VARIANT, BlockPeripheralVariant.WirelessModemUpOff )
.withProperty( Properties.FACING, EnumFacing.NORTH );
.withProperty( VARIANT, BlockPeripheralVariant.WirelessModemUpOff )
.withProperty( FACING, EnumFacing.NORTH );
}
else
{
return getDefaultState()
.withProperty( Properties.VARIANT, BlockPeripheralVariant.WirelessModemOff )
.withProperty( Properties.FACING, dir );
.withProperty( VARIANT, BlockPeripheralVariant.WirelessModemOff )
.withProperty( FACING, dir );
}
}
case Monitor:
return getDefaultState().withProperty( Properties.VARIANT, BlockPeripheralVariant.Monitor );
return getDefaultState().withProperty( VARIANT, BlockPeripheralVariant.Monitor );
case Printer:
return getDefaultState().withProperty( Properties.VARIANT, BlockPeripheralVariant.PrinterEmpty );
return getDefaultState().withProperty( VARIANT, BlockPeripheralVariant.PrinterEmpty );
case AdvancedMonitor:
return getDefaultState().withProperty( Properties.VARIANT, BlockPeripheralVariant.AdvancedMonitor );
return getDefaultState().withProperty( VARIANT, BlockPeripheralVariant.AdvancedMonitor );
case Speaker:
return getDefaultState().withProperty( Properties.VARIANT, BlockPeripheralVariant.Speaker );
return getDefaultState().withProperty( VARIANT, BlockPeripheralVariant.Speaker );
}
}
@ -405,7 +403,7 @@ public class BlockPeripheral extends BlockGeneric
public static PeripheralType getPeripheralType( IBlockState state )
{
return state.getValue( Properties.VARIANT ).getPeripheralType();
return state.getValue( VARIANT ).getPeripheralType();
}
private TileGeneric createTile( PeripheralType type )

View File

@ -128,38 +128,27 @@ public abstract class TilePeripheralBase extends TileGeneric implements IPeriphe
public NBTTagCompound writeToNBT( NBTTagCompound nbt )
{
// Write properties
nbt = super.writeToNBT( nbt );
nbt.setInteger( "dir", m_dir.getIndex() );
nbt.setInteger( "anim", m_anim );
if( m_label != null ) nbt.setString( "label", m_label );
return nbt;
return super.writeToNBT( nbt );
}
@Override
public void readDescription( @Nonnull NBTTagCompound nbt )
protected void readDescription( @Nonnull NBTTagCompound nbt )
{
super.readDescription( nbt );
m_dir = EnumFacing.byIndex( nbt.getInteger( "dir" ) );
m_anim = nbt.getInteger( "anim" );
if( nbt.hasKey( "label" ) )
{
m_label = nbt.getString( "label" );
}
else
{
m_label = null;
}
m_label = nbt.hasKey( "label" ) ? nbt.getString( "label" ) : null;
}
@Override
public void writeDescription( @Nonnull NBTTagCompound nbt )
protected void writeDescription( @Nonnull NBTTagCompound nbt )
{
super.writeDescription( nbt );
nbt.setInteger( "dir", m_dir.getIndex() );
nbt.setInteger( "anim", m_anim );
if( m_label != null )
{
nbt.setString( "label", m_label );
}
if( m_label != null ) nbt.setString( "label", m_label );
}
}

View File

@ -48,35 +48,21 @@ public class TileDiskDrive extends TilePeripheralBase implements DefaultInventor
{
private static class MountInfo
{
public String mountPath;
String mountPath;
}
// Members
private final Map<IComputerAccess, MountInfo> m_computers;
private final Map<IComputerAccess, MountInfo> m_computers = new HashMap<>();
@Nonnull
private ItemStack m_diskStack;
private ItemStack m_diskStack = ItemStack.EMPTY;
private final IItemHandlerModifiable m_itemHandler = new InvWrapper( this );
private IMount m_diskMount;
private IMount m_diskMount = null;
private boolean m_recordQueued;
private boolean m_recordPlaying;
private boolean m_restartRecord;
private boolean m_recordQueued = false;
private boolean m_recordPlaying = false;
private boolean m_restartRecord = false;
private boolean m_ejectQueued;
public TileDiskDrive()
{
m_computers = new HashMap<>();
m_diskStack = ItemStack.EMPTY;
m_diskMount = null;
m_recordQueued = false;
m_recordPlaying = false;
m_restartRecord = false;
}
@Override
public void destroy()
{
@ -93,44 +79,34 @@ public class TileDiskDrive extends TilePeripheralBase implements DefaultInventor
if( player.isSneaking() )
{
// Try to put a disk into the drive
if( !getWorld().isRemote )
ItemStack disk = player.getHeldItem( hand );
if( disk.isEmpty() ) return false;
if( !getWorld().isRemote && getStackInSlot( 0 ).isEmpty() && MediaProviders.get( disk ) != null )
{
ItemStack disk = player.getHeldItem( hand );
if( !disk.isEmpty() && getStackInSlot( 0 ).isEmpty() )
{
if( MediaProviders.get( disk ) != null )
{
setInventorySlotContents( 0, disk );
player.setHeldItem( hand, ItemStack.EMPTY );
return true;
}
}
setDiskStack( disk );
player.setHeldItem( hand, ItemStack.EMPTY );
}
return true;
}
else
{
// Open the GUI
if( !getWorld().isRemote )
{
Containers.openDiskDriveGUI( player, this );
}
if( !getWorld().isRemote ) Containers.openDiskDriveGUI( player, this );
return true;
}
return false;
}
@Override
public EnumFacing getDirection()
{
IBlockState state = getBlockState();
return state.getValue( BlockPeripheral.Properties.FACING );
return getBlockState().getValue( BlockPeripheral.FACING );
}
@Override
public void setDirection( EnumFacing dir )
{
if( dir.getAxis() == EnumFacing.Axis.Y ) dir = EnumFacing.NORTH;
setBlockState( getBlockState().withProperty( BlockPeripheral.Properties.FACING, dir ) );
setBlockState( getBlockState().withProperty( BlockPeripheral.FACING, dir ) );
}
@Override
@ -149,14 +125,13 @@ public class TileDiskDrive extends TilePeripheralBase implements DefaultInventor
@Override
public NBTTagCompound writeToNBT( NBTTagCompound nbt )
{
nbt = super.writeToNBT( nbt );
if( !m_diskStack.isEmpty() )
{
NBTTagCompound item = new NBTTagCompound();
m_diskStack.writeToNBT( item );
nbt.setTag( "item", item );
}
return nbt;
return super.writeToNBT( nbt );
}
@Override
@ -241,12 +216,12 @@ public class TileDiskDrive extends TilePeripheralBase implements DefaultInventor
if( m_diskStack.getCount() <= count )
{
ItemStack disk = m_diskStack;
setInventorySlotContents( 0, ItemStack.EMPTY );
setInventorySlotContents( slot, ItemStack.EMPTY );
return disk;
}
ItemStack part = m_diskStack.splitStack( count );
setInventorySlotContents( 0, m_diskStack.isEmpty() ? ItemStack.EMPTY : m_diskStack );
setInventorySlotContents( slot, m_diskStack.isEmpty() ? ItemStack.EMPTY : m_diskStack );
return part;
}
@ -273,10 +248,7 @@ public class TileDiskDrive extends TilePeripheralBase implements DefaultInventor
if( !m_diskStack.isEmpty() )
{
Set<IComputerAccess> computers = m_computers.keySet();
for( IComputerAccess computer : computers )
{
unmountDisk( computer );
}
for( IComputerAccess computer : computers ) unmountDisk( computer );
}
// Stop music
@ -299,10 +271,7 @@ public class TileDiskDrive extends TilePeripheralBase implements DefaultInventor
if( !m_diskStack.isEmpty() )
{
Set<IComputerAccess> computers = m_computers.keySet();
for( IComputerAccess computer : computers )
{
mountDisk( computer );
}
for( IComputerAccess computer : computers ) mountDisk( computer );
}
}
}
@ -501,61 +470,45 @@ public class TileDiskDrive extends TilePeripheralBase implements DefaultInventor
private synchronized void ejectContents( boolean destroyed )
{
if( getWorld().isRemote )
if( getWorld().isRemote || m_diskStack.isEmpty() ) return;
// Remove the disks from the inventory
ItemStack disks = m_diskStack;
setDiskStack( ItemStack.EMPTY );
// Spawn the item in the world
int xOff = 0;
int zOff = 0;
if( !destroyed )
{
return;
EnumFacing dir = getDirection();
xOff = dir.getXOffset();
zOff = dir.getZOffset();
}
if( !m_diskStack.isEmpty() )
{
// Remove the disks from the inventory
ItemStack disks = m_diskStack;
setInventorySlotContents( 0, ItemStack.EMPTY );
BlockPos pos = getPos();
double x = pos.getX() + 0.5 + xOff * 0.5;
double y = pos.getY() + 0.75;
double z = pos.getZ() + 0.5 + zOff * 0.5;
EntityItem entityitem = new EntityItem( getWorld(), x, y, z, disks );
entityitem.motionX = xOff * 0.15;
entityitem.motionY = 0.0;
entityitem.motionZ = zOff * 0.15;
// Spawn the item in the world
int xOff = 0;
int zOff = 0;
if( !destroyed )
{
EnumFacing dir = getDirection();
xOff = dir.getXOffset();
zOff = dir.getZOffset();
}
BlockPos pos = getPos();
double x = pos.getX() + 0.5 + xOff * 0.5;
double y = pos.getY() + 0.75;
double z = pos.getZ() + 0.5 + zOff * 0.5;
EntityItem entityitem = new EntityItem( getWorld(), x, y, z, disks );
entityitem.motionX = xOff * 0.15;
entityitem.motionY = 0.0;
entityitem.motionZ = zOff * 0.15;
getWorld().spawnEntity( entityitem );
if( !destroyed )
{
getWorld().playBroadcastSound( 1000, getPos(), 0 );
}
}
getWorld().spawnEntity( entityitem );
if( !destroyed ) getWorld().playBroadcastSound( 1000, getPos(), 0 );
}
@Override
public final void readDescription( @Nonnull NBTTagCompound nbt )
protected final void readDescription( @Nonnull NBTTagCompound nbt )
{
super.readDescription( nbt );
if( nbt.hasKey( "item" ) )
{
m_diskStack = new ItemStack( nbt.getCompoundTag( "item" ) );
}
else
{
m_diskStack = ItemStack.EMPTY;
}
m_diskStack = nbt.hasKey( "item" ) ? new ItemStack( nbt.getCompoundTag( "item" ) ) : ItemStack.EMPTY;
updateBlock();
}
@Override
public void writeDescription( @Nonnull NBTTagCompound nbt )
protected void writeDescription( @Nonnull NBTTagCompound nbt )
{
super.writeDescription( nbt );
if( !m_diskStack.isEmpty() )

View File

@ -43,28 +43,20 @@ import java.util.List;
public class BlockCable extends BlockGeneric
{
// Statics
public static final class Properties
{
public static final PropertyEnum<BlockCableModemVariant> MODEM = PropertyEnum.create( "modem", BlockCableModemVariant.class );
public static final PropertyBool CABLE = PropertyBool.create( "cable" );
public static final PropertyBool NORTH = PropertyBool.create( "north" );
public static final PropertyBool SOUTH = PropertyBool.create( "south" );
public static final PropertyBool EAST = PropertyBool.create( "east" );
public static final PropertyBool WEST = PropertyBool.create( "west" );
public static final PropertyBool UP = PropertyBool.create( "up" );
public static final PropertyBool DOWN = PropertyBool.create( "down" );
static final EnumMap<EnumFacing, PropertyBool> CONNECTIONS =
new EnumMap<>( new ImmutableMap.Builder<EnumFacing, PropertyBool>()
.put( EnumFacing.DOWN, DOWN ).put( EnumFacing.UP, UP )
.put( EnumFacing.NORTH, NORTH ).put( EnumFacing.SOUTH, SOUTH )
.put( EnumFacing.WEST, WEST ).put( EnumFacing.EAST, EAST )
.build() );
}
// Members
public static final PropertyEnum<BlockCableModemVariant> MODEM = PropertyEnum.create( "modem", BlockCableModemVariant.class );
static final PropertyBool CABLE = PropertyBool.create( "cable" );
static final PropertyBool NORTH = PropertyBool.create( "north" );
static final PropertyBool SOUTH = PropertyBool.create( "south" );
static final PropertyBool EAST = PropertyBool.create( "east" );
static final PropertyBool WEST = PropertyBool.create( "west" );
static final PropertyBool UP = PropertyBool.create( "up" );
static final PropertyBool DOWN = PropertyBool.create( "down" );
static final EnumMap<EnumFacing, PropertyBool> CONNECTIONS =
new EnumMap<>( new ImmutableMap.Builder<EnumFacing, PropertyBool>()
.put( EnumFacing.DOWN, DOWN ).put( EnumFacing.UP, UP )
.put( EnumFacing.NORTH, NORTH ).put( EnumFacing.SOUTH, SOUTH )
.put( EnumFacing.WEST, WEST ).put( EnumFacing.EAST, EAST )
.build() );
public BlockCable()
{
@ -73,14 +65,14 @@ public class BlockCable extends BlockGeneric
setTranslationKey( "computercraft:cable" );
setCreativeTab( ComputerCraft.mainCreativeTab );
setDefaultState( blockState.getBaseState()
.withProperty( Properties.MODEM, BlockCableModemVariant.None )
.withProperty( Properties.CABLE, false )
.withProperty( Properties.NORTH, false )
.withProperty( Properties.SOUTH, false )
.withProperty( Properties.EAST, false )
.withProperty( Properties.WEST, false )
.withProperty( Properties.UP, false )
.withProperty( Properties.DOWN, false )
.withProperty( MODEM, BlockCableModemVariant.None )
.withProperty( CABLE, false )
.withProperty( NORTH, false )
.withProperty( SOUTH, false )
.withProperty( EAST, false )
.withProperty( WEST, false )
.withProperty( UP, false )
.withProperty( DOWN, false )
);
}
@ -89,14 +81,14 @@ public class BlockCable extends BlockGeneric
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer( this,
Properties.MODEM,
Properties.CABLE,
Properties.NORTH,
Properties.SOUTH,
Properties.EAST,
Properties.WEST,
Properties.UP,
Properties.DOWN
MODEM,
CABLE,
NORTH,
SOUTH,
EAST,
WEST,
UP,
DOWN
);
}
@ -108,18 +100,18 @@ public class BlockCable extends BlockGeneric
IBlockState state = getDefaultState();
if( meta < 6 )
{
state = state.withProperty( Properties.CABLE, false );
state = state.withProperty( Properties.MODEM, BlockCableModemVariant.fromFacing( EnumFacing.byIndex( meta ) ) );
state = state.withProperty( CABLE, false );
state = state.withProperty( MODEM, BlockCableModemVariant.from( EnumFacing.byIndex( meta ) ) );
}
else if( meta < 12 )
{
state = state.withProperty( Properties.CABLE, true );
state = state.withProperty( Properties.MODEM, BlockCableModemVariant.fromFacing( EnumFacing.byIndex( meta - 6 ) ) );
state = state.withProperty( CABLE, true );
state = state.withProperty( MODEM, BlockCableModemVariant.from( EnumFacing.byIndex( meta - 6 ) ) );
}
else if( meta == 13 )
{
state = state.withProperty( Properties.CABLE, true );
state = state.withProperty( Properties.MODEM, BlockCableModemVariant.None );
state = state.withProperty( CABLE, true );
state = state.withProperty( MODEM, BlockCableModemVariant.None );
}
return state;
}
@ -128,8 +120,8 @@ public class BlockCable extends BlockGeneric
public int getMetaFromState( IBlockState state )
{
int meta = 0;
boolean cable = state.getValue( Properties.CABLE );
BlockCableModemVariant modem = state.getValue( Properties.MODEM );
boolean cable = state.getValue( CABLE );
BlockCableModemVariant modem = state.getValue( MODEM );
if( cable && modem != BlockCableModemVariant.None )
{
meta = 6 + modem.getFacing().getIndex();
@ -154,30 +146,30 @@ public class BlockCable extends BlockGeneric
{
case Cable:
return getDefaultState()
.withProperty( Properties.CABLE, true )
.withProperty( Properties.MODEM, BlockCableModemVariant.None );
.withProperty( CABLE, true )
.withProperty( MODEM, BlockCableModemVariant.None );
default:
case WiredModem:
return getDefaultState()
.withProperty( Properties.CABLE, false )
.withProperty( Properties.MODEM, BlockCableModemVariant.fromFacing( placedSide.getOpposite() ) );
.withProperty( CABLE, false )
.withProperty( MODEM, BlockCableModemVariant.from( placedSide.getOpposite() ) );
case WiredModemWithCable:
return getDefaultState()
.withProperty( Properties.CABLE, true )
.withProperty( Properties.MODEM, BlockCableModemVariant.fromFacing( placedSide.getOpposite() ) );
.withProperty( CABLE, true )
.withProperty( MODEM, BlockCableModemVariant.from( placedSide.getOpposite() ) );
}
}
public static boolean canConnectIn( IBlockState state, EnumFacing direction )
{
return state.getValue( BlockCable.Properties.CABLE )
&& state.getValue( BlockCable.Properties.MODEM ).getFacing() != direction;
return state.getValue( CABLE )
&& state.getValue( MODEM ).getFacing() != direction;
}
public static boolean doesConnectVisually( IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction )
{
if( !state.getValue( Properties.CABLE ) ) return false;
if( state.getValue( Properties.MODEM ).getFacing() == direction ) return true;
if( !state.getValue( CABLE ) ) return false;
if( state.getValue( MODEM ).getFacing() == direction ) return true;
return ComputerCraftAPI.getWiredElementAt( world, pos.offset( direction ), direction.getOpposite() ) != null;
}
@ -187,22 +179,19 @@ public class BlockCable extends BlockGeneric
public IBlockState getActualState( @Nonnull IBlockState state, IBlockAccess world, BlockPos pos )
{
state = state
.withProperty( Properties.NORTH, doesConnectVisually( state, world, pos, EnumFacing.NORTH ) )
.withProperty( Properties.SOUTH, doesConnectVisually( state, world, pos, EnumFacing.SOUTH ) )
.withProperty( Properties.EAST, doesConnectVisually( state, world, pos, EnumFacing.EAST ) )
.withProperty( Properties.WEST, doesConnectVisually( state, world, pos, EnumFacing.WEST ) )
.withProperty( Properties.UP, doesConnectVisually( state, world, pos, EnumFacing.UP ) )
.withProperty( Properties.DOWN, doesConnectVisually( state, world, pos, EnumFacing.DOWN ) );
.withProperty( NORTH, doesConnectVisually( state, world, pos, EnumFacing.NORTH ) )
.withProperty( SOUTH, doesConnectVisually( state, world, pos, EnumFacing.SOUTH ) )
.withProperty( EAST, doesConnectVisually( state, world, pos, EnumFacing.EAST ) )
.withProperty( WEST, doesConnectVisually( state, world, pos, EnumFacing.WEST ) )
.withProperty( UP, doesConnectVisually( state, world, pos, EnumFacing.UP ) )
.withProperty( DOWN, doesConnectVisually( state, world, pos, EnumFacing.DOWN ) );
TileEntity tile = world.getTileEntity( pos );
int anim = tile instanceof TileCable ? ((TileCable) tile).getState() : 0;
BlockCableModemVariant modem = state.getValue( Properties.MODEM );
if( modem != BlockCableModemVariant.None )
{
modem = BlockCableModemVariant.values()[1 + 6 * anim + modem.getFacing().getIndex()];
}
state = state.withProperty( Properties.MODEM, modem );
BlockCableModemVariant modem = state.getValue( MODEM );
if( modem != BlockCableModemVariant.None ) modem = BlockCableModemVariant.from( modem.getFacing(), anim );
state = state.withProperty( MODEM, modem );
return state;
}
@ -216,8 +205,8 @@ public class BlockCable extends BlockGeneric
public static PeripheralType getPeripheralType( IBlockState state )
{
boolean cable = state.getValue( Properties.CABLE );
BlockCableModemVariant modem = state.getValue( Properties.MODEM );
boolean cable = state.getValue( CABLE );
BlockCableModemVariant modem = state.getValue( MODEM );
if( cable && modem != BlockCableModemVariant.None )
{
return PeripheralType.WiredModemWithCable;
@ -310,19 +299,22 @@ public class BlockCable extends BlockGeneric
TileCable cable = (TileCable) tile;
ItemStack item;
IBlockState newState;
AxisAlignedBB bb = CableBounds.getModemBounds( state );
if( WorldUtil.isVecInsideInclusive( bb, hit.hitVec.subtract( pos.getX(), pos.getY(), pos.getZ() ) ) )
{
world.setBlockState( pos, state.withProperty( Properties.MODEM, BlockCableModemVariant.None ), 3 );
newState = state.withProperty( MODEM, BlockCableModemVariant.None );
item = PeripheralItemFactory.create( PeripheralType.WiredModem, null, 1 );
}
else
{
world.setBlockState( pos, state.withProperty( Properties.CABLE, false ), 3 );
newState = state.withProperty( CABLE, false );
item = PeripheralItemFactory.create( PeripheralType.Cable, null, 1 );
}
world.setBlockState( pos, newState, 3 );
cable.modemChanged();
cable.connectionsChanged();
if( !world.isRemote && !player.capabilities.isCreativeMode )

View File

@ -10,6 +10,7 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public enum BlockCableModemVariant implements IStringSerializable
{
@ -39,25 +40,7 @@ public enum BlockCableModemVariant implements IStringSerializable
WestOnPeripheral( "west_on_peripheral", EnumFacing.WEST ),
EastOnPeripheral( "east_on_peripheral", EnumFacing.EAST );
public static BlockCableModemVariant fromFacing( EnumFacing facing )
{
switch( facing )
{
case DOWN:
return DownOff;
case UP:
return UpOff;
case NORTH:
return NorthOff;
case SOUTH:
return SouthOff;
case WEST:
return WestOff;
case EAST:
return EastOff;
}
return NorthOff;
}
private static final BlockCableModemVariant[] VALUES = values();
private final String name;
private final EnumFacing facing;
@ -68,6 +51,19 @@ public enum BlockCableModemVariant implements IStringSerializable
this.facing = facing;
}
@Nonnull
public static BlockCableModemVariant from( @Nullable EnumFacing facing )
{
return facing == null ? None : VALUES[1 + facing.getIndex()];
}
@Nonnull
public static BlockCableModemVariant from( @Nullable EnumFacing facing, int state )
{
return facing == null ? None : VALUES[1 + 6 * state + facing.ordinal()];
}
@Nonnull
@Override
public String getName()

View File

@ -21,15 +21,8 @@ import javax.annotation.Nonnull;
public class BlockWiredModemFull extends BlockGeneric
{
// Statics
public static final class Properties
{
public static final PropertyBool MODEM_ON = PropertyBool.create( "modem" );
public static final PropertyBool PERIPHERAL_ON = PropertyBool.create( "peripheral" );
}
// Members
private static final PropertyBool MODEM_ON = PropertyBool.create( "modem" );
private static final PropertyBool PERIPHERAL_ON = PropertyBool.create( "peripheral" );
public BlockWiredModemFull()
{
@ -38,8 +31,8 @@ public class BlockWiredModemFull extends BlockGeneric
setTranslationKey( "computercraft:wired_modem_full" );
setCreativeTab( ComputerCraft.mainCreativeTab );
setDefaultState( blockState.getBaseState()
.withProperty( Properties.MODEM_ON, false )
.withProperty( Properties.PERIPHERAL_ON, false )
.withProperty( MODEM_ON, false )
.withProperty( PERIPHERAL_ON, false )
);
}
@ -48,8 +41,8 @@ public class BlockWiredModemFull extends BlockGeneric
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer( this,
Properties.MODEM_ON,
Properties.PERIPHERAL_ON
MODEM_ON,
PERIPHERAL_ON
);
}
@ -70,8 +63,8 @@ public class BlockWiredModemFull extends BlockGeneric
TileWiredModemFull modem = (TileWiredModemFull) te;
int anim = modem.getState();
state = state
.withProperty( Properties.MODEM_ON, (anim & 1) != 0 )
.withProperty( Properties.PERIPHERAL_ON, (anim & 2) != 0 );
.withProperty( MODEM_ON, (anim & 1) != 0 )
.withProperty( PERIPHERAL_ON, (anim & 2) != 0 );
}
return state;

View File

@ -16,8 +16,6 @@ import net.minecraft.util.math.AxisAlignedBB;
import java.util.EnumMap;
import java.util.List;
import static dan200.computercraft.shared.peripheral.modem.wired.BlockCable.Properties.*;
public final class CableBounds
{
public static final double MIN = 0.375;
@ -47,7 +45,7 @@ public final class CableBounds
int index = 0;
for( EnumFacing facing : EnumFacing.VALUES )
{
if( state.getValue( CONNECTIONS.get( facing ) ) ) index |= 1 << facing.ordinal();
if( state.getValue( BlockCable.CONNECTIONS.get( facing ) ) ) index |= 1 << facing.ordinal();
}
return index;
@ -72,32 +70,32 @@ public final class CableBounds
public static AxisAlignedBB getCableBounds( IBlockState state )
{
if( !state.getValue( CABLE ) ) return BlockCable.NULL_AABB;
if( !state.getValue( BlockCable.CABLE ) ) return BlockCable.NULL_AABB;
return getCableBounds( getCableIndex( state ) );
}
public static void getCableBounds( IBlockState state, List<AxisAlignedBB> bounds )
{
if( !state.getValue( CABLE ) ) return;
if( !state.getValue( BlockCable.CABLE ) ) return;
bounds.add( SHAPE_CABLE_CORE );
for( EnumFacing facing : EnumFacing.VALUES )
{
if( state.getValue( CONNECTIONS.get( facing ) ) ) bounds.add( SHAPE_CABLE_ARM.get( facing ) );
if( state.getValue( BlockCable.CONNECTIONS.get( facing ) ) ) bounds.add( SHAPE_CABLE_ARM.get( facing ) );
}
}
public static AxisAlignedBB getModemBounds( IBlockState state )
{
EnumFacing facing = state.getValue( MODEM ).getFacing();
EnumFacing facing = state.getValue( BlockCable.MODEM ).getFacing();
return facing == null ? Block.NULL_AABB : ModemBounds.getBounds( facing );
}
public static AxisAlignedBB getBounds( IBlockState state )
{
if( !state.getValue( CABLE ) ) return getModemBounds( state );
if( !state.getValue( BlockCable.CABLE ) ) return getModemBounds( state );
EnumFacing facing = state.getValue( MODEM ).getFacing();
EnumFacing facing = state.getValue( BlockCable.MODEM ).getFacing();
int cableIndex = getCableIndex( state );
int index = cableIndex + ((facing == null ? 0 : facing.ordinal() + 1) << 6);
@ -111,7 +109,7 @@ public final class CableBounds
public static void getBounds( IBlockState state, List<AxisAlignedBB> bounds )
{
EnumFacing facing = state.getValue( MODEM ).getFacing();
EnumFacing facing = state.getValue( BlockCable.MODEM ).getFacing();
if( facing != null ) bounds.add( getModemBounds( state ) );
getCableBounds( state, bounds );
}

View File

@ -74,7 +74,7 @@ public class ItemCable extends ItemPeripheralBase
{
if( !stack.isEmpty() )
{
IBlockState newState = existingState.withProperty( BlockCable.Properties.CABLE, true );
IBlockState newState = existingState.withProperty( BlockCable.CABLE, true );
world.setBlockState( pos, newState, 3 );
SoundType soundType = newState.getBlock().getSoundType( newState, world, pos, player );
world.playSound( null, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, soundType.getPlaceSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F );
@ -106,7 +106,7 @@ public class ItemCable extends ItemPeripheralBase
{
if( !stack.isEmpty() )
{
IBlockState newState = offsetExistingState.withProperty( BlockCable.Properties.MODEM, BlockCableModemVariant.fromFacing( side.getOpposite() ) );
IBlockState newState = offsetExistingState.withProperty( BlockCable.MODEM, BlockCableModemVariant.from( side.getOpposite() ) );
world.setBlockState( offset, newState, 3 );
SoundType soundType = newState.getBlock().getSoundType( newState, world, offset, player );
world.playSound( null, offset.getX() + 0.5, offset.getY() + 0.5, offset.getZ() + 0.5, soundType.getPlaceSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F );
@ -129,7 +129,7 @@ public class ItemCable extends ItemPeripheralBase
{
if( !stack.isEmpty() )
{
IBlockState newState = offsetExistingState.withProperty( BlockCable.Properties.CABLE, true );
IBlockState newState = offsetExistingState.withProperty( BlockCable.CABLE, true );
world.setBlockState( offset, newState, 3 );
SoundType soundType = newState.getBlock().getSoundType( newState, world, offset, player );
world.playSound( null, offset.getX() + 0.5, offset.getY() + 0.5, offset.getZ() + 0.5, soundType.getPlaceSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F );

View File

@ -170,7 +170,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile
private EnumFacing getDirection()
{
IBlockState state = getBlockState();
EnumFacing facing = state.getValue( BlockCable.Properties.MODEM ).getFacing();
EnumFacing facing = state.getValue( BlockCable.MODEM ).getFacing();
return facing != null ? facing : EnumFacing.NORTH;
}
@ -183,24 +183,20 @@ public class TileCable extends TileGeneric implements IPeripheralTile
switch( getPeripheralType() )
{
case WiredModem:
{
// Drop everything and remove block
getBlock().dropBlockAsItem( getWorld(), getPos(), getBlockState(), 0 );
getBlockType().dropBlockAsItem( getWorld(), getPos(), getBlockState(), 0 );
getWorld().setBlockToAir( getPos() );
// This'll call #destroy(), so we don't need to reset the network here.
return;
}
case WiredModemWithCable:
{
// Drop the modem and convert to cable
Block.spawnAsEntity( getWorld(), getPos(), PeripheralItemFactory.create( PeripheralType.WiredModem, null, 1 ) );
setBlockState( getBlockState().withProperty( BlockCable.Properties.MODEM, BlockCableModemVariant.None ) );
setBlockState( getBlockState().withProperty( BlockCable.MODEM, BlockCableModemVariant.None ) );
modemChanged();
connectionsChanged();
return;
}
}
}
@ -227,42 +223,34 @@ public class TileCable extends TileGeneric implements IPeripheralTile
@Override
public boolean onActivate( EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ )
{
if( getPeripheralType() == PeripheralType.WiredModemWithCable && !player.isSneaking() )
{
if( !getWorld().isRemote )
{
// On server, we interacted if a peripheral was found
String oldPeriphName = m_peripheral.getConnectedName();
togglePeripheralAccess();
String periphName = m_peripheral.getConnectedName();
if( getPeripheralType() != PeripheralType.WiredModemWithCable || player.isSneaking() ) return false;
if( !Objects.equal( periphName, oldPeriphName ) )
if( !getWorld().isRemote )
{
String oldName = m_peripheral.getConnectedName();
togglePeripheralAccess();
String newName = m_peripheral.getConnectedName();
if( !Objects.equal( newName, oldName ) )
{
if( oldName != null )
{
if( oldPeriphName != null )
{
player.sendMessage(
new TextComponentTranslation( "chat.computercraft.wired_modem.peripheral_disconnected",
CommandCopy.createCopyText( oldPeriphName ) )
);
}
if( periphName != null )
{
player.sendMessage(
new TextComponentTranslation( "chat.computercraft.wired_modem.peripheral_connected",
CommandCopy.createCopyText( periphName ) )
);
}
return true;
player.sendMessage(
new TextComponentTranslation( "chat.computercraft.wired_modem.peripheral_disconnected",
CommandCopy.createCopyText( oldName ) )
);
}
if( newName != null )
{
player.sendMessage(
new TextComponentTranslation( "chat.computercraft.wired_modem.peripheral_connected",
CommandCopy.createCopyText( newName ) )
);
}
}
else
{
// On client, we can't know this, so we assume so to be safe
// The server will correct us if we're wrong
return true;
}
}
return false;
return true;
}
@Override
@ -279,10 +267,9 @@ public class TileCable extends TileGeneric implements IPeripheralTile
public NBTTagCompound writeToNBT( NBTTagCompound nbt )
{
// Write properties
nbt = super.writeToNBT( nbt );
nbt.setBoolean( "peripheralAccess", m_peripheralAccessAllowed );
m_peripheral.writeNBT( nbt, "" );
return nbt;
return super.writeToNBT( nbt );
}
@Override
@ -320,27 +307,26 @@ public class TileCable extends TileGeneric implements IPeripheralTile
@Override
protected void updateTick()
{
if( !getWorld().isRemote )
if( getWorld().isRemote ) return;
updateDirection();
if( m_modem.getModemState().pollChanged() ) updateState();
if( !m_connectionsFormed )
{
updateDirection();
m_connectionsFormed = true;
if( m_modem.getModemState().pollChanged() ) updateState();
if( !m_connectionsFormed )
connectionsChanged();
if( m_peripheralAccessAllowed )
{
m_connectionsFormed = true;
connectionsChanged();
if( m_peripheralAccessAllowed )
{
m_peripheral.attach( world, pos, modemDirection );
updateConnectedPeripherals();
}
m_peripheral.attach( world, pos, modemDirection );
updateConnectedPeripherals();
}
}
}
public void connectionsChanged()
void connectionsChanged()
{
if( getWorld().isRemote ) return;
@ -368,7 +354,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile
}
}
public void modemChanged()
void modemChanged()
{
if( getWorld().isRemote ) return;
@ -383,7 +369,6 @@ public class TileCable extends TileGeneric implements IPeripheralTile
}
}
// private stuff
private void togglePeripheralAccess()
{
if( !m_peripheralAccessAllowed )

View File

@ -38,9 +38,9 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
{
private final TileWiredModemFull m_entity;
private FullElement( TileWiredModemFull m_entity )
private FullElement( TileWiredModemFull entity )
{
this.m_entity = m_entity;
m_entity = entity;
}
@Override
@ -209,10 +209,9 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
@Override
public NBTTagCompound writeToNBT( NBTTagCompound nbt )
{
nbt = super.writeToNBT( nbt );
nbt.setBoolean( "peripheralAccess", m_peripheralAccessAllowed );
for( int i = 0; i < m_peripherals.length; i++ ) m_peripherals[i].writeNBT( nbt, "_" + i );
return nbt;
return super.writeToNBT( nbt );
}
public int getState()
@ -257,23 +256,22 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
@Override
protected void updateTick()
{
if( !getWorld().isRemote )
if( getWorld().isRemote ) return;
if( m_modemState.pollChanged() ) updateState();
if( !m_connectionsFormed )
{
if( m_modemState.pollChanged() ) updateState();
m_connectionsFormed = true;
if( !m_connectionsFormed )
connectionsChanged();
if( m_peripheralAccessAllowed )
{
m_connectionsFormed = true;
connectionsChanged();
if( m_peripheralAccessAllowed )
for( EnumFacing facing : EnumFacing.VALUES )
{
for( EnumFacing facing : EnumFacing.VALUES )
{
m_peripherals[facing.ordinal()].attach( world, getPos(), facing );
}
updateConnectedPeripherals();
m_peripherals[facing.ordinal()].attach( world, getPos(), facing );
}
updateConnectedPeripherals();
}
}
}
@ -330,9 +328,9 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
if( !m_peripheralAccessAllowed ) return Collections.emptySet();
Set<String> peripherals = new HashSet<>( 6 );
for( WiredModemLocalPeripheral m_peripheral : m_peripherals )
for( WiredModemLocalPeripheral peripheral : m_peripherals )
{
String name = m_peripheral.getConnectedName();
String name = peripheral.getConnectedName();
if( name != null ) peripherals.add( name );
}
return peripherals;
@ -343,7 +341,7 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
if( !m_peripheralAccessAllowed ) return Collections.emptyMap();
Map<String, IPeripheral> peripherals = new HashMap<>( 6 );
for( WiredModemLocalPeripheral m_peripheral : m_peripherals ) m_peripheral.extendMap( peripherals );
for( WiredModemLocalPeripheral peripheral : m_peripherals ) peripheral.extendMap( peripherals );
return peripherals;
}

View File

@ -30,6 +30,9 @@ import java.util.Map;
*/
public final class WiredModemLocalPeripheral
{
private static final String NBT_PERIPHERAL_TYPE = "peripheralType";
private static final String NBT_PERIPHERAL_ID = "peripheralID";
private int id;
private String type;
@ -115,17 +118,17 @@ public final class WiredModemLocalPeripheral
public void writeNBT( @Nonnull NBTTagCompound tag, @Nonnull String suffix )
{
if( id >= 0 ) tag.setInteger( "peripheralID" + suffix, id );
if( type != null ) tag.setString( "peripheralType" + suffix, type );
if( id >= 0 ) tag.setInteger( NBT_PERIPHERAL_TYPE + suffix, id );
if( type != null ) tag.setString( NBT_PERIPHERAL_TYPE + suffix, type );
}
public void readNBT( @Nonnull NBTTagCompound tag, @Nonnull String suffix )
{
id = tag.hasKey( "peripheralID" + suffix, Constants.NBT.TAG_ANY_NUMERIC )
? tag.getInteger( "peripheralID" + suffix ) : -1;
id = tag.hasKey( NBT_PERIPHERAL_ID + suffix, Constants.NBT.TAG_ANY_NUMERIC )
? tag.getInteger( NBT_PERIPHERAL_ID + suffix ) : -1;
type = tag.hasKey( "peripheralType" + suffix, Constants.NBT.TAG_STRING )
? tag.getString( "peripheralType" + suffix ) : null;
type = tag.hasKey( NBT_PERIPHERAL_TYPE + suffix, Constants.NBT.TAG_STRING )
? tag.getString( NBT_PERIPHERAL_TYPE + suffix ) : null;
}
private static IPeripheral getPeripheralFrom( World world, BlockPos pos, EnumFacing direction )

View File

@ -29,11 +29,8 @@ import javax.annotation.Nonnull;
public class BlockAdvancedModem extends BlockGeneric
{
public static final class Properties
{
public static final PropertyDirection FACING = BlockDirectional.FACING;
public static final PropertyBool ON = PropertyBool.create( "on" );
}
public static final PropertyDirection FACING = BlockDirectional.FACING;
private static final PropertyBool ON = PropertyBool.create( "on" );
public BlockAdvancedModem()
{
@ -42,8 +39,8 @@ public class BlockAdvancedModem extends BlockGeneric
setTranslationKey( "computercraft:advanced_modem" );
setCreativeTab( ComputerCraft.mainCreativeTab );
setDefaultState( blockState.getBaseState()
.withProperty( Properties.FACING, EnumFacing.NORTH )
.withProperty( Properties.ON, false )
.withProperty( FACING, EnumFacing.NORTH )
.withProperty( ON, false )
);
}
@ -51,7 +48,7 @@ public class BlockAdvancedModem extends BlockGeneric
@Override
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer( this, Properties.FACING, Properties.ON );
return new BlockStateContainer( this, FACING, ON );
}
@Nonnull
@ -59,13 +56,13 @@ public class BlockAdvancedModem extends BlockGeneric
@Deprecated
public IBlockState getStateFromMeta( int meta )
{
return getDefaultState().withProperty( Properties.FACING, EnumFacing.byIndex( meta ) );
return getDefaultState().withProperty( FACING, EnumFacing.byIndex( meta ) );
}
@Override
public int getMetaFromState( IBlockState state )
{
return state.getValue( Properties.FACING ).getIndex();
return state.getValue( FACING ).getIndex();
}
@Nonnull
@ -74,7 +71,7 @@ public class BlockAdvancedModem extends BlockGeneric
public IBlockState getActualState( @Nonnull IBlockState state, IBlockAccess world, BlockPos pos )
{
TileEntity tile = world.getTileEntity( pos );
return state.withProperty( Properties.ON, tile instanceof TileAdvancedModem && ((TileAdvancedModem) tile).isOn() );
return state.withProperty( ON, tile instanceof TileAdvancedModem && ((TileAdvancedModem) tile).isOn() );
}
@Nonnull
@ -82,7 +79,7 @@ public class BlockAdvancedModem extends BlockGeneric
@Deprecated
public IBlockState getStateForPlacement( World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer )
{
return getDefaultState().withProperty( Properties.FACING, facing.getOpposite() );
return getDefaultState().withProperty( FACING, facing.getOpposite() );
}
@Override
@ -124,6 +121,6 @@ public class BlockAdvancedModem extends BlockGeneric
@Deprecated
public AxisAlignedBB getBoundingBox( IBlockState state, IBlockAccess source, BlockPos pos )
{
return ModemBounds.getBounds( state.getValue( Properties.FACING ) );
return ModemBounds.getBounds( state.getValue( FACING ) );
}
}

View File

@ -18,6 +18,6 @@ public class TileAdvancedModem extends TileWirelessModemBase
@Override
protected EnumFacing getDirection()
{
return getBlockState().getValue( BlockAdvancedModem.Properties.FACING );
return getBlockState().getValue( BlockAdvancedModem.FACING );
}
}

View File

@ -30,7 +30,7 @@ public class TileWirelessModem extends TileWirelessModemBase implements IDirecti
{
// Wireless Modem
IBlockState state = getBlockState();
switch( state.getValue( BlockPeripheral.Properties.VARIANT ) )
switch( state.getValue( BlockPeripheral.VARIANT ) )
{
case WirelessModemDownOff:
case WirelessModemDownOn:
@ -39,7 +39,7 @@ public class TileWirelessModem extends TileWirelessModemBase implements IDirecti
case WirelessModemUpOn:
return EnumFacing.UP;
default:
return state.getValue( BlockPeripheral.Properties.FACING );
return state.getValue( BlockPeripheral.FACING );
}
}
@ -50,22 +50,22 @@ public class TileWirelessModem extends TileWirelessModemBase implements IDirecti
if( dir == EnumFacing.UP )
{
setBlockState( getBlockState()
.withProperty( BlockPeripheral.Properties.VARIANT, BlockPeripheralVariant.WirelessModemUpOff )
.withProperty( BlockPeripheral.Properties.FACING, EnumFacing.NORTH )
.withProperty( BlockPeripheral.VARIANT, BlockPeripheralVariant.WirelessModemUpOff )
.withProperty( BlockPeripheral.FACING, EnumFacing.NORTH )
);
}
else if( dir == EnumFacing.DOWN )
{
setBlockState( getBlockState()
.withProperty( BlockPeripheral.Properties.VARIANT, BlockPeripheralVariant.WirelessModemDownOff )
.withProperty( BlockPeripheral.Properties.FACING, EnumFacing.NORTH )
.withProperty( BlockPeripheral.VARIANT, BlockPeripheralVariant.WirelessModemDownOff )
.withProperty( BlockPeripheral.FACING, EnumFacing.NORTH )
);
}
else
{
setBlockState( getBlockState()
.withProperty( BlockPeripheral.Properties.VARIANT, BlockPeripheralVariant.WirelessModemOff )
.withProperty( BlockPeripheral.Properties.FACING, dir )
.withProperty( BlockPeripheral.VARIANT, BlockPeripheralVariant.WirelessModemOff )
.withProperty( BlockPeripheral.FACING, dir )
);
}
}

View File

@ -9,6 +9,8 @@ package dan200.computercraft.shared.peripheral.monitor;
import dan200.computercraft.shared.common.ClientTerminal;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.HashSet;
import java.util.Iterator;
@ -35,6 +37,7 @@ public class ClientMonitor extends ClientTerminal
return origin;
}
@SideOnly( Side.CLIENT )
public void createLists()
{
if( renderDisplayLists == null )
@ -53,6 +56,7 @@ public class ClientMonitor extends ClientTerminal
}
}
@SideOnly( Side.CLIENT )
public void destroy()
{
if( renderDisplayLists != null )
@ -71,6 +75,7 @@ public class ClientMonitor extends ClientTerminal
}
}
@SideOnly( Side.CLIENT )
public static void destroyAll()
{
synchronized( allMonitors )

View File

@ -45,7 +45,7 @@ public class TileMonitor extends TileGeneric implements ITilePeripheral, IPeriph
private final Set<IComputerAccess> m_computers = Collections.newSetFromMap( new ConcurrentHashMap<>() );
private boolean m_destroyed = false;
private boolean m_ignoreMe = false;
private boolean visiting = false;
private int m_width = 1;
private int m_height = 1;
@ -60,7 +60,7 @@ public class TileMonitor extends TileGeneric implements ITilePeripheral, IPeriph
public void onLoad()
{
super.onLoad();
m_advanced = getBlockState().getValue( BlockPeripheral.Properties.VARIANT )
m_advanced = getBlockState().getValue( BlockPeripheral.VARIANT )
.getPeripheralType() == PeripheralType.AdvancedMonitor;
world.scheduleUpdate( getPos(), getBlockType(), 0 );
}
@ -68,14 +68,10 @@ public class TileMonitor extends TileGeneric implements ITilePeripheral, IPeriph
@Override
public void destroy()
{
if( !m_destroyed )
{
m_destroyed = true;
if( !getWorld().isRemote )
{
contractNeighbours();
}
}
if( m_destroyed ) return;
m_destroyed = true;
if( !getWorld().isRemote ) contractNeighbours();
}
@Override
@ -97,12 +93,10 @@ public class TileMonitor extends TileGeneric implements ITilePeripheral, IPeriph
{
if( !player.isSneaking() && getFront() == side )
{
if( !getWorld().isRemote )
{
monitorTouched( hitX, hitY, hitZ );
}
if( !getWorld().isRemote ) monitorTouched( hitX, hitY, hitZ );
return true;
}
return false;
}
@ -110,13 +104,12 @@ public class TileMonitor extends TileGeneric implements ITilePeripheral, IPeriph
@Override
public NBTTagCompound writeToNBT( NBTTagCompound nbt )
{
nbt = super.writeToNBT( nbt );
nbt.setInteger( "xIndex", m_xIndex );
nbt.setInteger( "yIndex", m_yIndex );
nbt.setInteger( "width", m_width );
nbt.setInteger( "height", m_height );
nbt.setInteger( "dir", m_dir );
return nbt;
return super.writeToNBT( nbt );
}
@Override
@ -193,11 +186,9 @@ public class TileMonitor extends TileGeneric implements ITilePeripheral, IPeriph
private ServerMonitor createServerMonitor()
{
if( m_serverMonitor != null )
{
return m_serverMonitor;
}
else if( m_xIndex == 0 && m_yIndex == 0 )
if( m_serverMonitor != null ) return m_serverMonitor;
if( m_xIndex == 0 && m_yIndex == 0 )
{
// If we're the origin, set up the new monitor
m_serverMonitor = new ServerMonitor( m_advanced, this );
@ -241,7 +232,7 @@ public class TileMonitor extends TileGeneric implements ITilePeripheral, IPeriph
// Networking stuff
@Override
public void writeDescription( @Nonnull NBTTagCompound nbt )
protected void writeDescription( @Nonnull NBTTagCompound nbt )
{
super.writeDescription( nbt );
nbt.setInteger( "xIndex", m_xIndex );
@ -257,7 +248,7 @@ public class TileMonitor extends TileGeneric implements ITilePeripheral, IPeriph
}
@Override
public final void readDescription( @Nonnull NBTTagCompound nbt )
protected final void readDescription( @Nonnull NBTTagCompound nbt )
{
super.readDescription( nbt );
@ -408,8 +399,8 @@ public class TileMonitor extends TileGeneric implements ITilePeripheral, IPeriph
if( !(tile instanceof TileMonitor) ) return null;
TileMonitor monitor = (TileMonitor) tile;
return monitor.getDir() == getDir() && monitor.m_advanced == m_advanced &&
!monitor.m_destroyed && !monitor.m_ignoreMe ? monitor : null;
return !monitor.visiting && monitor.getDir() == getDir() && monitor.m_advanced == m_advanced &&
!monitor.m_destroyed ? monitor : null;
}
private TileMonitor getNeighbour( int x, int y )
@ -550,7 +541,7 @@ public class TileMonitor extends TileGeneric implements ITilePeripheral, IPeriph
public void contractNeighbours()
{
m_ignoreMe = true;
visiting = true;
if( m_xIndex > 0 )
{
TileMonitor left = getNeighbour( m_xIndex - 1, m_yIndex );
@ -571,7 +562,7 @@ public class TileMonitor extends TileGeneric implements ITilePeripheral, IPeriph
TileMonitor above = getNeighbour( m_xIndex, m_yIndex + 1 );
if( above != null ) above.contract();
}
m_ignoreMe = false;
visiting = false;
}
public void contract()

View File

@ -18,7 +18,9 @@ import javax.annotation.Nonnull;
public class ContainerPrinter extends Container
{
private TilePrinter m_printer;
private static final int PROPERTY_PRINTING = 0;
private final TilePrinter m_printer;
private boolean m_lastPrinting;
public ContainerPrinter( IInventory playerInventory, TilePrinter printer )
@ -30,31 +32,22 @@ public class ContainerPrinter extends Container
addSlotToContainer( new Slot( m_printer, 0, 13, 35 ) );
// In-tray
for( int i = 0; i < 6; i++ )
{
addSlotToContainer( new Slot( m_printer, i + 1, 61 + i * 18, 22 ) );
}
for( int x = 0; x < 6; x++ ) addSlotToContainer( new Slot( m_printer, x + 1, 61 + x * 18, 22 ) );
// Out-tray
for( int i = 0; i < 6; i++ )
{
addSlotToContainer( new Slot( m_printer, i + 7, 61 + i * 18, 49 ) );
}
for( int x = 0; x < 6; x++ ) addSlotToContainer( new Slot( m_printer, x + 7, 61 + x * 18, 49 ) );
// Player inv
for( int j = 0; j < 3; j++ )
for( int y = 0; y < 3; y++ )
{
for( int i1 = 0; i1 < 9; i1++ )
for( int x = 0; x < 9; x++ )
{
addSlotToContainer( new Slot( playerInventory, i1 + j * 9 + 9, 8 + i1 * 18, 84 + j * 18 ) );
addSlotToContainer( new Slot( playerInventory, x + y * 9 + 9, 8 + x * 18, 84 + y * 18 ) );
}
}
// Player hotbar
for( int k = 0; k < 9; k++ )
{
addSlotToContainer( new Slot( playerInventory, k, 8 + k * 18, 142 ) );
}
for( int x = 0; x < 9; x++ ) addSlotToContainer( new Slot( playerInventory, x, 8 + x * 18, 142 ) );
}
public boolean isPrinting()
@ -68,10 +61,10 @@ public class ContainerPrinter extends Container
}
@Override
public void addListener( IContainerListener crafting )
public void addListener( IContainerListener listener )
{
super.addListener( crafting );
crafting.sendWindowProperty( this, 0, m_printer.isPrinting() ? 1 : 0 );
super.addListener( listener );
listener.sendWindowProperty( this, PROPERTY_PRINTING, m_printer.isPrinting() ? 1 : 0 );
}
@Override
@ -82,23 +75,23 @@ public class ContainerPrinter extends Container
if( !m_printer.getWorld().isRemote )
{
boolean printing = m_printer.isPrinting();
for( IContainerListener listener : listeners )
if( printing != m_lastPrinting )
{
if( printing != m_lastPrinting )
for( IContainerListener listener : listeners )
{
listener.sendWindowProperty( this, 0, printing ? 1 : 0 );
listener.sendWindowProperty( this, PROPERTY_PRINTING, printing ? 1 : 0 );
}
m_lastPrinting = printing;
}
m_lastPrinting = printing;
}
}
@Override
public void updateProgressBar( int i, int j )
public void updateProgressBar( int property, int value )
{
if( m_printer.getWorld().isRemote )
{
m_lastPrinting = j > 0;
if( property == PROPERTY_PRINTING ) m_lastPrinting = value != 0;
}
}

View File

@ -51,21 +51,13 @@ public class TilePrinter extends TilePeripheralBase implements DefaultSidedInven
// Members
private final NonNullList<ItemStack> m_inventory;
private final NonNullList<ItemStack> m_inventory = NonNullList.withSize( 13, ItemStack.EMPTY );
private final IItemHandlerModifiable m_itemHandlerAll = new InvWrapper( this );
private IItemHandlerModifiable[] m_itemHandlerSides;
private final Terminal m_page;
private String m_pageTitle;
private boolean m_printing;
public TilePrinter()
{
m_inventory = NonNullList.withSize( 13, ItemStack.EMPTY );
m_page = new Terminal( ItemPrintout.LINE_MAX_LENGTH, ItemPrintout.LINES_PER_PAGE );
m_pageTitle = "";
m_printing = false;
}
private final Terminal m_page = new Terminal( ItemPrintout.LINE_MAX_LENGTH, ItemPrintout.LINES_PER_PAGE );
private String m_pageTitle = "";
private boolean m_printing = false;
@Override
public void destroy()
@ -76,15 +68,10 @@ public class TilePrinter extends TilePeripheralBase implements DefaultSidedInven
@Override
public boolean onActivate( EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ )
{
if( !player.isSneaking() )
{
if( !getWorld().isRemote )
{
Containers.openPrinterGUI( player, this );
}
return true;
}
return false;
if( player.isSneaking() ) return false;
if( !getWorld().isRemote ) Containers.openPrinterGUI( player, this );
return true;
}
@Override
@ -108,7 +95,7 @@ public class TilePrinter extends TilePeripheralBase implements DefaultSidedInven
{
NBTTagCompound itemTag = nbttaglist.getCompoundTagAt( i );
int j = itemTag.getByte( "Slot" ) & 0xff;
if( j >= 0 && j < m_inventory.size() )
if( j < m_inventory.size() )
{
m_inventory.set( j, new ItemStack( itemTag ) );
}
@ -120,8 +107,6 @@ public class TilePrinter extends TilePeripheralBase implements DefaultSidedInven
@Override
public NBTTagCompound writeToNBT( NBTTagCompound nbt )
{
nbt = super.writeToNBT( nbt );
// Write page
synchronized( m_page )
{
@ -147,7 +132,7 @@ public class TilePrinter extends TilePeripheralBase implements DefaultSidedInven
nbt.setTag( "Items", nbttaglist );
}
return nbt;
return super.writeToNBT( nbt );
}
@Override
@ -314,12 +299,12 @@ public class TilePrinter extends TilePeripheralBase implements DefaultSidedInven
{
switch( side )
{
case DOWN:
return bottomSlots; // Bottom (Out tray)
case UP:
return topSlots; // Top (In tray)
default:
return sideSlots; // Sides (Ink)
case DOWN: // Bottom (Out tray)
return bottomSlots;
case UP: // Top (In tray)
return topSlots;
default: // Sides (Ink)
return sideSlots;
}
}
@ -333,11 +318,7 @@ public class TilePrinter extends TilePeripheralBase implements DefaultSidedInven
public Terminal getCurrentPage()
{
if( m_printing )
{
return m_page;
}
return null;
return m_printing ? m_page : null;
}
public boolean startNewPage()
@ -430,14 +411,7 @@ public class TilePrinter extends TilePeripheralBase implements DefaultSidedInven
{
// Setup the new page
int colour = inkStack.getItemDamage();
if( colour >= 0 && colour < 16 )
{
m_page.setTextColour( 15 - colour );
}
else
{
m_page.setTextColour( 15 );
}
m_page.setTextColour( colour >= 0 && colour < 16 ? 15 - colour : 15 );
m_page.clear();
if( paperStack.getItem() instanceof ItemPrintout )

View File

@ -123,8 +123,7 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
@Override
public void updateUpgradeNBTData()
{
InventoryPlayer inventory = m_entity instanceof EntityPlayer ? ((EntityPlayer) m_entity).inventory : null;
if( inventory != null ) inventory.markDirty();
if( m_entity instanceof EntityPlayer ) ((EntityPlayer) m_entity).inventory.markDirty();
}
@Override
@ -160,7 +159,7 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
synchronized( this )
{
ItemPocketComputer.setUpgrade( m_stack, upgrade );
if( m_entity instanceof EntityPlayer ) ((EntityPlayer) m_entity).inventory.markDirty();
updateUpgradeNBTData();
m_upgrade = upgrade;
invalidatePeripheral();

View File

@ -475,5 +475,5 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
private static final IItemPropertyGetter COMPUTER_STATE = ( stack, world, player ) -> getState( stack ).ordinal();
private static final IItemPropertyGetter COMPUTER_COLOURED = ( stack, world, player ) ->
((ItemPocketComputer) stack.getItem()).getColour( stack ) != -1 ? 1 : 0;
IColouredItem.getColourBasic( stack ) != -1 ? 1 : 0;
}

View File

@ -20,12 +20,11 @@ public final class PocketComputerItemFactory
@Nonnull
public static ItemStack create( int id, String label, int colour, ComputerFamily family, IPocketUpgrade upgrade )
{
ItemPocketComputer computer = ComputerCraft.Items.pocketComputer;
switch( family )
{
case Normal:
case Advanced:
return computer.create( id, label, colour, family, upgrade );
return ComputerCraft.Items.pocketComputer.create( id, label, colour, family, upgrade );
default:
return ItemStack.EMPTY;
}

View File

@ -7,6 +7,7 @@
package dan200.computercraft.shared.pocket.peripherals;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.pocket.AbstractPocketUpgrade;
import dan200.computercraft.api.pocket.IPocketAccess;
import dan200.computercraft.shared.peripheral.PeripheralType;
import dan200.computercraft.shared.peripheral.common.PeripheralItemFactory;

View File

@ -7,11 +7,11 @@
package dan200.computercraft.shared.pocket.peripherals;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.pocket.AbstractPocketUpgrade;
import dan200.computercraft.api.pocket.IPocketAccess;
import dan200.computercraft.shared.peripheral.PeripheralType;
import dan200.computercraft.shared.peripheral.common.PeripheralItemFactory;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.ResourceLocation;
import javax.annotation.Nonnull;
@ -42,14 +42,9 @@ public class PocketSpeaker extends AbstractPocketUpgrade
PocketSpeakerPeripheral speaker = (PocketSpeakerPeripheral) peripheral;
Entity entity = access.getValidEntity();
if( entity instanceof EntityLivingBase )
if( entity != null )
{
EntityLivingBase player = (EntityLivingBase) entity;
speaker.setLocation( entity.getEntityWorld(), player.posX, player.posY + player.getEyeHeight(), player.posZ );
}
else if( entity != null )
{
speaker.setLocation( entity.getEntityWorld(), entity.posX, entity.posY, entity.posZ );
speaker.setLocation( entity.getEntityWorld(), entity.getPositionEyes( 1.0f ) );
}
speaker.update();

View File

@ -16,9 +16,9 @@ public class PocketSpeakerPeripheral extends SpeakerPeripheral
private World world = null;
private Vec3d position = Vec3d.ZERO;
void setLocation( World world, double x, double y, double z )
void setLocation( World world, Vec3d position )
{
position = new Vec3d( x, y, z );
this.position = position;
this.world = world;
}

View File

@ -57,6 +57,8 @@ public class PocketComputerUpgradeRecipe extends IForgeRegistryEntry.Impl<IRecip
ItemStack computer = ItemStack.EMPTY;
int computerX = -1;
int computerY = -1;
computer:
for( int y = 0; y < inventory.getHeight(); y++ )
{
for( int x = 0; x < inventory.getWidth(); x++ )
@ -67,25 +69,15 @@ public class PocketComputerUpgradeRecipe extends IForgeRegistryEntry.Impl<IRecip
computer = item;
computerX = x;
computerY = y;
break;
break computer;
}
}
if( !computer.isEmpty() )
{
break;
}
}
if( computer.isEmpty() )
{
return ItemStack.EMPTY;
}
if( computer.isEmpty() ) return ItemStack.EMPTY;
ItemPocketComputer itemComputer = (ItemPocketComputer) computer.getItem();
if( itemComputer.getUpgrade( computer ) != null )
{
return ItemStack.EMPTY;
}
if( itemComputer.getUpgrade( computer ) != null ) return ItemStack.EMPTY;
// Check for upgrades around the item
IPocketUpgrade upgrade = null;
@ -108,10 +100,7 @@ public class PocketComputerUpgradeRecipe extends IForgeRegistryEntry.Impl<IRecip
}
}
if( upgrade == null )
{
return ItemStack.EMPTY;
}
if( upgrade == null ) return ItemStack.EMPTY;
// Construct the new stack
ComputerFamily family = itemComputer.getFamily( computer );

View File

@ -47,9 +47,8 @@ import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import pl.asie.charset.ModCharset;
public class ComputerCraftProxyCommon implements IComputerCraftProxy
public class ComputerCraftProxyCommon
{
@Override
public void preInit()
{
NetworkHandler.setup();
@ -62,7 +61,6 @@ public class ComputerCraftProxyCommon implements IComputerCraftProxy
);
}
@Override
public void init()
{
registerProviders();
@ -72,8 +70,7 @@ public class ComputerCraftProxyCommon implements IComputerCraftProxy
if( Loader.isModLoaded( ModCharset.MODID ) ) IntegrationCharset.register();
}
@Override
public void initServer( MinecraftServer server )
public static void initServer( MinecraftServer server )
{
CommandHandler handler = (CommandHandler) server.getCommandManager();
handler.registerCommand( new CommandComputerCraft() );

View File

@ -1,18 +0,0 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.proxy;
import net.minecraft.server.MinecraftServer;
public interface IComputerCraftProxy
{
void preInit();
void init();
void initServer( MinecraftServer server );
}

View File

@ -15,6 +15,7 @@ import dan200.computercraft.shared.turtle.core.TurtleBrain;
import dan200.computercraft.shared.turtle.items.ITurtleItem;
import dan200.computercraft.shared.turtle.items.TurtleItemFactory;
import dan200.computercraft.shared.util.DirectionUtil;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockFaceShape;
@ -39,14 +40,7 @@ import javax.annotation.Nonnull;
public class BlockTurtle extends BlockComputerBase
{
// Statics
public static final class Properties
{
public static final PropertyDirection FACING = PropertyDirection.create( "facing", EnumFacing.Plane.HORIZONTAL );
}
// Members
public static final PropertyDirection FACING = BlockHorizontal.FACING;
public BlockTurtle()
{
@ -55,7 +49,7 @@ public class BlockTurtle extends BlockComputerBase
setTranslationKey( "computercraft:turtle" );
setCreativeTab( ComputerCraft.mainCreativeTab );
setDefaultState( blockState.getBaseState()
.withProperty( Properties.FACING, EnumFacing.NORTH )
.withProperty( FACING, EnumFacing.NORTH )
);
}
@ -93,7 +87,7 @@ public class BlockTurtle extends BlockComputerBase
@Override
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer( this, Properties.FACING );
return new BlockStateContainer( this, FACING );
}
@Nonnull
@ -115,7 +109,7 @@ public class BlockTurtle extends BlockComputerBase
@Deprecated
public IBlockState getActualState( @Nonnull IBlockState state, IBlockAccess world, BlockPos pos )
{
return state.withProperty( Properties.FACING, getDirection( world, pos ) );
return state.withProperty( FACING, getDirection( world, pos ) );
}
@Override

View File

@ -290,8 +290,6 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
@Override
public NBTTagCompound writeToNBT( NBTTagCompound nbt )
{
nbt = super.writeToNBT( nbt );
// Write inventory
NBTTagList nbttaglist = new NBTTagList();
for( int i = 0; i < INVENTORY_SIZE; i++ )
@ -309,7 +307,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
// Write brain
nbt = m_brain.writeToNBT( nbt );
return nbt;
return super.writeToNBT( nbt );
}
@Override
@ -545,14 +543,14 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
// Networking stuff
@Override
public void writeDescription( @Nonnull NBTTagCompound nbt )
protected void writeDescription( @Nonnull NBTTagCompound nbt )
{
super.writeDescription( nbt );
m_brain.writeDescription( nbt );
}
@Override
public void readDescription( @Nonnull NBTTagCompound nbt )
protected void readDescription( @Nonnull NBTTagCompound nbt )
{
super.readDescription( nbt );
m_brain.readDescription( nbt );

View File

@ -29,6 +29,7 @@ import net.minecraft.entity.MoverType;
import net.minecraft.inventory.IInventory;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EntitySelectors;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ResourceLocation;
@ -160,11 +161,11 @@ public class TurtleBrain implements ITurtleAccess
// Read overlay
if( nbt.hasKey( "overlay_mod" ) )
{
String overlay_mod = nbt.getString( "overlay_mod" );
String overlayMod = nbt.getString( "overlay_mod" );
if( nbt.hasKey( "overlay_path" ) )
{
String overlay_path = nbt.getString( "overlay_path" );
m_overlay = new ResourceLocation( overlay_mod, overlay_path );
String overlayPath = nbt.getString( "overlay_path" );
m_overlay = new ResourceLocation( overlayMod, overlayPath );
}
else
{
@ -336,9 +337,9 @@ public class TurtleBrain implements ITurtleAccess
// Overlay
if( nbt.hasKey( "overlay_mod" ) && nbt.hasKey( "overlay_path" ) )
{
String overlay_mod = nbt.getString( "overlay_mod" );
String overlay_path = nbt.getString( "overlay_path" );
m_overlay = new ResourceLocation( overlay_mod, overlay_path );
String overlayMod = nbt.getString( "overlay_mod" );
String overlayPath = nbt.getString( "overlay_path" );
m_overlay = new ResourceLocation( overlayMod, overlayPath );
}
else
{
@ -988,7 +989,7 @@ public class TurtleBrain implements ITurtleAccess
}
AxisAlignedBB aabb = new AxisAlignedBB( minX, minY, minZ, maxX, maxY, maxZ );
List<Entity> list = world.getEntitiesWithinAABBExcludingEntity( null, aabb );
List<Entity> list = world.getEntitiesWithinAABB( Entity.class, aabb, EntitySelectors.NOT_SPECTATING );
if( !list.isEmpty() )
{
double pushStep = 1.0f / ANIM_DURATION;

View File

@ -105,30 +105,24 @@ public class TurtleCompareCommand implements ITurtleCommand
}
}
// Compare them
if( selectedStack.isEmpty() && lookAtStack.isEmpty() )
// If they're both empty, obviously the same
if( selectedStack.isEmpty() && lookAtStack.isEmpty() ) return TurtleCommandResult.success();
// If the items don't match, obviously different.
if( selectedStack.isEmpty() || lookAtStack == null || selectedStack.getItem() != lookAtStack.getItem() )
{
return TurtleCommandResult.failure();
}
// If the damage matches, or the damage doesn't matter, then the same.
if( !selectedStack.getHasSubtypes() || selectedStack.getItemDamage() == lookAtStack.getItemDamage() )
{
return TurtleCommandResult.success();
}
else if( !selectedStack.isEmpty() && lookAtStack != null )
{
if( selectedStack.getItem() == lookAtStack.getItem() )
{
if( !selectedStack.getHasSubtypes() )
{
return TurtleCommandResult.success();
}
else if( selectedStack.getItemDamage() == lookAtStack.getItemDamage() )
{
return TurtleCommandResult.success();
}
else if( selectedStack.getTranslationKey().equals( lookAtStack.getTranslationKey() ) )
{
return TurtleCommandResult.success();
}
}
}
return TurtleCommandResult.failure();
// Otherwise just double check the translation is the same. It's a pretty good guess.
return selectedStack.getTranslationKey().equals( lookAtStack.getTranslationKey() )
? TurtleCommandResult.success()
: TurtleCommandResult.failure();
}
}

View File

@ -108,19 +108,19 @@ public class TurtlePlaceCommand implements ITurtleCommand
}
}
public static ItemStack deploy( @Nonnull ItemStack stack, ITurtleAccess turtle, EnumFacing direction, Object[] extraArguments, String[] o_errorMessage )
public static ItemStack deploy( @Nonnull ItemStack stack, ITurtleAccess turtle, EnumFacing direction, Object[] extraArguments, String[] outErrorMessage )
{
// Create a fake player, and orient it appropriately
BlockPos playerPosition = turtle.getPosition().offset( direction );
TurtlePlayer turtlePlayer = createPlayer( turtle, playerPosition, direction );
return deploy( stack, turtle, turtlePlayer, direction, extraArguments, o_errorMessage );
return deploy( stack, turtle, turtlePlayer, direction, extraArguments, outErrorMessage );
}
public static ItemStack deploy( @Nonnull ItemStack stack, ITurtleAccess turtle, TurtlePlayer turtlePlayer, EnumFacing direction, Object[] extraArguments, String[] o_errorMessage )
public static ItemStack deploy( @Nonnull ItemStack stack, ITurtleAccess turtle, TurtlePlayer turtlePlayer, EnumFacing direction, Object[] extraArguments, String[] outErrorMessage )
{
// Deploy on an entity
ItemStack remainder = deployOnEntity( stack, turtle, turtlePlayer, direction, extraArguments, o_errorMessage );
ItemStack remainder = deployOnEntity( stack, turtle, turtlePlayer, direction, extraArguments, outErrorMessage );
if( remainder != stack )
{
return remainder;
@ -129,14 +129,14 @@ public class TurtlePlaceCommand implements ITurtleCommand
// Deploy on the block immediately in front
BlockPos position = turtle.getPosition();
BlockPos newPosition = position.offset( direction );
remainder = deployOnBlock( stack, turtle, turtlePlayer, newPosition, direction.getOpposite(), extraArguments, true, o_errorMessage );
remainder = deployOnBlock( stack, turtle, turtlePlayer, newPosition, direction.getOpposite(), extraArguments, true, outErrorMessage );
if( remainder != stack )
{
return remainder;
}
// Deploy on the block one block away
remainder = deployOnBlock( stack, turtle, turtlePlayer, newPosition.offset( direction ), direction.getOpposite(), extraArguments, false, o_errorMessage );
remainder = deployOnBlock( stack, turtle, turtlePlayer, newPosition.offset( direction ), direction.getOpposite(), extraArguments, false, outErrorMessage );
if( remainder != stack )
{
return remainder;
@ -145,7 +145,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
if( direction.getAxis() != EnumFacing.Axis.Y )
{
// Deploy down on the block in front
remainder = deployOnBlock( stack, turtle, turtlePlayer, newPosition.down(), EnumFacing.UP, extraArguments, false, o_errorMessage );
remainder = deployOnBlock( stack, turtle, turtlePlayer, newPosition.down(), EnumFacing.UP, extraArguments, false, outErrorMessage );
if( remainder != stack )
{
return remainder;
@ -153,7 +153,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
}
// Deploy back onto the turtle
remainder = deployOnBlock( stack, turtle, turtlePlayer, position, direction, extraArguments, false, o_errorMessage );
remainder = deployOnBlock( stack, turtle, turtlePlayer, position, direction, extraArguments, false, outErrorMessage );
if( remainder != stack )
{
return remainder;
@ -206,7 +206,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
}
@Nonnull
private static ItemStack deployOnEntity( @Nonnull ItemStack stack, final ITurtleAccess turtle, TurtlePlayer turtlePlayer, EnumFacing direction, Object[] extraArguments, String[] o_errorMessage )
private static ItemStack deployOnEntity( @Nonnull ItemStack stack, final ITurtleAccess turtle, TurtlePlayer turtlePlayer, EnumFacing direction, Object[] extraArguments, String[] outErrorMessage )
{
// See if there is an entity present
final World world = turtle.getWorld();
@ -288,7 +288,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
}
}
private static boolean canDeployOnBlock( @Nonnull ItemStack stack, ITurtleAccess turtle, TurtlePlayer player, BlockPos position, EnumFacing side, boolean allowReplaceable, String[] o_errorMessage )
private static boolean canDeployOnBlock( @Nonnull ItemStack stack, ITurtleAccess turtle, TurtlePlayer player, BlockPos position, EnumFacing side, boolean allowReplaceable, String[] outErrorMessage )
{
World world = turtle.getWorld();
if( !world.isValid( position ) || world.isAirBlock( position ) ||
@ -311,7 +311,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
: TurtlePermissions.isBlockEditable( world, position.offset( side ), player );
if( !editable )
{
if( o_errorMessage != null ) o_errorMessage[0] = "Cannot place in protected area";
if( outErrorMessage != null ) outErrorMessage[0] = "Cannot place in protected area";
return false;
}
}
@ -321,19 +321,19 @@ public class TurtlePlaceCommand implements ITurtleCommand
}
@Nonnull
private static ItemStack deployOnBlock( @Nonnull ItemStack stack, ITurtleAccess turtle, TurtlePlayer turtlePlayer, BlockPos position, EnumFacing side, Object[] extraArguments, boolean allowReplace, String[] o_errorMessage )
private static ItemStack deployOnBlock( @Nonnull ItemStack stack, ITurtleAccess turtle, TurtlePlayer turtlePlayer, BlockPos position, EnumFacing side, Object[] extraArguments, boolean allowReplace, String[] outErrorMessage )
{
// Check if there's something suitable to place onto
if( !canDeployOnBlock( stack, turtle, turtlePlayer, position, side, allowReplace, o_errorMessage ) )
{
return stack;
}
// Re-orient the fake player
EnumFacing playerDir = side.getOpposite();
BlockPos playerPosition = position.offset( side );
orientPlayer( turtle, turtlePlayer, playerPosition, playerDir );
// Check if there's something suitable to place onto
if( !canDeployOnBlock( stack, turtle, turtlePlayer, position, side, allowReplace, outErrorMessage ) )
{
return stack;
}
// Calculate where the turtle would hit the block
float hitX = 0.5f + side.getXOffset() * 0.5f;
float hitY = 0.5f + side.getYOffset() * 0.5f;

View File

@ -40,14 +40,7 @@ public class ContainerTurtle extends Container implements IContainerComputer
m_turtleInvStartX = turtleInvStartX;
m_turtle = turtle;
if( !m_turtle.getWorld().isRemote )
{
m_selectedSlot = m_turtle.getSelectedSlot();
}
else
{
m_selectedSlot = 0;
}
m_selectedSlot = m_turtle.getWorld().isRemote ? 0 : m_turtle.getSelectedSlot();
// Turtle inventory
for( int y = 0; y < 4; y++ )
@ -139,7 +132,7 @@ public class ContainerTurtle extends Container implements IContainerComputer
}
@Nonnull
protected ItemStack tryItemMerge( EntityPlayer player, int slotNum, int firstSlot, int lastSlot, boolean reverse )
private ItemStack tryItemMerge( EntityPlayer player, int slotNum, int firstSlot, int lastSlot, boolean reverse )
{
Slot slot = inventorySlots.get( slotNum );
ItemStack originalStack = ItemStack.EMPTY;

View File

@ -107,9 +107,9 @@ public class ItemTurtleNormal extends ItemTurtleBase
NBTTagCompound nbt = stack.getTagCompound();
if( nbt != null && nbt.hasKey( "overlay_mod" ) && nbt.hasKey( "overlay_path" ) )
{
String overlay_mod = nbt.getString( "overlay_mod" );
String overlay_path = nbt.getString( "overlay_path" );
return new ResourceLocation( overlay_mod, overlay_path );
String overlayMod = nbt.getString( "overlay_mod" );
String overlayPath = nbt.getString( "overlay_path" );
return new ResourceLocation( overlayMod, overlayPath );
}
return null;
}

View File

@ -33,7 +33,7 @@ public class TurtleRecipe extends ComputerConvertRecipe
@Nonnull
@Override
protected ItemStack convert( IComputerItem item, @Nonnull ItemStack stack )
protected ItemStack convert( @Nonnull IComputerItem item, @Nonnull ItemStack stack )
{
int computerID = item.getComputerID( stack );
String label = item.getLabel( stack );

View File

@ -6,6 +6,7 @@
package dan200.computercraft.shared.turtle.upgrades;
import dan200.computercraft.api.AbstractTurtleUpgrade;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.TurtleSide;

View File

@ -6,6 +6,7 @@
package dan200.computercraft.shared.turtle.upgrades;
import dan200.computercraft.api.AbstractTurtleUpgrade;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.turtle.*;
import dan200.computercraft.shared.peripheral.PeripheralType;

View File

@ -7,6 +7,7 @@
package dan200.computercraft.shared.turtle.upgrades;
import dan200.computercraft.api.AbstractTurtleUpgrade;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.TurtleSide;

View File

@ -7,6 +7,7 @@
package dan200.computercraft.shared.turtle.upgrades;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.AbstractTurtleUpgrade;
import dan200.computercraft.api.turtle.*;
import dan200.computercraft.api.turtle.event.TurtleAttackEvent;
import dan200.computercraft.api.turtle.event.TurtleBlockEvent;

View File

@ -18,7 +18,7 @@ public class CreativeTabMain extends CreativeTabs
{
public CreativeTabMain( int i )
{
super( i, "CC: Tweaked" );
super( i, ComputerCraft.MOD_ID );
}
@Nonnull
@ -28,12 +28,4 @@ public class CreativeTabMain extends CreativeTabs
{
return new ItemStack( ComputerCraft.Blocks.computer );
}
@Nonnull
@Override
@SideOnly( Side.CLIENT )
public String getTranslationKey()
{
return getTabLabel();
}
}

View File

@ -1,35 +0,0 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.util;
import dan200.computercraft.ComputerCraft;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
public class CreativeTabTreasure extends CreativeTabs
{
public CreativeTabTreasure( int i )
{
super( i, "Treasure Disks" );
}
@Nonnull
@Override
public ItemStack createIcon()
{
return new ItemStack( ComputerCraft.Items.treasureDisk );
}
@Nonnull
@Override
public String getTranslationKey()
{
return getTabLabel();
}
}

View File

@ -48,7 +48,7 @@ public class ImpostorRecipe extends ShapedRecipes
@Nonnull
@Override
public ItemStack getCraftingResult( @Nonnull InventoryCrafting _inventory )
public ItemStack getCraftingResult( @Nonnull InventoryCrafting inventory )
{
return ItemStack.EMPTY;
}

View File

@ -22,64 +22,46 @@ public final class NBTUtil
private static NBTBase toNBTTag( Object object )
{
if( object != null )
if( object == null ) return null;
if( object instanceof Boolean ) return new NBTTagByte( (byte) ((boolean) (Boolean) object ? 1 : 0) );
if( object instanceof Number ) return new NBTTagDouble( ((Number) object).doubleValue() );
if( object instanceof String ) return new NBTTagString( object.toString() );
if( object instanceof Map )
{
if( object instanceof Boolean )
Map<?, ?> m = (Map<?, ?>) object;
NBTTagCompound nbt = new NBTTagCompound();
int i = 0;
for( Map.Entry<?, ?> entry : m.entrySet() )
{
boolean b = (Boolean) object;
return new NBTTagByte( b ? (byte) 1 : (byte) 0 );
}
else if( object instanceof Number )
{
Double d = ((Number) object).doubleValue();
return new NBTTagDouble( d );
}
else if( object instanceof String )
{
String s = object.toString();
return new NBTTagString( s );
}
else if( object instanceof Map )
{
Map<?, ?> m = (Map<?, ?>) object;
NBTTagCompound nbt = new NBTTagCompound();
int i = 0;
for( Map.Entry<?, ?> entry : m.entrySet() )
NBTBase key = toNBTTag( entry.getKey() );
NBTBase value = toNBTTag( entry.getKey() );
if( key != null && value != null )
{
NBTBase key = toNBTTag( entry.getKey() );
NBTBase value = toNBTTag( entry.getKey() );
if( key != null && value != null )
{
nbt.setTag( "k" + i, key );
nbt.setTag( "v" + i, value );
i++;
}
nbt.setTag( "k" + i, key );
nbt.setTag( "v" + i, value );
i++;
}
nbt.setInteger( "len", m.size() );
return nbt;
}
nbt.setInteger( "len", m.size() );
return nbt;
}
return null;
}
public static NBTTagCompound encodeObjects( Object[] objects )
{
if( objects != null && objects.length > 0 )
if( objects == null || objects.length <= 0 ) return null;
NBTTagCompound nbt = new NBTTagCompound();
nbt.setInteger( "len", objects.length );
for( int i = 0; i < objects.length; i++ )
{
NBTTagCompound nbt = new NBTTagCompound();
nbt.setInteger( "len", objects.length );
for( int i = 0; i < objects.length; i++ )
{
Object object = objects[i];
NBTBase tag = toNBTTag( object );
if( tag != null )
{
nbt.setTag( Integer.toString( i ), tag );
}
}
return nbt;
Object object = objects[i];
NBTBase tag = toNBTTag( object );
if( tag != null ) nbt.setTag( Integer.toString( i ), tag );
}
return null;
return nbt;
}
private static Object fromNBTTag( NBTBase tag )
@ -153,14 +135,14 @@ public final class NBTUtil
byte[] array = ((NBTTagByteArray) tag).getByteArray();
Map<Integer, Byte> map = new HashMap<>( array.length );
for( int i = 0; i < array.length; i++ ) map.put( i + 1, array[i] );
return array;
return map;
}
case Constants.NBT.TAG_INT_ARRAY:
{
int[] array = ((NBTTagIntArray) tag).getIntArray();
Map<Integer, Integer> map = new HashMap<>( array.length );
for( int i = 0; i < array.length; i++ ) map.put( i + 1, array[i] );
return array;
return map;
}
default:
@ -171,17 +153,15 @@ public final class NBTUtil
public static Object[] decodeObjects( NBTTagCompound tagCompound )
{
int len = tagCompound.getInteger( "len" );
if( len > 0 )
if( len <= 0 ) return null;
Object[] objects = new Object[len];
for( int i = 0; i < len; i++ )
{
Object[] objects = new Object[len];
for( int i = 0; i < len; i++ )
{
String key = Integer.toString( i );
if( tagCompound.hasKey( key ) ) objects[i] = fromNBTTag( tagCompound.getTag( key ) );
}
return objects;
String key = Integer.toString( i );
if( tagCompound.hasKey( key ) ) objects[i] = fromNBTTag( tagCompound.getTag( key ) );
}
return null;
return objects;
}
public static NBTTagCompound readCompoundTag( PacketBuffer buf )

View File

@ -8,7 +8,6 @@ package dan200.computercraft.shared.util;
import dan200.computercraft.shared.BundledRedstone;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -35,7 +34,7 @@ public final class RedstoneUtil
IBlockState block = world.getBlockState( pos );
BlockPos neighbourPos = pos.offset( side );
IBlockState neighbour = world.getBlockState( neighbourPos );
if( neighbour.getBlock() != Blocks.AIR )
if( neighbour.getBlock().isAir( neighbour, world, neighbourPos ) )
{
world.neighborChanged( neighbourPos, block.getBlock(), pos );
if( neighbour.getBlock().isNormalCube( neighbour, world, neighbourPos ) )

View File

@ -25,7 +25,7 @@ public final class WiredNetwork implements IWiredNetwork
HashSet<WiredNode> nodes;
private HashMap<String, IPeripheral> peripherals = new HashMap<>();
public WiredNetwork( WiredNode node )
WiredNetwork( WiredNode node )
{
nodes = new HashSet<>( 1 );
nodes.add( node );
@ -358,9 +358,9 @@ public final class WiredNetwork implements IWiredNetwork
if( neighbourPoint == null )
{
neighbourPoint = new TransmitPoint( neighbour, newDistance, newInterdimensional );
points.put( neighbour, neighbourPoint );
transmitTo.add( neighbourPoint );
TransmitPoint nextPoint = new TransmitPoint( neighbour, newDistance, newInterdimensional );
points.put( neighbour, nextPoint );
transmitTo.add( nextPoint );
}
else if( newDistance < neighbourPoint.distance )
{

View File

@ -1,3 +1,5 @@
itemGroup.computercraft=CC: Tweaked
tile.computercraft:computer.name=Computer
tile.computercraft:advanced_computer.name=Advanced Computer
tile.computercraft:drive.name=Disk Drive

View File

@ -74,7 +74,7 @@ for _, language in ipairs(secondary) do
end
local h = io.open(path:format(language), "wb")
local previous_blank = flase
local previous_blank = true
for _, line in ipairs(primary_contents) do
if line == "" then
if not previous_blank then