Search in sources :

Example 91 with EnumHand

use of net.minecraft.util.EnumHand in project Spark-Client by Spark-Client-Development.

the class ShulkerAura method openShulk.

private void openShulk(BlockPos shulkPos) {
    Vec3d pos = new Vec3d(shulkPos).add(0.5, 0.5, 0.5);
    List<Vec3d> vecs = RaytraceUtil.getVisiblePointsForBox(mc.world.getBlockState(shulkPos).getBoundingBox(mc.world, shulkPos));
    if (!vecs.isEmpty())
        pos = PlayerUtil.getClosestPoint(vecs);
    final RayTraceResult result = mc.world.rayTraceBlocks(PlayerUtil.getEyePos(), pos, false, true, false);
    EnumFacing facing = (result == null || !shulkPos.equals(result.getBlockPos()) || result.sideHit == null) ? EnumFacing.UP : result.sideHit;
    // rotate if needed
    if (!Spark.rotationManager.rotate(RotationUtil.getViewRotations(pos, mc.player), AntiCheatConfig.INSTANCE.getCrystalRotStep(), 2, false)) {
        return;
    }
    // send packet
    EnumHand hand = EnumHand.OFF_HAND;
    if (mc.player.getHeldItemOffhand().getItem() instanceof ItemEndCrystal && !(mc.player.getHeldItemMainhand().getItem() instanceof ItemEndCrystal))
        hand = EnumHand.MAIN_HAND;
    mc.player.connection.sendPacket(new CPacketPlayerTryUseItemOnBlock(shulkPos, facing, hand, (float) pos.x, (float) pos.y, (float) pos.z));
    flag = true;
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) EnumHand(net.minecraft.util.EnumHand) RayTraceResult(net.minecraft.util.math.RayTraceResult) ItemEndCrystal(net.minecraft.item.ItemEndCrystal) Vec3d(net.minecraft.util.math.Vec3d) CPacketPlayerTryUseItemOnBlock(net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock)

Example 92 with EnumHand

use of net.minecraft.util.EnumHand in project Spark-Client by Spark-Client-Development.

the class TntAura method OnUpdate.

@SubscribeEvent
void OnUpdate(PlayerUpdateEvent event) {
    BlockPos newPos = GetTntBlock();
    if (newPos == null || (targetFloorPos != null && !targetFloorPos.equals(newPos))) {
        if (targetFloorPos == null)
            Spark.sendInfo("TntAura has no target!");
        else
            Spark.sendInfo("TntAura has lost target!");
        targetFloorPos = null;
        disable();
        return;
    }
    targetFloorPos = newPos;
    if (cooldown > 0) {
        cooldown--;
        return;
    }
    if (pause.isOn()) {
        // pause if tnt is exploding
        List<Entity> l = mc.world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(targetFloorPos));
        for (Entity e : l) {
            if (e instanceof EntityTNTPrimed) {
                EntityTNTPrimed tnt = (EntityTNTPrimed) e;
                if (tnt.ticksExisted > 60)
                    return;
            }
        }
    }
    BlockPos targetPos = targetFloorPos.add(0, getH(), 0);
    ArrayList<BlockPos> toPlace = new ArrayList<BlockPos>();
    for (BlockPos s : WorldUtils.getSurroundBlocks(targetPos)) {
        toPlace.add(s.add(0, 0, 0));
        toPlace.add(s.add(0, -1, 0));
        toPlace.add(s.add(0, -2, 0));
    }
    // sort by distance
    Collections.sort(toPlace, new Comparator<BlockPos>() {

        @Override
        public int compare(BlockPos fruit2, BlockPos fruit1) {
            return (int) ((PlayerUtil.getDistance(fruit1) - PlayerUtil.getDistance(fruit2)) * 5);
        }
    });
    for (BlockPos pos : toPlace) {
        if (mc.world.getBlockState(pos).getBlock().material.isReplaceable()) {
            BlockInteractUtil.BlockPlaceResult res = place(pos, new HardSolidBlockSwitchItem());
            if (res != BlockInteractUtil.BlockPlaceResult.FAILED) {
                return;
            }
        }
    }
    if (mc.world.getBlockState(targetPos).getBlock() == Blocks.TNT) {
        if (closeTop.isOn()) {
            if (mc.world.getBlockState(targetPos.add(0, 1, 0)).getBlock().material.isReplaceable()) {
                place(targetPos.add(0, 1, 0), new HardSolidBlockSwitchItem());
                return;
            }
        }
        Vec3d pos = PlayerUtil.getClosestPoint(RaytraceUtil.getPointToLookAtBlock(targetPos));
        EnumFacing facing = EnumFacing.UP;
        if (pos == null)
            pos = new Vec3d(targetPos.getX() + 0.5, targetPos.getY() + 0.5, targetPos.getZ() + 0.5);
        else
            facing = mc.world.rayTraceBlocks(new Vec3d(mc.player.posX, mc.player.posY + (double) mc.player.getEyeHeight(), mc.player.posZ), pos, false).sideHit;
        if (AntiCheatConfig.INSTANCE.getBlockRotate())
            if (!Spark.rotationManager.rotate(Spark.rotationManager.getLegitRotations(pos), AntiCheatConfig.getInstance().getBlockRotStep(), 6, false, true))
                return;
        EnumHand hand = Spark.switchManager.Switch(new SpecItemSwitchItem(Items.FLINT_AND_STEEL), ItemSwitcher.usedHand.Both);
        if (hand == null)
            return;
        BlockInteractUtil.processRightClickBlock(targetPos, facing, true, hand, pos);
        cooldown = delay.getValue();
    } else
        place(targetPos, new SpecBlockSwitchItem(Blocks.TNT));
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) EntityTNTPrimed(net.minecraft.entity.item.EntityTNTPrimed) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) Vec3d(net.minecraft.util.math.Vec3d) BlockInteractUtil(me.wallhacks.spark.util.player.BlockInteractUtil) EnumHand(net.minecraft.util.EnumHand) BlockPos(net.minecraft.util.math.BlockPos) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 93 with EnumHand

