Search in sources :

Example 1 with SChangeBlockPacket

use of net.minecraft.network.play.server.SChangeBlockPacket in project Overloaded by CJ-MC-Mods.

the class PlayerInteractionUtil method tryHarvestBlock.

public static boolean tryHarvestBlock(ServerPlayerEntity player, ServerWorld world, BlockPos pos) {
    int exp = net.minecraftforge.common.ForgeHooks.onBlockBreakEvent(world, player.gameMode.getGameModeForPlayer(), player, pos);
    if (exp == -1) {
        return false;
    } else {
        BlockState iblockstate = world.getBlockState(pos);
        TileEntity tileentity = world.getBlockEntity(pos);
        Block block = iblockstate.getBlock();
        if ((block instanceof CommandBlockBlock || block instanceof StructureBlock) && !player.canUseGameMasterBlocks()) {
            world.sendBlockUpdated(pos, iblockstate, iblockstate, 3);
            return false;
        } else {
            world.levelEvent(null, 2001, pos, Block.getId(iblockstate));
            boolean flag1;
            if (player.abilities.instabuild) {
                flag1 = removeBlock(world, pos, player, false);
                player.connection.send(new SChangeBlockPacket(world, pos));
            } else {
                ItemStack itemstack1 = player.getMainHandItem();
                ItemStack itemstack2 = itemstack1.isEmpty() ? ItemStack.EMPTY : itemstack1.copy();
                boolean flag = iblockstate.canHarvestBlock(world, pos, player);
                itemstack1.mineBlock(world, iblockstate, pos, player);
                flag1 = removeBlock(world, pos, player, flag);
                if (flag1 && flag) {
                    iblockstate.getBlock().playerDestroy(world, player, pos, iblockstate, tileentity, itemstack2);
                }
            }
            // Drop experience
            if (!player.isCreative() && flag1 && exp > 0) {
                iblockstate.getBlock().popExperience(world, player.blockPosition(), exp);
            }
            return flag1;
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) SChangeBlockPacket(net.minecraft.network.play.server.SChangeBlockPacket) ItemStack(net.minecraft.item.ItemStack)

Example 2 with SChangeBlockPacket

use of net.minecraft.network.play.server.SChangeBlockPacket in project Arclight by IzzelAliz.

the class PlayerInteractionManagerMixin_1_15 method func_219441_a.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public ActionResultType func_219441_a(PlayerEntity playerIn, World worldIn, ItemStack stackIn, Hand handIn, BlockRayTraceResult blockRaytraceResultIn) {
    BlockPos blockpos = blockRaytraceResultIn.getPos();
    BlockState blockstate = worldIn.getBlockState(blockpos);
    ActionResultType resultType = ActionResultType.PASS;
    boolean cancelledBlock = false;
    if (this.gameType == GameType.SPECTATOR) {
        INamedContainerProvider provider = blockstate.getContainer(worldIn, blockpos);
        cancelledBlock = !(provider instanceof INamedContainerProvider);
    }
    if (playerIn.getCooldownTracker().hasCooldown(stackIn.getItem())) {
        cancelledBlock = true;
    }
    PlayerInteractEvent bukkitEvent = CraftEventFactory.callPlayerInteractEvent(playerIn, Action.RIGHT_CLICK_BLOCK, blockpos, blockRaytraceResultIn.getFace(), stackIn, cancelledBlock, handIn);
    bridge$setFiredInteract(true);
    bridge$setInteractResult(bukkitEvent.useItemInHand() == Event.Result.DENY);
    if (bukkitEvent.useInteractedBlock() == Event.Result.DENY) {
        if (blockstate.getBlock() instanceof DoorBlock) {
            boolean bottom = blockstate.get(DoorBlock.HALF) == DoubleBlockHalf.LOWER;
            ((ServerPlayerEntity) playerIn).connection.sendPacket(new SChangeBlockPacket(this.world, bottom ? blockpos.up() : blockpos.down()));
        } else if (blockstate.getBlock() instanceof CakeBlock) {
            ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().sendHealthUpdate();
        }
        ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().updateInventory();
        resultType = ((bukkitEvent.useItemInHand() != Event.Result.ALLOW) ? ActionResultType.SUCCESS : ActionResultType.PASS);
    } else if (this.gameType == GameType.SPECTATOR) {
        INamedContainerProvider inamedcontainerprovider = blockstate.getContainer(worldIn, blockpos);
        if (inamedcontainerprovider != null) {
            playerIn.openContainer(inamedcontainerprovider);
            return ActionResultType.SUCCESS;
        } else {
            return ActionResultType.PASS;
        }
    } else {
        net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock(playerIn, handIn, blockpos, blockRaytraceResultIn.getFace());
        if (event.isCanceled())
            return event.getCancellationResult();
        ItemUseContext itemusecontext = new ItemUseContext(playerIn, handIn, blockRaytraceResultIn);
        if (event.getUseItem() != net.minecraftforge.eventbus.api.Event.Result.DENY) {
            ActionResultType result = stackIn.onItemUseFirst(itemusecontext);
            if (result != ActionResultType.PASS)
                return result;
        }
        boolean flag = !playerIn.getHeldItemMainhand().isEmpty() || !playerIn.getHeldItemOffhand().isEmpty();
        boolean flag1 = (playerIn.isSecondaryUseActive() && flag) && !(playerIn.getHeldItemMainhand().doesSneakBypassUse(worldIn, blockpos, playerIn) && playerIn.getHeldItemOffhand().doesSneakBypassUse(worldIn, blockpos, playerIn));
        if (event.getUseBlock() != net.minecraftforge.eventbus.api.Event.Result.DENY && !flag1) {
            resultType = blockstate.onBlockActivated(worldIn, playerIn, handIn, blockRaytraceResultIn);
            if (resultType.isSuccessOrConsume()) {
                return resultType;
            }
        }
        if (!stackIn.isEmpty() && resultType != ActionResultType.SUCCESS && !bridge$getInteractResult()) {
            if (event.getUseItem() == net.minecraftforge.eventbus.api.Event.Result.DENY) {
                return ActionResultType.PASS;
            }
            if (this.isCreative()) {
                int i = stackIn.getCount();
                resultType = stackIn.onItemUse(itemusecontext);
                stackIn.setCount(i);
                return resultType;
            } else {
                return stackIn.onItemUse(itemusecontext);
            }
        } else {
            return resultType;
        }
    }
    return resultType;
}
Also used : ItemUseContext(net.minecraft.item.ItemUseContext) ActionResultType(net.minecraft.util.ActionResultType) SChangeBlockPacket(net.minecraft.network.play.server.SChangeBlockPacket) PlayerInteractEvent(org.bukkit.event.player.PlayerInteractEvent) INamedContainerProvider(net.minecraft.inventory.container.INamedContainerProvider) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) CakeBlock(net.minecraft.block.CakeBlock) BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) DoorBlock(net.minecraft.block.DoorBlock) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 3 with SChangeBlockPacket

