Search in sources :

Example 1 with ItemPlacementContext

use of net.minecraft.item.ItemPlacementContext in project MasaGadget by plusls.

the class MixinWorldUtils method fixDoEasyPlaceAction0.

// 修复 漏斗,原木放置问题
// 核心思路是修改玩家看的位置以及 side
@Inject(method = "doEasyPlaceAction", at = @At(value = "INVOKE", target = "Lfi/dy/masa/litematica/util/WorldUtils;cacheEasyPlacePosition(Lnet/minecraft/util/math/BlockPos;)V", ordinal = 0, remap = true), locals = LocalCapture.CAPTURE_FAILHARD)
private static void fixDoEasyPlaceAction0(MinecraftClient mc, CallbackInfoReturnable<ActionResult> cir, RayTraceUtils.RayTraceWrapper traceWrapper) {
    if (!Configs.Litematica.FIX_ACCURATE_PROTOCOL.getBooleanValue()) {
        return;
    }
    BlockHitResult trace = Objects.requireNonNull(traceWrapper).getBlockHitResult();
    BlockPos pos = Objects.requireNonNull(trace).getBlockPos();
    World world = Objects.requireNonNull(SchematicWorldHandler.getSchematicWorld());
    BlockState stateSchematic = world.getBlockState(pos);
    ItemStack stack = MaterialCache.getInstance().getRequiredBuildItemForState(stateSchematic);
    Hand hand = EntityUtils.getUsedHandForItem(Objects.requireNonNull(mc.player), stack);
    Vec3d hitPos = trace.getPos();
    Direction newSide = BlockUtils.getFirstPropertyFacingValue(stateSchematic);
    easyPlaceActionNewSide.set(newSide);
    easyPlaceActionOldYaw.set(mc.player.getYaw());
    if (newSide == null && stateSchematic.contains(Properties.AXIS)) {
        // 原木之类的
        newSide = Direction.from(stateSchematic.get(Properties.AXIS), Direction.AxisDirection.POSITIVE);
        easyPlaceActionNewSide.set(newSide);
    }
    if (newSide != null && !(stateSchematic.getBlock() instanceof SlabBlock)) {
        // fuck mojang
        // 有时候放的东西是反向的,需要特判
        mc.player.setYaw(newSide.asRotation());
        ItemStack itemStack = new ItemStack(stateSchematic.getBlock().asItem());
        ItemPlacementContext itemPlacementContext = new ItemPlacementContext(mc.player, hand, itemStack, new BlockHitResult(hitPos, newSide, pos, false));
        BlockState testState = stateSchematic.getBlock().getPlacementState(itemPlacementContext);
        if (testState != null) {
            Direction testDirection = BlockUtils.getFirstPropertyFacingValue(testState);
            if (testDirection != null && testDirection != newSide) {
                newSide = newSide.getOpposite();
                easyPlaceActionNewSide.set(newSide);
                mc.player.setYaw(newSide.asRotation());
            }
        }
        mc.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.LookAndOnGround(mc.player.getYaw(), mc.player.getPitch(), mc.player.isOnGround()));
    }
    if (stateSchematic.getBlock() instanceof FenceGateBlock && stateSchematic.get(Properties.OPEN)) {
        interactBlockCount.set(1);
    }
}
Also used : PlayerMoveC2SPacket(net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket) World(net.minecraft.world.World) ClientWorld(net.minecraft.client.world.ClientWorld) Hand(net.minecraft.util.Hand) Direction(net.minecraft.util.math.Direction) Vec3d(net.minecraft.util.math.Vec3d) BlockPos(net.minecraft.util.math.BlockPos) ItemPlacementContext(net.minecraft.item.ItemPlacementContext) BlockHitResult(net.minecraft.util.hit.BlockHitResult) ItemStack(net.minecraft.item.ItemStack) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with ItemPlacementContext

use of net.minecraft.item.ItemPlacementContext in project tweakermore by Fallen-Breath.

the class PlacementTweaksMixin method tweakmAutoPickSchematicBlock.

@Inject(method = "tryPlaceBlock", at = @At("HEAD"), remap = false)
private static void tweakmAutoPickSchematicBlock(ClientPlayerInteractionManager controller, ClientPlayerEntity player, ClientWorld world, BlockPos posIn, Direction sideIn, Direction sideRotatedIn, float playerYaw, Vec3d hitVec, Hand hand, PositionUtils.HitPart hitPart, boolean isFirstClick, CallbackInfoReturnable<ActionResult> cir) {
    MinecraftClient mc = MinecraftClient.getInstance();
    if (mc.player != null) {
        if (DataManager.getToolMode() != ToolMode.REBUILD && !Configs.Generic.EASY_PLACE_MODE.getBooleanValue()) {
            if (TweakerMoreConfigs.TWEAKM_AUTO_PICK_SCHEMATIC_BLOCK.getBooleanValue() && EntityUtils.shouldPickBlock(mc.player)) {
                BlockHitResult hitResult = new BlockHitResult(hitVec, sideIn, posIn, false);
                ItemPlacementContext ctx = new ItemPlacementContext(new ItemUsageContext(player, hand, hitResult));
                doSchematicWorldPickBlock(mc, ctx.getBlockPos(), hand);
            }
        }
    }
}
Also used : MinecraftClient(net.minecraft.client.MinecraftClient) ItemUsageContext(net.minecraft.item.ItemUsageContext) ItemPlacementContext(net.minecraft.item.ItemPlacementContext) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with ItemPlacementContext

use of net.minecraft.item.ItemPlacementContext in project Carrier by GabrielOlvH.

the class CarriableChest method tryPlace.

