Posted August 18, 20187 yr Hi, I'm doing special weapon that when right-clicked moves player in short distance and damages all mobs that are in the way. That's what I've tried @Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) { ItemStack stack = player.getHeldItem(hand); Vec3d vec = player.getLookVec(); player.setVelocity(vec.x * 2, 0, vec.z * 2); stack.damageItem(15, player); List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(player, player.getEntityBoundingBox().expand(4, 0, 4)); for (Entity entity : entities) { if (entity instanceof IMob) { entity.attackEntityFrom(DamageSource.GENERIC, 5.0f); } } return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack); } It's cool and all but getEntitiesWithinAABBExcludingEntity is getting mobs that are around player so I need something completely different. Any tips what to look at and use? Edited August 18, 20187 yr by Oen44
August 18, 20187 yr Use the player.getPitchYaw(); player.getPosition(); properties along with the entity.getPosition(); vector and do some quick trig to detect if the entity is infront of the camera's view? I probably wouldn't be much help with the trig part but I know it's possible.
August 18, 20187 yr Author 56 minutes ago, oreo said: Use the player.getPitchYaw(); player.getPosition(); properties along with the entity.getPosition(); vector and do some quick trig to detect if the entity is infront of the camera's view? I probably wouldn't be much help with the trig part but I know it's possible. Yeah... That didn't help at all. Anyway, tried using RayCasting, saving surrounding mobs to array every tick, on right-click doing some position checking with every mob in array etc. Something worked in some way but not close to what I need. The worst part is about positioning BETWEEN player position and end position. All depends on player rotation, if player is facing North, leave X, decrease Z etc. I managed to handle this way North, South, West and East. But what about between? That bothers me so much... Anyone knows how to check every position (or block) from Start to End? Edited August 18, 20187 yr by Oen44
August 18, 20187 yr 31 minutes ago, Oen44 said: Anyway, tried using RayCasting, saving surrounding mobs to array every tick, on right-click doing some position checking with every mob in array etc. Something worked in some way but not close to what I need. Just check if the player's look vector intersects with the entity's AABB like I do here.
August 18, 20187 yr Author 15 minutes ago, V0idWa1k3r said: Just check if the player's look vector intersects with the entity's AABB like I do here. Awesome! Works like a charm, thank you!
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.