Search in sources :

Example 6 with HitResult

use of net.minecraft.util.hit.HitResult in project wildmod by Osmiooo.

the class ChestBoatItem method use.

public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
    ItemStack itemStack = user.getStackInHand(hand);
    HitResult hitResult = raycast(world, user, RaycastContext.FluidHandling.ANY);
    if (hitResult.getType() == net.minecraft.util.hit.HitResult.Type.MISS) {
        return TypedActionResult.pass(itemStack);
    } else {
        Vec3d vec3d = user.getRotationVec(1.0F);
        double d = 5.0D;
        List<Entity> list = world.getOtherEntities(user, user.getBoundingBox().stretch(vec3d.multiply(5.0D)).expand(1.0D), RIDERS);
        if (!list.isEmpty()) {
            Vec3d vec3d2 = user.getEyePos();
            Iterator var11 = list.iterator();
            while (var11.hasNext()) {
                Entity entity = (Entity) var11.next();
                Box box = entity.getBoundingBox().expand((double) entity.getTargetingMargin());
                if (box.contains(vec3d2)) {
                    return TypedActionResult.pass(itemStack);
                }
            }
        }
        if (hitResult.getType() == net.minecraft.util.hit.HitResult.Type.BLOCK) {
            ChestBoatEntity vec3d2 = new ChestBoatEntity(world, hitResult.getPos().x, hitResult.getPos().y, hitResult.getPos().z);
            vec3d2.setBoatType(this.type);
            vec3d2.setYaw(user.getYaw());
            if (!world.isSpaceEmpty(vec3d2, vec3d2.getBoundingBox())) {
                return TypedActionResult.fail(itemStack);
            } else {
                if (!world.isClient) {
                    world.spawnEntity(vec3d2);
                    world.emitGameEvent(user, GameEvent.ENTITY_PLACE, new BlockPos(hitResult.getPos()));
                    if (!user.getAbilities().creativeMode) {
                        itemStack.decrement(1);
                    }
                }
                user.incrementStat(Stats.USED.getOrCreateStat(this));
                return TypedActionResult.success(itemStack, world.isClient());
            }
        } else {
            return TypedActionResult.pass(itemStack);
        }
    }
}
Also used : HitResult(net.minecraft.util.hit.HitResult) ChestBoatEntity(frozenblock.wild.mod.entity.chestboat.ChestBoatEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Iterator(java.util.Iterator) Box(net.minecraft.util.math.Box) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) ChestBoatEntity(frozenblock.wild.mod.entity.chestboat.ChestBoatEntity) Vec3d(net.minecraft.util.math.Vec3d)

Example 7 with HitResult

use of net.minecraft.util.hit.HitResult in project wildmod by Osmiooo.

the class MangroveBoatItem method use.

public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
    ItemStack itemStack = user.getStackInHand(hand);
    HitResult hitResult = raycast(world, user, RaycastContext.FluidHandling.ANY);
    if (hitResult.getType() == net.minecraft.util.hit.HitResult.Type.MISS) {
        return TypedActionResult.pass(itemStack);
    } else {
        Vec3d vec3d = user.getRotationVec(1.0F);
        double d = 5.0D;
        List<Entity> list = world.getOtherEntities(user, user.getBoundingBox().stretch(vec3d.multiply(5.0D)).expand(1.0D), RIDERS);
        if (!list.isEmpty()) {
            Vec3d vec3d2 = user.getEyePos();
            Iterator var11 = list.iterator();
            while (var11.hasNext()) {
                Entity entity = (Entity) var11.next();
                Box box = entity.getBoundingBox().expand((double) entity.getTargetingMargin());
                if (box.contains(vec3d2)) {
                    return TypedActionResult.pass(itemStack);
                }
            }
        }
        if (hitResult.getType() == net.minecraft.util.hit.HitResult.Type.BLOCK) {
            MangroveBoatEntity vec3d2 = new MangroveBoatEntity(world, hitResult.getPos().x, hitResult.getPos().y, hitResult.getPos().z);
            vec3d2.setYaw(user.getYaw());
            if (!world.isSpaceEmpty(vec3d2, vec3d2.getBoundingBox())) {
                return TypedActionResult.fail(itemStack);
            } else {
                if (!world.isClient) {
                    world.spawnEntity(vec3d2);
                    world.emitGameEvent(user, GameEvent.ENTITY_PLACE, new BlockPos(hitResult.getPos()));
                    if (!user.getAbilities().creativeMode) {
                        itemStack.decrement(1);
                    }
                }
                user.incrementStat(Stats.USED.getOrCreateStat(this));
                return TypedActionResult.success(itemStack, world.isClient());
            }
        } else {
            return TypedActionResult.pass(itemStack);
        }
    }
}
Also used : HitResult(net.minecraft.util.hit.HitResult) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) MangroveBoatEntity(frozenblock.wild.mod.entity.MangroveBoatEntity) Iterator(java.util.Iterator) Box(net.minecraft.util.math.Box) MangroveBoatEntity(frozenblock.wild.mod.entity.MangroveBoatEntity) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d)

Example 8 with HitResult

use of net.minecraft.util.hit.HitResult in project KiwiClient by TangyKiwi.

the class Dupe method build.

