Search in sources :

Example 46 with EnumHand

use of net.minecraft.util.EnumHand in project MatterOverdrive-Community-Edition-1.12.2 by Matter-Overdrive-Community-Edition.

the class RenderMatterScannerInfoHandler method onRenderWorldLast.

public void onRenderWorldLast(RenderHandler renderHandler, RenderWorldLastEvent event) {
    EntityPlayer player = Minecraft.getMinecraft().player;
    boolean holdingPad = false;
    EnumHand hand = EnumHand.MAIN_HAND;
    ItemStack heldItem = ItemStack.EMPTY;
    if (!player.getHeldItem(EnumHand.MAIN_HAND).isEmpty()) {
        hand = EnumHand.MAIN_HAND;
        heldItem = player.getHeldItem(EnumHand.MAIN_HAND);
        if (heldItem.getItem() instanceof IBlockScanner) {
            holdingPad = true;
        } else {
            heldItem = ItemStack.EMPTY;
        }
    } else if (!player.getHeldItem(EnumHand.OFF_HAND).isEmpty()) {
        hand = EnumHand.OFF_HAND;
        heldItem = player.getHeldItem(EnumHand.OFF_HAND);
        if (heldItem.getItem() instanceof IBlockScanner) {
            holdingPad = true;
        } else {
            heldItem = ItemStack.EMPTY;
        }
    }
    if (holdingPad && !heldItem.isEmpty() && player.getActiveHand() == hand) {
        GlStateManager.pushMatrix();
        renderInfo(Minecraft.getMinecraft().player, heldItem, event.getPartialTicks());
        GlStateManager.popMatrix();
    } else if (MOPlayerCapabilityProvider.GetAndroidCapability(Minecraft.getMinecraft().player).isAndroid()) {
        renderInfo(Minecraft.getMinecraft().player, Minecraft.getMinecraft().objectMouseOver, ItemStack.EMPTY, event.getPartialTicks());
    }
}
Also used : EnumHand(net.minecraft.util.EnumHand) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IBlockScanner(matteroverdrive.api.inventory.IBlockScanner) ItemStack(net.minecraft.item.ItemStack)

Example 47 with EnumHand

use of net.minecraft.util.EnumHand in project Advent-Of-Ascension by Tslat.

the class SoulSpark method doEntityImpact.

@Override
public boolean doEntityImpact(BaseEnergyShot shot, Entity target, EntityLivingBase shooter) {
    if (!EntityUtil.isSpecExempt(target, shooter) && !EntityUtil.isTypeImmune(target, Enums.MobProperties.BLASTER_IMMUNE)) {
        if (shooter instanceof EntityPlayerMP && !((EntityPlayerMP) shooter).capabilities.isCreativeMode) {
            EntityPlayer player = (EntityPlayer) shooter;
            PlayerDataManager.PlayerStats stats = PlayerUtil.getAdventPlayer(player).stats();
            if (stats.getResourceValue(Enums.Resources.ENERGY) < 200) {
                PlayerUtil.notifyPlayerOfInsufficientResources((EntityPlayerMP) player, Enums.Resources.ENERGY, 200);
                return false;
            }
            if (stats.getResourceValue(Enums.Resources.SOUL) < 50) {
                PlayerUtil.notifyPlayerOfInsufficientResources((EntityPlayerMP) player, Enums.Resources.SOUL, 50);
                return false;
            }
            stats.consumeResource(Enums.Resources.ENERGY, 200, false);
            stats.consumeResource(Enums.Resources.SOUL, 50, false);
            EnumHand hand = player.getActiveHand();
            ItemStack stack = player.getHeldItem(hand);
            if (stack.getItem() != this)
                stack = player.getHeldItem(hand == EnumHand.MAIN_HAND ? EnumHand.OFF_HAND : EnumHand.MAIN_HAND);
            if (stack.getItem() != this)
                return false;
            stack.damageItem(1, shooter);
        }
        target.setDead();
        return true;
    }
    return false;
}
Also used : EnumHand(net.minecraft.util.EnumHand) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack) PlayerDataManager(net.tslat.aoa3.utils.player.PlayerDataManager)