use of net.minecraft.network.play.server.SChangeBlockPacket in project FastAsyncWorldEdit by IntellectualSites.

the class ForgePlayer method sendFakeBlock.

@Override
public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) {
    World world = getWorld();
    if (!(world instanceof ForgeWorld)) {
        return;
    }
    BlockPos loc = ForgeAdapter.toBlockPos(pos);
    if (block == null) {
        final SChangeBlockPacket packetOut = new SChangeBlockPacket(((ForgeWorld) world).getWorld(), loc);
        player.connection.sendPacket(packetOut);
    } else {
        final SChangeBlockPacket packetOut = new SChangeBlockPacket();
        PacketBuffer buf = new PacketBuffer(Unpooled.buffer());
        buf.writeBlockPos(loc);
        buf.writeVarInt(Block.getStateId(ForgeAdapter.adapt(block.toImmutableState())));
        try {
            packetOut.readPacketData(buf);
        } catch (IOException e) {
            return;
        }
        player.connection.sendPacket(packetOut);
        if (block instanceof BaseBlock && block.getBlockType().equals(BlockTypes.STRUCTURE_BLOCK)) {
            final BaseBlock baseBlock = (BaseBlock) block;
            final CompoundTag nbtData = baseBlock.getNbtData();
            if (nbtData != null) {
                player.connection.sendPacket(new SUpdateTileEntityPacket(new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()), STRUCTURE_BLOCK_PACKET_ID, NBTConverter.toNative(nbtData)));
            }
        }
    }
}
Also used : SChangeBlockPacket(net.minecraft.network.play.server.SChangeBlockPacket) SUpdateTileEntityPacket(net.minecraft.network.play.server.SUpdateTileEntityPacket) BlockPos(net.minecraft.util.math.BlockPos) IOException(java.io.IOException) World(com.sk89q.worldedit.world.World) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) PacketBuffer(net.minecraft.network.PacketBuffer) CompoundTag(com.sk89q.jnbt.CompoundTag)

