Posted November 26, 201410 yr Hello, I notice that is inpossible rotate the yaw attribute of any entities setted always to 0: I tried this code but doesn't works: EntityCreeper Creeper = new EntityCreeper(player.worldObj); Creeper.setLocationAndAngles(event.x + 0.5D, event.y, event.z + 0.5D, fYaw, 0.0F); player.worldObj.spawnEntityInWorld(Creeper ); Creeper.setPositionAndRotation(event.x + 0.5D, event.y, event.z + 0.5D, fYaw, 0.0F); Creeper.rotationYaw = fYaw; Creeper.setAngles(fYaw, 0.0F); please help ...
November 26, 201410 yr We need to see more of your code. I see that you set the rotation yaw to fyaw but I don't know what fyaw is set to elsewhere in your code...
November 26, 201410 yr Author We need to see more of your code. I see that you set the rotation yaw to fyaw but I don't know what fyaw is set to elsewhere in your code... The Code into "onBreakBlock(BreakEvent event)" function (with "@SubscribeEvent" tag): fYaw = 90.0F; EntityCreeper Creeper = new EntityCreeper(player.worldObj); Creeper.setLocationAndAngles(event.x + 0.5D, event.y, event.z + 0.5D, fYaw, 0.0F); player.worldObj.spawnEntityInWorld(Creeper); Creeper.setPositionAndRotation(event.x + 0.5D, event.y, event.z + 0.5D, fYaw, 0.0F); Creeper.rotationYaw = fYaw; Creeper.setAngles(fYaw, 0.0F); //Creeper.setRotationYawHead(fYaw); <=== Works but rotate head only
November 26, 201410 yr There should be a variable in your entity called rotationYaw try setting that to the value of fYaw and it should work.
November 26, 201410 yr Author There should be a variable in your entity called rotationYaw try setting that to the value of fYaw and it should work. maybe you haven't noticed, but it already does ... Creeper.rotationYaw = fYaw;
November 26, 201410 yr Spawn the entity after you change all the variables. Make sure it only spawns serverside with if (!player.worldObj.isRemote).
November 26, 201410 yr The setAngles() method isn't doing what you think it is. Here is the text that the forge gives for what that method does. Adds par1*0.15 to the entity's yaw, and *subtracts* par2*0.15 from the pitch. Clamps pitch from -90 to 90. Both arguments in degrees. try removing that method and see if your entity rotates how you think it should. I tried a test using myself as the entity and when I changed the rotationYaw variable by itself it did work without any added code so try only changing that variable. Also try david's suggestion.
November 26, 201410 yr Author Spawn the entity after you change all the variables. Make sure it only spawns serverside with if (!player.worldObj.isRemote). Well, I tried this code in creative mode for watch better the creeper movements and not in "paceful" mode, obviously: @SubscribeEvent public void onBreakBlock(BreakEvent event) { if (!player.worldObj.isRemote) { fYaw = 90.0F; // or = 270.0F or = 180.0F EntityCreeper Logger = new EntityCreeper(player.worldObj); Logger.setLocationAndAngles(event.x + 0.5D, event.y, event.z + 0.5D, fYaw, 0.0F); Logger.rotationYaw = fYaw; // <===== Tried With and WithOut this line player.worldObj.spawnEntityInWorld(Logger); } } Results same problem: the Creeper spawn allways with the same Yaw direction (0.0F). The setAngles() method isn't doing what you think it is. Here is the text that the forge gives for what that method does. Adds par1*0.15 to the entity's yaw, and *subtracts* par2*0.15 from the pitch. Clamps pitch from -90 to 90. Both arguments in degrees. try removing that method and see if your entity rotates how you think it should. I tried a test using myself as the entity and when I changed the rotationYaw variable by itself it did work without any added code so try only changing that variable. Also try david's suggestion. Seriously, I tried all code combinations but nothing to do ... Can I see your testing code? thank you so much ...
November 26, 201410 yr I just left the house for the day when I arrive back I can post the source code. If I forget pm me and I'll remember
November 27, 201410 yr here is the code that worked for me... @Override public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack item){ int yaw = ((int) player.rotationYaw)%360; if (yaw<0) yaw+=360; if (315<yaw || yaw<=45) world.setBlockMetadataWithNotify(x, y, z, 2, 3); if (45<yaw && yaw<=135) world.setBlockMetadataWithNotify(x, y, z, 5, 3); if (135<yaw && yaw<=225) world.setBlockMetadataWithNotify(x, y, z, 3, 3); if (225<yaw && yaw<=315) world.setBlockMetadataWithNotify(x, y, z, 4, 3); player.rotationYaw = 90; } the other code you see there just rotates the block depending on which direction you are facing which is unimportant in this case. What is important is the last line player.rotationYaw = 90; when run and I place the block my character is rotated to the position of 90 degrees so it is working for me.
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.