use of net.minecraft.util.EnumHand in project pnc-repressurized by TeamPneumatic.

the class RenderPressureTubeModule method render.

@Override
public void render(TileEntityPressureTube tile, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
    if (tile.getCamouflage() != null) {
        return;
    }
    Minecraft mc = Minecraft.getMinecraft();
    EnumHand holdingModule = null;
    if (mc.player.getHeldItem(EnumHand.MAIN_HAND).getItem() instanceof ItemTubeModule) {
        holdingModule = EnumHand.MAIN_HAND;
    } else if (mc.player.getHeldItem(EnumHand.OFF_HAND).getItem() instanceof ItemTubeModule) {
        holdingModule = EnumHand.OFF_HAND;
    }
    boolean render = false;
    for (int i = 0; i < tile.modules.length; i++) {
        if (tile.modules[i] != null)
            render = true;
    }
    if (!render && holdingModule == null)
        return;
    GlStateManager.pushMatrix();
    mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    GlStateManager.enableTexture2D();
    GlStateManager.disableAlpha();
    GlStateManager.color(1, 1, 1);
    GlStateManager.translate((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
    GlStateManager.scale(1.0F, -1F, -1F);
    // "fake" module is for showing a preview of where the module would be placed
    if (holdingModule != null)
        attachFakeModule(mc, tile, holdingModule);
    for (int i = 0; i < tile.modules.length; i++) {
        TubeModule module = tile.modules[i];
        if (module != null) {
            if (module.isFake()) {
                GlStateManager.enableBlend();
                GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
                GlStateManager.color(1, 1, 1, 0.5f);
            }
            module.getModel().renderModel(0.0625f, module, partialTicks);
            module.doExtraRendering();
            if (module.isFake()) {
                tile.modules[i] = null;
                GlStateManager.disableBlend();
            }
            GlStateManager.color(1, 1, 1, 1);
        }
    }
    GlStateManager.enableAlpha();
    GlStateManager.popMatrix();
}
Also used : EnumHand(net.minecraft.util.EnumHand) TubeModule(me.desht.pneumaticcraft.common.block.tubes.TubeModule) ItemTubeModule(me.desht.pneumaticcraft.common.item.ItemTubeModule) Minecraft(net.minecraft.client.Minecraft) ItemTubeModule(me.desht.pneumaticcraft.common.item.ItemTubeModule)

Example 94 with EnumHand

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

the class BlockController method onBlockActivated.

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (InvUtils.isDebugItem(playerIn, hand))
        return true;
    if (!playerIn.isSneaking()) {
        if (!worldIn.isRemote) {
            if (!Config.content().disableMapJ().get(SYMBOL)) {
                List<EntityEntry> entries = ForgeRegistries.ENTITIES.getValues().stream().filter(entity -> entity.getEntityClass() != null && !Modifier.isAbstract(entity.getEntityClass().getModifiers()) && !Config.content().spawnerBlacklist().contains(entity.getRegistryName())).collect(Collectors.toList());
                PacketHandler.sendToClient(AvailableEntities.create(pos, worldIn.provider.getDimension(), entries), (EntityPlayerMP) playerIn);
            } else {
                VersionUtil.sendMessage(playerIn, new TextComponentString("Spawner Controller is disabled."), true);
            }
        }
        return true;
    }
    return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
Also used : PacketHandler(com.yogpc.qp.packet.PacketHandler) VersionUtil(com.yogpc.qp.version.VersionUtil) EntityEntry(net.minecraftforge.fml.common.registry.EntityEntry) EnumHand(net.minecraft.util.EnumHand) ReflectionHelper(net.minecraftforge.fml.relauncher.ReflectionHelper) BlockStateContainer(net.minecraft.block.state.BlockStateContainer) IDismantleable(cofh.api.block.IDismantleable) ArrayList(java.util.ArrayList) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack) Block(net.minecraft.block.Block) InvUtils(com.yogpc.qp.compat.InvUtils) MobSpawnerBaseLogic(net.minecraft.tileentity.MobSpawnerBaseLogic) QuarryPlusI(com.yogpc.qp.QuarryPlusI) TileEntityMobSpawner(net.minecraft.tileentity.TileEntityMobSpawner) WorldServer(net.minecraft.world.WorldServer) AvailableEntities(com.yogpc.qp.packet.controller.AvailableEntities) ACTING(com.yogpc.qp.block.ADismCBlock.ACTING) World(net.minecraft.world.World) Config(com.yogpc.qp.Config) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) Field(java.lang.reflect.Field) Collectors(java.util.stream.Collectors) QuarryPlus(com.yogpc.qp.QuarryPlus) FakePlayerFactory(net.minecraftforge.common.util.FakePlayerFactory) TextComponentString(net.minecraft.util.text.TextComponentString) IBlockState(net.minecraft.block.state.IBlockState) List(java.util.List) Stream(java.util.stream.Stream) Material(net.minecraft.block.material.Material) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Modifier(java.lang.reflect.Modifier) ForgeRegistries(net.minecraftforge.fml.common.registry.ForgeRegistries) ResourceLocation(net.minecraft.util.ResourceLocation) Optional(java.util.Optional) TileEntity(net.minecraft.tileentity.TileEntity) ItemBlock(net.minecraft.item.ItemBlock) FakePlayer(net.minecraftforge.common.util.FakePlayer) EntityEntry(net.minecraftforge.fml.common.registry.EntityEntry) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 95 with EnumHand

