Search in sources :

Example 31 with EnumHand

use of net.minecraft.util.EnumHand in project QuarryPlus by Kotori316.

the class BlockRefinery method onBlockActivated.

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack stack = playerIn.getHeldItem(hand);
    if (InvUtils.isDebugItem(playerIn, hand))
        return true;
    if (BuildcraftHelper.isWrench(playerIn, hand, stack, new RayTraceResult(new Vec3d(hitX, hitY, hitZ), facing, pos))) {
        worldIn.setBlockState(pos, state.withProperty(FACING, state.getValue(FACING).rotateYCCW()));
        return true;
    }
    Optional<TileRefinery> tileEntity = Optional.ofNullable((TileRefinery) worldIn.getTileEntity(pos));
    Consumer<TileRefinery> sendPacket = t -> PacketHandler.sendToAround(TileMessage.create(t), worldIn, pos);
    if (stack.getItem() == QuarryPlusI.itemTool() && stack.getItemDamage() == 0) {
        if (!worldIn.isRemote) {
            Consumer<TileRefinery> consumer1 = t -> t.sendEnchantMassage(playerIn);
            tileEntity.ifPresent(consumer1.andThen(sendPacket));
        }
        return true;
    } else if (FluidUtil.getFluidHandler(stack) != null) {
        if (!worldIn.isRemote) {
            Consumer<TileRefinery> consumer1 = refinery -> fill(refinery, playerIn, hand, facing);
            tileEntity.ifPresent(consumer1.andThen(sendPacket));
        }
        return true;
    } else if (!worldIn.isRemote) {
        tileEntity.ifPresent(sendPacket);
    }
    return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
Also used : TileRefinery(com.yogpc.qp.tile.TileRefinery) FluidUtil(net.minecraftforge.fluids.FluidUtil) PacketHandler(com.yogpc.qp.packet.PacketHandler) Item(net.minecraft.item.Item) EnumHand(net.minecraft.util.EnumHand) BlockStateContainer(net.minecraft.block.state.BlockStateContainer) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) RayTraceResult(net.minecraft.util.math.RayTraceResult) TileRefinery(com.yogpc.qp.tile.TileRefinery) Vec3d(net.minecraft.util.math.Vec3d) Side(net.minecraftforge.fml.relauncher.Side) InvUtils(com.yogpc.qp.compat.InvUtils) QuarryPlusI(com.yogpc.qp.QuarryPlusI) CreativeTabs(net.minecraft.creativetab.CreativeTabs) NonNullList(net.minecraft.util.NonNullList) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) IBlockAccess(net.minecraft.world.IBlockAccess) BuildcraftHelper(com.yogpc.qp.compat.BuildcraftHelper) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) CapabilityFluidHandler(net.minecraftforge.fluids.capability.CapabilityFluidHandler) World(net.minecraft.world.World) TileMessage(com.yogpc.qp.packet.TileMessage) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) QuarryPlus(com.yogpc.qp.QuarryPlus) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) Consumer(java.util.function.Consumer) IBlockState(net.minecraft.block.state.IBlockState) List(java.util.List) Material(net.minecraft.block.material.Material) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemBlockRefinery(com.yogpc.qp.item.ItemBlockRefinery) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) Optional(java.util.Optional) TileEntity(net.minecraft.tileentity.TileEntity) IEnchantableTile(com.yogpc.qp.tile.IEnchantableTile) Consumer(java.util.function.Consumer) RayTraceResult(net.minecraft.util.math.RayTraceResult) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d)

Example 32 with EnumHand

use of net.minecraft.util.EnumHand in project pyrotech-1.12 by codetaylor.

the class CampfireComfortEffectEventHandler method on.

