1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-01-07 07:50:27 +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" /> <option name="m_ignoreStaticMethods" value="true" />
</inspection_tool> </inspection_tool>
<inspection_tool class="LocalVariableName" enabled="true" level="WEAK WARNING" enabled_by_default="true" /> <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_ignoreForLoopParameters" value="false" />
<option name="m_ignoreCatchParameters" value="false" /> <option name="m_ignoreCatchParameters" value="false" />
<option name="m_regex" value="[a-z][A-Za-z\d]*" /> <option name="m_regex" value="[a-z][A-Za-z\d]*" />
<option name="m_minLength" value="1" /> <option name="m_minLength" value="1" />
<option name="m_maxLength" value="20" /> <option name="m_maxLength" value="50" />
</inspection_tool> </inspection_tool>
<inspection_tool class="LocalVariableNamingConventionJS" enabled="false" level="WARNING" enabled_by_default="false"> <inspection_tool class="LocalVariableNamingConventionJS" enabled="false" level="WARNING" enabled_by_default="false">
<option name="m_regex" value="[a-z][A-Za-z]*" /> <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="NewExceptionWithoutArguments" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="NewGroovyClassNamingConvention" enabled="false" level="WARNING" enabled_by_default="false" /> <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="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="NewObjectEquality" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="NewStringBufferWithCharArgument" 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" /> <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_ignoreSingleCharacterNames" value="false" />
<option name="m_ignoreOverridesOfLibraryMethods" value="false" /> <option name="m_ignoreOverridesOfLibraryMethods" value="false" />
</inspection_tool> </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_regex" value="[a-z][A-Za-z\d]*" />
<option name="m_minLength" value="1" /> <option name="m_minLength" value="1" />
<option name="m_maxLength" value="20" /> <option name="m_maxLength" value="50" />
</inspection_tool> </inspection_tool>
<inspection_tool class="ParameterNamingConventionJS" enabled="false" level="WARNING" enabled_by_default="false"> <inspection_tool class="ParameterNamingConventionJS" enabled="false" level="WARNING" enabled_by_default="false">
<option name="m_regex" value="[a-z][A-Za-z]*" /> <option name="m_regex" value="[a-z][A-Za-z]*" />

View File

@ -1,5 +1,5 @@
# Mod properties # Mod properties
mod_version=1.81.1 mod_version=1.82.0
# Minecraft properties # Minecraft properties
mc_version=1.12.2 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.items.ItemPocketComputer;
import dan200.computercraft.shared.pocket.peripherals.PocketModem; import dan200.computercraft.shared.pocket.peripherals.PocketModem;
import dan200.computercraft.shared.pocket.peripherals.PocketSpeaker; 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.blocks.BlockTurtle;
import dan200.computercraft.shared.turtle.items.ItemTurtleAdvanced; import dan200.computercraft.shared.turtle.items.ItemTurtleAdvanced;
import dan200.computercraft.shared.turtle.items.ItemTurtleLegacy; import dan200.computercraft.shared.turtle.items.ItemTurtleLegacy;
@ -248,7 +248,7 @@ public class ComputerCraft
clientSide = "dan200.computercraft.client.proxy.ComputerCraftProxyClient", clientSide = "dan200.computercraft.client.proxy.ComputerCraftProxyClient",
serverSide = "dan200.computercraft.shared.proxy.ComputerCraftProxyCommon" serverSide = "dan200.computercraft.shared.proxy.ComputerCraftProxyCommon"
) )
private static IComputerCraftProxy proxy; private static ComputerCraftProxyCommon proxy;
@Mod.EventHandler @Mod.EventHandler
public void preInit( FMLPreInitializationEvent event ) public void preInit( FMLPreInitializationEvent event )
@ -270,7 +270,7 @@ public class ComputerCraft
@Mod.EventHandler @Mod.EventHandler
public void onServerStarting( FMLServerStartingEvent event ) public void onServerStarting( FMLServerStartingEvent event )
{ {
proxy.initServer( event.getServer() ); ComputerCraftProxyCommon.initServer( event.getServer() );
} }
@Mod.EventHandler @Mod.EventHandler

View File

@ -4,7 +4,7 @@
* Send enquiries to dratcliffe@gmail.com * 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.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleUpgradeType; import dan200.computercraft.api.turtle.TurtleUpgradeType;
@ -15,6 +15,11 @@ import net.minecraft.util.ResourceLocation;
import javax.annotation.Nonnull; 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 public abstract class AbstractTurtleUpgrade implements ITurtleUpgrade
{ {
private final ResourceLocation id; private final ResourceLocation id;
@ -23,7 +28,7 @@ public abstract class AbstractTurtleUpgrade implements ITurtleUpgrade
private final String adjective; private final String adjective;
private final ItemStack stack; 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.id = id;
this.legacyId = legacyId; this.legacyId = legacyId;
@ -32,27 +37,27 @@ public abstract class AbstractTurtleUpgrade implements ITurtleUpgrade
this.stack = stack; 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 ) ); 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 ) ); 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 ); 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 ) ); 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 ) ); 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: * 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. * @param stack The {@link ItemStack} to modify.
* @return The name, or null if this item does not represent an item with audio. * @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 * 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.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import javax.annotation.Nonnull; 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 public abstract class AbstractPocketUpgrade implements IPocketUpgrade
{ {
private final ResourceLocation id; private final ResourceLocation id;

View File

@ -11,7 +11,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -21,7 +20,6 @@ import java.util.Objects;
/** /**
* Fired when a turtle attempts to interact with an inventory. * Fired when a turtle attempts to interact with an inventory.
*/ */
@Cancelable
public abstract class TurtleInventoryEvent extends TurtleBlockEvent public abstract class TurtleInventoryEvent extends TurtleBlockEvent
{ {
private final IItemHandler handler; 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.media.items.ItemDiskLegacy;
import dan200.computercraft.shared.pocket.items.ItemPocketComputer; import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
import dan200.computercraft.shared.turtle.items.ItemTurtleBase; import dan200.computercraft.shared.turtle.items.ItemTurtleBase;
import dan200.computercraft.shared.util.Colour;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemMeshDefinition; import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.client.renderer.block.model.IBakedModel; import net.minecraft.client.renderer.block.model.IBakedModel;
@ -132,7 +133,10 @@ public final class ClientRegistry
case 1: // Frame colour case 1: // Frame colour
return ComputerCraft.Items.pocketComputer.getColour( stack ); return ComputerCraft.Items.pocketComputer.getColour( stack );
case 2: // Light colour case 2: // Light colour
return ItemPocketComputer.getLightState( stack ); {
int light = ItemPocketComputer.getLightState( stack );
return light == -1 ? Colour.Black.getHex() : light;
}
} }
}, ComputerCraft.Items.pocketComputer ); }, ComputerCraft.Items.pocketComputer );

View File

@ -61,11 +61,11 @@ public class TileEntityCableRenderer extends TileEntitySpecialRenderer<TileCable
state = state.getActualState( world, pos ); state = state.getActualState( world, pos );
if( te.getPeripheralType() != PeripheralType.Cable && WorldUtil.isVecInsideInclusive( CableBounds.getModemBounds( state ), hit.hitVec.subtract( pos.getX(), pos.getY(), pos.getZ() ) ) ) 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 else
{ {
state = state.withProperty( BlockCable.Properties.MODEM, BlockCableModemVariant.None ); state = state.withProperty( BlockCable.MODEM, BlockCableModemVariant.None );
} }
IBakedModel model = mc.getBlockRendererDispatcher().getModelForState( state ); 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 IAPIEnvironment m_environment;
private final Set<String> m_mounts = new HashSet<>(); 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() public void unmountAll()
{ {
FileSystem fileSystem = m_environment.getFileSystem(); 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(); m_mounts.clear();
} }