Example 48 with EnumHand

use of net.minecraft.util.EnumHand in project 3arthh4ck by 3arthqu4ke.

the class ServerTimeHelper method place.

private void place(BlockPos pos, int sleep) {
    SwingTime time = placeSwing.getValue();
    THREAD.schedule(() -> {
        if (InventoryUtil.isHolding(Items.END_CRYSTAL)) {
            EnumHand hand = InventoryUtil.getHand(Items.END_CRYSTAL);
            RayTraceResult ray = RotationUtil.rayTraceTo(pos, mc.world);
            float[] f = RayTraceUtil.hitVecToPlaceVec(pos, ray.hitVec);
            if (time == SwingTime.Pre) {
                Swing.Packet.swing(hand);
                Swing.Client.swing(hand);
            }
            mc.player.connection.sendPacket(new CPacketPlayerTryUseItemOnBlock(pos, ray.sideHit, hand, f[0], f[1], f[2]));
            if (time == SwingTime.Post) {
                Swing.Packet.swing(hand);
                Swing.Client.swing(hand);
            }
        }
    }, sleep, TimeUnit.MILLISECONDS);
}
Also used : EnumHand(net.minecraft.util.EnumHand) RayTraceResult(net.minecraft.util.math.RayTraceResult) SwingTime(me.earth.earthhack.impl.modules.combat.autocrystal.modes.SwingTime) CPacketPlayerTryUseItemOnBlock(net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock)

Example 49 with EnumHand

use of net.minecraft.util.EnumHand in project 3arthh4ck by 3arthqu4ke.

the class ListenerSpawnObject method invoke.

