poopoodice Posted May 14, 2020 Posted May 14, 2020 It has troubled me for a long time, I already made a bullet that can fire correctly, but what I want is that it reduces damages and its range when hit a block/entity instead of just got removed. And currently it extends ThrowableEntity. What I tried to do was to check in onImpact() if the bullet was hitting a block, if true reduces range and damage, but the problem is if the bullet hit both of them at the same time (which can be pretty big since it moves really fast), it only returns the first thing got hit and then it moves to the next position and ignores the other(s) hits. I also try to find every single block between the start vec and destination vec (entity hit), but it will be really terrible if there are lots of bullets in the world doing that at the same time.. any ideas will be appreciated. Quote
poopoodice Posted May 14, 2020 Author Posted May 14, 2020 (edited) AxisAlignedBB axisalignedbb = this.getBoundingBox().expand(this.getMotion()).grow(1.0D); Vec3d from = this.getPositionVec(); Vec3d to = this.getPositionVec().add(new Vec3d(this.getMotion().getX(), this.getMotion().getY(), this.getMotion().getZ())); EntityRayTraceResult entityResult = ProjectileHelper.rayTraceEntities(world, this, from, to, axisalignedbb, (entity) entity -> != getThrower()); BlockRayTraceResult blockResult = world.rayTraceBlocks(new RayTraceContext(from, to, RayTraceContext.BlockMode.COLLIDER, RayTraceContext.FluidMode.ANY, this)); as shown above, both entity/block ray trace only gets the first block/entity hit. does doing multiple raytracing such as splitting one raytracing into multiple like BlockRayTraceResult blockResult for (int i=0;i<10;i++) { blockResult = //split into 10 sections, just an example world.rayTraceBlocks(new RayTraceContext(from, from + (to - from) / 10 * i, RayTraceContext.BlockMode.COLLIDER, RayTraceContext.FluidMode.ANY, this)); if (.......... ..... } sounds like a good idea, or it will cause bad performances? Edited May 14, 2020 by poopoodice Quote
Draco18s Posted May 14, 2020 Posted May 14, 2020 On 5/14/2020 at 10:46 AM, poopoodice said: (from, from + (to - from) / 10 * i, Expand This doesn't actually do what you're thinking of trying to make it do. Its firing 10 rays from the same origin out to a different max distance. If there's an entity/block within the first ray's path, then all ten rays will find the same entity. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
poopoodice Posted May 14, 2020 Author Posted May 14, 2020 (edited) On 5/14/2020 at 5:51 PM, Draco18s said: This doesn't actually do what you're thinking of trying to make it do. Its firing 10 rays from the same origin out to a different max distance. If there's an entity/block within the first ray's path, then all ten rays will find the same entity. Expand Oops, I meant to type BlockRayTraceResult blockResult for (int i=0;i<10;i++) { blockResult = //split into 10 sections, just an example world.rayTraceBlocks(new RayTraceContext(from.add((to.subtract(from)).mul(0.1D, 0.1D, 0.1D).mul(i, i, i)) , to, RayTraceContext.BlockMode.COLLIDER, RayTraceContext.FluidMode.ANY, this)); if (.......... ..... } but it's just an example, don't think it will work properly without any disadvantages such as cause lags,, etc. Edited May 14, 2020 by poopoodice Quote
Recommended Posts
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.