Search in sources :

Example 1 with EntityRayTraceResult

use of net.minecraft.util.math.EntityRayTraceResult in project Overloaded by CJ-MC-Mods.

the class ItemRailGun method use.

@Override
@Nonnull
@OnlyIn(Dist.CLIENT)
public ActionResult<ItemStack> use(World worldIn, @Nonnull PlayerEntity playerIn, @Nonnull Hand handIn) {
    if (worldIn.isClientSide) {
        int distance = OverloadedConfig.INSTANCE.railGun.maxRange;
        Vector3d vec3d = playerIn.getEyePosition(Minecraft.getInstance().getFrameTime());
        Vector3d vec3d1 = playerIn.getViewVector(Minecraft.getInstance().getFrameTime());
        Vector3d vec3d2 = vec3d.add(vec3d1.x * distance, vec3d1.y * distance, vec3d1.z * distance);
        float f = 1.0F;
        AxisAlignedBB axisalignedbb = playerIn.getBoundingBox().expandTowards(vec3d1.scale(distance)).inflate(1.0D, 1.0D, 1.0D);
        EntityRayTraceResult ray = ProjectileHelper.getEntityHitResult(playerIn, vec3d, vec3d2, axisalignedbb, (p_215312_0_) -> !p_215312_0_.isSpectator() && p_215312_0_.isPickable(), distance * distance);
        if (ray != null) {
            Vector3d moveVev = playerIn.getEyePosition(1).subtract(ray.getLocation()).normalize().scale(-1.0);
            Overloaded.proxy.networkWrapper.sendToServer(new RailGunFireMessage(ray.getEntity().getId(), moveVev, handIn));
        } else {
            Overloaded.proxy.networkWrapper.sendToServer(new RailGunFireMessage(0, Vector3d.ZERO, handIn));
        }
    }
    return new ActionResult<>(ActionResultType.SUCCESS, playerIn.getItemInHand(handIn));
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) RailGunFireMessage(com.cjm721.overloaded.network.packets.RailGunFireMessage) EntityRayTraceResult(net.minecraft.util.math.EntityRayTraceResult) Vector3d(net.minecraft.util.math.vector.Vector3d) Nonnull(javax.annotation.Nonnull) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Aggregations

RailGunFireMessage (com.cjm721.overloaded.network.packets.RailGunFireMessage)1 Nonnull (javax.annotation.Nonnull)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 EntityRayTraceResult (net.minecraft.util.math.EntityRayTraceResult)1 Vector3d (net.minecraft.util.math.vector.Vector3d)1 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)1