@Override
public void invoke(PacketEvent.Receive<SPacketSpawnObject> event) {
    EntityPlayerSP player = mc.player;
    if (module.instant.getValue() && player != null && Managers.SWITCH.getLastSwitch() >= module.coolDown.getValue() && !DamageUtil.isWeaknessed() && module.timer.passed(module.delay.getValue()) && event.getPacket().getType() == 51) {
        SPacketSpawnObject packet = event.getPacket();
        LegConstellation constellation = module.constellation;
        if (constellation != null && // TODO: make it place asnyc?
        !constellation.firstNeedsObby && !constellation.secondNeedsObby && (InventoryUtil.isHolding(Items.END_CRYSTAL) || module.autoSwitch.getValue() != LegAutoSwitch.None)) {
            double x = packet.getX();
            double y = packet.getY();
            double z = packet.getZ();
            BlockPos pos = new BlockPos(x, y - 1, z);
            BlockPos previous = module.targetPos;
            if (!pos.equals(previous)) {
                return;
            }
            BlockPos targetPos = constellation.firstPos.equals(previous) ? constellation.secondPos : constellation.firstPos;
            EntityEnderCrystal entity = new EntityEnderCrystal(mc.world, x, y, z);
            if (!module.rotate.getValue().noRotate(ACRotate.Break) && !RotationUtil.isLegit(entity) || !module.rotate.getValue().noRotate(ACRotate.Place) && !RotationUtil.isLegit(targetPos)) {
                return;
            }
            RayTraceResult result = RotationUtil.rayTraceTo(targetPos, mc.world);
            if (result == null) {
                result = new RayTraceResult(new Vec3d(0.5, 1.0, 0.5), EnumFacing.UP);
            }
            entity.setUniqueId(packet.getUniqueId());
            entity.setEntityId(packet.getEntityID());
            entity.setShowBottom(false);
            int slot = InventoryUtil.findHotbarItem(Items.END_CRYSTAL);
            RayTraceResult finalResult = result;
            Locks.acquire(Locks.PLACE_SWITCH_LOCK, () -> {
                int last = player.inventory.currentItem;
                EnumHand hand = player.getHeldItemMainhand().getItem() == Items.END_CRYSTAL || slot != -2 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND;
                player.connection.sendPacket(new CPacketUseEntity(entity));
                player.connection.sendPacket(new CPacketAnimation(EnumHand.MAIN_HAND));
                InventoryUtil.switchTo(slot);
                player.connection.sendPacket(new CPacketPlayerTryUseItemOnBlock(targetPos, finalResult.sideHit, hand, (float) finalResult.hitVec.x, (float) finalResult.hitVec.y, (float) finalResult.hitVec.z));
                player.connection.sendPacket(new CPacketAnimation(hand));
                if (last != slot && module.autoSwitch.getValue() != LegAutoSwitch.Keep) {
                    InventoryUtil.switchTo(last);
                }
            });
            module.targetPos = targetPos;
            if (module.setDead.getValue()) {
                event.addPostEvent(() -> {
                    if (mc.world != null) {
                        Entity e = mc.world.getEntityByID(packet.getEntityID());
                        if (e != null) {
                            Managers.SET_DEAD.setDead(e);
                        }
                    }
                });
            }
            module.timer.reset(module.delay.getValue());
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) CPacketUseEntity(net.minecraft.network.play.client.CPacketUseEntity) SPacketSpawnObject(net.minecraft.network.play.server.SPacketSpawnObject) EntityEnderCrystal(net.minecraft.entity.item.EntityEnderCrystal) RayTraceResult(net.minecraft.util.math.RayTraceResult) CPacketAnimation(net.minecraft.network.play.client.CPacketAnimation) Vec3d(net.minecraft.util.math.Vec3d) CPacketPlayerTryUseItemOnBlock(net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock) CPacketUseEntity(net.minecraft.network.play.client.CPacketUseEntity) EnumHand(net.minecraft.util.EnumHand) BlockPos(net.minecraft.util.math.BlockPos) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP)

Example 50 with EnumHand

use of net.minecraft.util.EnumHand in project 3arthh4ck by 3arthqu4ke.

the class ListenerObby method rotateCheck.

@Override
protected boolean rotateCheck() {
    if (crystalPos != null && (!module.isAnvil || module.ticks > 3 && module.hasMined)) {
        IBlockStateHelper helper = new BlockStateHelper();
        helper.addBlockState(crystalPos, Blocks.OBSIDIAN.getDefaultState());
        RayTraceResult ray = null;
        if (module.rotations != null) {
            ray = RotationUtil.rayTraceWithYP(crystalPos, helper, module.rotations[0], module.rotations[1], (b, p) -> p.equals(crystalPos));
        }
        if (ray == null) {
            double x = RotationUtil.getRotationPlayer().posX;
            double y = RotationUtil.getRotationPlayer().posY;
            double z = RotationUtil.getRotationPlayer().posZ;
            module.rotations = RotationUtil.getRotations(crystalPos.getX() + 0.5f, crystalPos.getY() + 1, crystalPos.getZ() + 0.5f, x, y, z, mc.player.getEyeHeight());
            ray = RotationUtil.rayTraceWithYP(crystalPos, helper, module.rotations[0], module.rotations[1], (b, p) -> p.equals(crystalPos));
            if (ray == null) {
                ray = new RayTraceResult(new Vec3d(0.5, 1.0, 0.5), EnumFacing.UP, crystalPos);
            }
        }
        int crystalSlot = module.crystalSlot;
        RayTraceResult finalResult = ray;
        float[] f = RayTraceUtil.hitVecToPlaceVec(crystalPos, ray.hitVec);
        EnumHand h = InventoryUtil.getHand(crystalSlot);
        BlockPos finalPos = crystalPos;
        module.post.add(() -> {
            InventoryUtil.switchTo(crystalSlot);
            mc.player.connection.sendPacket(new CPacketPlayerTryUseItemOnBlock(finalPos, finalResult.sideHit, h, f[0], f[1], f[2]));
        });
    }
    return super.rotateCheck();
}
Also used : ObbyListener(me.earth.earthhack.impl.util.helpers.blocks.ObbyListener) RayTraceUtil(me.earth.earthhack.impl.util.math.RayTraceUtil) Blocks(net.minecraft.init.Blocks) BlockStateHelper(me.earth.earthhack.impl.util.minecraft.blocks.states.BlockStateHelper) Managers(me.earth.earthhack.impl.managers.Managers) EntityEnderCrystal(net.minecraft.entity.item.EntityEnderCrystal) Rotate(me.earth.earthhack.impl.util.helpers.blocks.modes.Rotate) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) RotationUtil(me.earth.earthhack.impl.util.math.rotation.RotationUtil) BlockUtil(me.earth.earthhack.impl.util.minecraft.blocks.BlockUtil) EnumHand(net.minecraft.util.EnumHand) HelperLiquids(me.earth.earthhack.impl.modules.combat.autocrystal.HelperLiquids) MotionUpdateEvent(me.earth.earthhack.impl.event.events.network.MotionUpdateEvent) RayTraceResult(net.minecraft.util.math.RayTraceResult) MathUtil(me.earth.earthhack.impl.util.math.MathUtil) PositionUtil(me.earth.earthhack.impl.util.math.position.PositionUtil) CPacketPlayerTryUseItemOnBlock(net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock) Vec3d(net.minecraft.util.math.Vec3d) MineSlots(me.earth.earthhack.impl.modules.combat.autocrystal.util.MineSlots) LegSwitch(me.earth.earthhack.impl.modules.combat.legswitch.LegSwitch) Stage(me.earth.earthhack.api.event.events.Stage) InventoryUtil(me.earth.earthhack.impl.util.minecraft.InventoryUtil) EventBus(me.earth.earthhack.api.event.bus.api.EventBus) MineUtil(me.earth.earthhack.impl.util.minecraft.blocks.mine.MineUtil) PacketUtil(me.earth.earthhack.impl.util.network.PacketUtil) EntityItem(net.minecraft.entity.item.EntityItem) Entity(net.minecraft.entity.Entity) TargetResult(me.earth.earthhack.impl.util.helpers.blocks.util.TargetResult) Items(net.minecraft.init.Items) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) DamageUtil(me.earth.earthhack.impl.util.minecraft.DamageUtil) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) IBlockState(net.minecraft.block.state.IBlockState) List(java.util.List) Swing(me.earth.earthhack.impl.util.minecraft.Swing) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IBlockStateHelper(me.earth.earthhack.impl.util.minecraft.blocks.states.IBlockStateHelper) EntityUtil(me.earth.earthhack.impl.util.minecraft.entity.EntityUtil) IBlockStateHelper(me.earth.earthhack.impl.util.minecraft.blocks.states.IBlockStateHelper) EnumHand(net.minecraft.util.EnumHand) BlockStateHelper(me.earth.earthhack.impl.util.minecraft.blocks.states.BlockStateHelper) IBlockStateHelper(me.earth.earthhack.impl.util.minecraft.blocks.states.IBlockStateHelper) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d) CPacketPlayerTryUseItemOnBlock(net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock)

Aggregations

EnumHand (net.minecraft.util.EnumHand)117 ItemStack (net.minecraft.item.ItemStack)62 EntityPlayer (net.minecraft.entity.player.EntityPlayer)55 BlockPos (net.minecraft.util.math.BlockPos)45 EnumFacing (net.minecraft.util.EnumFacing)32 Vec3d (net.minecraft.util.math.Vec3d)24 World (net.minecraft.world.World)24 Entity (net.minecraft.entity.Entity)23 RayTraceResult (net.minecraft.util.math.RayTraceResult)21 EntityLivingBase (net.minecraft.entity.EntityLivingBase)19 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)19 Item (net.minecraft.item.Item)18 CPacketPlayerTryUseItemOnBlock (net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock)18 IBlockState (net.minecraft.block.state.IBlockState)17 TileEntity (net.minecraft.tileentity.TileEntity)16 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)15 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)14 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)13 List (java.util.List)12 Block (net.minecraft.block.Block)11