2013-12-27 23:59:59 +01:00
|
|
|
package appeng.tile.networking;
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.io.IOException;
|
2014-02-02 08:32:10 +01:00
|
|
|
import java.util.EnumSet;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-03-28 05:31:37 +01:00
|
|
|
import appeng.api.implementations.IPowerChannelState;
|
2014-03-25 18:13:34 +01:00
|
|
|
import appeng.api.implementations.tiles.IWirelessAccessPoint;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.networking.GridFlags;
|
2014-03-25 18:13:34 +01:00
|
|
|
import appeng.api.networking.IGrid;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.networking.events.MENetworkChannelsChanged;
|
|
|
|
import appeng.api.networking.events.MENetworkEventSubscribe;
|
|
|
|
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
|
|
|
import appeng.api.util.AECableType;
|
|
|
|
import appeng.api.util.DimensionalCoord;
|
2014-02-09 06:08:27 +01:00
|
|
|
import appeng.core.AEConfig;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.me.GridAccessException;
|
|
|
|
import appeng.tile.events.AETileEventHandler;
|
|
|
|
import appeng.tile.events.TileEventType;
|
|
|
|
import appeng.tile.grid.AENetworkInvTile;
|
|
|
|
import appeng.tile.inventory.AppEngInternalInventory;
|
|
|
|
import appeng.tile.inventory.InvOperation;
|
2014-03-28 05:31:37 +01:00
|
|
|
import appeng.util.Platform;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-03-28 05:31:37 +01:00
|
|
|
public class TileWireless extends AENetworkInvTile implements IWirelessAccessPoint, IPowerChannelState
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
public static final int POWERED_FLAG = 1;
|
|
|
|
public static final int CHANNEL_FLAG = 2;
|
|
|
|
|
|
|
|
final int sides[] = new int[] { 0 };
|
|
|
|
AppEngInternalInventory inv = new AppEngInternalInventory( this, 1 );
|
|
|
|
|
|
|
|
public int clientFlags = 0;
|
|
|
|
|
|
|
|
public TileWireless() {
|
2014-01-31 22:12:15 +01:00
|
|
|
gridProxy.setFlags( GridFlags.REQUIRE_CHANNEL );
|
2014-02-02 08:32:10 +01:00
|
|
|
gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
addNewHandler( new TileWirelessHandler() );
|
|
|
|
}
|
|
|
|
|
2014-02-02 08:32:10 +01:00
|
|
|
@Override
|
|
|
|
public void setOrientation(ForgeDirection inForward, ForgeDirection inUp)
|
|
|
|
{
|
|
|
|
super.setOrientation( inForward, inUp );
|
|
|
|
gridProxy.setValidSides( EnumSet.of( getForward().getOpposite() ) );
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@MENetworkEventSubscribe
|
|
|
|
public void chanRender(MENetworkChannelsChanged c)
|
|
|
|
{
|
|
|
|
markForUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
@MENetworkEventSubscribe
|
|
|
|
public void powerRender(MENetworkPowerStatusChange c)
|
|
|
|
{
|
|
|
|
markForUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
class TileWirelessHandler extends AETileEventHandler
|
|
|
|
{
|
|
|
|
|
|
|
|
public TileWirelessHandler() {
|
2014-01-26 07:46:16 +01:00
|
|
|
super( TileEventType.NETWORK );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public boolean readFromStream(ByteBuf data) throws IOException
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
boolean eh = super.readFromStream( data );
|
|
|
|
|
|
|
|
int old = clientFlags;
|
|
|
|
clientFlags = data.readByte();
|
|
|
|
|
|
|
|
return eh || old != clientFlags;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public void writeToStream(ByteBuf data) throws IOException
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
clientFlags = 0;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if ( gridProxy.getEnergy().isNetworkPowered() )
|
|
|
|
clientFlags |= POWERED_FLAG;
|
|
|
|
|
|
|
|
if ( gridProxy.getNode().meetsChannelRequirements() )
|
|
|
|
clientFlags |= CHANNEL_FLAG;
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
// meh
|
|
|
|
}
|
|
|
|
|
|
|
|
data.writeByte( (byte) clientFlags );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public AECableType getCableConnectionType(ForgeDirection dir)
|
|
|
|
{
|
|
|
|
return AECableType.SMART;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public DimensionalCoord getLocation()
|
|
|
|
{
|
|
|
|
return new DimensionalCoord( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IInventory getInternalInventory()
|
|
|
|
{
|
|
|
|
return inv;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReady()
|
|
|
|
{
|
|
|
|
updatePower();
|
|
|
|
super.onReady();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public void markDirty()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
updatePower();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updatePower()
|
|
|
|
{
|
2014-02-09 06:08:27 +01:00
|
|
|
gridProxy.setIdlePowerUsage( AEConfig.instance.wireless_getPowerDrain( getBoosters() ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-03-14 03:59:37 +01:00
|
|
|
public int[] getAccessibleSlotsBySide(ForgeDirection side)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return sides;
|
|
|
|
}
|
|
|
|
|
2014-03-25 18:13:34 +01:00
|
|
|
@Override
|
2014-02-04 05:23:14 +01:00
|
|
|
public double getRange()
|
|
|
|
{
|
2014-02-09 06:08:27 +01:00
|
|
|
return AEConfig.instance.wireless_getMaxRange( getBoosters() );
|
2014-02-04 05:23:14 +01:00
|
|
|
}
|
2014-03-28 05:31:37 +01:00
|
|
|
|
2014-03-25 18:13:34 +01:00
|
|
|
@Override
|
|
|
|
public boolean isActive()
|
|
|
|
{
|
2014-03-28 05:31:37 +01:00
|
|
|
if ( Platform.isClient() )
|
|
|
|
return isPowered() && (CHANNEL_FLAG == (clientFlags & CHANNEL_FLAG));
|
|
|
|
|
2014-03-25 18:13:34 +01:00
|
|
|
return gridProxy.isActive();
|
|
|
|
}
|
2014-03-28 05:31:37 +01:00
|
|
|
|
2014-03-25 18:13:34 +01:00
|
|
|
@Override
|
|
|
|
public IGrid getGrid()
|
|
|
|
{
|
2014-03-28 05:31:37 +01:00
|
|
|
try
|
|
|
|
{
|
2014-03-25 18:13:34 +01:00
|
|
|
return gridProxy.getGrid();
|
2014-03-28 05:31:37 +01:00
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
2014-03-25 18:13:34 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2014-03-28 05:31:37 +01:00
|
|
|
|
2014-02-04 05:23:14 +01:00
|
|
|
private int getBoosters()
|
|
|
|
{
|
|
|
|
ItemStack boosters = inv.getStackInSlot( 0 );
|
|
|
|
return boosters == null ? 0 : boosters.stackSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added)
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
|
2014-03-28 05:31:37 +01:00
|
|
|
@Override
|
|
|
|
public boolean isPowered()
|
|
|
|
{
|
|
|
|
return POWERED_FLAG == (clientFlags & POWERED_FLAG);
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|