Jump to content

Recommended Posts

Posted

I've been searching a mod which can do same as one Bukkit plugin can, generate round world. Apparently I didn't find any and no one wanted to port it so I decided to do it myself. I have experience about programming on multiple languages including C#, Java, PHP etc, but I don't have any experience about Bukkit plugins or Forge mods. So where to start exactly? It's very hard to find how to use Forge for creating mods (or I'm just dumb) and even harder to find corresponding structure so I can make the Plugin work as expected. I tried to port the main java file but I can't do even that.

 

There's the original java file (Bukkit):

Spoiler

package com.wimbli.WorldBorder;

import org.bukkit.Location;
import org.bukkit.plugin.java.JavaPlugin;


public class WorldBorder extends JavaPlugin
{
	public static volatile WorldBorder plugin = null;
	public static volatile WBCommand wbCommand = null;
	private BlockPlaceListener blockPlaceListener = null;
	private MobSpawnListener mobSpawnListener = null;

	@Override
	public void onEnable()
	{
		if (plugin == null)
			plugin = this;
		if (wbCommand == null)
			wbCommand = new WBCommand();

		// Load (or create new) config file
		Config.load(this, false);

		// our one real command, though it does also have aliases "wb" and "worldborder"
		getCommand("wborder").setExecutor(wbCommand);

		// keep an eye on teleports, to redirect them to a spot inside the border if necessary
		getServer().getPluginManager().registerEvents(new WBListener(), this);
		
		if (Config.preventBlockPlace()) 
			enableBlockPlaceListener(true);

		if (Config.preventMobSpawn())
			enableMobSpawnListener(true);

		// integrate with DynMap if it's available
		DynMapFeatures.setup();

		// Well I for one find this info useful, so...
		Location spawn = getServer().getWorlds().get(0).getSpawnLocation();
		Config.log("For reference, the main world's spawn location is at X: " + Config.coord.format(spawn.getX()) + " Y: " + Config.coord.format(spawn.getY()) + " Z: " + Config.coord.format(spawn.getZ()));
	}

	@Override
	public void onDisable()
	{
		DynMapFeatures.removeAllBorders();
		Config.StopBorderTimer();
		Config.StoreFillTask();
		Config.StopFillTask();
	}

	// for other plugins to hook into
	public BorderData getWorldBorder(String worldName)
	{
		return Config.Border(worldName);
	}

	/**
	 * @deprecated  Replaced by {@link #getWorldBorder(String worldName)};
	 * this method name starts with an uppercase letter, which it shouldn't
	 */
	public BorderData GetWorldBorder(String worldName)
	{
		return getWorldBorder(worldName);
	}

	public void enableBlockPlaceListener(boolean enable)
	{
		if (enable) 
			getServer().getPluginManager().registerEvents(this.blockPlaceListener = new BlockPlaceListener(), this);
		else if (blockPlaceListener != null)
			blockPlaceListener.unregister();
	}

	public void enableMobSpawnListener(boolean enable)
	{
		if (enable)
			getServer().getPluginManager().registerEvents(this.mobSpawnListener = new MobSpawnListener(), this);
		else if (mobSpawnListener != null)
			mobSpawnListener.unregister();
	}
}

 

An there's my version of it (Forge):

Spoiler

Yes, I commented the lines which I have no idea what to do..


package fi.liznet.WorldBorderForge;

import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

// import org.bukkit.Location;
// import org.bukkit.plugin.java.JavaPlugin;


public class WorldBorder
{
	public static volatile WorldBorder plugin = null;
	public static volatile WBCommand wbCommand = null;
	private BlockPlaceListener blockPlaceListener = null;
	private MobSpawnListener mobSpawnListener = null;

	@EventHandler
	public void onEnable(FMLPreInitializationEvent event)
	{
		if (plugin == null)
			plugin = this;
		if (wbCommand == null)
			wbCommand = new WBCommand();

		// Load (or create new) config file
		Config.load(this, false);

		// our one real command, though it does also have aliases "wb" and "worldborder"
		//getCommand("wborder").setExecutor(wbCommand);

		// keep an eye on teleports, to redirect them to a spot inside the border if necessary
		//getServer().getPluginManager().registerEvents(new WBListener(), this);
		
		if (Config.preventBlockPlace()) 
			enableBlockPlaceListener(true);

		if (Config.preventMobSpawn())
			enableMobSpawnListener(true);

		// integrate with DynMap if it's available
		DynMapFeatures.setup();

		// Well I for one find this info useful, so...
		
		//Location spawn = getServer().getWorlds().get(0).getSpawnLocation();
		//World world = Minecraft.getMinecraft().theWorld;
		//MinecraftServer.getServer()
		//getSpawnPoint()
		
		//Config.log("For reference, the main world's spawn location is at X: " + Config.coord.format(spawn.getX()) + " Y: " + Config.coord.format(spawn.getY()) + " Z: " + Config.coord.format(spawn.getZ()));
	}

