Skip to content

Commit

Permalink
Add full block wired modems
Browse files Browse the repository at this point in the history
These act similarly to conventional wired modems, but with the advantage
that they are a full block. This means they can be attached to
peripherals which are not solid (such as chests). Further more, as they
do not have a direction, they allow wrapping peripherals on all 6 sides.

It's worth noting that wired modems do not require a cable - they will
automatically form connections to adjacent network elements when placed.
  • Loading branch information
SquidDev committed Feb 21, 2018
1 parent 5c7828d commit 922f424
Show file tree
Hide file tree
Showing 18 changed files with 618 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/main/java/dan200/computercraft/ComputerCraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import dan200.computercraft.shared.network.PacketHandler;
import dan200.computercraft.shared.peripheral.common.BlockCable;
import dan200.computercraft.shared.peripheral.common.BlockPeripheral;
import dan200.computercraft.shared.peripheral.common.BlockWiredModemFull;
import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive;
import dan200.computercraft.shared.peripheral.modem.BlockAdvancedModem;
import dan200.computercraft.shared.peripheral.modem.WirelessNetwork;
Expand Down Expand Up @@ -180,6 +181,7 @@ public static class Blocks
public static BlockTurtle turtleAdvanced;
public static BlockCommandComputer commandComputer;
public static BlockAdvancedModem advancedModem;
public static BlockWiredModemFull wiredModemFull;
}

public static class Items
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public ModelResourceLocation getModelLocation( @Nonnull ItemStack stack )
registerItemModel( ComputerCraft.Blocks.commandComputer, "command_computer" );
registerItemModel( ComputerCraft.Blocks.advancedModem, "advanced_modem" );
registerItemModel( ComputerCraft.Blocks.peripheral, 5, "speaker" );
registerItemModel( ComputerCraft.Blocks.wiredModemFull, "wired_modem_full" );

registerItemModel( ComputerCraft.Items.disk, "disk" );
registerItemModel( ComputerCraft.Items.diskExpanded, "disk_expanded" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public enum PeripheralType implements IStringSerializable
Cable( "cable" ),
WiredModemWithCable( "wired_modem_with_cable" ),
AdvancedModem( "advanced_modem" ),
Speaker( "speaker" );
Speaker( "speaker" ),
WiredModemFull( "wired_modem_full" );

private String m_name;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2017. Do not distribute without permission.
* Send enquiries to [email protected]
*/

package dan200.computercraft.shared.peripheral.common;

import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.peripheral.PeripheralType;
import dan200.computercraft.shared.peripheral.modem.TileWiredModemFull;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;

import javax.annotation.Nonnull;

public class BlockWiredModemFull extends BlockPeripheralBase
{
// Statics

public static class Properties
{
public static final PropertyBool MODEM_ON = PropertyBool.create( "modem" );
public static final PropertyBool PERIPHERAL_ON = PropertyBool.create( "peripheral" );
}

// Members

public BlockWiredModemFull()
{
setHardness( 1.5f );
setUnlocalizedName( "computercraft:wired_modem_full" );
setCreativeTab( ComputerCraft.mainCreativeTab );
setDefaultState( blockState.getBaseState()
.withProperty( Properties.MODEM_ON, false )
.withProperty( Properties.PERIPHERAL_ON, false )
);
}

@Override
protected IBlockState getDefaultBlockState( PeripheralType type, EnumFacing placedSide )
{
return getDefaultState();
}

@Nonnull
@Override
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer( this,
Properties.MODEM_ON,
Properties.PERIPHERAL_ON
);
}

@Override
public int getMetaFromState( IBlockState state )
{
return 0;
}

@Nonnull
@Override
@Deprecated
public IBlockState getActualState( @Nonnull IBlockState state, IBlockAccess world, BlockPos pos )
{
TileEntity te = world.getTileEntity( pos );
if( te instanceof TileWiredModemFull )
{
TileWiredModemFull modem = (TileWiredModemFull) te;
int anim = modem.getAnim();
state = state
.withProperty( Properties.MODEM_ON, (anim & 1) != 0 )
.withProperty( Properties.PERIPHERAL_ON, (anim & 2) != 0 );
}

return state;
}

@Override
public PeripheralType getPeripheralType( int damage )
{
return PeripheralType.WiredModemFull;
}

@Override
public PeripheralType getPeripheralType( IBlockState state )
{
return PeripheralType.WiredModemFull;
}

@Override
public TilePeripheralBase createTile( PeripheralType type )
{
return new TileWiredModemFull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -102,6 +102,8 @@ public String getUnlocalizedName( @Nonnull ItemStack stack )
{
return "tile.computercraft:speaker";
}
case WiredModemFull:
return "tile.computercraft:wired_modem";
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package dan200.computercraft.shared.peripheral.common;

import dan200.computercraft.shared.peripheral.PeripheralType;
import net.minecraft.block.Block;

public class ItemWiredModemFull extends ItemPeripheralBase
{
public ItemWiredModemFull( Block block )
{
super( block );
}

@Override
public PeripheralType getPeripheralType( int damage )
{
return PeripheralType.WiredModemFull;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public static ItemStack create( PeripheralType type, String label, int quantity
{
return advancedModem.create( type, label, quantity );
}
case WiredModemFull:
return new ItemStack( ComputerCraft.Blocks.wiredModemFull, quantity );
}
return ItemStack.EMPTY;
}
Expand Down
Loading

0 comments on commit 922f424

Please sign in to comment.