Minecraft BE Tap with a wooden sword to jump

This article

――This is an explanation of the plug-in that I made with the intention of making a simple plug-in that even beginners can make. I hope it's a useful reference. -Introduced on Blog, and source published and downloaded on Github I will.

Introduction

This is an article about the Nukkit plugin used when building a server with Minecraft BE (formerly PE). If you can use Java to some extent, you can read it. I think it will be helpful if you can read it while checking it even if you are not.

What kind of structure is it

First, I will introduce how the plug-in is structured. In the plugin, event processing according to Minecraft is prepared in Nukkit, and we will write the processing using them.

@EventHandler
public void onJoin(PlayerJoinEvent event){
    //Description
}

In the above example, we are writing a function that takes PlayerJoinEvent as an argument. This will call it when the player joins the server.

There are many other types of events, and we will create plugins while using these.

Explanation of what was created

This time, I made a thing that when you tap with a wooden sword, it jumps in the direction you are facing. This also uses events. Let's take a look at the source.

@Override
public void onEnable(){
    this.getServer().getLogger().info("§b[TapFly]Started");
    this.getServer().getPluginManager().registerEvents(this, this);
}

@EventHandler
public void onInteract(PlayerInteractEvent e){
    Player pl = e.getPlayer();
    Item item = pl.getInventory().getItemInHand();
    int itemid = item.getId();
    if(itemid == Item.WOODEN_SWORD) {
        double yaw = pl.getYaw();
        double pitch = pl.getPitch();
        double addX = -Math.sin(yaw * Math.PI / 180) * Math.cos(pitch * Math.PI / 180);
        double addY = -Math.sin(pitch * Math.PI / 180);
        double addZ = Math.cos(yaw * Math.PI / 180) * Math.cos(pitch * Math.PI / 180);
        pl.setMotion(new Vector3(addX, addY, addZ));
    }
}

This is part of the plugin source. I've written a lot, but there are two functions. Let's separate these.

The first function, onEnable.

@Override
public void onEnable()

This is the first function called in the plugin. Sometimes called at the beginning, it is used to initialize values. In this case, we are registering for the event to be called and outputting characters to the console.

The second function, onIteract.

@EventHandler
public void onInteract(PlayerInteractEvent e)

This is an event that occurs when the player taps something. You can get the player object from this event, from which you can get the name or the item object you have in your hand. This time, I judge whether it is a wooden sword from the acquired item object and fly it in the direction it is facing. Also, flying in the direction you are facing is calculated using a triangle. However, it doesn't matter if you fly in the direction you are facing, it is important that you can handle it using events. You will be able to do various things by using events to get things about them, make decisions, and process them.

Recommended Posts

Minecraft BE Tap with a wooden sword to jump
How to sign a Minecraft MOD
To not be a static uncle
Fixed to be able to save a specific column empty with active record
There seems to be a word "de-Java".
I want to be able to read a file using refile with administrate [rails6]
It's a pain to deal with old dates
Be careful to avoid access blocking with scraping
[Rails] rails new to create a database with PostgreSQL
Convert a string to a character-by-character array with swift
[Ruby] I want to do a method jump!
Transition to a view controller with Swift WebKit
Rip a CD to MP3 with Ubuntu 18.04 LTS
Site summary to be helpful in Minecraft modding 1.12.2
Minecraft BE server development from PHP to Java
I tried to break a block with java (1)