View File

@ -34,9 +34,9 @@ public class FSAPI implements ILuaAPI
private IAPIEnvironment m_env; private IAPIEnvironment m_env;
private FileSystem m_fileSystem; private FileSystem m_fileSystem;
public FSAPI( IAPIEnvironment _env ) public FSAPI( IAPIEnvironment env )
{ {
m_env = _env; m_env = env;
m_fileSystem = null; m_fileSystem = null;
} }

View File

@ -228,9 +228,9 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
private final PeripheralWrapper[] m_peripherals; private final PeripheralWrapper[] m_peripherals;
private boolean m_running; private boolean m_running;
public PeripheralAPI( IAPIEnvironment _environment ) public PeripheralAPI( IAPIEnvironment environment )
{ {
m_environment = _environment; m_environment = environment;
m_environment.setPeripheralChangeListener( this ); m_environment.setPeripheralChangeListener( this );
m_peripherals = new PeripheralWrapper[6]; m_peripherals = new PeripheralWrapper[6];

View File

@ -24,10 +24,10 @@ public class TermAPI implements ILuaAPI
private final Terminal m_terminal; private final Terminal m_terminal;
private final IComputerEnvironment m_environment; private final IComputerEnvironment m_environment;
public TermAPI( IAPIEnvironment _environment ) public TermAPI( IAPIEnvironment environment )
{ {
m_terminal = _environment.getTerminal(); m_terminal = environment.getTerminal();
m_environment = _environment.getComputerEnvironment(); m_environment = environment.getComputerEnvironment();
} }
@Override @Override

View File

@ -28,10 +28,10 @@ public class ComputerSystem extends ComputerAccess implements IComputerSystem
{ {
private final IAPIEnvironment m_environment; private final IAPIEnvironment m_environment;
ComputerSystem( IAPIEnvironment m_environment ) ComputerSystem( IAPIEnvironment environment )
{ {
super( m_environment ); super( environment );
this.m_environment = m_environment; this.m_environment = environment;
} }
@Nonnull @Nonnull

View File

@ -26,8 +26,8 @@ import java.util.concurrent.TimeUnit;
* the executor goes through three stages: * the executor goes through three stages:
* *
* When {@link State#COOL}, the computer is allocated {@link ComputerCraft#maxMainComputerTime}ns to execute any work * 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 * this tick. At the beginning of the tick, we execute as many {@link MainThread} tasks as possible, until our
* or the global time frame has expired. * 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 * Then, when other objects (such as {@link TileEntity}) are ticked, we update how much time we've used using
* {@link IWorkMonitor#trackWork(long, TimeUnit)}. * {@link IWorkMonitor#trackWork(long, TimeUnit)}.

View File

@ -23,9 +23,9 @@ public class FileSystemWrapperMount implements IFileSystem
{ {
private final FileSystem m_filesystem; private final FileSystem m_filesystem;
public FileSystemWrapperMount( FileSystem m_filesystem ) public FileSystemWrapperMount( FileSystem filesystem )
{ {
this.m_filesystem = m_filesystem; this.m_filesystem = filesystem;
} }
@Override @Override

View File

@ -22,6 +22,8 @@ public final class BundledRedstone
{ {
private static final Set<IBundledRedstoneProvider> providers = new LinkedHashSet<>(); private static final Set<IBundledRedstoneProvider> providers = new LinkedHashSet<>();
private BundledRedstone() {}
public static void register( @Nonnull IBundledRedstoneProvider provider ) public static void register( @Nonnull IBundledRedstoneProvider provider )
{ {
Preconditions.checkNotNull( provider, "provider cannot be null" ); Preconditions.checkNotNull( provider, "provider cannot be null" );

View File

@ -52,10 +52,10 @@ public abstract class BlockGeneric extends Block implements ITileEntityProvider
@Override @Override
@Deprecated @Deprecated
@SuppressWarnings( "deprecation" ) @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 ); TileEntity tile = world.getTileEntity( pos );
if( tile instanceof TileGeneric ) ((TileGeneric) tile).onNeighbourChange( neighbour ); if( tile instanceof TileGeneric ) ((TileGeneric) tile).onNeighbourChange( neighbourPos );
} }
@Override @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 ) public final int getStrongPower( IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing oppositeSide )
{ {
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile instanceof TileGeneric && tile.hasWorld() ) return tile instanceof TileGeneric && tile.hasWorld() ? ((TileGeneric) tile).getRedstoneOutput( oppositeSide.getOpposite() ) : 0;
{
return ((TileGeneric) tile).getRedstoneOutput( oppositeSide.getOpposite() );
}
return 0;
} }
@Override @Override
@ -114,11 +110,7 @@ public abstract class BlockGeneric extends Block implements ITileEntityProvider
public int getBundledRedstoneOutput( World world, BlockPos pos, EnumFacing side ) public int getBundledRedstoneOutput( World world, BlockPos pos, EnumFacing side )
{ {
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile instanceof TileGeneric && tile.hasWorld() ) return tile instanceof TileGeneric && tile.hasWorld() ? ((TileGeneric) tile).getBundledRedstoneOutput( side ) : 0;
{
return ((TileGeneric) tile).getBundledRedstoneOutput( side );
}
return 0;
} }
@Nonnull @Nonnull

View File

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

View File

@ -130,7 +130,6 @@ public abstract class TileGeneric extends TileEntity
@Override @Override
public final SPacketUpdateTileEntity getUpdatePacket() public final SPacketUpdateTileEntity getUpdatePacket()
{ {
// Communicate properties
NBTTagCompound nbt = new NBTTagCompound(); NBTTagCompound nbt = new NBTTagCompound();
writeDescription( nbt ); writeDescription( nbt );
return new SPacketUpdateTileEntity( getPos(), 0, 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 net.minecraft.world.World;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -67,38 +68,30 @@ public class CommandAPI implements ILuaAPI
private static Map<Object, Object> createOutput( String output ) private static Map<Object, Object> createOutput( String output )
{ {
Map<Object, Object> result = new HashMap<>( 1 ); return Collections.singletonMap( 1, output );
result.put( 1, output );
return result;
} }
private Object[] doCommand( String command ) private Object[] doCommand( String command )
{ {
MinecraftServer server = m_computer.getWorld().getMinecraftServer(); MinecraftServer server = m_computer.getWorld().getMinecraftServer();
if( server != null && server.isCommandBlockEnabled() ) 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
{ {
return new Object[] { false, createOutput( "Command blocks disabled by server" ) }; 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 ) private static Object getBlockInfo( World world, BlockPos pos )
@ -120,7 +113,7 @@ public class CommandAPI implements ILuaAPI
table.put( "state", stateTable ); table.put( "state", stateTable );
TileEntity tile = world.getTileEntity( pos ); 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; return table;
} }

View File

@ -9,6 +9,7 @@ package dan200.computercraft.shared.computer.blocks;
import dan200.computercraft.ComputerCraft; import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.items.ComputerItemFactory; import dan200.computercraft.shared.computer.items.ComputerItemFactory;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.properties.PropertyEnum;
@ -28,7 +29,7 @@ public class BlockCommandComputer extends BlockComputerBase
public static final class Properties 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 ); 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.ComputerCraft;
import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.items.ComputerItemFactory; import dan200.computercraft.shared.computer.items.ComputerItemFactory;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.properties.PropertyDirection;
@ -28,7 +29,7 @@ public class BlockComputer extends BlockComputerBase
// Statics // Statics
public static final class Properties 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 PropertyBool ADVANCED = PropertyBool.create( "advanced" );
public static final PropertyEnum<ComputerState> STATE = PropertyEnum.create( "state", ComputerState.class ); 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 ) ); 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 ); TileEntity tile = world.getTileEntity( pos );
if( tile instanceof TileComputerBase ) if( tile instanceof TileComputerBase ) ((TileComputerBase) tile).updateInput();
{
TileComputerBase computer = (TileComputerBase) tile;
computer.updateInput();
}
} }
@Override @Override

View File

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

View File

@ -9,7 +9,6 @@ package dan200.computercraft.shared.computer.recipe;
import dan200.computercraft.shared.computer.items.IComputerItem; import dan200.computercraft.shared.computer.items.IComputerItem;
import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.item.crafting.ShapedRecipes; import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.crafting.CraftingHelper; import net.minecraftforge.common.crafting.CraftingHelper;
@ -27,47 +26,30 @@ public abstract class ComputerConvertRecipe extends ShapedRecipes
} }
@Nonnull @Nonnull
protected abstract ItemStack convert( IComputerItem item, @Nonnull ItemStack stack ); protected abstract ItemStack convert( @Nonnull IComputerItem item, @Nonnull ItemStack stack );
@Override @Override
public boolean matches( @Nonnull InventoryCrafting inventory, @Nonnull World world ) public boolean matches( @Nonnull InventoryCrafting inventory, @Nonnull World world )
{ {
// See if we match the recipe, and extract the input computercraft ID if( !super.matches( inventory, world ) ) return false;
ItemStack computerStack = null;
for( int y = 0; y < 3; y++ ) for( int i = 0; i < inventory.getSizeInventory(); i++ )
{ {
for( int x = 0; x < 3; x++ ) if( inventory.getStackInSlot( i ).getItem() instanceof IComputerItem ) return true;
{
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;
}
} }
return computerStack != null; return false;
} }
@Nonnull @Nonnull
@Override @Override
public ItemStack getCraftingResult( @Nonnull InventoryCrafting inventory ) 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.getStackInSlot( i );
{ if( stack.getItem() instanceof IComputerItem ) return convert( (IComputerItem) stack.getItem(), stack );
ItemStack stack = inventory.getStackInRowAndColumn( x, y );
// If we're a computer, convert!
if( stack.getItem() instanceof IComputerItem )
{
return convert( (IComputerItem) stack.getItem(), stack );
}
}
} }
return ItemStack.EMPTY; return ItemStack.EMPTY;

