Applied-Energistics-2-tiler.../core/features/registries/LocateableRegistry.java

49 lines
1.1 KiB
Java
Raw Normal View History

package appeng.core.features.registries;
import java.util.HashMap;
2014-01-20 17:41:37 +01:00
import net.minecraftforge.common.MinecraftForge;
import appeng.api.events.LocatableEventAnnounce;
import appeng.api.events.LocatableEventAnnounce.LocatableEvent;
import appeng.api.features.ILocatable;
2014-03-24 05:00:12 +01:00
import appeng.api.features.ILocatableRegistry;
import appeng.util.Platform;
2014-02-09 02:34:52 +01:00
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
2014-03-24 05:00:12 +01:00
public class LocateableRegistry implements ILocatableRegistry
{
private HashMap<Long, ILocatable> set;
2014-02-09 02:34:52 +01:00
@SubscribeEvent
public void updateLocateable(LocatableEventAnnounce e)
{
if ( Platform.isClient() )
return; // IGNORE!
if ( e.change == LocatableEvent.Register )
{
set.put( e.target.getLocatableSerial(), e.target );
2014-01-20 17:41:37 +01:00
}
else if ( e.change == LocatableEvent.Unregister )
{
set.remove( e.target.getLocatableSerial() );
}
}
public LocateableRegistry() {
set = new HashMap();
2014-01-20 17:41:37 +01:00
MinecraftForge.EVENT_BUS.register( this );
}
/**
* Find a locate-able object by its serial.
*/
@Override
2014-09-20 22:41:45 +02:00
public Object findLocatableBySerial(long ser)
{
return set.get( ser );
}
}