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

项目:Cyclic    文件:ItemSleepingMat.java   
@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);
}
项目:OpenBlocks    文件:ItemSleepingBag.java   
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;
}
项目:Cyclic    文件:ItemSleepingMat.java   
/**
 * 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;
}
项目:Cyclic    文件:ItemSleepingMat.java   
@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);
  }
}
项目:CustomWorldGen    文件:PlayerSleepInBedEvent.java   
public SleepResult getResultStatus()
{
    return result;
}
项目:CustomWorldGen    文件:PlayerSleepInBedEvent.java   
public void setResult(SleepResult result)
{
    this.result = result;
}
项目:CustomWorldGen    文件:ForgeEventFactory.java   
public static SleepResult onPlayerSleepInBed(EntityPlayer player, BlockPos pos)
{
    PlayerSleepInBedEvent event = new PlayerSleepInBedEvent(player, pos);
    MinecraftForge.EVENT_BUS.post(event);
    return event.getResultStatus();
}
项目:CustomWorldGen    文件:EnumHelper.java   
public static SleepResult addStatus(String name)
{
    return addEnum(SleepResult.class, name);
}