Search in sources :

Example 56 with EnumHand

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

the class ListenerUpdate method invoke.

@Override
public void invoke(MotionUpdateEvent event) {
    if (event.getStage() == Stage.PRE && module.mode.getValue() == FastEatMode.Update && module.isValid(mc.player.getActiveItemStack())) {
        EnumHand hand = mc.player.getActiveHand();
        // noinspection ConstantConditions
        if (// this can happen!
        hand == null) {
            hand = mc.player.getHeldItemOffhand().equals(mc.player.getActiveItemStack()) ? EnumHand.OFF_HAND : EnumHand.MAIN_HAND;
        }
        mc.player.connection.sendPacket(new CPacketPlayerTryUseItem(hand));
    } else if (event.getStage() == Stage.POST && module.mode.getValue() == FastEatMode.Packet && module.isValid(mc.player.getActiveItemStack()) && mc.player.getItemInUseMaxCount() > module.speed.getValue() - 1 && module.speed.getValue() < 25) {
        for (int i = 0; i < 32; i++) {
            mc.player.connection.sendPacket(new CPacketPlayer(mc.player.onGround));
        }
        mc.player.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.RELEASE_USE_ITEM, BlockPos.ORIGIN, EnumFacing.DOWN));
        mc.player.stopActiveHand();
    }
}
Also used : CPacketPlayerTryUseItem(net.minecraft.network.play.client.CPacketPlayerTryUseItem) CPacketPlayerDigging(net.minecraft.network.play.client.CPacketPlayerDigging) EnumHand(net.minecraft.util.EnumHand) CPacketPlayer(net.minecraft.network.play.client.CPacketPlayer)

Example 57 with EnumHand

use of net.minecraft.util.EnumHand in project defrag by Edouard127.

the class MixinMinecraft method rightClickMouseAtInvokeGetHeldItem.

// Fix random crystal placing when eating gapple in offhand
@Inject(method = "rightClickMouse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/entity/EntityPlayerSP;getHeldItem(Lnet/minecraft/util/EnumHand;)Lnet/minecraft/item/ItemStack;"), cancellable = true)
public void rightClickMouseAtInvokeGetHeldItem(CallbackInfo ci) {
    EntityPlayerSP player = Wrapper.getPlayer();
    WorldClient world = Wrapper.getWorld();
    PlayerControllerMP playerController = Wrapper.getMinecraft().playerController;
    RayTraceResult objectMouseOver = Wrapper.getMinecraft().objectMouseOver;
    if (player == null || world == null || playerController == null)
        return;
    if (CrystalAura.INSTANCE.isDisabled() || CrystalAura.INSTANCE.getInactiveTicks() > 2)
        return;
    if (player.getHeldItemOffhand().getItem() == Items.END_CRYSTAL)
        return;
    if (HotbarManager.INSTANCE.getServerSideItem(player).getItem() != Items.END_CRYSTAL)
        return;
    ci.cancel();
    for (EnumHand enumhand : EnumHand.values()) {
        ItemStack itemstack = player.getHeldItem(enumhand);
        if (itemstack.isEmpty() && (objectMouseOver == null || objectMouseOver.typeOfHit == RayTraceResult.Type.MISS)) {
            ForgeHooks.onEmptyClick(player, enumhand);
        }
        if (!itemstack.isEmpty() && playerController.processRightClick(player, world, enumhand) == EnumActionResult.SUCCESS) {
            Wrapper.getMinecraft().entityRenderer.itemRenderer.resetEquippedProgress(enumhand);
        }
    }
}
Also used : PlayerControllerMP(net.minecraft.client.multiplayer.PlayerControllerMP) AccessorPlayerControllerMP(com.lambda.client.mixin.client.accessor.player.AccessorPlayerControllerMP) EnumHand(net.minecraft.util.EnumHand) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) AccessorEntityPlayerSP(com.lambda.client.mixin.client.accessor.player.AccessorEntityPlayerSP) ItemStack(net.minecraft.item.ItemStack) WorldClient(net.minecraft.client.multiplayer.WorldClient) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 58 with EnumHand

use of net.minecraft.util.EnumHand in project GregTech by GregTechCE.

the class PlayerInventoryUIFactory method readHolderFromSyncData.