@SubscribeEvent
public void on(PlayerInteractEvent.RightClickItem event) {
    ItemStack itemStack = event.getItemStack();
    Item item = itemStack.getItem();
    if (!(item instanceof ItemFood)) {
        // We're only interested if the item is food.
        return;
    }
    ItemFood itemFood = (ItemFood) item;
    if (this.isAlwaysEdible(itemFood)) {
        // We're only interested in food that isn't already always edible.
        return;
    }
    EntityLivingBase entityLiving = event.getEntityLiving();
    if (!(entityLiving instanceof EntityPlayer)) {
        // If the entity isn't a player, we're not interested.
        return;
    }
    EntityPlayer player = (EntityPlayer) entityLiving;
    if (player.canEat(false)) {
        // We're only interested in players that can't eat.
        return;
    }
    PotionEffect effect = player.getActivePotionEffect(ModuleTechBasic.Potions.COMFORT);
    if (effect == null) {
        // If the player doesn't have the appropriate effect, we're not interested.
        return;
    }
    World world = player.getEntityWorld();
    EnumHand hand = event.getHand();
    if (world.isRemote) {
        int itemStackCount = itemStack.getCount();
        ActionResult<ItemStack> actionResult = this.useFood(itemStack, world, player, hand);
        ItemStack resultItemStack = actionResult.getResult();
        if (resultItemStack != itemStack || resultItemStack.getCount() != itemStackCount) {
            player.setHeldItem(hand, resultItemStack);
            if (resultItemStack.isEmpty()) {
                net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, itemStack, hand);
            }
        }
    } else {
        int i = itemStack.getCount();
        int j = itemStack.getMetadata();
        ItemStack copyBeforeUse = itemStack.copy();
        ActionResult<ItemStack> actionResult = this.useFood(itemStack, world, player, hand);
        ItemStack resultItemStack = actionResult.getResult();
        player.setHeldItem(hand, resultItemStack);
        if (player.isCreative()) {
            resultItemStack.setCount(i);
            if (resultItemStack.isItemStackDamageable()) {
                resultItemStack.setItemDamage(j);
            }
        }
        if (resultItemStack.isEmpty()) {
            net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, copyBeforeUse, hand);
            player.setHeldItem(hand, ItemStack.EMPTY);
        }
        if (!player.isHandActive()) {
            ((EntityPlayerMP) player).sendContainerToPlayer(player.inventoryContainer);
        }
    }
    event.setCanceled(true);
}
Also used : Item(net.minecraft.item.Item) ItemFood(net.minecraft.item.ItemFood) PotionEffect(net.minecraft.potion.PotionEffect) EnumHand(net.minecraft.util.EnumHand) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 33 with EnumHand

use of net.minecraft.util.EnumHand in project UniqueEnchantments by TinyModularThings.

the class UtilsHandler method damageShield.

public static void damageShield(float damage, EntityPlayer player) {
    if (damage >= 3.0F && player.getActiveItemStack().getItem().isShield(player.getActiveItemStack(), player)) {
        ItemStack copyBeforeUse = player.getActiveItemStack().copy();
        int i = 1 + MathHelper.floor(damage);
        player.getActiveItemStack().damageItem(i, player);
        if (player.getActiveItemStack().isEmpty()) {
            EnumHand enumhand = player.getActiveHand();
            net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, copyBeforeUse, enumhand);
            if (enumhand == EnumHand.MAIN_HAND) {
                player.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, ItemStack.EMPTY);
            } else {
                player.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, ItemStack.EMPTY);
            }
            player.resetActiveHand();
            player.playSound(SoundEvents.ITEM_SHIELD_BREAK, 0.8F, 0.8F + player.world.rand.nextFloat() * 0.4F);
        }
    }
}
Also used : EnumHand(net.minecraft.util.EnumHand) ItemStack(net.minecraft.item.ItemStack)

Example 34 with EnumHand

use of net.minecraft.util.EnumHand in project tweakeroo by maruohon.

the class PlacementTweaks method onAttackTick.

private static void onAttackTick(Minecraft mc) {
    if (FeatureToggle.TWEAK_FAST_LEFT_CLICK.getBooleanValue()) {
        final int count = Configs.Generic.FAST_LEFT_CLICK_COUNT.getIntegerValue();
        for (int i = 0; i < count; ++i) {
            InventoryUtils.trySwapCurrentToolIfNearlyBroken(EnumHand.MAIN_HAND);
            isEmulatedClick = true;
            ((IMinecraftAccessor) mc).leftClickMouseAccessor();
            isEmulatedClick = false;
        }
    } else {
        EnumHand hand = EnumHand.MAIN_HAND;
        InventoryUtils.trySwapCurrentToolIfNearlyBroken(hand);
        tryRestockHand(mc.player, hand, stackBeforeUse[hand.ordinal()]);
    }
}
Also used : IMinecraftAccessor(fi.dy.masa.tweakeroo.util.IMinecraftAccessor) EnumHand(net.minecraft.util.EnumHand)

Example 35 with EnumHand

use of net.minecraft.util.EnumHand in project tweakeroo by maruohon.

the class PlacementTweaks method onUsingTick.