	public void onDisable()
	{
		DynMapFeatures.removeAllBorders();
		Config.StopBorderTimer();
		Config.StoreFillTask();
		Config.StopFillTask();
	}

	// for other plugins to hook into
	public BorderData getWorldBorder(String worldName)
	{
		return Config.Border(worldName);
	}

	/**
	 * @deprecated  Replaced by {@link #getWorldBorder(String worldName)};
	 * this method name starts with an uppercase letter, which it shouldn't
	 */
	public BorderData GetWorldBorder(String worldName)
	{
		return getWorldBorder(worldName);
	}

	public void enableBlockPlaceListener(boolean enable)
	{
		if (enable) {
			//getServer().getPluginManager().registerEvents(this.blockPlaceListener = new BlockPlaceListener(), this);
		}else if (blockPlaceListener != null)
			blockPlaceListener.unregister();
	}

	public void enableMobSpawnListener(boolean enable)
	{
		if (enable){
			//getServer().getPluginManager().registerEvents(this.mobSpawnListener = new MobSpawnListener(), this);
		}else if (mobSpawnListener != null)
			mobSpawnListener.unregister();
	}
}

 

 

So can you guys help me to make some progress? I'm totally noob what comes to modding Minecraft, so any kind of advice is welcome.

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why.

Posted
1 hour ago, Awesome_Spider said:

Umm. Why are you even trying to "port" a bukkit plugin to a forge mod in the first place? They are not the same thing, they are way different. That said, if you want to make a mod, there are many tutorials. Here is a good one:

http://shadowfacts.net/tutorials/forge-modding-111/

I need it for my server, there's apparently zero mods which can do same as this plugin. My only choice is try to make one myself or "port" the plugin. Thanks for the link, I'll check it tomorrow.

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why.

Posted
2 hours ago, Kokkie said:

This isn't that hard... You just test for the position of the player and tp him back if he goes further than the border you set

Yes I know that and I've done similar thing before. But I also need to pre-generate a round map, I think it's a little bit harder.

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why.

Posted
Just now, Kokkie said:

I think it is impossible as minecraft always generates an infinite map

No it's not, I linked the plugin earlier and I used it myself on my old server.

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why.

Posted
28 minutes ago, Kokkie said:

I think it is impossible as minecraft always generates an infinite map

Actually it is capped at +/- 30M if my memory serves.  May as well be infinite. :)  And based on my recollection of Worldborder it is possible to have similar functionality as a server side Forge mod.

Posted
4 hours ago, OreCruncher said:

Actually it is capped at +/- 30M if my memory serves.  May as well be infinite. :)  And based on my recollection of Worldborder it is possible to have similar functionality as a server side Forge mod.

I was thinking that is it easier to port Bukkit plugin to Sponge plugin instead of Forge mod? In my opinion it can make sense because they're both plugins. Correct me if I'm wrong.

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why.

Posted

I have not implemented anything within the Sponge framework so I don't really know.  I suspect, though, there will be some work porting the code from the Bukkit plugin framework to the Sponge plugin framework.

Posted

That 30M number is set in the server.properties file (max-world-size). So, if you're really only interested in having a small world (that can be square instead of round), then your job is easy.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted
8 hours ago, jeffryfisher said:

That 30M number is set in the server.properties file (max-world-size). So, if you're really only interested in having a small world (that can be square instead of round), then your job is easy.

The main reason why I'm doing this is the round shaped world.

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why.

Posted
8 hours ago, OreCruncher said:

I have not implemented anything within the Sponge framework so I don't really know.  I suspect, though, there will be some work porting the code from the Bukkit plugin framework to the Sponge plugin framework.

I made a littlebit googling and it seems that it's easier to port it as a Sponge plugin. I'll try different methods and report which is better.

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know 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...

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