@Override
@SideOnly(Side.CLIENT)
protected PlayerInventoryHolder readHolderFromSyncData(PacketBuffer syncData) {
    EntityPlayer entityPlayer = Minecraft.getMinecraft().player;
    EnumHand enumHand = EnumHand.values()[syncData.readByte()];
    ItemStack itemStack;
    try {
        itemStack = syncData.readItemStack();
    } catch (IOException exception) {
        throw new RuntimeException(exception);
    }
    return new PlayerInventoryHolder(entityPlayer, enumHand, itemStack);
}
Also used : EnumHand(net.minecraft.util.EnumHand) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IOException(java.io.IOException) ItemStack(net.minecraft.item.ItemStack) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 59 with EnumHand

use of net.minecraft.util.EnumHand in project ImmersiveEngineering by BluSunrize.

the class ApiUtils method consumePlayerIngredient.

public static void consumePlayerIngredient(EntityPlayer player, IngredientStack ingredient) {
    int amount = ingredient.inputSize;
    ItemStack itemstack;
    for (EnumHand hand : EnumHand.values()) {
        itemstack = player.getHeldItem(hand);
        if (ingredient.matchesItemStackIgnoringSize(itemstack)) {
            int taken = Math.min(amount, itemstack.stackSize);
            amount -= taken;
            itemstack.stackSize -= taken;
            if (itemstack.stackSize <= 0)
                player.setHeldItem(hand, null);
            if (amount <= 0)
                return;
        }
    }
    for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
        itemstack = player.inventory.getStackInSlot(i);
        if (ingredient.matchesItemStackIgnoringSize(itemstack)) {
            int taken = Math.min(amount, itemstack.stackSize);
            amount -= taken;
            itemstack.stackSize -= taken;
            if (itemstack.stackSize <= 0)
                player.inventory.setInventorySlotContents(i, null);
            if (amount <= 0)
                return;
        }
    }
}
Also used : EnumHand(net.minecraft.util.EnumHand) ItemStack(net.minecraft.item.ItemStack)

Example 60 with EnumHand

use of net.minecraft.util.EnumHand in project NetherEx by LogicTechCorp.

the class EventHandler method onPlayerRightClickBlock.

@SubscribeEvent
public static void onPlayerRightClickBlock(PlayerInteractEvent.RightClickBlock event) {
    World world = event.getWorld();
    BlockPos pos = event.getPos();
    EntityPlayer player = event.getEntityPlayer();
    ItemStack stack = event.getItemStack();
    if (stack.getItem() == NetherExItems.TOOL_SHOVEL_BONE || ConfigHandler.block.netherrack.allowAllShovelsToFlatten && stack.getItem() instanceof ItemHoe) {
        IBlockState state = world.getBlockState(pos);
        Block block = state.getBlock();
        if (block == Blocks.NETHERRACK || block == NetherExBlocks.BLOCK_NETHERRACK || block == NetherExBlocks.BLOCK_HYPHAE) {
            for (EnumHand hand : EnumHand.values()) {
                if (player.getHeldItem(hand).getItem() instanceof ItemSpade) {
                    player.swingArm(hand);
                }
            }
            int meta = block == Blocks.NETHERRACK ? 0 : block == NetherExBlocks.BLOCK_HYPHAE ? 3 : NetherExBlocks.BLOCK_NETHERRACK.getMetaFromState(state) + 1;
            world.playSound(player, pos, SoundEvents.ITEM_SHOVEL_FLATTEN, SoundCategory.BLOCKS, 1.0F, 1.0F);
            world.setBlockState(pos, NetherExBlocks.BLOCK_NETHERRACK_PATH.getDefaultState().withProperty(BlockNetherrackPath.TYPE, BlockNetherrackPath.EnumType.fromMeta(meta)), 11);
            stack.damageItem(1, player);
        }
    }
    if (stack.getItem() == NetherExItems.TOOL_HOE_BONE || ConfigHandler.block.soulSand.allowAllHoesToTill && stack.getItem() instanceof ItemHoe) {
        if (world.getBlockState(pos).getBlock() == Blocks.SOUL_SAND) {
            for (EnumHand hand : EnumHand.values()) {
                if (player.getHeldItem(hand).getItem() instanceof ItemHoe) {
                    player.swingArm(hand);
                }
            }
            world.playSound(player, pos, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
            world.setBlockState(pos, NetherExBlocks.BLOCK_SAND_SOUL_TILLED.getDefaultState(), 11);
            stack.damageItem(1, player);
        }
    }
}
Also used : ItemHoe(net.minecraft.item.ItemHoe) IBlockState(net.minecraft.block.state.IBlockState) ItemSpade(net.minecraft.item.ItemSpade) EnumHand(net.minecraft.util.EnumHand) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

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