Search in sources :

Example 1 with RangedWeaponItem

use of net.minecraft.item.RangedWeaponItem in project BleachHack by BleachDrinker420.

the class BowBot method onTick.

@BleachSubscribe
public void onTick(EventTick event) {
    if (!(mc.player.getMainHandStack().getItem() instanceof RangedWeaponItem) || !mc.player.isUsingItem())
        return;
    if (getSetting(0).asToggle().getState()) {
        if (mc.player.getMainHandStack().getItem() == Items.CROSSBOW && (float) mc.player.getItemUseTime() / (float) CrossbowItem.getPullTime(mc.player.getMainHandStack()) >= 1f) {
            mc.player.stopUsingItem();
            mc.player.networkHandler.sendPacket(new PlayerActionC2SPacket(Action.RELEASE_USE_ITEM, BlockPos.ORIGIN, Direction.UP));
            mc.interactionManager.interactItem(mc.player, mc.world, Hand.MAIN_HAND);
        } else if (mc.player.getMainHandStack().getItem() == Items.BOW && BowItem.getPullProgress(mc.player.getItemUseTime()) >= getSetting(0).asToggle().getChild(0).asSlider().getValueFloat()) {
            mc.player.stopUsingItem();
            mc.player.networkHandler.sendPacket(new PlayerActionC2SPacket(Action.RELEASE_USE_ITEM, BlockPos.ORIGIN, Direction.UP));
        }
    }
    // Credit: https://github.com/Wurst-Imperium/Wurst7/blob/master/src/main/java/net/wurstclient/hacks/BowAimbotHack.java
    SettingToggle aimToggle = getSetting(1).asToggle();
    if (aimToggle.getState()) {
        LivingEntity target = Streams.stream(mc.world.getEntities()).filter(e -> EntityUtils.isAttackable(e, true) && (!aimToggle.getChild(3).asToggle().getState() || mc.player.canSee(e))).filter(e -> (aimToggle.getChild(0).asToggle().getState() && EntityUtils.isPlayer(e)) || (aimToggle.getChild(1).asToggle().getState() && EntityUtils.isMob(e)) || (aimToggle.getChild(2).asToggle().getState() && EntityUtils.isAnimal(e))).sorted(Comparator.comparing(mc.player::distanceTo)).map(e -> (LivingEntity) e).findFirst().orElse(null);
        if (target == null)
            return;
        // set velocity
        float velocity = (72000 - mc.player.getItemUseTimeLeft()) / 20F;
        velocity = Math.min(1f, (velocity * velocity + velocity * 2) / 3);
        // set position to aim at
        Vec3d newTargetVec = target.getPos().add(target.getVelocity());
        double d = mc.player.getEyePos().distanceTo(target.getBoundingBox().offset(target.getVelocity()).getCenter());
        double x = newTargetVec.x + (newTargetVec.x - target.getX()) * d - mc.player.getX();
        double y = newTargetVec.y + (newTargetVec.y - target.getY()) * d + target.getHeight() * 0.5 - mc.player.getY() - mc.player.getEyeHeight(mc.player.getPose());
        double z = newTargetVec.z + (newTargetVec.z - target.getZ()) * d - mc.player.getZ();
        // set yaw
        mc.player.setYaw((float) Math.toDegrees(Math.atan2(z, x)) - 90);
        // calculate needed pitch
        double hDistance = Math.sqrt(x * x + z * z);
        double hDistanceSq = hDistance * hDistance;
        float g = 0.006F;
        float velocitySq = velocity * velocity;
        float velocityPow4 = velocitySq * velocitySq;
        float neededPitch = (float) -Math.toDegrees(Math.atan((velocitySq - Math.sqrt(velocityPow4 - g * (g * hDistanceSq + 2 * y * velocitySq))) / (g * hDistance)));
        // set pitch
        if (Float.isNaN(neededPitch)) {
            WorldUtils.facePos(target.getX(), target.getY() + target.getHeight() / 2, target.getZ());
        } else {
            mc.player.setPitch(neededPitch);
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe) SettingSlider(org.bleachhack.setting.module.SettingSlider) EntityUtils(org.bleachhack.util.world.EntityUtils) ModuleCategory(org.bleachhack.module.ModuleCategory) CrossbowItem(net.minecraft.item.CrossbowItem) LivingEntity(net.minecraft.entity.LivingEntity) RangedWeaponItem(net.minecraft.item.RangedWeaponItem) PlayerActionC2SPacket(net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) Streams(com.google.common.collect.Streams) Module(org.bleachhack.module.Module) Action(net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket.Action) WorldUtils(org.bleachhack.util.world.WorldUtils) Direction(net.minecraft.util.math.Direction) Vec3d(net.minecraft.util.math.Vec3d) Hand(net.minecraft.util.Hand) SettingToggle(org.bleachhack.setting.module.SettingToggle) BowItem(net.minecraft.item.BowItem) Comparator(java.util.Comparator) EventTick(org.bleachhack.event.events.EventTick) PlayerActionC2SPacket(net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket) SettingToggle(org.bleachhack.setting.module.SettingToggle) RangedWeaponItem(net.minecraft.item.RangedWeaponItem) Vec3d(net.minecraft.util.math.Vec3d) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Example 2 with RangedWeaponItem

use of net.minecraft.item.RangedWeaponItem in project Biome-Makeover by Lemonszz.

the class StoneGolemEntity method getArrowType.

public ItemStack getArrowType(ItemStack stack) {
    if (stack.getItem() instanceof RangedWeaponItem) {
        Predicate<ItemStack> predicate = ((RangedWeaponItem) stack.getItem()).getHeldProjectiles();
        ItemStack itemStack = RangedWeaponItem.getHeldProjectile(this, predicate);
        return itemStack.isEmpty() ? new ItemStack(Items.ARROW) : itemStack;
    } else {
        return ItemStack.EMPTY;
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) RangedWeaponItem(net.minecraft.item.RangedWeaponItem)

Aggregations

RangedWeaponItem (net.minecraft.item.RangedWeaponItem)2 Streams (com.google.common.collect.Streams)1 Comparator (java.util.Comparator)1 LivingEntity (net.minecraft.entity.LivingEntity)1 BowItem (net.minecraft.item.BowItem)1 CrossbowItem (net.minecraft.item.CrossbowItem)1 ItemStack (net.minecraft.item.ItemStack)1 Items (net.minecraft.item.Items)1 PlayerActionC2SPacket (net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket)1 Action (net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket.Action)1 Hand (net.minecraft.util.Hand)1 BlockPos (net.minecraft.util.math.BlockPos)1 Direction (net.minecraft.util.math.Direction)1 Vec3d (net.minecraft.util.math.Vec3d)1 EventTick (org.bleachhack.event.events.EventTick)1 BleachSubscribe (org.bleachhack.eventbus.BleachSubscribe)1 Module (org.bleachhack.module.Module)1 ModuleCategory (org.bleachhack.module.ModuleCategory)1 SettingSlider (org.bleachhack.setting.module.SettingSlider)1 SettingToggle (org.bleachhack.setting.module.SettingToggle)1