Example 4 with SChangeBlockPacket

use of net.minecraft.network.play.server.SChangeBlockPacket in project Arclight by IzzelAliz.

the class BucketItemMixin method arclight$bucketFill.

// @formatter:on
@Inject(method = "onItemRightClick", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/block/IBucketPickupHandler;pickupFluid(Lnet/minecraft/world/IWorld;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Lnet/minecraft/fluid/Fluid;"))
private void arclight$bucketFill(World worldIn, PlayerEntity playerIn, Hand handIn, CallbackInfoReturnable<ActionResult<ItemStack>> cir, ItemStack stack, RayTraceResult result) {
    BlockPos pos = ((BlockRayTraceResult) result).getPos();
    BlockState state = worldIn.getBlockState(pos);
    Fluid dummyFluid = ((IBucketPickupHandler) state.getBlock()).pickupFluid(DummyGeneratorAccess.INSTANCE, pos, state);
    PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(worldIn, playerIn, pos, pos, ((BlockRayTraceResult) result).getFace(), stack, dummyFluid.getFilledBucket());
    if (event.isCancelled()) {
        ((ServerPlayerEntity) playerIn).connection.sendPacket(new SChangeBlockPacket(worldIn, pos));
        ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().updateInventory();
        cir.setReturnValue(new ActionResult<>(ActionResultType.FAIL, stack));
    } else {
        arclight$captureItem = event.getItemStack();
    }
}
Also used : PlayerBucketFillEvent(org.bukkit.event.player.PlayerBucketFillEvent) IBucketPickupHandler(net.minecraft.block.IBucketPickupHandler) BlockState(net.minecraft.block.BlockState) SChangeBlockPacket(net.minecraft.network.play.server.SChangeBlockPacket) Fluid(net.minecraft.fluid.Fluid) BlockPos(net.minecraft.util.math.BlockPos) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with SChangeBlockPacket

use of net.minecraft.network.play.server.SChangeBlockPacket in project Arclight by IzzelAliz.

the class BucketItemMixin method arclight$bucketEmpty.

@Inject(method = "tryPlaceContainedLiquid", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/dimension/Dimension;doesWaterVaporize()Z"))
private void arclight$bucketEmpty(PlayerEntity player, World worldIn, BlockPos posIn, BlockRayTraceResult p_180616_4_, CallbackInfoReturnable<Boolean> cir) {
    if (player != null) {
        PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent(worldIn, player, posIn, arclight$click, arclight$direction, arclight$stack);
        if (event.isCancelled()) {
            ((ServerPlayerEntity) player).connection.sendPacket(new SChangeBlockPacket(worldIn, posIn));
            ((ServerPlayerEntityBridge) player).bridge$getBukkitEntity().updateInventory();
            cir.setReturnValue(false);
        }
    }
}
Also used : SChangeBlockPacket(net.minecraft.network.play.server.SChangeBlockPacket) PlayerBucketEmptyEvent(org.bukkit.event.player.PlayerBucketEmptyEvent) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

SChangeBlockPacket (net.minecraft.network.play.server.SChangeBlockPacket)7 BlockState (net.minecraft.block.BlockState)4 BlockPos (net.minecraft.util.math.BlockPos)4 DoorBlock (net.minecraft.block.DoorBlock)3 PlayerInteractEvent (org.bukkit.event.player.PlayerInteractEvent)3 Overwrite (org.spongepowered.asm.mixin.Overwrite)3 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)2 CakeBlock (net.minecraft.block.CakeBlock)2 INamedContainerProvider (net.minecraft.inventory.container.INamedContainerProvider)2 ItemUseContext (net.minecraft.item.ItemUseContext)2 TileEntity (net.minecraft.tileentity.TileEntity)2 ActionResultType (net.minecraft.util.ActionResultType)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2 CompoundTag (com.sk89q.jnbt.CompoundTag)1 World (com.sk89q.worldedit.world.World)1 BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)1 IOException (java.io.IOException)1 IBucketPickupHandler (net.minecraft.block.IBucketPickupHandler)1 TrapDoorBlock (net.minecraft.block.TrapDoorBlock)1 Fluid (net.minecraft.fluid.Fluid)1