Jump to content

I Need Help with Intellij IDEA


Naranjo

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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