public void onAdded(IRule eventType) { active.add(getGenericFromType(eventType)); HashSet activeTypes = new HashSet(); for (IRule existing: active) { activeTypes.add(existing.getProvider().getUnlocalisedName()); } for (IRuleProvider provider: getCollectionFromType(eventType)) { if (activeTypes.contains(provider.getUnlocalisedName())) { try { IRule type = provider.getProvided(); if (type instanceof IHasEventBus) { EventBus bus = ((IHasEventBus) type).getEventBus(); if (bus != null) { bus.register(type); } } } catch (Exception e) {} } } if (eventType instanceof IReward) { ((IReward)eventType).onAdded(this == client); } }
public void onRemoved(IRule eventType) { active.remove(getGenericFromType(eventType)); HashSet activeTypes = new HashSet(); for (IRule existing: active) { activeTypes.add(existing.getProvider().getUnlocalisedName()); } for (IRuleProvider provider: getCollectionFromType(eventType)) { if (!activeTypes.contains(provider.getUnlocalisedName())) { try { IRule type = provider.getProvided(); if (type instanceof IHasEventBus) { EventBus bus = ((IHasEventBus) type).getEventBus(); if (bus != null) { bus.unregister(type); } } } catch (Exception e) {} } } if (eventType instanceof IReward) { ((IReward)eventType).onRemoved(); } }
@Mod.EventHandler public void forgePreInitialization(FMLPreInitializationEvent event) { // RegistryEvent.Register(registerItems、registerBlocks)が呼ばれるようにする。 EventBus bus = MinecraftForge.EVENT_BUS; bus.register(this); config = new ModConfig(event.getSuggestedConfigurationFile()); config.syncConfig(); this.meta.description = "Make your auto-trading system!!\n自動的に取引を行えるシステムを作るためのMODです。"; this.meta.url = "https://a1lic.net/"; this.meta.authorList.add("alice"); this.meta.credits = "alice"; // falseにしないとMod listで情報が出ない。 this.meta.autogenerated = false; proxy.preInit(); }
@Override public void subscribeClient(String classname, EventBus bus) { try { bus.register(Class.forName(classname).newInstance()); } catch (Exception ex) { VCLoggers.loggerErrors.log(LogLevel.Error, "Could not subscribe %s to %s on client-only side!!", ex, classname, bus.toString()); } }
@Override public void fireNetRegistrationEvent(EventBus bus, NetworkManager manager, Set<String> channelSet, String channel, Side side) { if (side == Side.CLIENT) { 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)); } }
private static Object hackDisableEventBus() throws NoSuchFieldException, IllegalAccessException { Object cache = MinecraftForge.EVENT_BUS; Field busField = MinecraftForge.class.getDeclaredField(fieldName_EVENT_BUS); busField.setAccessible(true); removeFinalModifierFromField(busField); busField.set(null,new EventBus()); return cache; }
/** * Gets the private "internal" register method of the {@link EventBus} * @see ForgeEventHandler#register */ private static Method getRegisterMethod() { try { Method register = EventBus.class.getDeclaredMethod("register", Class.class, Object.class, Method.class, ModContainer.class); register.setAccessible(true); return register; } catch (Exception ex) {ex.printStackTrace(); return null;} }
@Mod.EventHandler public void forgeInitialization(FMLInitializationEvent event) { EventBus bus = MinecraftForge.EVENT_BUS; bus.register(this.config); //bus.register(new CraftingEvent()); bus.register(new MyPlayerEvent()); bus.register(new VillagerEvent()); proxy.init(); }
@EventHandler public void construct(FMLConstructionEvent event) { EventBus bus = MinecraftForge.EVENT_BUS; bus.register(proxy); bus.register(new SelectionListener()); }
@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(); }
public MinecraftBackdoor(WolTestEnvironment testEnv, EventBus eventBus) { this.testEnv = testEnv; this.eventBus = eventBus; this.player = new PlayerBackdoor(testEnv); }
static void unregister(EventBus bus, Class<?> hanlder) { bus.listenerOwners.keySet().stream().filter(hanlder::isInstance).forEach(bus::unregister); }
public static boolean net$minecraft$client$multiplayer$WorldClient$init(EventBus bus, WorldEvent.Load event) { return HookTargetsClient.abortClientLoadEvent(bus, event); }
public static boolean bdb$init(EventBus bus, WorldEvent.Load event) { // This is me being lazy. Dealing with names is obnoxious. Hopefully we can get this gone when we port to 1.9? return HookTargetsClient.abortClientLoadEvent(bus, event); }
public static boolean abortClientLoadEvent(EventBus bus, WorldEvent.Load event) { if (clientWorldLoadEventAbort.get() == Boolean.TRUE) return false; return bus.post(event); }
private ForgeEventHandler(EventBus bus, Class<T> eventClass, boolean clientOnly) { super(eventClass, clientOnly); this.bus = bus; }
/** * @return The bus on which the handler shall be registered */ public final EventBus getBus() { return this.bus; }
/** Return which event bus this should be returned to **/ public EventBus getEventBus();
@Override public EventBus getEventBus() { return MinecraftForge.EVENT_BUS; }
@Override public EventBus getEventBus() { return null; }
/** * Directly registers a method to an {@link EventBus} using the private {@link EventBus#register(Object)} method * This is useful e.g. for generic methods because their event class can't properly be determined because of type erasure * * @param bus the event bus * @param eventClass the event class * @param target the event listener * @param method the listening method * @param mod the mod container * @return whether the listener was successfully registered */ public static <T extends Event> boolean registerMethodToEventBus(EventBus bus, Class<T> eventClass, Object target, Method method, ModContainer mod) { if (!method.isAnnotationPresent(SubscribeEvent.class)) return false; try {ForgeEventHandler.register.invoke(bus, eventClass, target, method, mod);} catch (Exception ex) {ex.printStackTrace(); return false;} return true; }
public void subscribeClient(String classname, EventBus bus) { }
/** * The FML event bus. Subscribe here for FML related events * * @Deprecated Use {@link MinecraftForge#EVENT_BUS} they're the same thing now * @return the event bus */ @Deprecated public EventBus bus() { return eventBus; }
/** * Creates a new forge event handler without registering it to the event bus. * Use {@link ForgeEventHandler#registerForgeHandler(ForgeEventHandler, ModContainer)} to do that * * @param <T> the event type * @param bus the event bus corresponding to the event * @param eventClass the event class * @param clientOnly whether this event is for client use only * @return the forge event handler */ public static <T extends Event> ForgeEventHandler<T> newForgeEventHandler(EventBus bus, Class<T> eventClass, boolean clientOnly) { ForgeEventHandler<T> handler = new ForgeEventHandler<T>(bus, eventClass, clientOnly); putEventHandlers(handler); return handler; }
/** * Creates a new forge event handler and registers it immediately to the event bus * * @param <T> the event type * @param bus the event bus corresponding to the event * @param eventClass the event class * @param clientOnly whether this event is for client use only * @param mod the mod container, needed by the event bus to register the event <br> * (retrievable via {@link net.minecraftforge.fml.common.Loader#activeModContainer()} or {@link net.minecraftforge.fml.common.Loader#getReversedModObjectList()}) * @return the forge event handler */ public static <T extends Event> ForgeEventHandler<T> newForgeEventHandler(EventBus bus, Class<T> eventClass, boolean clientOnly, ModContainer mod) { ForgeEventHandler<T> handler = newForgeEventHandler(bus, eventClass, clientOnly); ForgeEventHandler.registerForgeHandler(handler, mod); return handler; }
void fireNetRegistrationEvent(EventBus bus, NetworkManager manager, Set<String> channelSet, String channel, Side side);