Posted October 29, 201410 yr 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. http://www.minecraftforum.net/topic/1937703-162smpforge-pet-mastery-hatch-level-battle/
October 29, 201410 yr 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!
October 29, 201410 yr Author no error, like i said it spawns but it is teleported. http://www.minecraftforum.net/topic/1937703-162smpforge-pet-mastery-hatch-level-battle/
October 29, 201410 yr Try setting the pos fields? Check out my mod, Realms of Chaos, here. If I helped you, be sure to press the "Thank You" button!
October 29, 201410 yr Author entity.setLocationAndAngles(x, y, z, MathHelper.wrapAngleTo180_float(world.rand.nextFloat() * 360.0F), 0.0F); this should set the pos fields. and its already in but doesnt work unfortunatly. http://www.minecraftforum.net/topic/1937703-162smpforge-pet-mastery-hatch-level-battle/
October 29, 201410 yr 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.