private int getBusID(EventBus a) { try { Field declaredField = EventBus.class.getDeclaredField("busID"); declaredField.setAccessible(true); return declaredField.getInt(a); } catch (Exception ex) { return 0; } }
@Override public void fireNetRegistrationEvent(EventBus bus, NetworkManager manager, Set<String> channelSet, String channel, Side side) { if (side == Side.CLIENT) { waitForPlayClient(); bus.post(new FMLNetworkEvent.CustomPacketRegistrationEvent<NetHandlerPlayClient>(manager, channelSet, channel, side, NetHandlerPlayClient.class)); } else { bus.post(new FMLNetworkEvent.CustomPacketRegistrationEvent<NetHandlerPlayServer>(manager, channelSet, channel, side, NetHandlerPlayServer.class)); } }
/** * Constructs a pseudo container that TC can use to 'see' the items in the * ME network. * * @param inventorySize * @throws Exception * When the TC rendering code can not be found, the bridge will not * construct. */ public MEItemAspectBridgeContainer( final int inventorySize ) throws Exception { // Create the inventory this.internalInventory = new TheInternalInventory( "TC Inventory Bridge", inventorySize, 1 ); // Have we hooked to TC's event handler? if( thaumcraftClientEvents.get() == null ) { // Access the listenerOwners field Field loField = EventBus.class.getDeclaredField( "listenerOwners" ); loField.setAccessible( true ); // Get the owners Map<Object, ModContainer> owners = (Map<Object, ModContainer>)loField.get( FMLCommonHandler.instance().bus() ); // Attempt to locate TC's event handler for( Entry<Object, ModContainer> set : owners.entrySet() ) { Object Owner = set.getKey(); if( Owner instanceof thaumcraft.client.lib.ClientTickEventsFML ) { thaumcraftClientEvents = new WeakReference<ClientTickEventsFML>( (ClientTickEventsFML)Owner ); break; } } // Get rid of the references, cause I'm paranoid. owners = null; loField = null; // Did we locate it? if( thaumcraftClientEvents == null ) { throw new Exception( "Unable to find TC event handler" ); } } }
public void register(IEventListener listener, EventBus bus, Class<? extends Event> clazz) { try { clazz.newInstance().getListenerList().register(getBusID(bus), EventPriority.NORMAL, listener); } catch (Exception e) { } }
public void unregister(IEventListener listener, EventBus bus, Class<? extends Event> clazz) { try { clazz.newInstance().getListenerList().unregister(getBusID(bus), listener); } catch (Exception e) { } }
@Override public void fireNetRegistrationEvent(EventBus bus, NetworkManager manager, Set<String> channelSet, String channel, Side side) { bus.post(new FMLNetworkEvent.CustomPacketRegistrationEvent<NetHandlerPlayServer>(manager, channelSet, channel, side, NetHandlerPlayServer.class)); }
FMLEventChannel(String name) { this.channels = NetworkRegistry.INSTANCE.newChannel(name, new NetworkEventFiringHandler(this)); this.eventBus = new EventBus(); }
private HandlerType(String eventIdentifier, EventBus bus) { this.eventIdentifier = eventIdentifier; this.bus = bus; }
public void listen(EventBus eventBus) { eventBus.register(this); }
@Override public void registerEventHandlers(EventBus bus) { MinecraftForge.EVENT_BUS.register(DrawBlockHighlightEventHandler.getInstance()); }
/** * The FML event bus. Subscribe here for FML related events * * @return the event bus */ public EventBus bus() { return eventBus; }
@Override public void registerEventHandlers(EventBus bus) { bus.register(TickEventHandler.getInstance()); }
void fireNetRegistrationEvent(EventBus bus, NetworkManager manager, Set<String> channelSet, String channel, Side side);
void registerEventHandlers(EventBus bus);