@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
    builder.executes(context -> {
        HitResult hr = MinecraftClient.getInstance().crosshairTarget;
        if (hr instanceof BlockHitResult) {
            BlockHitResult bhr = (BlockHitResult) hr;
            BlockState bs = MinecraftClient.getInstance().world.getBlockState(bhr.getBlockPos());
            if (bs.getBlock() instanceof ShulkerBoxBlock) {
                MinecraftClient.getInstance().interactionManager.interactBlock(MinecraftClient.getInstance().player, MinecraftClient.getInstance().world, Hand.MAIN_HAND, bhr);
                preDoDupe = true;
            }
        } else {
            Utils.mc.inGameHud.getChatHud().addMessage(new LiteralText("Please look at a shulker box"));
        }
        return SINGLE_SUCCESS;
    });
}
Also used : BlockHitResult(net.minecraft.util.hit.BlockHitResult) HitResult(net.minecraft.util.hit.HitResult) BlockState(net.minecraft.block.BlockState) ShulkerBoxBlock(net.minecraft.block.ShulkerBoxBlock) BlockHitResult(net.minecraft.util.hit.BlockHitResult) LiteralText(net.minecraft.text.LiteralText)

Example 9 with HitResult

use of net.minecraft.util.hit.HitResult in project Client by MatHax.

the class ClickTP method onTick.

@EventHandler
private void onTick(TickEvent.Post event) {
    if (mc.player.isUsingItem())
        return;
    if (mc.options.useKey.isPressed()) {
        HitResult hitResult = mc.player.raycast(maxDistance.get(), 1f / 20f, false);
        if (hitResult.getType() == HitResult.Type.ENTITY && mc.player.interact(((EntityHitResult) hitResult).getEntity(), Hand.MAIN_HAND) != ActionResult.PASS)
            return;
        if (hitResult.getType() == HitResult.Type.BLOCK) {
            BlockPos pos = ((BlockHitResult) hitResult).getBlockPos();
            Direction side = ((BlockHitResult) hitResult).getSide();
            if (mc.world.getBlockState(pos).onUse(mc.world, mc.player, Hand.MAIN_HAND, (BlockHitResult) hitResult) != ActionResult.PASS)
                return;
            BlockState state = mc.world.getBlockState(pos);
            VoxelShape shape = state.getCollisionShape(mc.world, pos);
            if (shape.isEmpty())
                shape = state.getOutlineShape(mc.world, pos);
            double height = shape.isEmpty() ? 1 : shape.getMax(Direction.Axis.Y);
            mc.player.setPosition(pos.getX() + 0.5 + side.getOffsetX(), pos.getY() + height, pos.getZ() + 0.5 + side.getOffsetZ());
        }
    }
}
Also used : BlockHitResult(net.minecraft.util.hit.BlockHitResult) HitResult(net.minecraft.util.hit.HitResult) EntityHitResult(net.minecraft.util.hit.EntityHitResult) BlockState(net.minecraft.block.BlockState) VoxelShape(net.minecraft.util.shape.VoxelShape) BlockPos(net.minecraft.util.math.BlockPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Direction(net.minecraft.util.math.Direction) EventHandler(mathax.client.eventbus.EventHandler)

Example 10 with HitResult

use of net.minecraft.util.hit.HitResult in project MCDungeonsWeapons by chronosacaria.

the class CombatEventHandler method checkForOffHandAttack.

public static void checkForOffHandAttack() {
    MinecraftClient mc = MinecraftClient.getInstance();
    PlayerEntity player = mc.player;
    HitResult hitResult = mc.crosshairTarget;
    if (MinecraftClient.getInstance().world != null && MinecraftClient.getInstance().currentScreen == null && !MinecraftClient.getInstance().isPaused() && player != null && !player.isBlocking()) {
        ItemStack offhand = player.getOffHandStack();
        if (offhand.getItem() instanceof IOffhandAttack) {
            if (hitResult instanceof EntityHitResult) {
                if (mc.crosshairTarget != null && mc.interactionManager != null) {
                    mc.interactionManager.attackEntity(player, ((EntityHitResult) mc.crosshairTarget).getEntity());
                }
            }
        }
    }
}
Also used : HitResult(net.minecraft.util.hit.HitResult) EntityHitResult(net.minecraft.util.hit.EntityHitResult) IOffhandAttack(chronosacaria.mcdw.api.interfaces.IOffhandAttack) MinecraftClient(net.minecraft.client.MinecraftClient) ItemStack(net.minecraft.item.ItemStack) EntityHitResult(net.minecraft.util.hit.EntityHitResult) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

HitResult (net.minecraft.util.hit.HitResult)15 BlockPos (net.minecraft.util.math.BlockPos)10 BlockHitResult (net.minecraft.util.hit.BlockHitResult)9 PlayerEntity (net.minecraft.entity.player.PlayerEntity)5 ItemStack (net.minecraft.item.ItemStack)5 EntityHitResult (net.minecraft.util.hit.EntityHitResult)5 Entity (net.minecraft.entity.Entity)4 Vec3d (net.minecraft.util.math.Vec3d)4 BlockState (net.minecraft.block.BlockState)3 MinecraftClient (net.minecraft.client.MinecraftClient)3 Box (net.minecraft.util.math.Box)3 EventTarget (dev.hypnotic.event.EventTarget)2 Iterator (java.util.Iterator)2 BlockEntity (net.minecraft.block.entity.BlockEntity)2 LiteralText (net.minecraft.text.LiteralText)2 Direction (net.minecraft.util.math.Direction)2 VoxelShape (net.minecraft.util.shape.VoxelShape)2 World (net.minecraft.world.World)2 IOffhandAttack (chronosacaria.mcdw.api.interfaces.IOffhandAttack)1 DataFixUtils (com.mojang.datafixers.DataFixUtils)1