View File

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

View File

@ -24,13 +24,13 @@ public class PartAdvancedModem implements IMultipart
@Override @Override
public IPartSlot getSlotForPlacement( World world, BlockPos pos, IBlockState state, EnumFacing facing, float hitX, float hitY, float hitZ, EntityLivingBase placer ) 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 @Override
public IPartSlot getSlotFromWorld( IBlockAccess world, BlockPos pos, IBlockState state ) 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 @Override

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -10,6 +10,7 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable; import net.minecraft.util.IStringSerializable;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public enum BlockCableModemVariant implements IStringSerializable public enum BlockCableModemVariant implements IStringSerializable
{ {
@ -39,25 +40,7 @@ public enum BlockCableModemVariant implements IStringSerializable
WestOnPeripheral( "west_on_peripheral", EnumFacing.WEST ), WestOnPeripheral( "west_on_peripheral", EnumFacing.WEST ),
EastOnPeripheral( "east_on_peripheral", EnumFacing.EAST ); EastOnPeripheral( "east_on_peripheral", EnumFacing.EAST );
public static BlockCableModemVariant fromFacing( EnumFacing facing ) private static final BlockCableModemVariant[] VALUES = values();
{
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 final String name; private final String name;
private final EnumFacing facing; private final EnumFacing facing;
@ -68,6 +51,19 @@ public enum BlockCableModemVariant implements IStringSerializable
this.facing = facing; 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 @Nonnull
@Override @Override
public String getName() public String getName()

View File

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

View File

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

View File

@ -74,7 +74,7 @@ public class ItemCable extends ItemPeripheralBase
{ {
if( !stack.isEmpty() ) if( !stack.isEmpty() )
{ {
IBlockState newState = existingState.withProperty( BlockCable.Properties.CABLE, true ); IBlockState newState = existingState.withProperty( BlockCable.CABLE, true );
world.setBlockState( pos, newState, 3 ); world.setBlockState( pos, newState, 3 );
SoundType soundType = newState.getBlock().getSoundType( newState, world, pos, player ); 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 ); 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() ) 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 ); world.setBlockState( offset, newState, 3 );
SoundType soundType = newState.getBlock().getSoundType( newState, world, offset, player ); 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 ); 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() ) if( !stack.isEmpty() )
{ {
IBlockState newState = offsetExistingState.withProperty( BlockCable.Properties.CABLE, true ); IBlockState newState = offsetExistingState.withProperty( BlockCable.CABLE, true );
world.setBlockState( offset, newState, 3 ); world.setBlockState( offset, newState, 3 );
SoundType soundType = newState.getBlock().getSoundType( newState, world, offset, player ); 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 ); 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() private EnumFacing getDirection()
{ {
IBlockState state = getBlockState(); IBlockState state = getBlockState();
EnumFacing facing = state.getValue( BlockCable.Properties.MODEM ).getFacing(); EnumFacing facing = state.getValue( BlockCable.MODEM ).getFacing();
return facing != null ? facing : EnumFacing.NORTH; return facing != null ? facing : EnumFacing.NORTH;
} }
@ -183,24 +183,20 @@ public class TileCable extends TileGeneric implements IPeripheralTile
switch( getPeripheralType() ) switch( getPeripheralType() )
{ {
case WiredModem: case WiredModem:
{
// Drop everything and remove block // Drop everything and remove block
getBlock().dropBlockAsItem( getWorld(), getPos(), getBlockState(), 0 ); getBlockType().dropBlockAsItem( getWorld(), getPos(), getBlockState(), 0 );
getWorld().setBlockToAir( getPos() ); getWorld().setBlockToAir( getPos() );
// This'll call #destroy(), so we don't need to reset the network here. // This'll call #destroy(), so we don't need to reset the network here.
return; return;
}
case WiredModemWithCable: case WiredModemWithCable:
{
// Drop the modem and convert to cable // Drop the modem and convert to cable
Block.spawnAsEntity( getWorld(), getPos(), PeripheralItemFactory.create( PeripheralType.WiredModem, null, 1 ) ); 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(); modemChanged();
connectionsChanged(); connectionsChanged();
return; return;
}
} }
} }
@ -227,42 +223,34 @@ public class TileCable extends TileGeneric implements IPeripheralTile
@Override @Override
public boolean onActivate( EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ ) public boolean onActivate( EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ )
{ {
if( getPeripheralType() == PeripheralType.WiredModemWithCable && !player.isSneaking() ) if( getPeripheralType() != PeripheralType.WiredModemWithCable || player.isSneaking() ) return false;
{
if( !getWorld().isRemote )
{
// On server, we interacted if a peripheral was found
String oldPeriphName = m_peripheral.getConnectedName();
togglePeripheralAccess();
String periphName = m_peripheral.getConnectedName();
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",
player.sendMessage( CommandCopy.createCopyText( oldName ) )
new TextComponentTranslation( "chat.computercraft.wired_modem.peripheral_disconnected", );
CommandCopy.createCopyText( oldPeriphName ) ) }
); if( newName != null )
} {
if( periphName != null ) player.sendMessage(
{ new TextComponentTranslation( "chat.computercraft.wired_modem.peripheral_connected",
player.sendMessage( CommandCopy.createCopyText( newName ) )
new TextComponentTranslation( "chat.computercraft.wired_modem.peripheral_connected", );
CommandCopy.createCopyText( periphName ) )
);
}
return true;
} }
} }
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 @Override
@ -279,10 +267,9 @@ public class TileCable extends TileGeneric implements IPeripheralTile
public NBTTagCompound writeToNBT( NBTTagCompound nbt ) public NBTTagCompound writeToNBT( NBTTagCompound nbt )
{ {
// Write properties // Write properties
nbt = super.writeToNBT( nbt );
nbt.setBoolean( "peripheralAccess", m_peripheralAccessAllowed ); nbt.setBoolean( "peripheralAccess", m_peripheralAccessAllowed );
m_peripheral.writeNBT( nbt, "" ); m_peripheral.writeNBT( nbt, "" );
return nbt; return super.writeToNBT( nbt );
} }
@Override @Override
@ -320,27 +307,26 @@ public class TileCable extends TileGeneric implements IPeripheralTile
@Override @Override
protected void updateTick() 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(); connectionsChanged();
if( m_peripheralAccessAllowed )
if( !m_connectionsFormed )
{ {
m_connectionsFormed = true; m_peripheral.attach( world, pos, modemDirection );
updateConnectedPeripherals();
connectionsChanged();
if( m_peripheralAccessAllowed )
{
m_peripheral.attach( world, pos, modemDirection );
updateConnectedPeripherals();
}
} }
} }
} }
public void connectionsChanged() void connectionsChanged()
{ {
if( getWorld().isRemote ) return; if( getWorld().isRemote ) return;
@ -368,7 +354,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile
} }
} }
public void modemChanged() void modemChanged()
{ {
if( getWorld().isRemote ) return; if( getWorld().isRemote ) return;
@ -383,7 +369,6 @@ public class TileCable extends TileGeneric implements IPeripheralTile
} }
} }
// private stuff
private void togglePeripheralAccess() private void togglePeripheralAccess()
{ {
if( !m_peripheralAccessAllowed ) if( !m_peripheralAccessAllowed )

View File

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

View File

@ -30,6 +30,9 @@ import java.util.Map;
*/ */
public final class WiredModemLocalPeripheral public final class WiredModemLocalPeripheral
{ {
private static final String NBT_PERIPHERAL_TYPE = "peripheralType";
private static final String NBT_PERIPHERAL_ID = "peripheralID";
private int id; private int id;
private String type; private String type;
@ -115,17 +118,17 @@ public final class WiredModemLocalPeripheral
public void writeNBT( @Nonnull NBTTagCompound tag, @Nonnull String suffix ) public void writeNBT( @Nonnull NBTTagCompound tag, @Nonnull String suffix )
{ {
if( id >= 0 ) tag.setInteger( "peripheralID" + suffix, id ); if( id >= 0 ) tag.setInteger( NBT_PERIPHERAL_TYPE + suffix, id );
if( type != null ) tag.setString( "peripheralType" + suffix, type ); if( type != null ) tag.setString( NBT_PERIPHERAL_TYPE + suffix, type );
} }
public void readNBT( @Nonnull NBTTagCompound tag, @Nonnull String suffix ) public void readNBT( @Nonnull NBTTagCompound tag, @Nonnull String suffix )
{ {
id = tag.hasKey( "peripheralID" + suffix, Constants.NBT.TAG_ANY_NUMERIC ) id = tag.hasKey( NBT_PERIPHERAL_ID + suffix, Constants.NBT.TAG_ANY_NUMERIC )
? tag.getInteger( "peripheralID" + suffix ) : -1; ? tag.getInteger( NBT_PERIPHERAL_ID + suffix ) : -1;
type = tag.hasKey( "peripheralType" + suffix, Constants.NBT.TAG_STRING ) type = tag.hasKey( NBT_PERIPHERAL_TYPE + suffix, Constants.NBT.TAG_STRING )
? tag.getString( "peripheralType" + suffix ) : null; ? tag.getString( NBT_PERIPHERAL_TYPE + suffix ) : null;
} }
private static IPeripheral getPeripheralFrom( World world, BlockPos pos, EnumFacing direction ) 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 class BlockAdvancedModem extends BlockGeneric
{ {
public static final class Properties public static final PropertyDirection FACING = BlockDirectional.FACING;
{ private static final PropertyBool ON = PropertyBool.create( "on" );
public static final PropertyDirection FACING = BlockDirectional.FACING;
public static final PropertyBool ON = PropertyBool.create( "on" );
}
public BlockAdvancedModem() public BlockAdvancedModem()
{ {
@ -42,8 +39,8 @@ public class BlockAdvancedModem extends BlockGeneric
setTranslationKey( "computercraft:advanced_modem" ); setTranslationKey( "computercraft:advanced_modem" );
setCreativeTab( ComputerCraft.mainCreativeTab ); setCreativeTab( ComputerCraft.mainCreativeTab );
setDefaultState( blockState.getBaseState() setDefaultState( blockState.getBaseState()
.withProperty( Properties.FACING, EnumFacing.NORTH ) .withProperty( FACING, EnumFacing.NORTH )
.withProperty( Properties.ON, false ) .withProperty( ON, false )
); );
} }
@ -51,7 +48,7 @@ public class BlockAdvancedModem extends BlockGeneric
@Override @Override
protected BlockStateContainer createBlockState() protected BlockStateContainer createBlockState()
{ {
return new BlockStateContainer( this, Properties.FACING, Properties.ON ); return new BlockStateContainer( this, FACING, ON );
} }
@Nonnull @Nonnull
@ -59,13 +56,13 @@ public class BlockAdvancedModem extends BlockGeneric
@Deprecated @Deprecated
public IBlockState getStateFromMeta( int meta ) public IBlockState getStateFromMeta( int meta )
{ {
return getDefaultState().withProperty( Properties.FACING, EnumFacing.byIndex( meta ) ); return getDefaultState().withProperty( FACING, EnumFacing.byIndex( meta ) );
} }
@Override @Override
public int getMetaFromState( IBlockState state ) public int getMetaFromState( IBlockState state )
{ {
return state.getValue( Properties.FACING ).getIndex(); return state.getValue( FACING ).getIndex();
} }
@Nonnull @Nonnull
@ -74,7 +71,7 @@ public class BlockAdvancedModem extends BlockGeneric
public IBlockState getActualState( @Nonnull IBlockState state, IBlockAccess world, BlockPos pos ) public IBlockState getActualState( @Nonnull IBlockState state, IBlockAccess world, BlockPos pos )
{ {
TileEntity tile = world.getTileEntity( 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 @Nonnull
@ -82,7 +79,7 @@ public class BlockAdvancedModem extends BlockGeneric
@Deprecated @Deprecated
public IBlockState getStateForPlacement( World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer ) 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 @Override
@ -124,6 +121,6 @@ public class BlockAdvancedModem extends BlockGeneric
@Deprecated @Deprecated
public AxisAlignedBB getBoundingBox( IBlockState state, IBlockAccess source, BlockPos pos ) 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 @Override
protected EnumFacing getDirection() 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 // Wireless Modem
IBlockState state = getBlockState(); IBlockState state = getBlockState();
switch( state.getValue( BlockPeripheral.Properties.VARIANT ) ) switch( state.getValue( BlockPeripheral.VARIANT ) )
{ {
case WirelessModemDownOff: case WirelessModemDownOff:
case WirelessModemDownOn: case WirelessModemDownOn:
@ -39,7 +39,7 @@ public class TileWirelessModem extends TileWirelessModemBase implements IDirecti
case WirelessModemUpOn: case WirelessModemUpOn:
return EnumFacing.UP; return EnumFacing.UP;
default: 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 ) if( dir == EnumFacing.UP )
{ {
setBlockState( getBlockState() setBlockState( getBlockState()
.withProperty( BlockPeripheral.Properties.VARIANT, BlockPeripheralVariant.WirelessModemUpOff ) .withProperty( BlockPeripheral.VARIANT, BlockPeripheralVariant.WirelessModemUpOff )
.withProperty( BlockPeripheral.Properties.FACING, EnumFacing.NORTH ) .withProperty( BlockPeripheral.FACING, EnumFacing.NORTH )
); );
} }
else if( dir == EnumFacing.DOWN ) else if( dir == EnumFacing.DOWN )
{ {
setBlockState( getBlockState() setBlockState( getBlockState()
.withProperty( BlockPeripheral.Properties.VARIANT, BlockPeripheralVariant.WirelessModemDownOff ) .withProperty( BlockPeripheral.VARIANT, BlockPeripheralVariant.WirelessModemDownOff )
.withProperty( BlockPeripheral.Properties.FACING, EnumFacing.NORTH ) .withProperty( BlockPeripheral.FACING, EnumFacing.NORTH )
); );
} }
else else
{ {
setBlockState( getBlockState() setBlockState( getBlockState()
.withProperty( BlockPeripheral.Properties.VARIANT, BlockPeripheralVariant.WirelessModemOff ) .withProperty( BlockPeripheral.VARIANT, BlockPeripheralVariant.WirelessModemOff )
.withProperty( BlockPeripheral.Properties.FACING, dir ) .withProperty( BlockPeripheral.FACING, dir )
); );
} }
} }

View File

@ -9,6 +9,8 @@ package dan200.computercraft.shared.peripheral.monitor;
import dan200.computercraft.shared.common.ClientTerminal; import dan200.computercraft.shared.common.ClientTerminal;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.math.BlockPos; 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.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -35,6 +37,7 @@ public class ClientMonitor extends ClientTerminal
return origin; return origin;
} }
@SideOnly( Side.CLIENT )
public void createLists() public void createLists()
{ {
if( renderDisplayLists == null ) if( renderDisplayLists == null )
@ -53,6 +56,7 @@ public class ClientMonitor extends ClientTerminal
} }
} }
@SideOnly( Side.CLIENT )
public void destroy() public void destroy()
{ {
if( renderDisplayLists != null ) if( renderDisplayLists != null )
@ -71,6 +75,7 @@ public class ClientMonitor extends ClientTerminal
} }
} }
@SideOnly( Side.CLIENT )
public static void destroyAll() public static void destroyAll()
{ {
synchronized( allMonitors ) 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 final Set<IComputerAccess> m_computers = Collections.newSetFromMap( new ConcurrentHashMap<>() );
private boolean m_destroyed = false; private boolean m_destroyed = false;
private boolean m_ignoreMe = false; private boolean visiting = false;
private int m_width = 1; private int m_width = 1;
private int m_height = 1; private int m_height = 1;
@ -60,7 +60,7 @@ public class TileMonitor extends TileGeneric implements ITilePeripheral, IPeriph
public void onLoad() public void onLoad()
{ {
super.onLoad(); super.onLoad();
m_advanced = getBlockState().getValue( BlockPeripheral.Properties.VARIANT ) m_advanced = getBlockState().getValue( BlockPeripheral.VARIANT )
.getPeripheralType() == PeripheralType.AdvancedMonitor; .getPeripheralType() == PeripheralType.AdvancedMonitor;
world.scheduleUpdate( getPos(), getBlockType(), 0 ); world.scheduleUpdate( getPos(), getBlockType(), 0 );
} }
@ -68,14 +68,10 @@ public class TileMonitor extends TileGeneric implements ITilePeripheral, IPeriph
@Override @Override
public void destroy() public void destroy()
{ {
if( !m_destroyed ) if( m_destroyed ) return;
{
m_destroyed = true; m_destroyed = true;
if( !getWorld().isRemote ) if( !getWorld().isRemote ) contractNeighbours();
{
contractNeighbours();
}
}
} }
@Override @Override
@ -97,12 +93,10 @@ public class TileMonitor extends TileGeneric implements ITilePeripheral, IPeriph
{ {
if( !player.isSneaking() && getFront() == side ) if( !player.isSneaking() && getFront() == side )
{ {
if( !getWorld().isRemote ) if( !getWorld().isRemote ) monitorTouched( hitX, hitY, hitZ );
{
monitorTouched( hitX, hitY, hitZ );
}
return true; return true;
} }
return false; return false;
} }
@ -110,13 +104,12 @@ public class TileMonitor extends TileGeneric implements ITilePeripheral, IPeriph
@Override @Override
public NBTTagCompound writeToNBT( NBTTagCompound nbt ) public NBTTagCompound writeToNBT( NBTTagCompound nbt )
{ {
nbt = super.writeToNBT( nbt );
nbt.setInteger( "xIndex", m_xIndex ); nbt.setInteger( "xIndex", m_xIndex );
nbt.setInteger( "yIndex", m_yIndex ); nbt.setInteger( "yIndex", m_yIndex );
nbt.setInteger( "width", m_width ); nbt.setInteger( "width", m_width );
nbt.setInteger( "height", m_height ); nbt.setInteger( "height", m_height );
nbt.setInteger( "dir", m_dir ); nbt.setInteger( "dir", m_dir );
return nbt; return super.writeToNBT( nbt );
} }
@Override @Override
@ -193,11 +186,9 @@ public class TileMonitor extends TileGeneric implements ITilePeripheral, IPeriph
private ServerMonitor createServerMonitor() private ServerMonitor createServerMonitor()
{ {
if( m_serverMonitor != null ) if( m_serverMonitor != null ) return m_serverMonitor;
{
return m_serverMonitor; if( m_xIndex == 0 && m_yIndex == 0 )
}
else if( m_xIndex == 0 && m_yIndex == 0 )
{ {
// If we're the origin, set up the new monitor // If we're the origin, set up the new monitor
m_serverMonitor = new ServerMonitor( m_advanced, this ); m_serverMonitor = new ServerMonitor( m_advanced, this );
@ -241,7 +232,7 @@ public class TileMonitor extends TileGeneric implements ITilePeripheral, IPeriph
// Networking stuff // Networking stuff
@Override @Override
public void writeDescription( @Nonnull NBTTagCompound nbt ) protected void writeDescription( @Nonnull NBTTagCompound nbt )
{ {
super.writeDescription( nbt ); super.writeDescription( nbt );
nbt.setInteger( "xIndex", m_xIndex ); nbt.setInteger( "xIndex", m_xIndex );
@ -257,7 +248,7 @@ public class TileMonitor extends TileGeneric implements ITilePeripheral, IPeriph
} }
@Override @Override
public final void readDescription( @Nonnull NBTTagCompound nbt ) protected final void readDescription( @Nonnull NBTTagCompound nbt )
{ {
super.readDescription( nbt ); super.readDescription( nbt );
@ -408,8 +399,8 @@ public class TileMonitor extends TileGeneric implements ITilePeripheral, IPeriph
if( !(tile instanceof TileMonitor) ) return null; if( !(tile instanceof TileMonitor) ) return null;
TileMonitor monitor = (TileMonitor) tile; TileMonitor monitor = (TileMonitor) tile;
return monitor.getDir() == getDir() && monitor.m_advanced == m_advanced && return !monitor.visiting && monitor.getDir() == getDir() && monitor.m_advanced == m_advanced &&
!monitor.m_destroyed && !monitor.m_ignoreMe ? monitor : null; !monitor.m_destroyed ? monitor : null;
} }
private TileMonitor getNeighbour( int x, int y ) private TileMonitor getNeighbour( int x, int y )
@ -550,7 +541,7 @@ public class TileMonitor extends TileGeneric implements ITilePeripheral, IPeriph
public void contractNeighbours() public void contractNeighbours()
{ {
m_ignoreMe = true; visiting = true;
if( m_xIndex > 0 ) if( m_xIndex > 0 )
{ {
TileMonitor left = getNeighbour( m_xIndex - 1, m_yIndex ); 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 ); TileMonitor above = getNeighbour( m_xIndex, m_yIndex + 1 );
if( above != null ) above.contract(); if( above != null ) above.contract();
} }
m_ignoreMe = false; visiting = false;
} }
public void contract() public void contract()

View File

@ -18,7 +18,9 @@ import javax.annotation.Nonnull;
public class ContainerPrinter extends Container 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; private boolean m_lastPrinting;
public ContainerPrinter( IInventory playerInventory, TilePrinter printer ) public ContainerPrinter( IInventory playerInventory, TilePrinter printer )
@ -30,31 +32,22 @@ public class ContainerPrinter extends Container
addSlotToContainer( new Slot( m_printer, 0, 13, 35 ) ); addSlotToContainer( new Slot( m_printer, 0, 13, 35 ) );
// In-tray // In-tray
for( int i = 0; i < 6; i++ ) for( int x = 0; x < 6; x++ ) addSlotToContainer( new Slot( m_printer, x + 1, 61 + x * 18, 22 ) );
{
addSlotToContainer( new Slot( m_printer, i + 1, 61 + i * 18, 22 ) );
}
// Out-tray // Out-tray
for( int i = 0; i < 6; i++ ) for( int x = 0; x < 6; x++ ) addSlotToContainer( new Slot( m_printer, x + 7, 61 + x * 18, 49 ) );
{
addSlotToContainer( new Slot( m_printer, i + 7, 61 + i * 18, 49 ) );
}
// Player inv // 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 // Player hotbar
for( int k = 0; k < 9; k++ ) for( int x = 0; x < 9; x++ ) addSlotToContainer( new Slot( playerInventory, x, 8 + x * 18, 142 ) );
{
addSlotToContainer( new Slot( playerInventory, k, 8 + k * 18, 142 ) );
}
} }
public boolean isPrinting() public boolean isPrinting()
@ -68,10 +61,10 @@ public class ContainerPrinter extends Container
} }
@Override @Override
public void addListener( IContainerListener crafting ) public void addListener( IContainerListener listener )
{ {
super.addListener( crafting ); super.addListener( listener );
crafting.sendWindowProperty( this, 0, m_printer.isPrinting() ? 1 : 0 ); listener.sendWindowProperty( this, PROPERTY_PRINTING, m_printer.isPrinting() ? 1 : 0 );
} }
@Override @Override
@ -82,23 +75,23 @@ public class ContainerPrinter extends Container
if( !m_printer.getWorld().isRemote ) if( !m_printer.getWorld().isRemote )
{ {
boolean printing = m_printer.isPrinting(); 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 @Override
public void updateProgressBar( int i, int j ) public void updateProgressBar( int property, int value )
{ {
if( m_printer.getWorld().isRemote ) 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 // 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 final IItemHandlerModifiable m_itemHandlerAll = new InvWrapper( this );
private IItemHandlerModifiable[] m_itemHandlerSides; private IItemHandlerModifiable[] m_itemHandlerSides;
private final Terminal m_page; private final Terminal m_page = new Terminal( ItemPrintout.LINE_MAX_LENGTH, ItemPrintout.LINES_PER_PAGE );
private String m_pageTitle; private String m_pageTitle = "";
private boolean m_printing; private boolean m_printing = false;
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;
}
@Override @Override
public void destroy() public void destroy()
@ -76,15 +68,10 @@ public class TilePrinter extends TilePeripheralBase implements DefaultSidedInven
@Override @Override
public boolean onActivate( EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ ) public boolean onActivate( EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ )
{ {
if( !player.isSneaking() ) if( player.isSneaking() ) return false;
{
if( !getWorld().isRemote ) if( !getWorld().isRemote ) Containers.openPrinterGUI( player, this );
{ return true;
Containers.openPrinterGUI( player, this );
}
return true;
}
return false;
} }
@Override @Override
@ -108,7 +95,7 @@ public class TilePrinter extends TilePeripheralBase implements DefaultSidedInven
{ {
NBTTagCompound itemTag = nbttaglist.getCompoundTagAt( i ); NBTTagCompound itemTag = nbttaglist.getCompoundTagAt( i );
int j = itemTag.getByte( "Slot" ) & 0xff; 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 ) ); m_inventory.set( j, new ItemStack( itemTag ) );
} }
@ -120,8 +107,6 @@ public class TilePrinter extends TilePeripheralBase implements DefaultSidedInven
@Override @Override
public NBTTagCompound writeToNBT( NBTTagCompound nbt ) public NBTTagCompound writeToNBT( NBTTagCompound nbt )
{ {
nbt = super.writeToNBT( nbt );
// Write page // Write page
synchronized( m_page ) synchronized( m_page )
{ {
@ -147,7 +132,7 @@ public class TilePrinter extends TilePeripheralBase implements DefaultSidedInven
nbt.setTag( "Items", nbttaglist ); nbt.setTag( "Items", nbttaglist );
} }
return nbt; return super.writeToNBT( nbt );
} }
@Override @Override
@ -314,12 +299,12 @@ public class TilePrinter extends TilePeripheralBase implements DefaultSidedInven
{ {
switch( side ) switch( side )
{ {
case DOWN: case DOWN: // Bottom (Out tray)
return bottomSlots; // Bottom (Out tray) return bottomSlots;
case UP: case UP: // Top (In tray)
return topSlots; // Top (In tray) return topSlots;
default: default: // Sides (Ink)
return sideSlots; // Sides (Ink) return sideSlots;
} }
} }
@ -333,11 +318,7 @@ public class TilePrinter extends TilePeripheralBase implements DefaultSidedInven
public Terminal getCurrentPage() public Terminal getCurrentPage()
{ {
if( m_printing ) return m_printing ? m_page : null;
{
return m_page;
}
return null;
} }
public boolean startNewPage() public boolean startNewPage()
@ -430,14 +411,7 @@ public class TilePrinter extends TilePeripheralBase implements DefaultSidedInven
{ {
// Setup the new page // Setup the new page
int colour = inkStack.getItemDamage(); int colour = inkStack.getItemDamage();
if( colour >= 0 && colour < 16 ) m_page.setTextColour( colour >= 0 && colour < 16 ? 15 - colour : 15 );
{
m_page.setTextColour( 15 - colour );
}
else
{
m_page.setTextColour( 15 );
}
m_page.clear(); m_page.clear();
if( paperStack.getItem() instanceof ItemPrintout ) if( paperStack.getItem() instanceof ItemPrintout )

View File

@ -123,8 +123,7 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
@Override @Override
public void updateUpgradeNBTData() public void updateUpgradeNBTData()
{ {
InventoryPlayer inventory = m_entity instanceof EntityPlayer ? ((EntityPlayer) m_entity).inventory : null; if( m_entity instanceof EntityPlayer ) ((EntityPlayer) m_entity).inventory.markDirty();
if( inventory != null ) inventory.markDirty();
} }
@Override @Override
@ -160,7 +159,7 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
synchronized( this ) synchronized( this )
{ {
ItemPocketComputer.setUpgrade( m_stack, upgrade ); ItemPocketComputer.setUpgrade( m_stack, upgrade );
if( m_entity instanceof EntityPlayer ) ((EntityPlayer) m_entity).inventory.markDirty(); updateUpgradeNBTData();
m_upgrade = upgrade; m_upgrade = upgrade;
invalidatePeripheral(); 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_STATE = ( stack, world, player ) -> getState( stack ).ordinal();
private static final IItemPropertyGetter COMPUTER_COLOURED = ( stack, world, player ) -> 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 @Nonnull
public static ItemStack create( int id, String label, int colour, ComputerFamily family, IPocketUpgrade upgrade ) public static ItemStack create( int id, String label, int colour, ComputerFamily family, IPocketUpgrade upgrade )
{ {
ItemPocketComputer computer = ComputerCraft.Items.pocketComputer;
switch( family ) switch( family )
{ {
case Normal: case Normal:
case Advanced: case Advanced:
return computer.create( id, label, colour, family, upgrade ); return ComputerCraft.Items.pocketComputer.create( id, label, colour, family, upgrade );
default: default:
return ItemStack.EMPTY; return ItemStack.EMPTY;
} }

View File

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

View File

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

View File

@ -16,9 +16,9 @@ public class PocketSpeakerPeripheral extends SpeakerPeripheral
private World world = null; private World world = null;
private Vec3d position = Vec3d.ZERO; 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; this.world = world;
} }

View File

@ -57,6 +57,8 @@ public class PocketComputerUpgradeRecipe extends IForgeRegistryEntry.Impl<IRecip
ItemStack computer = ItemStack.EMPTY; ItemStack computer = ItemStack.EMPTY;
int computerX = -1; int computerX = -1;
int computerY = -1; int computerY = -1;
computer:
for( int y = 0; y < inventory.getHeight(); y++ ) for( int y = 0; y < inventory.getHeight(); y++ )
{ {
for( int x = 0; x < inventory.getWidth(); x++ ) for( int x = 0; x < inventory.getWidth(); x++ )
@ -67,25 +69,15 @@ public class PocketComputerUpgradeRecipe extends IForgeRegistryEntry.Impl<IRecip
computer = item; computer = item;
computerX = x; computerX = x;
computerY = y; computerY = y;
break; break computer;
} }
} }
if( !computer.isEmpty() )
{
break;
}
} }
if( computer.isEmpty() ) if( computer.isEmpty() ) return ItemStack.EMPTY;
{
return ItemStack.EMPTY;
}
ItemPocketComputer itemComputer = (ItemPocketComputer) computer.getItem(); ItemPocketComputer itemComputer = (ItemPocketComputer) computer.getItem();
if( itemComputer.getUpgrade( computer ) != null ) if( itemComputer.getUpgrade( computer ) != null ) return ItemStack.EMPTY;
{
return ItemStack.EMPTY;
}
// Check for upgrades around the item // Check for upgrades around the item
IPocketUpgrade upgrade = null; IPocketUpgrade upgrade = null;
@ -108,10 +100,7 @@ public class PocketComputerUpgradeRecipe extends IForgeRegistryEntry.Impl<IRecip
} }
} }
if( upgrade == null ) if( upgrade == null ) return ItemStack.EMPTY;
{
return ItemStack.EMPTY;
}
// Construct the new stack // Construct the new stack
ComputerFamily family = itemComputer.getFamily( computer ); 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 net.minecraftforge.fml.common.registry.EntityRegistry;
import pl.asie.charset.ModCharset; import pl.asie.charset.ModCharset;
public class ComputerCraftProxyCommon implements IComputerCraftProxy public class ComputerCraftProxyCommon
{ {
@Override
public void preInit() public void preInit()
{ {
NetworkHandler.setup(); NetworkHandler.setup();
@ -62,7 +61,6 @@ public class ComputerCraftProxyCommon implements IComputerCraftProxy
); );
} }
@Override
public void init() public void init()
{ {
registerProviders(); registerProviders();
@ -72,8 +70,7 @@ public class ComputerCraftProxyCommon implements IComputerCraftProxy
if( Loader.isModLoaded( ModCharset.MODID ) ) IntegrationCharset.register(); if( Loader.isModLoaded( ModCharset.MODID ) ) IntegrationCharset.register();
} }
@Override public static void initServer( MinecraftServer server )
public void initServer( MinecraftServer server )
{ {
CommandHandler handler = (CommandHandler) server.getCommandManager(); CommandHandler handler = (CommandHandler) server.getCommandManager();
handler.registerCommand( new CommandComputerCraft() ); 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.ITurtleItem;
import dan200.computercraft.shared.turtle.items.TurtleItemFactory; import dan200.computercraft.shared.turtle.items.TurtleItemFactory;
import dan200.computercraft.shared.util.DirectionUtil; import dan200.computercraft.shared.util.DirectionUtil;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockFaceShape; import net.minecraft.block.state.BlockFaceShape;
@ -39,14 +40,7 @@ import javax.annotation.Nonnull;
public class BlockTurtle extends BlockComputerBase public class BlockTurtle extends BlockComputerBase
{ {
// Statics public static final PropertyDirection FACING = BlockHorizontal.FACING;
public static final class Properties
{
public static final PropertyDirection FACING = PropertyDirection.create( "facing", EnumFacing.Plane.HORIZONTAL );
}
// Members
public BlockTurtle() public BlockTurtle()
{ {
@ -55,7 +49,7 @@ public class BlockTurtle extends BlockComputerBase
setTranslationKey( "computercraft:turtle" ); setTranslationKey( "computercraft:turtle" );
setCreativeTab( ComputerCraft.mainCreativeTab ); setCreativeTab( ComputerCraft.mainCreativeTab );
setDefaultState( blockState.getBaseState() setDefaultState( blockState.getBaseState()
.withProperty( Properties.FACING, EnumFacing.NORTH ) .withProperty( FACING, EnumFacing.NORTH )
); );
} }
@ -93,7 +87,7 @@ public class BlockTurtle extends BlockComputerBase
@Override @Override
protected BlockStateContainer createBlockState() protected BlockStateContainer createBlockState()
{ {
return new BlockStateContainer( this, Properties.FACING ); return new BlockStateContainer( this, FACING );
} }
@Nonnull @Nonnull
@ -115,7 +109,7 @@ public class BlockTurtle extends BlockComputerBase
@Deprecated @Deprecated
public IBlockState getActualState( @Nonnull IBlockState state, IBlockAccess world, BlockPos pos ) 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 @Override

View File

@ -290,8 +290,6 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
@Override @Override
public NBTTagCompound writeToNBT( NBTTagCompound nbt ) public NBTTagCompound writeToNBT( NBTTagCompound nbt )
{ {
nbt = super.writeToNBT( nbt );
// Write inventory // Write inventory
NBTTagList nbttaglist = new NBTTagList(); NBTTagList nbttaglist = new NBTTagList();
for( int i = 0; i < INVENTORY_SIZE; i++ ) for( int i = 0; i < INVENTORY_SIZE; i++ )
@ -309,7 +307,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
// Write brain // Write brain
nbt = m_brain.writeToNBT( nbt ); nbt = m_brain.writeToNBT( nbt );
return nbt; return super.writeToNBT( nbt );
} }
@Override @Override
@ -545,14 +543,14 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
// Networking stuff // Networking stuff
@Override @Override
public void writeDescription( @Nonnull NBTTagCompound nbt ) protected void writeDescription( @Nonnull NBTTagCompound nbt )
{ {
super.writeDescription( nbt ); super.writeDescription( nbt );
m_brain.writeDescription( nbt ); m_brain.writeDescription( nbt );
} }
@Override @Override
public void readDescription( @Nonnull NBTTagCompound nbt ) protected void readDescription( @Nonnull NBTTagCompound nbt )
{ {
super.readDescription( nbt ); super.readDescription( nbt );
m_brain.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.inventory.IInventory;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EntitySelectors;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
@ -160,11 +161,11 @@ public class TurtleBrain implements ITurtleAccess
// Read overlay // Read overlay
if( nbt.hasKey( "overlay_mod" ) ) if( nbt.hasKey( "overlay_mod" ) )
{ {
String overlay_mod = nbt.getString( "overlay_mod" ); String overlayMod = nbt.getString( "overlay_mod" );
if( nbt.hasKey( "overlay_path" ) ) if( nbt.hasKey( "overlay_path" ) )
{ {
String overlay_path = nbt.getString( "overlay_path" ); String overlayPath = nbt.getString( "overlay_path" );
m_overlay = new ResourceLocation( overlay_mod, overlay_path ); m_overlay = new ResourceLocation( overlayMod, overlayPath );
} }
else else
{ {
@ -336,9 +337,9 @@ public class TurtleBrain implements ITurtleAccess
// Overlay // Overlay
if( nbt.hasKey( "overlay_mod" ) && nbt.hasKey( "overlay_path" ) ) if( nbt.hasKey( "overlay_mod" ) && nbt.hasKey( "overlay_path" ) )
{ {
String overlay_mod = nbt.getString( "overlay_mod" ); String overlayMod = nbt.getString( "overlay_mod" );
String overlay_path = nbt.getString( "overlay_path" ); String overlayPath = nbt.getString( "overlay_path" );
m_overlay = new ResourceLocation( overlay_mod, overlay_path ); m_overlay = new ResourceLocation( overlayMod, overlayPath );
} }
else else
{ {
@ -988,7 +989,7 @@ public class TurtleBrain implements ITurtleAccess
} }
AxisAlignedBB aabb = new AxisAlignedBB( minX, minY, minZ, maxX, maxY, maxZ ); 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() ) if( !list.isEmpty() )
{ {
double pushStep = 1.0f / ANIM_DURATION; double pushStep = 1.0f / ANIM_DURATION;

View File

@ -105,30 +105,24 @@ public class TurtleCompareCommand implements ITurtleCommand
} }
} }
// Compare them // If they're both empty, obviously the same
if( selectedStack.isEmpty() && lookAtStack.isEmpty() ) 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(); 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 // Create a fake player, and orient it appropriately
BlockPos playerPosition = turtle.getPosition().offset( direction ); BlockPos playerPosition = turtle.getPosition().offset( direction );
TurtlePlayer turtlePlayer = createPlayer( turtle, playerPosition, 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 // 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 ) if( remainder != stack )
{ {
return remainder; return remainder;
@ -129,14 +129,14 @@ public class TurtlePlaceCommand implements ITurtleCommand
// Deploy on the block immediately in front // Deploy on the block immediately in front
BlockPos position = turtle.getPosition(); BlockPos position = turtle.getPosition();
BlockPos newPosition = position.offset( direction ); 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 ) if( remainder != stack )
{ {
return remainder; return remainder;
} }
// Deploy on the block one block away // 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 ) if( remainder != stack )
{ {
return remainder; return remainder;
@ -145,7 +145,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
if( direction.getAxis() != EnumFacing.Axis.Y ) if( direction.getAxis() != EnumFacing.Axis.Y )
{ {
// Deploy down on the block in front // 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 ) if( remainder != stack )
{ {
return remainder; return remainder;
@ -153,7 +153,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
} }
// Deploy back onto the turtle // 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 ) if( remainder != stack )
{ {
return remainder; return remainder;
@ -206,7 +206,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
} }
@Nonnull @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 // See if there is an entity present
final World world = turtle.getWorld(); 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(); World world = turtle.getWorld();
if( !world.isValid( position ) || world.isAirBlock( position ) || if( !world.isValid( position ) || world.isAirBlock( position ) ||
@ -311,7 +311,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
: TurtlePermissions.isBlockEditable( world, position.offset( side ), player ); : TurtlePermissions.isBlockEditable( world, position.offset( side ), player );
if( !editable ) 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; return false;
} }
} }
@ -321,19 +321,19 @@ public class TurtlePlaceCommand implements ITurtleCommand
} }
@Nonnull @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 // Re-orient the fake player
EnumFacing playerDir = side.getOpposite(); EnumFacing playerDir = side.getOpposite();
BlockPos playerPosition = position.offset( side ); BlockPos playerPosition = position.offset( side );
orientPlayer( turtle, turtlePlayer, playerPosition, playerDir ); 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 // Calculate where the turtle would hit the block
float hitX = 0.5f + side.getXOffset() * 0.5f; float hitX = 0.5f + side.getXOffset() * 0.5f;
float hitY = 0.5f + side.getYOffset() * 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_turtleInvStartX = turtleInvStartX;
m_turtle = turtle; m_turtle = turtle;
if( !m_turtle.getWorld().isRemote ) m_selectedSlot = m_turtle.getWorld().isRemote ? 0 : m_turtle.getSelectedSlot();
{
m_selectedSlot = m_turtle.getSelectedSlot();
}
else
{
m_selectedSlot = 0;
}
// Turtle inventory // Turtle inventory
for( int y = 0; y < 4; y++ ) for( int y = 0; y < 4; y++ )
@ -139,7 +132,7 @@ public class ContainerTurtle extends Container implements IContainerComputer
} }
@Nonnull @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 ); Slot slot = inventorySlots.get( slotNum );
ItemStack originalStack = ItemStack.EMPTY; ItemStack originalStack = ItemStack.EMPTY;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -18,7 +18,7 @@ public class CreativeTabMain extends CreativeTabs
{ {
public CreativeTabMain( int i ) public CreativeTabMain( int i )
{ {
super( i, "CC: Tweaked" ); super( i, ComputerCraft.MOD_ID );
} }
@Nonnull @Nonnull
@ -28,12 +28,4 @@ public class CreativeTabMain extends CreativeTabs
{ {
return new ItemStack( ComputerCraft.Blocks.computer ); 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 @Nonnull
@Override @Override
public ItemStack getCraftingResult( @Nonnull InventoryCrafting _inventory ) public ItemStack getCraftingResult( @Nonnull InventoryCrafting inventory )
{ {
return ItemStack.EMPTY; return ItemStack.EMPTY;
} }

View File

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

View File

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

View File

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

View File

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

View File

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