Jump to content

Get dedicated server instance?


SanAndreaP

Recommended Posts

Is there a way to get a dedicated server instance? I need it for some entity manipulation in my GUI. This code works fine on the client:

FMLCommonHandler.instance().getMinecraftServerInstance()

 

but on a dedicated server, it gives me a null value. Here's my CommonProxy:

 

package SanAndreasP.mods.ClaySoldiersMod;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.client.Minecraft;
import net.minecraft.server.MinecraftServer;
import net.minecraft.src.*;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.common.registry.GameRegistry;

public class CSM_CommonProxy implements IGuiHandler {

@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	List<Entity> entities = world.getEntitiesWithinAABB(CSM_EntityClayNexus.class, AxisAlignedBB.getBoundingBox(x, y, z, x+1D, y+1D, z+1D));

	for(Entity entity : entities) {
		if (entity != null && entity instanceof CSM_EntityClayNexus) {
			return new CSM_ContainerNexus(player.inventory, (CSM_EntityClayNexus)entity, ID == 0);
		} else {
			return null;
		}
	}

	return null;
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {

	List<Entity> entitiesC = world.getEntitiesWithinAABB(CSM_EntityClayNexus.class, AxisAlignedBB.getBoundingBox(x, y, z, x+1D, y+1D, z+1D));
	List<Entity> entitiesS = new ArrayList<Entity>();
	System.out.println();

	try {
		entitiesS = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(0).getEntitiesWithinAABB(CSM_EntityClayNexus.class, AxisAlignedBB.getBoundingBox(x, y, z, x+1D, y+1D, z+1D));
	} catch (NullPointerException e) {

	}



	CSM_EntityClayNexus clientEntity = null, serverEntity = null;

	for(Entity entity : entitiesS) {
		if(entity != null && entity instanceof CSM_EntityClayNexus) {
			serverEntity = (CSM_EntityClayNexus)entity;
			break;
		}
	}
	for(Entity entity : entitiesC) {
		if(entity != null && entity instanceof CSM_EntityClayNexus) {
			clientEntity = (CSM_EntityClayNexus)entity;
			break;
		}
	}

	if(clientEntity != null && serverEntity != null) {
		System.out.println(ID);
		return new CSM_GuiNexus(player, clientEntity, serverEntity, ID == 0);
	} else if(clientEntity != null) {
		System.out.println(ID);
		return new CSM_GuiNexus(player, clientEntity, clientEntity, ID == 0);
	} else {
		return null;
	}
}

public boolean isClient() {
	return false;
}

public void registerRenderInformation() { }

public void showEffect(String effect, Object... data) { }

}

 

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

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.