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 am trying to spawn an entity but it doesnt work as properly.

 

Whenever the entity spawns it appears on my screen for a brief second and dissapears after.

I think it has something to do with the fact that the postion of the entity is incorrect or  something and that is teleported to the origin of the world.

 

This is my current code:

public static void summonEntity(Class<? extends Entity> clazz, World world, double x, double y, double z, SummoningCircleLogic logic, AdditionalSummonInfo info){
	Entity entity = getEntityByClass(clazz, world);
	entity.setLocationAndAngles(x, y, z, MathHelper.wrapAngleTo180_float(world.rand.nextFloat() * 360.0F), 0.0F);
	if(entity instanceof EntityLiving){
		EntityLiving living = (EntityLiving) entity;
		living.rotationYawHead = living.rotationYaw;
        living.renderYawOffset = living.rotationYaw;
	}
	world.spawnEntityInWorld(entity);
	if(entity instanceof ISummonedEntity){
		((ISummonedEntity) entity).onSummoned(logic);
		((ISummonedEntity) entity).playSummonedSound(world, x, y, z);
	}
}

public static Entity getEntityByClass(Class<? extends Entity> clazz, World world){
	try {
		Class[] type = {World.class};
		Constructor cons = clazz.getConstructor(type);
		Object[] obj = {world};
		return (Entity) cons.newInstance(obj);
	} catch (NoSuchMethodException e1) {
		e1.printStackTrace();
	} catch (SecurityException e1) {
		e1.printStackTrace();
	} catch (InstantiationException e) {
		e.printStackTrace();
	} catch (IllegalAccessException e) {
		e.printStackTrace();
	} catch (IllegalArgumentException e) {
		e.printStackTrace();
	} catch (InvocationTargetException e) {
		e.printStackTrace();
	}
	return null;
}

 

BTW all this is executed server side only. so no need to do the !world.isRemote check.

Is there an error on the console? Post it.

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

In your Entity's onUpdate function do System.out.println("x:"+x+"y:"+"z:"+z) to make sure that it's coordinates are being inputed correctly.

The proud(ish) developer of Ancients

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.