java类net.minecraft.entity.player.EntityPlayer.SleepResult的实例源码

ItemSleepingMat.java 文件源码 项目:Cyclic 阅读 154 收藏 0 点赞 0 评论 0
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
  ItemStack stack = player.getHeldItem(hand);
  if (!world.isRemote) {
    EntityPlayerMP mp = (EntityPlayerMP) player;
    //      final EntityPlayer.SleepResult result = player.trySleep(player.getPosition());
    //trySleep was changed in 1.11.2 to literally check for the specific exact  Blocks.BED in world. because fuck modders amirite?
    //and it just assumes unsafely its there and then dies.
    EntityPlayer.SleepResult result = this.canPlayerSleep(player, world);
    if (result == EntityPlayer.SleepResult.OK) {
      final IPlayerExtendedProperties sleep = CapabilityRegistry.getPlayerProperties(player);
      if (sleep != null) {
        onSleepSuccess(world, hand, stack, mp, sleep);
      }
      else {
        //should never happen... but just in case
        UtilChat.addChatMessage(player, "tile.bed.noSleep");
      }
    }
    else {
      UtilChat.addChatMessage(player, "tile.bed.noSleep");
    }
  }
  return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
}
ItemSleepingBag.java 文件源码 项目:OpenBlocks 阅读 18 收藏 0 点赞 0 评论 0
private static boolean trySleep(World world, EntityPlayer player) {
    final BlockPos pos = player.getPosition();

    if (!isNotSuffocating(world, pos) || !isSolidEnough(world, pos.down())) {
        player.sendMessage(new TextComponentTranslation("openblocks.misc.oh_no_ground"));
        return false;
    }

    final EntityPlayer.SleepResult sleepResult = player.trySleep(pos);

    if (sleepResult == SleepResult.OK) return true;

    switch (sleepResult) {
        case NOT_POSSIBLE_NOW:
            player.sendMessage(new TextComponentTranslation("tile.bed.noSleep"));
            break;
        case NOT_SAFE:
            player.sendMessage(new TextComponentTranslation("tile.bed.notSafe"));
            break;
        default:
            break;
    }

    return false;
}
ItemSleepingMat.java 文件源码 项目:Cyclic 阅读 24 收藏 0 点赞 0 评论 0
/**
 * hack in the vanilla sleep test, or at least something similar
 * 
 * @param player
 * @param world
 * @return
 */
private SleepResult canPlayerSleep(EntityPlayer player, World world) {
  if (player.isEntityAlive() == false) {
    return EntityPlayer.SleepResult.OTHER_PROBLEM;
  }
  if (world.isDaytime()) {
    return EntityPlayer.SleepResult.NOT_POSSIBLE_NOW;
  }
  PlayerSleepInBedEvent event = new PlayerSleepInBedEvent(player, player.getPosition());
  MinecraftForge.EVENT_BUS.post(event);
  if (event.getResultStatus() != null) {
    return event.getResultStatus();
  }
  return EntityPlayer.SleepResult.OK;
}
ItemSleepingMat.java 文件源码 项目:Cyclic 阅读 22 收藏 0 点赞 0 评论 0
@SubscribeEvent
public void handleSleepInBed(PlayerSleepInBedEvent event) {
  EntityPlayer p = event.getEntityPlayer();
  final IPlayerExtendedProperties sleep = p.getCapability(ModCyclic.CAPABILITYSTORAGE, null);
  if (sleep != null && sleep.isSleeping()) {
    event.setResult(EntityPlayer.SleepResult.OK);
  }
}
PlayerSleepInBedEvent.java 文件源码 项目:CustomWorldGen 阅读 19 收藏 0 点赞 0 评论 0
public SleepResult getResultStatus()
{
    return result;
}
PlayerSleepInBedEvent.java 文件源码 项目:CustomWorldGen 阅读 19 收藏 0 点赞 0 评论 0
public void setResult(SleepResult result)
{
    this.result = result;
}
ForgeEventFactory.java 文件源码 项目:CustomWorldGen 阅读 65 收藏 0 点赞 0 评论 0
public static SleepResult onPlayerSleepInBed(EntityPlayer player, BlockPos pos)
{
    PlayerSleepInBedEvent event = new PlayerSleepInBedEvent(player, pos);
    MinecraftForge.EVENT_BUS.post(event);
    return event.getResultStatus();
}
EnumHelper.java 文件源码 项目:CustomWorldGen 阅读 21 收藏 0 点赞 0 评论 0
public static SleepResult addStatus(String name)
{
    return addEnum(SleepResult.class, name);
}


问题


面经


文章

微信
公众号

扫码关注公众号