2013-12-27 23:59:59 +01:00
|
|
|
package appeng.core.features.registries;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
2013-12-27 23:59:59 +01:00
|
|
|
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;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.util.Platform;
|
2014-02-09 02:34:52 +01:00
|
|
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-03-24 05:00:12 +01:00
|
|
|
public class LocateableRegistry implements ILocatableRegistry
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
private HashMap<Long, ILocatable> set;
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
@SubscribeEvent
|
2013-12-27 23:59:59 +01:00
|
|
|
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 )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
set.remove( e.target.getLocatableSerial() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public LocateableRegistry() {
|
|
|
|
set = new HashMap();
|
2014-01-20 17:41:37 +01:00
|
|
|
MinecraftForge.EVENT_BUS.register( this );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find a locate-able object by its serial.
|
|
|
|
*/
|
|
|
|
@Override
|
2014-09-20 22:41:45 +02:00
|
|
|
public Object findLocatableBySerial(long ser)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return set.get( ser );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|