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;
|
|
|
|
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;
|
|
|
|
import appeng.api.networking.storage.IStorageGrid;
|
|
|
|
import appeng.api.storage.IMEMonitor;
|
|
|
|
import appeng.api.storage.IMEMonitorHandlerReciever;
|
|
|
|
import appeng.api.storage.StorageChannel;
|
|
|
|
import appeng.api.storage.data.IAEFluidStack;
|
|
|
|
import appeng.api.storage.data.IAEItemStack;
|
|
|
|
import appeng.api.storage.data.IItemList;
|
2014-02-04 05:23:14 +01:00
|
|
|
import appeng.tile.networking.TileWireless;
|
2014-02-03 05:33:50 +01:00
|
|
|
|
|
|
|
public class WirelessTerminalGuiObject implements IPortableCell
|
|
|
|
{
|
|
|
|
|
|
|
|
IWirelessTermHandler wth;
|
|
|
|
String encryptionKey;
|
|
|
|
|
|
|
|
IGrid targetGrid;
|
|
|
|
IStorageGrid sg;
|
|
|
|
IMEMonitor<IAEItemStack> itemStorage;
|
2014-02-04 05:23:14 +01:00
|
|
|
TileWireless myWap;
|
|
|
|
|
|
|
|
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 );
|
|
|
|
obj = AEApi.instance().registries().locateable().findLocateableBySerial( encKey );
|
|
|
|
}
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
if ( myWap.getGridNode( ForgeDirection.UNKNOWN ).getGrid() == targetGrid )
|
|
|
|
{
|
|
|
|
if ( testWap( myWap ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
IMachineSet tw = targetGrid.getMachines( TileWireless.class );
|
|
|
|
|
|
|
|
myWap = null;
|
|
|
|
|
|
|
|
for (IGridNode n : tw)
|
|
|
|
{
|
|
|
|
TileWireless wap = (TileWireless) n.getMachine();
|
|
|
|
if ( testWap( wap ) )
|
|
|
|
myWap = wap;
|
|
|
|
}
|
|
|
|
|
|
|
|
return myWap != null;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean testWap(TileWireless wap)
|
|
|
|
{
|
|
|
|
double rangeLimit = wap.getRange();
|
|
|
|
rangeLimit *= rangeLimit;
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
if ( wap.getWorldObj() == myPlayer.worldObj )
|
2014-02-04 05:23:14 +01:00
|
|
|
{
|
|
|
|
double offX = (double) wap.xCoord - myPlayer.posX;
|
|
|
|
double offY = (double) wap.yCoord - myPlayer.posY;
|
|
|
|
double offZ = (double) wap.zCoord - 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 )
|
|
|
|
{
|
|
|
|
if ( wap.getGridNode( ForgeDirection.UNKNOWN ).isActive() )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
public void addListener(IMEMonitorHandlerReciever<IAEItemStack> l, Object verificationToken)
|
|
|
|
{
|
2014-02-03 06:02:54 +01:00
|
|
|
if ( itemStorage != null )
|
|
|
|
itemStorage.addListener( l, verificationToken );
|
2014-02-03 05:33:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void removeListener(IMEMonitorHandlerReciever<IAEItemStack> l)
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|