2013-12-27 23:59:59 +01:00
|
|
|
package appeng.core.features.registries;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import appeng.api.features.IWirelessTermHandler;
|
|
|
|
import appeng.api.features.IWirelessTermRegistery;
|
2014-02-03 06:02:54 +01:00
|
|
|
import appeng.core.localization.PlayerMessages;
|
2014-02-03 05:33:50 +01:00
|
|
|
import appeng.core.sync.GuiBridge;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.util.Platform;
|
|
|
|
|
|
|
|
public class WirelessRegistry implements IWirelessTermRegistery
|
|
|
|
{
|
|
|
|
|
|
|
|
List<IWirelessTermHandler> handlers;
|
|
|
|
|
|
|
|
public WirelessRegistry() {
|
|
|
|
handlers = new ArrayList();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void registerWirelessHandler(IWirelessTermHandler handler)
|
|
|
|
{
|
2014-02-02 08:32:10 +01:00
|
|
|
if ( handler != null )
|
|
|
|
handlers.add( handler );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isWirelessTerminal(ItemStack is)
|
|
|
|
{
|
|
|
|
for (IWirelessTermHandler h : handlers)
|
|
|
|
{
|
|
|
|
if ( h.canHandle( is ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IWirelessTermHandler getWirelessTerminalHandler(ItemStack is)
|
|
|
|
{
|
|
|
|
for (IWirelessTermHandler h : handlers)
|
|
|
|
{
|
|
|
|
if ( h.canHandle( is ) )
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void OpenWirelessTermainlGui(ItemStack item, World w, EntityPlayer player)
|
|
|
|
{
|
|
|
|
if ( Platform.isClient() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
IWirelessTermHandler handler = getWirelessTerminalHandler( item );
|
|
|
|
if ( handler == null )
|
|
|
|
{
|
|
|
|
player.addChatMessage( "Item is not a wireless terminal." );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-03 05:33:50 +01:00
|
|
|
if ( handler.hasPower( player, 0.5, item ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-02-03 05:33:50 +01:00
|
|
|
Platform.openGUI( player, null, null, GuiBridge.GUI_WIRELESS_TERM );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2014-02-03 06:02:54 +01:00
|
|
|
else
|
|
|
|
player.sendChatToPlayer( PlayerMessages.DeviceNotPowered.get() );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|