@Override
@NotNull
public ActionResult tryPlace(@NotNull CarrierComponent carrier, @NotNull World world, @NotNull CarriablePlacementContext ctx) {
    if (world.isClient)
        return ActionResult.PASS;
    CarryingData carrying = carrier.getCarryingData();
    if (carrying == null)
        return ActionResult.PASS;
    BlockPos pos = ctx.getBlockPos();
    BlockState state = parent.getPlacementState(new ItemPlacementContext(carrier.getOwner(), Hand.MAIN_HAND, ItemStack.EMPTY, new BlockHitResult(new Vec3d(pos.getX(), pos.getY(), pos.getZ()), ctx.getSide(), ctx.getBlockPos(), false)));
    world.setBlockState(pos, state);
    BlockEntity blockEntity = world.getBlockEntity(pos);
    if (blockEntity != null) {
        NbtCompound tag = carrying.getBlockEntityTag();
        ((AccessorBlockEntity) blockEntity).carrier_writeIdentifyingData(tag);
        blockEntity.readNbt(tag);
    }
    carrier.setCarryingData(null);
    return ActionResult.SUCCESS;
}
Also used : CarryingData(me.steven.carrier.api.CarryingData) AccessorBlockEntity(me.steven.carrier.mixin.AccessorBlockEntity) BlockState(net.minecraft.block.BlockState) NbtCompound(net.minecraft.nbt.NbtCompound) BlockPos(net.minecraft.util.math.BlockPos) ItemPlacementContext(net.minecraft.item.ItemPlacementContext) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Vec3d(net.minecraft.util.math.Vec3d) AccessorBlockEntity(me.steven.carrier.mixin.AccessorBlockEntity) BlockEntity(net.minecraft.block.entity.BlockEntity) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with ItemPlacementContext

use of net.minecraft.item.ItemPlacementContext in project Biome-Makeover by Lemonszz.

the class IvyShapedBlock method getPlacementState.

@Nullable
public BlockState getPlacementState(ItemPlacementContext ctx) {
    World world = ctx.getWorld();
    BlockPos blockPos = ctx.getBlockPos();
    BlockState blockState = world.getBlockState(blockPos);
    return Arrays.stream(ctx.getPlacementDirections()).map((direction) -> this.getPlacementState(blockState, world, blockPos, direction)).filter(Objects::nonNull).findFirst().orElse(null);
}
Also used : java.util(java.util) BlockView(net.minecraft.world.BlockView) ImmutableMap(com.google.common.collect.ImmutableMap) Util(net.minecraft.util.Util) WorldView(net.minecraft.world.WorldView) BlockRotation(net.minecraft.util.BlockRotation) World(net.minecraft.world.World) ItemPlacementContext(net.minecraft.item.ItemPlacementContext) WorldAccess(net.minecraft.world.WorldAccess) StateManager(net.minecraft.state.StateManager) VoxelShapes(net.minecraft.util.shape.VoxelShapes) BMUtil(party.lemons.biomemakeover.util.BMUtil) BlockPos(net.minecraft.util.math.BlockPos) VoxelShape(net.minecraft.util.shape.VoxelShape) Maps(com.google.common.collect.Maps) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Direction(net.minecraft.util.math.Direction) Nullable(org.jetbrains.annotations.Nullable) net.minecraft.block(net.minecraft.block) BooleanProperty(net.minecraft.state.property.BooleanProperty) BlockMirror(net.minecraft.util.BlockMirror) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with ItemPlacementContext

use of net.minecraft.item.ItemPlacementContext in project Paradise-Lost by devs-immortal.

the class VialItem method use.

@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
    ItemStack itemStack = user.getStackInHand(hand);
    BlockHitResult hitResult = raycast(world, user, this.fluid == Fluids.EMPTY ? RaycastContext.FluidHandling.SOURCE_ONLY : RaycastContext.FluidHandling.NONE);
    if (hitResult.getType() == HitResult.Type.BLOCK) {
        BlockPos hitPos = hitResult.getBlockPos();
        if (this.fluid != Fluids.EMPTY && world.getBlockState(hitPos.up()).canReplace(new ItemPlacementContext(user, hand, itemStack, hitResult))) {
            world.setBlockState(hitPos.up(), fluid.getDefaultState().getBlockState());
            if (!user.isCreative()) {
                itemStack.decrement(1);
            }
            return TypedActionResult.success(itemStack, world.isClient());
        }
    }
    return TypedActionResult.fail(itemStack);
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) ItemPlacementContext(net.minecraft.item.ItemPlacementContext) ItemStack(net.minecraft.item.ItemStack) BlockHitResult(net.minecraft.util.hit.BlockHitResult)

Aggregations

ItemPlacementContext (net.minecraft.item.ItemPlacementContext)5 BlockHitResult (net.minecraft.util.hit.BlockHitResult)4 BlockPos (net.minecraft.util.math.BlockPos)4 ItemStack (net.minecraft.item.ItemStack)2 Direction (net.minecraft.util.math.Direction)2 Vec3d (net.minecraft.util.math.Vec3d)2 World (net.minecraft.world.World)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Maps (com.google.common.collect.Maps)1 java.util (java.util)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 CarryingData (me.steven.carrier.api.CarryingData)1 AccessorBlockEntity (me.steven.carrier.mixin.AccessorBlockEntity)1 net.minecraft.block (net.minecraft.block)1 BlockState (net.minecraft.block.BlockState)1 BlockEntity (net.minecraft.block.entity.BlockEntity)1 MinecraftClient (net.minecraft.client.MinecraftClient)1 ClientWorld (net.minecraft.client.world.ClientWorld)1