Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

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.

width=700 height=100http://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.

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

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.