Jump to content

Entity Spawning Problem


shucke

Recommended Posts

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.

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.



×
×
  • Create New...

Important Information

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