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

Hi. I want to cast (or convert) object with path given as string into EntityLivingBase variable. I'm newbie with modding, so please could you help me? I have tried this:

Object o = Class.forName("net.minecraft.entity.monster.EntitySkeleton");
EntityLivingBase living = (EntityLivingBase) o;

 

but it cant be just casted..

  • Author

I'm trying to create EntityLivingBase variable while i only have it's class path string. Could you please explain me with some code how to do this?

Maybe some better background would be helpful.. what are you trying to achieve by doing this?

  • Author

So I'm making a improvement to Morph modification. I added command which takes entity class as an argument and use it to invoke morphPlayer method.. but i need to give EntityLivingBase as argument there..

 

That's extended version of my code i have at the moment:

	public void processCommand(ICommandSender sender, String[] args) {
	if(args[0].equalsIgnoreCase("morph")) {
		EntityPlayerMP player;
		if(args.length > 2) {
			player = PlayerSelector.matchOnePlayer(sender, args[2]);
		} else {
			player = getCommandSenderAsPlayer(sender);
		}

		Object o = null;
		EntityLivingBase living = null;

		try {
			o = Class.forName(args[1]).getConstructor();
			living = (EntityLivingBase) o;
			Class<?> EH = Class.forName("morph.common.core.EntityHelper");
			Method method = EH.getMethod("morphPlayer", EntityPlayerMP.class, EntityLivingBase.class, boolean.class);
			method.invoke(null, player, living, true);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (SecurityException e) {
			e.printStackTrace();
		}

	}
}

 

So now I'm getting

java.lang.NoSuchMethodException: net.minecraft.entity.monster.EntitySkeleton.<init>()

        at java.lang.Class.getConstructor0(Unknown Source)

        at java.lang.Class.getConstructor(Unknown Source)

here

o = Class.forName(args[1]).getConstructor();

  • Author

What about modded entites? It's the biggest feature of Morph that it supports most modifications entities..

So, can I use your method with entites added with mods, like this:

drzhark.mocreatures.entity.passive.MoCEntityBird

  • Author

How can i cast Entity into EntityLivingBase?

EntityLivingBase living = (EntityLivingBase) EntityList.createEntityByName(args[1], player.getEntityWorld());

throws nullPointerException for args[1] = zombie, skeleton etc.

  • Author

It's me again. I have an issue with createEntityByName method.. sometimes it returns null. Maybe it's because of specified time or world? Is there any way to force creating entity using this method?

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.