use of net.minecraft.util.EnumHand in project aquaacrobatics by Fuzss.

the class ModelBipedMixin method setRotationAnglesPre.

@Inject(method = "setRotationAngles", at = @At(value = "FIELD", target = "Lnet/minecraft/client/model/ModelBiped;swingProgress:F"))
public void setRotationAnglesPre(float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, Entity entityIn, CallbackInfo callbackInfo) {
    if (!ConfigHandler.MiscellaneousConfig.eatingAnimation || !(entityIn instanceof EntityLivingBase)) {
        return;
    }
    EntityLivingBase livingEntityIn = (EntityLivingBase) entityIn;
    int inUseCount = livingEntityIn.getItemInUseCount();
    if (livingEntityIn.isHandActive() && inUseCount > 0) {
        EnumHand hand = livingEntityIn.getActiveHand();
        ItemStack stack = livingEntityIn.getHeldItem(hand);
        EnumHandSide handSide = livingEntityIn.getPrimaryHand();
        if (stack.getItemUseAction() == EnumAction.EAT || stack.getItemUseAction() == EnumAction.DRINK) {
            boolean isRight = (hand == EnumHand.MAIN_HAND ? handSide : handSide.opposite()) == EnumHandSide.RIGHT;
            float partialTicks = (float) MathHelper.frac(ageInTicks);
            float animationCount = inUseCount - partialTicks + 1.0F;
            float useRatio = animationCount / (float) stack.getMaxItemUseDuration();
            float f = 1.0F - (float) Math.pow(useRatio, 27.0D);
            if (useRatio < 0.8F) {
                f += MathHelper.abs(MathHelper.cos(animationCount / 4.0F * (float) Math.PI) * 0.1F);
            }
            ModelRenderer bipedArm = isRight ? this.bipedRightArm : this.bipedLeftArm;
            bipedArm.rotateAngleX = f * (bipedArm.rotateAngleX * 0.5F - ((float) Math.PI * 4.0F / 10.0F));
            bipedArm.rotateAngleY = f * (float) Math.PI / 6F * (isRight ? -1.0F : 1.0F);
        }
    }
}
Also used : ModelRenderer(net.minecraft.client.model.ModelRenderer) EnumHand(net.minecraft.util.EnumHand) EntityLivingBase(net.minecraft.entity.EntityLivingBase) ItemStack(net.minecraft.item.ItemStack) EnumHandSide(net.minecraft.util.EnumHandSide) Inject(org.spongepowered.asm.mixin.injection.Inject)

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