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 net.minecraftforge.event.ForgeSubscribe;
|
|
|
|
import appeng.api.events.LocatableEventAnnounce;
|
|
|
|
import appeng.api.events.LocatableEventAnnounce.LocatableEvent;
|
|
|
|
import appeng.api.features.ILocatable;
|
|
|
|
import appeng.api.features.ILocateableRegistry;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
|
|
|
|
public class LocateableRegistry implements ILocateableRegistry
|
|
|
|
{
|
|
|
|
|
|
|
|
private HashMap<Long, ILocatable> set;
|
|
|
|
|
|
|
|
@ForgeSubscribe
|
|
|
|
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
|
|
|
|
public Object findLocateableBySerial(long ser)
|
|
|
|
{
|
|
|
|
return set.get( ser );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|