This mod from “Absolute Beginner’s Guide To Minecraft Mods Programming, second edition” by Rogers Cadenhead will spawn a wolf when the player types the command “/petwolf”

The first thing to notice is that the starter code is MISSING an important line of code. The starter code below will spawn a wolf at the player’s location and set the collar color to pink. The starter code does NOT set the player to be the owner of the wolf.

Demo of the PetWolf Minecraft mod

Challenges

1. Can you set the player to be the owner of the wolf?

Check the Spigot API documentation for the Wolf class and look for one of the Tameable methods that lets you change the owner.

2. Can you randomize the collar color?

Check the Spigot API for the DyeColor class for a list of the class constants (for example DyeColor.PINK), create an array of type DyeColor that contains several colors, and randomly select a DyeColor from the list.

3. Can you give the wolf a random name?

The Wolf class lists the methods that can change a wolf’s custom name (look at the Nameable methods). Create an array of dog names, randomly select a name and use substring to get only the first half, randomly select a name and use substring to get only the second half, then set the wolf’s custom name to be the first half concatenated with the second half. This should generate interesting names like Coodo (Cooper + Fido), Root (Rover + Spot), Fiper (Fido + Cooper), Coover (Cooper + Rover), Fiot (Fido + Spot), Fiver (Fido + Rover) and Rodo (Rover + Fido).

Another demo of the PetWolf Minecraft mod

PetWolf Starter Code

Source: https://javaminecraft.com/source/PetWolf/PetWolf.java

package com.javaminecraft;

import java.util.logging.*;
import org.bukkit.*;
import org.bukkit.command.*;
import org.bukkit.entity.*;
import org.bukkit.plugin.java.*;

public class PetWolf extends JavaPlugin {
    public static final Logger LOG = Logger.getLogger("Minecraft");

    public boolean onCommand(CommandSender sender, Command command,
        String label, String[] arguments) {

        if (label.equalsIgnoreCase("petwolf")) {
            if (sender instanceof Player) {
                // get the player
                Player me = (Player) sender;
                // get the player's current location
                Location spot = me.getLocation();
                // get the game world
                World world = me.getWorld();

                // spawn one wolf
                Wolf wolf = world.spawn(spot, Wolf.class);
                // set the color of its collar
                wolf.setCollarColor(DyeColor.PINK);
                LOG.info("[PetWolf] Howl!");
                return true;
            }
        }
        return false;
    }
}


This summer I picked up “Absolute Beginner’s Guide To Minecraft Mods Programming, second edition” by Rogers Cadenhead. I decided to blog about the process. This will serve as a project journal, but also as notes to myself so that I have a record of the process.

Downloads

There are a few things I need to install on my MacBook (this is one of the first hurdles, because the author is using a PC):

Start the Server

Create a shell script named start-server.sh to launch the server. Bukkit’s wiki has directions for Mac OSX here.

cd /Users/rileyju/minecraftserver/
java -Xms1024M -Xmx1024M -jar spigotserver.jar

Before running the shell script, you must use chmod to allow the script to run

  • Open up Terminal.app
  • Type into Terminal.app
    • chmod a+x
    • Warning: Do not hit return yet!
    • drag the start_server.command into Terminal.app
  • hit return

When you want to start the server, just drag start-server.sh into the terminal and press return

On first run, you will get the error “Failed to load eula.txt” because you need to agree to the eula. Find eula.txt and edit it to say eula=true

Open server.properties file. Details here

  • Change the message-of-the-day to motd=Riley Mod Server
  • Change the game mode. survival is 0, creative is 1, adventure is 2, spectator is 3
  • Set pvp to false. true would mean that players can kill each other. false means that players cannot kill other players (also known as Player versus Environment (PvE)).
  • NOTICE that the query.port is set to 25565

Launch Client and Find Server

On the splash screen, click the Multiplayer button.

If you don’t see your server name (in my case “Riley Mod Server”), click Direct Connect. Source: you need to get the local IP address of your computer unless you are connecting to the server on the same machine your server is running on.

To connect on your own computer to a server ran on your computer, connect to localhost:25565

To get your IP address to connect to your server from another computer, go to the Command Prompt and enter ipconfig, then get the ipv4 address. Then connect to Your_ipv4_address:25565

Changing the Game Version

On first run, I got an “outdated server” error. The Spigot server is Minecraft v1.8.7

Open the Minecraft Launcher. In Java Edition, choose the Installations tab. Click the New Installation button. Give it a name like ModTester. Change the version to match the server: release 1.8.7

https://help.minecraft.net/hc/en-us/articles/360034754852-Change-Game-Version-for-Minecraft-Java-Edition


This summer I was working on translating a project with a dozen Python classes into Javascript ES6 classes. The following are “notes to myself” about the substitutions that can be made automatically in order to speed up the translation process.

replace all (this –> with that)
def __init__ --> constructor
def -->
(self): --> (){
(self, --> (
): --> ){
self. --> this.
# --> //#
else: --> }else{
print( --> console.log(
int( --> Math.floor(
str( --> (""+
True --> true
False --> false
None --> null
and not --> && !
if not --> if (!
while true: --> while (true){

The following substitutions need to be made manually (one at a time).

find and replace manually
and --> &&
result = --> let result =
temp = --> let temp =
.append --> .push
len(foo)
for i in range(
for each in --> for (let each of
while
.insert(0,"foo") --> .splice(0,0,"foo")
a in b --> b.includes(a)
@staticmethod \n def --> static
@classmethod \n def --> static
.sort(key=lambda x: x.getGrade(), reverse=False) --> .sort(function(a, b){return a.getGrade() - b.getGrade()})
.sort(key=lambda x: x.getGrade(), reverse=True) --> .sort(function(a, b){return b.getGrade() - a.getGrade()})




RECENT POSTS