MessagePictureBookInput.java 文件源码

java
阅读 22 收藏 0 点赞 0 评论 0

项目:MineCamera 作者:
@Override
public IMessage onMessage(MessagePictureBookInput message, MessageContext ctx) {
    if (ctx.side == Side.SERVER) {
        EntityPlayerMP player = ctx.getServerHandler().playerEntity;
        if (player != null && player.openContainer != null
                && player.openContainer instanceof ContainerPictureBook) {
            ContainerPictureBook contaner = (ContainerPictureBook) player.openContainer;
            if (contaner.getSlot(0).getHasStack() && contaner.getSlot(0).getStack().hasTagCompound()
                    && contaner.getSlot(0).getStack().getTagCompound().hasKey("pid")) {
                ItemStack itemStack = contaner.getSlot(0).getStack();
                String pid = itemStack.getTagCompound().getString("pid");
                if (contaner.getTotalPictureNum() <= 100) {
                    contaner.getListPid().add(pid);
                    contaner.setTotalPictureNum(contaner.getTotalPictureNum() + 1);
                    if (contaner.getTotalPictureNum() == 1) {
                        contaner.setIndex(0);
                    }
                } else {
                    player.addChatComponentMessage(new TextComponentTranslation("chat.picturebook.tomany"));
                    return null;
                }
            }
            contaner.getSlot(0).decrStackSize(64);
        }
    }
    return null;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号