当前位置: 首页>>代码示例>>Java>>正文


Java C08PacketPlayerBlockPlacement.getPlacedBlockDirection方法代码示例

本文整理汇总了Java中net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.getPlacedBlockDirection方法的典型用法代码示例。如果您正苦于以下问题:Java C08PacketPlayerBlockPlacement.getPlacedBlockDirection方法的具体用法?Java C08PacketPlayerBlockPlacement.getPlacedBlockDirection怎么用?Java C08PacketPlayerBlockPlacement.getPlacedBlockDirection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.minecraft.network.play.client.C08PacketPlayerBlockPlacement的用法示例。


在下文中一共展示了C08PacketPlayerBlockPlacement.getPlacedBlockDirection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processPlayerBlockPlacement

import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement; //导入方法依赖的package包/类
/**
 * Processes block placement and block activation (anvil, furnace, etc.)
 */
public void processPlayerBlockPlacement(C08PacketPlayerBlockPlacement packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());
    WorldServer worldserver = this.serverController.worldServerForDimension(this.playerEntity.dimension);
    ItemStack itemstack = this.playerEntity.inventory.getCurrentItem();
    boolean flag = false;
    BlockPos blockpos = packetIn.getPosition();
    EnumFacing enumfacing = EnumFacing.getFront(packetIn.getPlacedBlockDirection());
    this.playerEntity.markPlayerActive();

    if (packetIn.getPlacedBlockDirection() == 255)
    {
        if (itemstack == null)
        {
            return;
        }

        this.playerEntity.theItemInWorldManager.tryUseItem(this.playerEntity, worldserver, itemstack);
    }
    else if (blockpos.getY() < this.serverController.getBuildLimit() - 1 || enumfacing != EnumFacing.UP && blockpos.getY() < this.serverController.getBuildLimit())
    {
        if (this.hasMoved && this.playerEntity.getDistanceSq((double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 0.5D, (double)blockpos.getZ() + 0.5D) < 64.0D && !this.serverController.isBlockProtected(worldserver, blockpos, this.playerEntity) && worldserver.getWorldBorder().contains(blockpos))
        {
            this.playerEntity.theItemInWorldManager.activateBlockOrUseItem(this.playerEntity, worldserver, itemstack, blockpos, enumfacing, packetIn.getPlacedBlockOffsetX(), packetIn.getPlacedBlockOffsetY(), packetIn.getPlacedBlockOffsetZ());
        }

        flag = true;
    }
    else
    {
        ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("build.tooHigh", new Object[] {Integer.valueOf(this.serverController.getBuildLimit())});
        chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.RED);
        this.playerEntity.playerNetServerHandler.sendPacket(new S02PacketChat(chatcomponenttranslation));
        flag = true;
    }

    if (flag)
    {
        this.playerEntity.playerNetServerHandler.sendPacket(new S23PacketBlockChange(worldserver, blockpos));
        this.playerEntity.playerNetServerHandler.sendPacket(new S23PacketBlockChange(worldserver, blockpos.offset(enumfacing)));
    }

    itemstack = this.playerEntity.inventory.getCurrentItem();

    if (itemstack != null && itemstack.stackSize == 0)
    {
        this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem] = null;
        itemstack = null;
    }

    if (itemstack == null || itemstack.getMaxItemUseDuration() == 0)
    {
        this.playerEntity.isChangingQuantityOnly = true;
        this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem] = ItemStack.copyItemStack(this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem]);
        Slot slot = this.playerEntity.openContainer.getSlotFromInventory(this.playerEntity.inventory, this.playerEntity.inventory.currentItem);
        this.playerEntity.openContainer.detectAndSendChanges();
        this.playerEntity.isChangingQuantityOnly = false;

        if (!ItemStack.areItemStacksEqual(this.playerEntity.inventory.getCurrentItem(), packetIn.getStack()))
        {
            this.sendPacket(new S2FPacketSetSlot(this.playerEntity.openContainer.windowId, slot.slotNumber, this.playerEntity.inventory.getCurrentItem()));
        }
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:68,代码来源:NetHandlerPlayServer.java


注:本文中的net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.getPlacedBlockDirection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。