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

Hello, I am currently creating a mod and I need some help, if you want to help me out that is. I am new to Java, so please don't scold me for not knowing like the people in the discord server I'm in do.

 

So basically i have an item that I want to be able to fly with on right click, and be able to summon 3 bats on left click. I have the item registered into my RegistryHandler already.

 

If anyone could help me that would be greatly appreciated.

 

Thank You!

Override onItemRightClick in your item class, and set

player.abilities.allowFlying

to true (may not be the correct/best way, just an example)

 

For the left click one, there are a couple ways of doing it, but I'll introduce the one I'm using (You can find lots of posts by searching "left click").

Listen to 

MouseInputEvent

Use 

event.getAction() and event.getButton()

to check the action is under the correct condition, and use packets to spawn entities on the server.

world.addEntity(a new instance of BatEntity)

 

You can find lots of information using the searching bar on the top of this site.

  • Author

The way I'm doing the flying code is with events, and I have this:

 

package com.Naranjo.toolsofinsanitymod.events;

import com.Naranjo.toolsofinsanitymod.ToI;
import com.Naranjo.toolsofinsanitymod.items.ItemBase;
import com.Naranjo.toolsofinsanitymod.util.RegistryHandler;
import com.google.common.eventbus.Subscribe;
import net.minecraft.entity.FlyingEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerAbilities;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.ColorHandlerEvent;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(modid = ToI.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
public class ModClientEvents {

    @SubscribeEvent
    public static void onJumpWithWitchBroom(PlayerInteractEvent.RightClickItem event) {
        PlayerEntity player = event.getPlayer();
        if (player.getHeldItemMainhand().getItem() == RegistryHandler.NATEWITCHBROOM.get()) {
            player.abilities.allowFlying = true;
            ToI.LOGGER.info("Player tried to jump with Broom");

        };
        }

    }
}

How would I make it so I Right click or I switch to another slot in my hotbar I stop flying?

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.