private static void onUsingTick() {
    EntityPlayerSP player = GameUtils.getClientPlayer();
    if (player == null) {
        return;
    }
    Minecraft mc = GameUtils.getClient();
    if (posFirst != null && FeatureToggle.TWEAK_FAST_BLOCK_PLACEMENT.getBooleanValue() && canUseItemWithRestriction(FAST_PLACEMENT_ITEM_RESTRICTION, player)) {
        World world = player.getEntityWorld();
        final double reach = mc.playerController.getBlockReachDistance();
        final int maxCount = Configs.Generic.FAST_BLOCK_PLACEMENT_COUNT.getIntegerValue();
        mc.objectMouseOver = player.rayTrace(reach, mc.getRenderPartialTicks());
        for (int i = 0; i < maxCount; ++i) {
            RayTraceResult trace = mc.objectMouseOver;
            if (trace == null || trace.typeOfHit != RayTraceResult.Type.BLOCK) {
                break;
            }
            EnumHand hand = handFirst;
            EnumFacing side = trace.sideHit;
            BlockPos pos = trace.getBlockPos();
            BlockPos posNew = getPlacementPositionForTargetedPosition(pos, side, world);
            if (hand != null && posNew.equals(posLast) == false && canPlaceBlockIntoPosition(posNew, world) && isPositionAllowedByPlacementRestriction(posNew, side) && canPlaceBlockAgainst(world, pos, player, hand)) {
                /*
                    IBlockState state = world.getBlockState(pos);
                    float x = (float) (trace.hitVec.x - pos.getX());
                    float y = (float) (trace.hitVec.y - pos.getY());
                    float z = (float) (trace.hitVec.z - pos.getZ());

                    if (state.getBlock().onBlockActivated(world, posNew, state, player, hand, side, x, y, z))
                    {
                        return;
                    }
                    */
                Vec3d hitVec = hitVecFirst.add(posNew.getX(), posNew.getY(), posNew.getZ());
                EnumActionResult result = tryPlaceBlock(mc.playerController, player, mc.world, posNew, sideFirst, sideRotatedFirst, playerYawFirst, hitVec, hand, hitPartFirst, false);
                if (result == EnumActionResult.SUCCESS) {
                    posLast = posNew;
                    mc.objectMouseOver = player.rayTrace(reach, mc.getRenderPartialTicks());
                } else {
                    break;
                }
            } else {
                break;
            }
        }
        // Reset the timer to prevent the regular process method from re-firing
        ((IMinecraftAccessor) mc).setRightClickDelayTimer(4);
    } else if (FeatureToggle.TWEAK_FAST_RIGHT_CLICK.getBooleanValue() && isVanillaKeybindHeld(mc.gameSettings.keyBindUseItem) && canUseFastRightClick(mc.player)) {
        final int count = Configs.Generic.FAST_RIGHT_CLICK_COUNT.getIntegerValue();
        for (int i = 0; i < count; ++i) {
            isEmulatedClick = true;
            ((IMinecraftAccessor) mc).rightClickMouseAccessor();
            isEmulatedClick = false;
        }
    }
}
Also used : EnumActionResult(net.minecraft.util.EnumActionResult) EnumHand(net.minecraft.util.EnumHand) EnumFacing(net.minecraft.util.EnumFacing) IMinecraftAccessor(fi.dy.masa.tweakeroo.util.IMinecraftAccessor) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockPos(net.minecraft.util.math.BlockPos) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) World(net.minecraft.world.World) Minecraft(net.minecraft.client.Minecraft) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

EnumHand (net.minecraft.util.EnumHand)117 ItemStack (net.minecraft.item.ItemStack)58 EntityPlayer (net.minecraft.entity.player.EntityPlayer)50 BlockPos (net.minecraft.util.math.BlockPos)48 EnumFacing (net.minecraft.util.EnumFacing)36 Vec3d (net.minecraft.util.math.Vec3d)28 World (net.minecraft.world.World)26 Block (net.minecraft.block.Block)21 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)21 CPacketPlayerTryUseItemOnBlock (net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock)20 Entity (net.minecraft.entity.Entity)18 EntityLivingBase (net.minecraft.entity.EntityLivingBase)18 Item (net.minecraft.item.Item)17 IBlockState (net.minecraft.block.state.IBlockState)15 CPacketAnimation (net.minecraft.network.play.client.CPacketAnimation)15 TileEntity (net.minecraft.tileentity.TileEntity)15 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)14 RayTraceResult (net.minecraft.util.math.RayTraceResult)14 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)14 List (java.util.List)12