2014-02-03 05:33:50 +01:00
|
|
|
package appeng.helpers;
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.world.World;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-02-03 06:02:54 +01:00
|
|
|
import appeng.api.AEApi;
|
2014-02-03 05:33:50 +01:00
|
|
|
import appeng.api.config.AccessRestriction;
|
|
|
|
import appeng.api.config.Actionable;
|
|
|
|
import appeng.api.config.PowerMultiplier;
|
|
|
|
import appeng.api.features.IWirelessTermHandler;
|
|
|
|
import appeng.api.implementations.guiobjects.IPortableCell;
|
2014-03-25 18:13:34 +01:00
|
|
|
import appeng.api.implementations.tiles.IWirelessAccessPoint;
|
2014-02-03 05:33:50 +01:00
|
|
|
import appeng.api.networking.IGrid;
|
2014-02-03 06:02:54 +01:00
|
|
|
import appeng.api.networking.IGridHost;
|
|
|
|
import appeng.api.networking.IGridNode;
|
2014-02-04 05:23:14 +01:00
|
|
|
import appeng.api.networking.IMachineSet;
|
2014-02-03 05:33:50 +01:00
|
|
|
import appeng.api.networking.security.BaseActionSource;
|
2014-05-24 06:20:56 +02:00
|
|
|
import appeng.api.networking.security.IActionHost;
|
2014-02-03 05:33:50 +01:00
|
|
|
import appeng.api.networking.storage.IStorageGrid;
|
|
|
|
import appeng.api.storage.IMEMonitor;
|
2014-02-12 17:35:42 +01:00
|
|
|
import appeng.api.storage.IMEMonitorHandlerReceiver;
|
2014-02-03 05:33:50 +01:00
|
|
|
import appeng.api.storage.StorageChannel;
|
|
|
|
import appeng.api.storage.data.IAEFluidStack;
|
|
|
|
import appeng.api.storage.data.IAEItemStack;
|
|
|
|
import appeng.api.storage.data.IItemList;
|
2014-05-24 06:20:56 +02:00
|
|
|
import appeng.api.util.AECableType;
|
2014-03-25 18:13:34 +01:00
|
|
|
import appeng.api.util.DimensionalCoord;
|
2014-02-17 01:50:25 +01:00
|
|
|
import appeng.api.util.IConfigManager;
|
2014-02-04 05:23:14 +01:00
|
|
|
import appeng.tile.networking.TileWireless;
|
2014-02-03 05:33:50 +01:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
public class WirelessTerminalGuiObject implements IPortableCell, IActionHost
|
2014-02-03 05:33:50 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
IWirelessTermHandler wth;
|
|
|
|
String encryptionKey;
|
|
|
|
|
|
|
|
IGrid targetGrid;
|
|
|
|
IStorageGrid sg;
|
|
|
|
IMEMonitor<IAEItemStack> itemStorage;
|
2014-03-25 18:13:34 +01:00
|
|
|
IWirelessAccessPoint myWap;
|
2014-02-04 05:23:14 +01:00
|
|
|
|
|
|
|
double sqRange = Double.MAX_VALUE;
|
|
|
|
double myRange = Double.MAX_VALUE;
|
2014-02-03 05:33:50 +01:00
|
|
|
|
|
|
|
EntityPlayer myPlayer;
|
|
|
|
public ItemStack effectiveItem;
|
|
|
|
|
2014-02-04 05:23:14 +01:00
|
|
|
public double getRange()
|
|
|
|
{
|
|
|
|
return myRange;
|
|
|
|
}
|
|
|
|
|
2014-02-03 05:33:50 +01:00
|
|
|
public WirelessTerminalGuiObject(IWirelessTermHandler wh, ItemStack is, EntityPlayer ep, World w, int x, int y, int z) {
|
|
|
|
encryptionKey = wh.getEncryptionKey( is );
|
|
|
|
effectiveItem = is;
|
|
|
|
myPlayer = ep;
|
|
|
|
wth = wh;
|
|
|
|
|
2014-02-11 07:03:34 +01:00
|
|
|
Object obj = null;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
long encKey = Long.parseLong( encryptionKey );
|
2014-09-20 22:41:45 +02:00
|
|
|
obj = AEApi.instance().registries().locatable().findLocatableBySerial( encKey );
|
2014-02-11 07:03:34 +01:00
|
|
|
}
|
|
|
|
catch (NumberFormatException err)
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
|
2014-02-03 06:02:54 +01:00
|
|
|
if ( obj instanceof IGridHost )
|
|
|
|
{
|
|
|
|
IGridNode n = ((IGridHost) obj).getGridNode( ForgeDirection.UNKNOWN );
|
|
|
|
if ( n != null )
|
|
|
|
{
|
|
|
|
targetGrid = n.getGrid();
|
|
|
|
if ( targetGrid != null )
|
|
|
|
{
|
|
|
|
sg = targetGrid.getCache( IStorageGrid.class );
|
|
|
|
if ( sg != null )
|
|
|
|
itemStorage = sg.getItemInventory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean rangeCheck()
|
|
|
|
{
|
2014-02-04 05:23:14 +01:00
|
|
|
sqRange = myRange = Double.MAX_VALUE;
|
|
|
|
|
2014-02-03 06:02:54 +01:00
|
|
|
if ( targetGrid != null && itemStorage != null )
|
|
|
|
{
|
2014-02-04 05:23:14 +01:00
|
|
|
if ( myWap != null )
|
|
|
|
{
|
2014-03-25 18:13:34 +01:00
|
|
|
if ( myWap.getGrid() == targetGrid )
|
2014-02-04 05:23:14 +01:00
|
|
|
{
|
|
|
|
if ( testWap( myWap ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
IMachineSet tw = targetGrid.getMachines( TileWireless.class );
|
|
|
|
|
|
|
|
myWap = null;
|
|
|
|
|
|
|
|
for (IGridNode n : tw)
|
|
|
|
{
|
2014-03-25 18:13:34 +01:00
|
|
|
IWirelessAccessPoint wap = (IWirelessAccessPoint) n.getMachine();
|
2014-02-04 05:23:14 +01:00
|
|
|
if ( testWap( wap ) )
|
|
|
|
myWap = wap;
|
|
|
|
}
|
|
|
|
|
|
|
|
return myWap != null;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-25 18:13:34 +01:00
|
|
|
private boolean testWap(IWirelessAccessPoint wap)
|
2014-02-04 05:23:14 +01:00
|
|
|
{
|
|
|
|
double rangeLimit = wap.getRange();
|
|
|
|
rangeLimit *= rangeLimit;
|
|
|
|
|
2014-03-25 18:13:34 +01:00
|
|
|
DimensionalCoord dc = wap.getLocation();
|
2014-05-24 06:20:56 +02:00
|
|
|
|
|
|
|
if ( dc.getWorld() == myPlayer.worldObj )
|
2014-02-04 05:23:14 +01:00
|
|
|
{
|
2014-03-25 18:13:34 +01:00
|
|
|
double offX = (double) dc.x - myPlayer.posX;
|
|
|
|
double offY = (double) dc.y - myPlayer.posY;
|
|
|
|
double offZ = (double) dc.z - myPlayer.posZ;
|
2014-02-03 06:02:54 +01:00
|
|
|
|
2014-02-04 05:23:14 +01:00
|
|
|
double r = offX * offX + offY * offY + offZ * offZ;
|
|
|
|
if ( r < rangeLimit && sqRange > r )
|
|
|
|
{
|
2014-03-25 18:13:34 +01:00
|
|
|
if ( wap.isActive() )
|
2014-02-04 05:23:14 +01:00
|
|
|
{
|
|
|
|
sqRange = r;
|
|
|
|
myRange = Math.sqrt( r );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2014-02-03 06:02:54 +01:00
|
|
|
}
|
2014-02-03 05:33:50 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IMEMonitor<IAEItemStack> getItemInventory()
|
|
|
|
{
|
2014-02-03 06:02:54 +01:00
|
|
|
if ( sg == null )
|
|
|
|
return null;
|
2014-02-03 05:33:50 +01:00
|
|
|
return sg.getItemInventory();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IMEMonitor<IAEFluidStack> getFluidInventory()
|
|
|
|
{
|
2014-02-03 06:02:54 +01:00
|
|
|
if ( sg == null )
|
|
|
|
return null;
|
2014-02-03 05:33:50 +01:00
|
|
|
return sg.getFluidInventory();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-12 17:35:42 +01:00
|
|
|
public void addListener(IMEMonitorHandlerReceiver<IAEItemStack> l, Object verificationToken)
|
2014-02-03 05:33:50 +01:00
|
|
|
{
|
2014-02-03 06:02:54 +01:00
|
|
|
if ( itemStorage != null )
|
|
|
|
itemStorage.addListener( l, verificationToken );
|
2014-02-03 05:33:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-12 17:35:42 +01:00
|
|
|
public void removeListener(IMEMonitorHandlerReceiver<IAEItemStack> l)
|
2014-02-03 05:33:50 +01:00
|
|
|
{
|
2014-02-03 06:02:54 +01:00
|
|
|
if ( itemStorage != null )
|
|
|
|
itemStorage.removeListener( l );
|
2014-02-03 05:33:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IItemList<IAEItemStack> getAvailableItems(IItemList out)
|
|
|
|
{
|
2014-02-03 06:02:54 +01:00
|
|
|
if ( itemStorage != null )
|
|
|
|
return itemStorage.getAvailableItems( out );
|
|
|
|
return out;
|
2014-02-03 05:33:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IItemList<IAEItemStack> getStorageList()
|
|
|
|
{
|
2014-02-03 06:02:54 +01:00
|
|
|
if ( itemStorage != null )
|
|
|
|
return itemStorage.getStorageList();
|
|
|
|
return null;
|
2014-02-03 05:33:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public AccessRestriction getAccess()
|
|
|
|
{
|
2014-02-03 06:02:54 +01:00
|
|
|
if ( itemStorage != null )
|
|
|
|
return itemStorage.getAccess();
|
|
|
|
return AccessRestriction.NO_ACCESS;
|
2014-02-03 05:33:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isPrioritized(IAEItemStack input)
|
|
|
|
{
|
2014-02-03 06:02:54 +01:00
|
|
|
if ( itemStorage != null )
|
|
|
|
return itemStorage.isPrioritized( input );
|
|
|
|
return false;
|
2014-02-03 05:33:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canAccept(IAEItemStack input)
|
|
|
|
{
|
2014-02-03 06:02:54 +01:00
|
|
|
if ( itemStorage != null )
|
|
|
|
return itemStorage.canAccept( input );
|
|
|
|
return false;
|
2014-02-03 05:33:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getPriority()
|
|
|
|
{
|
2014-02-03 06:02:54 +01:00
|
|
|
if ( itemStorage != null )
|
|
|
|
return itemStorage.getPriority();
|
|
|
|
return 0;
|
2014-02-03 05:33:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSlot()
|
|
|
|
{
|
2014-02-03 06:02:54 +01:00
|
|
|
if ( itemStorage != null )
|
|
|
|
return itemStorage.getSlot();
|
|
|
|
return 0;
|
2014-02-03 05:33:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IAEItemStack injectItems(IAEItemStack input, Actionable type, BaseActionSource src)
|
|
|
|
{
|
2014-02-03 06:02:54 +01:00
|
|
|
if ( itemStorage != null )
|
|
|
|
return itemStorage.injectItems( input, type, src );
|
|
|
|
return input;
|
2014-02-03 05:33:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IAEItemStack extractItems(IAEItemStack request, Actionable mode, BaseActionSource src)
|
|
|
|
{
|
2014-02-03 06:02:54 +01:00
|
|
|
if ( itemStorage != null )
|
|
|
|
return itemStorage.extractItems( request, mode, src );
|
|
|
|
return null;
|
2014-02-03 05:33:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public StorageChannel getChannel()
|
|
|
|
{
|
2014-02-03 06:02:54 +01:00
|
|
|
if ( itemStorage != null )
|
|
|
|
return itemStorage.getChannel();
|
|
|
|
return StorageChannel.ITEMS;
|
2014-02-03 05:33:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double extractAEPower(double amt, Actionable mode, PowerMultiplier usePowerMultiplier)
|
|
|
|
{
|
2014-02-03 06:02:54 +01:00
|
|
|
if ( wth != null && effectiveItem != null )
|
|
|
|
{
|
|
|
|
if ( mode == Actionable.SIMULATE )
|
|
|
|
return wth.hasPower( myPlayer, amt, getItemStack() ) ? amt : 0;
|
|
|
|
return wth.usePower( myPlayer, amt, getItemStack() ) ? amt : 0;
|
|
|
|
}
|
|
|
|
return 0.0;
|
2014-02-03 05:33:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getItemStack()
|
|
|
|
{
|
|
|
|
return effectiveItem;
|
|
|
|
}
|
|
|
|
|
2014-02-17 01:50:25 +01:00
|
|
|
@Override
|
|
|
|
public IConfigManager getConfigManager()
|
|
|
|
{
|
|
|
|
return wth.getConfigManager( effectiveItem );
|
|
|
|
}
|
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
@Override
|
|
|
|
public IGridNode getGridNode(ForgeDirection dir)
|
|
|
|
{
|
|
|
|
return this.getActionableNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public AECableType getCableConnectionType(ForgeDirection dir)
|
|
|
|
{
|
|
|
|
return AECableType.NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void securityBreak()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IGridNode getActionableNode()
|
|
|
|
{
|
|
|
|
rangeCheck();
|
|
|
|
if ( myWap != null )
|
|
|
|
return myWap.getActionableNode();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-06-20 09:10:02 +02:00
|
|
|
@Override
|
|
|
|
public boolean validForPass(int i)
|
|
|
|
{
|
|
|
|
return itemStorage.validForPass( i );
|
|
|
|
}
|
|
|
|
|
2014-02-03 05:33:50 +01:00
|
|
|
}
|