Posted August 23, 201213 yr 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.
August 23, 201213 yr Try the modsloader one, or use a variable that gets initialized @ServerStartup, I use the variable style, I found it works better and it looks cleaner, but that is opinion. Please send me all the typo's you found, I'm from Belgium and I'm a little dyslectic and suck @ typing. http://dries007.net/banner.png[/img]
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.