Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hey!

I am trying to open a backpack GUI whenever a custom key binding is pressed. The only problem is it seems that ClientTickEvent is not being fired at all.

At this point I suspect that I'm ignorant of how events are subscribed. Let me show you my code.

 

PegasusVanguard.java

@Mod(PegasusVanguard.ID)
public class PegasusVanguard {

	public static final String ID = "pegasusvanguard";
	public static final String VERSION = "1.0";
	public static final Logger MOD_LOGGER = LogManager.getLogger();

	public PegasusVanguard() {
		FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setupCommon);
		FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setupClient);
	}

	@SubscribeEvent
	public void setupCommon(final FMLCommonSetupEvent event) {
		long t = System.currentTimeMillis();
		MOD_LOGGER.info("Initializing dual-side behaviour...");
		
		//MinecraftForge.EVENT_BUS.register(new EventSubscriber());
		ModCapabilities.registerAll();
		
		MOD_LOGGER.info(new StringBuilder("Done! (").append(Long.toString(System.currentTimeMillis() - t)).append("ms)"));
	}

	@SubscribeEvent
	public void setupClient(final FMLClientSetupEvent event) {
		long t = System.currentTimeMillis();
		MOD_LOGGER.info("Initializing client-side behaviour...");
		
		//MinecraftForge.EVENT_BUS.register(new ClientEventSubscriber());
		ModKeyBindings.registerAll();
		ModScreens.registerAll();
		
		MOD_LOGGER.info(new StringBuilder("Done! (").append(Long.toString(System.currentTimeMillis() - t)).append("ms)"));
	}
}

 

EventSubscriber.java

@EventBusSubscriber(modid = PegasusVanguard.ID, bus = EventBusSubscriber.Bus.MOD)
public class EventSubscriber {

	@SubscribeEvent
	public static void onRegisterBlocks(final RegistryEvent.Register<Block> event) {
		ModBlocks.registerAll(event);
		PegasusVanguard.MOD_LOGGER.info("Blocks registered!");
	}
	
	@SubscribeEvent
	public static void onRegisterItems(final RegistryEvent.Register<Item> event) {
		ModItems.registerAll(event);
		PegasusVanguard.MOD_LOGGER.info("Items registered!");
	}

	@SubscribeEvent
	public static void onRegisterContainers(final RegistryEvent.Register<ContainerType<?>> event) {
		ModContainers.registerAll(event);
		PegasusVanguard.MOD_LOGGER.info("Containers registered!");
	}

	@SubscribeEvent(priority = EventPriority.LOWEST)
	public static void onPlayerFall(LivingFallEvent event) {
		if (event.getEntityLiving() instanceof PlayerEntity) {
			PlayerEntity player = (PlayerEntity) event.getEntityLiving();

			if (PlayerUtil.isWearing(player, ModItems.getItemStack("armor.airforceboots"))) {
				event.setDamageMultiplier(0);

				if (player.isServerWorld()) {
					Vec3d v = player.getMotion();
					player.setVelocity(v.x, -v.y * 10, v.z);
					player.velocityChanged = true;
				}
			}
		}
	}
}

 

ClientEventSubscriber.java

@EventBusSubscriber(modid = PegasusVanguard.ID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public class ClientEventSubscriber {
	
	@SubscribeEvent
	public static void onKeyInput(TickEvent.ClientTickEvent event) {
		System.out.println("top notch debugging over here");
		if (event.phase == Phase.END && ModKeyBindings.openBackpack.isKeyDown() && Minecraft.getInstance().isGameFocused()) {
			ModNetworkHandler.CHANNEL.send(PacketDistributor.SERVER.noArg(), new PacketOpenGui(ModReference.Gui.BACKPACK));
		}
	}
}

 

The thing is, EventSubscriber code is called and executed normally (blocks and items are registered), but ClientEventSubscriber is not. The onKeyInput method is never reached, and I can't figure out why.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.