BlockCarpentersBed.java 文件源码

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

项目:carpentersblocks 作者:
@Override
/**
 * Called upon block activation (right click on the block.)
 */
protected void postOnBlockActivated(TEBase TE, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ, ActionResult actionResult)
{
    actionResult.setAltered();
    World world = TE.getWorldObj();

    int x = TE.xCoord;
    int y = TE.yCoord;
    int z = TE.zCoord;

    if (!Bed.isHeadOfBed(TE)) {

        TEBase TE_opp = Bed.getOppositeTE(TE);

        if (TE_opp != null) {
            x = TE_opp.xCoord;
            z = TE_opp.zCoord;
        } else {
            return;
        }

    }

    if (world.provider.canRespawnHere() && world.getBiomeGenForCoords(x, z) != BiomeGenBase.hell) {

        if (Bed.isOccupied(TE)) {

            EntityPlayer entityPlayer1 = null;
            Iterator iterator = world.playerEntities.iterator();

            while (iterator.hasNext()) {

                EntityPlayer entityPlayer2 = (EntityPlayer)iterator.next();

                if (entityPlayer2.isPlayerSleeping()) {

                    ChunkCoordinates chunkCoordinates = entityPlayer2.playerLocation;

                    if (chunkCoordinates.posX == x && chunkCoordinates.posY == y && chunkCoordinates.posZ == z) {
                        entityPlayer1 = entityPlayer2;
                    }

                }

            }

            if (entityPlayer1 != null) {
                ChatHandler.sendMessageToPlayer("tile.bed.occupied", entityPlayer, false);
                return;
            }

            setBedOccupied(world, x, y, z, entityPlayer, false);

        }

        EnumStatus enumstatus = entityPlayer.sleepInBedAt(x, y, z);

        if (enumstatus == EnumStatus.OK) {

            setBedOccupied(world, x, y, z, entityPlayer, true);

        } else {

            if (enumstatus == EnumStatus.NOT_POSSIBLE_NOW) {
                ChatHandler.sendMessageToPlayer("tile.bed.noSleep", entityPlayer, false);
            } else if (enumstatus == EnumStatus.NOT_SAFE) {
                ChatHandler.sendMessageToPlayer("tile.bed.notSafe", entityPlayer, false);
            }

        }

    } else {

        destroyBlock(world, x, y, z, false);
        world.newExplosion((Entity)null, x + 0.5F, y + 0.5F, z + 0.5F, 5.0F, true, true);

    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号