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);
}
}
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);
}
}
}
}
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;
}
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);
}
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);
}
Aggregations