Java 类net.minecraftforge.event.entity.player.PlayerSleepInBedEvent 实例源码

项目:Rediscovered-Mod-1.8    文件:RediscoveredEventHandler.java   
@SubscribeEvent
public void onPlayerSleepInBed(PlayerSleepInBedEvent event) 
{
    EntityPlayer player = event.entityPlayer;
    InventoryPlayer inv = player.inventory;
    ItemStack itemStack = inv.getStackInSlot(inv.currentItem);
    World world = event.entityLiving.worldObj;

    if(player.dimension == 0 && !world.isDaytime() && itemRand.nextInt(100)<=mod_Rediscovered.DreamChance && (itemStack == null || itemStack.getItem() != mod_Rediscovered.DreamPillow) && player instanceof EntityPlayerMP)
    {
        ExtendedPlayer props = ExtendedPlayer.get((EntityPlayer) event.entity);
        props.setRespawn(event.pos.getX(), event.pos.getY(), event.pos.getZ());
        EntityPlayerMP thePlayer = (EntityPlayerMP) player;
        thePlayer.mcServer.getConfigurationManager().transferPlayerToDimension(thePlayer, mod_Rediscovered.DimID, new SkyDimensionTeleporter(thePlayer.mcServer.worldServerForDimension(mod_Rediscovered.DimID)));
    }
}
项目:Rediscovered-Mod-1.8.8    文件:RediscoveredEventHandler.java   
@SubscribeEvent
public void onPlayerSleepInBed(PlayerSleepInBedEvent event) 
{
    EntityPlayer player = event.entityPlayer;
    InventoryPlayer inv = player.inventory;
    ItemStack itemStack = inv.getStackInSlot(inv.currentItem);
    World world = event.entityLiving.worldObj;

    if(player.dimension == 0 && !world.isDaytime() && itemRand.nextInt(100)<=mod_Rediscovered.DreamChance && (itemStack == null || itemStack.getItem() != mod_Rediscovered.DreamPillow) && player instanceof EntityPlayerMP)
    {
        ExtendedPlayer props = ExtendedPlayer.get((EntityPlayer) event.entity);
        props.setRespawn(event.pos.getX(), event.pos.getY(), event.pos.getZ());
        EntityPlayerMP thePlayer = (EntityPlayerMP) player;
        thePlayer.mcServer.getConfigurationManager().transferPlayerToDimension(thePlayer, mod_Rediscovered.DimID, new SkyDimensionTeleporter(thePlayer.mcServer.worldServerForDimension(mod_Rediscovered.DimID)));
    }
}
项目:Morph    文件:EventHandler.java   
@SubscribeEvent
public void onPlayerSleep(PlayerSleepInBedEvent event)
{
    EntityPlayer player = (EntityPlayer)event.entityPlayer;
    EnumStatus stats = EnumStatus.OTHER_PROBLEM;
    if(Morph.config.getSessionInt("canSleepMorphed") == 0)
    {
        if(FMLCommonHandler.instance().getEffectiveSide().isServer() && Morph.proxy.tickHandlerServer.getPlayerMorphInfo(player) != null)
        {
            event.result = stats;
            player.addChatMessage(new ChatComponentTranslation("morph.denySleep"));
        }
        else if(FMLCommonHandler.instance().getEffectiveSide().isClient() && Morph.proxy.tickHandlerClient.playerMorphInfo.containsKey(player.getCommandSenderName()))
        {
            event.result = stats;
        }
    }
}
项目:MidgarCrusade    文件:JoueurEvent.java   
@SubscribeEvent
   public void onSleep(PlayerSleepInBedEvent event)
{
    ServerPlayerBaseMagic pm;

    pm = Main.getPlayerServer(event.entityPlayer);

    if (pm != null)
    {
         if (pm.getPlayer().worldObj.rand.nextInt(2) == 0);
            // pm.travelToDimension(Main.DIM_ID, pm.getPlayer().dimension);
    }            
   }
项目: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);
  }
}
项目:AdvancedRocketry    文件:PlanetEventHandler.java   
@SubscribeEvent
public void sleepEvent(PlayerSleepInBedEvent event) {

    if(event.entity.worldObj.provider instanceof WorldProviderPlanet && 
            AtmosphereHandler.hasAtmosphereHandler(event.entity.worldObj.provider.dimensionId) && !AtmosphereHandler.getOxygenHandler(event.entity.worldObj.provider.dimensionId).getAtmosphereType(event.x, event.y, event.z).isBreathable()) {
        event.result = EnumStatus.OTHER_PROBLEM;
    }
}
项目:D3Core    文件:EventHandler.java   
@SubscribeEvent
public static void sleepEvent(PlayerSleepInBedEvent event)
{
    if (nosleep || D3Core.isAprilFools())
    {
        event.setResult(EntityPlayer.SleepResult.OTHER_PROBLEM);
    }
}
项目:NearbyMobFinder    文件:PlayerSleepInBedHandler.java   
@SubscribeEvent
public void onPlayerSleepEvent(PlayerSleepInBedEvent event)
{
    if (Settings.checkAtBed && NearbyMobLocator.areConditionsMet(event.entityPlayer, event.x, event.y, event.z))
    {
        ServerTickHandler.playerRequesting = event.entityPlayer;
        ServerTickHandler.nearbyMobList = NearbyMobLocator.findNearbyMobs(event.entityPlayer, event.x, event.y, event.z);
    }
}
项目:Rediscovered-Mod-1.6.4    文件:RediscoveredEventHandler.java   
@ForgeSubscribe
public void onPlayerSleepInBed(PlayerSleepInBedEvent event) 
{
    EntityPlayer player = event.entityPlayer;
    InventoryPlayer inv = player.inventory;
    ItemStack itemStack = inv.getStackInSlot(inv.currentItem);
    World world = event.entityLiving.worldObj;
    if(!mod_Rediscovered.DreamBedEnabled && player.dimension == 0 && !world.isDaytime() && itemRand.nextInt(100)<=mod_Rediscovered.DreamChance && (itemStack == null || itemStack.getItem() != mod_Rediscovered.DreamPillow) && player instanceof EntityPlayerMP)
    {
        ExtendedPlayer props = ExtendedPlayer.get((EntityPlayer) event.entity);
        props.setRespawn(event.x, event.y, event.z);
        EntityPlayerMP thePlayer = (EntityPlayerMP) player;
        thePlayer.mcServer.getConfigurationManager().transferPlayerToDimension(thePlayer, mod_Rediscovered.DimID, new SkyDimensionTeleporter(thePlayer.mcServer.worldServerForDimension(mod_Rediscovered.DimID)));
    }
}
项目:A-Cup-of-Java    文件:EventHandler.java   
@SubscribeEvent
public void playerSleepInBedEvent(PlayerSleepInBedEvent event)
{
    if (event.entityPlayer.isPotionActive(ModPotion.PotionCaffeine))
    {
        event.result = EntityPlayer.EnumStatus.OTHER_PROBLEM;
        event.entityPlayer.addChatMessage(new ChatComponentTranslation("msg." + Reference.MOD_ID.toLowerCase() + ":sleep.txt"));
    }
}
项目:Rediscovered-Mod-1.7.10    文件:RediscoveredEventHandler.java   
@SubscribeEvent
public void onPlayerSleepInBed(PlayerSleepInBedEvent event) 
{
    EntityPlayer player = event.entityPlayer;
    InventoryPlayer inv = player.inventory;
    ItemStack itemStack = inv.getStackInSlot(inv.currentItem);
    World world = event.entityLiving.worldObj;
    if(player.dimension == 0 && !world.isDaytime() && itemRand.nextInt(100)<=mod_Rediscovered.DreamChance && (itemStack == null || itemStack.getItem() != mod_Rediscovered.DreamPillow) && player instanceof EntityPlayerMP)
    {
        ExtendedPlayer props = ExtendedPlayer.get((EntityPlayer) event.entity);
        props.setRespawn(event.x, event.y, event.z);
        EntityPlayerMP thePlayer = (EntityPlayerMP) player;
        thePlayer.mcServer.getConfigurationManager().transferPlayerToDimension(thePlayer, mod_Rediscovered.DimID, new SkyDimensionTeleporter(thePlayer.mcServer.worldServerForDimension(mod_Rediscovered.DimID)));
    }
}
项目:HardModeTweaks    文件:SleepManager.java   
@SubscribeEvent
public void sleep(PlayerSleepInBedEvent event) {
    BedPlacements bedPlacements = getBedPlacements(event.getEntity().worldObj);
    if (bedPlacements.canSleep(event.getEntity(), event.getPos()))
        return;

    event.getEntityPlayer()
            .addChatComponentMessage(new TextComponentTranslation("tile.bed.recentlyPlaced"));
    event.setResult(EntityPlayer.EnumStatus.OTHER_PROBLEM);
}
项目:genera    文件:EventHandler.java   
@SubscribeEvent
public void playerSleep(PlayerSleepInBedEvent event) {
    if (event.getEntityPlayer().getEntityData().getInteger("genera.sacrifices_made") > 0)
        event.getEntityPlayer().getEntityData().setInteger("genera.sacrifices_made", 0);
}
项目: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();
}
项目:4Space-5    文件:EntityPlayer.java   
public EnumStatus sleepInBedAt(int p_71018_1_, int p_71018_2_, int p_71018_3_)
{
    PlayerSleepInBedEvent event = new PlayerSleepInBedEvent(this, p_71018_1_, p_71018_2_, p_71018_3_);
    MinecraftForge.EVENT_BUS.post(event);
    if (event.result != null) {
        return event.result;
    }
    if (!this.worldObj.isRemote)
    {
        if ((isPlayerSleeping()) || (!isEntityAlive())) {
            return EnumStatus.OTHER_PROBLEM;
        }
        if (!this.worldObj.provider.isSurfaceWorld()) {
            return EnumStatus.NOT_POSSIBLE_HERE;
        }
        if (this.worldObj.isDaytime()) {
            return EnumStatus.NOT_POSSIBLE_NOW;
        }
        if ((Math.abs(this.posX - p_71018_1_) > 3.0D) || (Math.abs(this.posY - p_71018_2_) > 2.0D) || (Math.abs(this.posZ - p_71018_3_) > 3.0D)) {
            return EnumStatus.TOO_FAR_AWAY;
        }
        double d0 = 8.0D;
        double d1 = 5.0D;
        List list = this.worldObj.getEntitiesWithinAABB(EntityMob.class, AxisAlignedBB.getBoundingBox(p_71018_1_ - d0, p_71018_2_ - d1, p_71018_3_ - d0, p_71018_1_ + d0, p_71018_2_ + d1, p_71018_3_ + d0));
        if (!list.isEmpty()) {
            return EnumStatus.NOT_SAFE;
        }
    }
    if (isRiding()) {
        mountEntity((Entity)null);
    }
    setSize(0.2F, 0.2F);
    this.yOffset = 0.2F;
    if (this.worldObj.blockExists(p_71018_1_, p_71018_2_, p_71018_3_))
    {
        int l = this.worldObj.getBlock(p_71018_1_, p_71018_2_, p_71018_3_).getBedDirection(this.worldObj, p_71018_1_, p_71018_2_, p_71018_3_);
        float f1 = 0.5F;
        float f = 0.5F;
        switch (l)
        {
        case 0: 
            f = 0.9F;
            break;
        case 1: 
            f1 = 0.1F;
            break;
        case 2: 
            f = 0.1F;
            break;
        case 3: 
            f1 = 0.9F;
        }
        func_71013_b(l);
        setPosition(p_71018_1_ + f1, p_71018_2_ + 0.9375F, p_71018_3_ + f);
    }
    else
    {
        setPosition(p_71018_1_ + 0.5F, p_71018_2_ + 0.9375F, p_71018_3_ + 0.5F);
    }
    this.sleeping = true;
    this.sleepTimer = 0;
    this.playerLocation = new ChunkCoordinates(p_71018_1_, p_71018_2_, p_71018_3_);
    this.motionX = (this.motionZ = this.motionY = 0.0D);
    if (!this.worldObj.isRemote) {
        this.worldObj.updateAllPlayersSleepingFlag();
    }
    return EnumStatus.OK;
}
项目:4Space-1.7    文件:EntityPlayer.java   
public EnumStatus sleepInBedAt(int p_71018_1_, int p_71018_2_, int p_71018_3_)
{
    PlayerSleepInBedEvent event = new PlayerSleepInBedEvent(this, p_71018_1_, p_71018_2_, p_71018_3_);
    MinecraftForge.EVENT_BUS.post(event);
    if (event.result != null) {
        return event.result;
    }
    if (!this.worldObj.isRemote)
    {
        if ((isPlayerSleeping()) || (!isEntityAlive())) {
            return EnumStatus.OTHER_PROBLEM;
        }
        if (!this.worldObj.provider.isSurfaceWorld()) {
            return EnumStatus.NOT_POSSIBLE_HERE;
        }
        if (this.worldObj.isDaytime()) {
            return EnumStatus.NOT_POSSIBLE_NOW;
        }
        if ((Math.abs(this.posX - p_71018_1_) > 3.0D) || (Math.abs(this.posY - p_71018_2_) > 2.0D) || (Math.abs(this.posZ - p_71018_3_) > 3.0D)) {
            return EnumStatus.TOO_FAR_AWAY;
        }
        double d0 = 8.0D;
        double d1 = 5.0D;
        List list = this.worldObj.getEntitiesWithinAABB(EntityMob.class, AxisAlignedBB.getBoundingBox(p_71018_1_ - d0, p_71018_2_ - d1, p_71018_3_ - d0, p_71018_1_ + d0, p_71018_2_ + d1, p_71018_3_ + d0));
        if (!list.isEmpty()) {
            return EnumStatus.NOT_SAFE;
        }
    }
    if (isRiding()) {
        mountEntity((Entity)null);
    }
    setSize(0.2F, 0.2F);
    this.yOffset = 0.2F;
    if (this.worldObj.blockExists(p_71018_1_, p_71018_2_, p_71018_3_))
    {
        int l = this.worldObj.getBlock(p_71018_1_, p_71018_2_, p_71018_3_).getBedDirection(this.worldObj, p_71018_1_, p_71018_2_, p_71018_3_);
        float f1 = 0.5F;
        float f = 0.5F;
        switch (l)
        {
        case 0: 
            f = 0.9F;
            break;
        case 1: 
            f1 = 0.1F;
            break;
        case 2: 
            f = 0.1F;
            break;
        case 3: 
            f1 = 0.9F;
        }
        func_71013_b(l);
        setPosition(p_71018_1_ + f1, p_71018_2_ + 0.9375F, p_71018_3_ + f);
    }
    else
    {
        setPosition(p_71018_1_ + 0.5F, p_71018_2_ + 0.9375F, p_71018_3_ + 0.5F);
    }
    this.sleeping = true;
    this.sleepTimer = 0;
    this.playerLocation = new ChunkCoordinates(p_71018_1_, p_71018_2_, p_71018_3_);
    this.motionX = (this.motionZ = this.motionY = 0.0D);
    if (!this.worldObj.isRemote) {
        this.worldObj.updateAllPlayersSleepingFlag();
    }
    return EnumStatus.OK;
}
项目:sprinkles_for_vanilla    文件:PlayerHandlers.java   
@SubscribeEvent
public void onPlayerSleep(PlayerSleepInBedEvent event)
{
    EntityPlayer.EnumStatus result = event.result;
    EntityPlayer player = event.entityPlayer;

    //If another mod has already set it to be disabled, we will not overwrite it. Also if the player is already sleeping, or the entity is alive we won't overwrite it
    //If the world is remote then that means that sleeping has successfully been carried out and we should let vanilla deal with it
    if ((result != null && result != EntityPlayer.EnumStatus.OK) || !SprinklesForVanilla.isOnServer || player.isPlayerSleeping() || !player.isEntityAlive() || player.worldObj.isRemote)
    {
        //This will make it so that under all circumstances, sleep is disabled.
        if (!Settings.sleepIsEnabled[1] && (result == null || result == EntityPlayer.EnumStatus.OK) && !player.worldObj.isRemote && SprinklesForVanilla.isOnServer)
        {
            event.result = EntityPlayer.EnumStatus.OTHER_PROBLEM;
        }
        return;
    }

    //Now we check distance from bed. If
    double distX = Settings.distanceFromBed[1][0];
    double distY = Settings.distanceFromBed[1][1];
    double distZ = Settings.distanceFromBed[1][2];
    if ((Math.abs(player.posX - event.pos.getX()) > distX || Math.abs(player.posY - event.pos.getY()) > distY || Math.abs(player.posZ - event.pos.getZ()) > distZ) && Settings.distanceFromBedCancelsSleep[1])
    {
        //We manually set it because it may be close enough with vanilla code
        event.result = EntityPlayer.EnumStatus.TOO_FAR_AWAY;
        return;
    }

    //This checks for nearby mobs
    distX = Settings.nearbyMobDistance[1][0];
    distY = Settings.nearbyMobDistance[1][1];
    distZ = Settings.nearbyMobDistance[1][2];
    if (!(player.worldObj.getEntitiesWithinAABB(EntityMob.class, AxisAlignedBB.fromBounds(event.pos.getX() - distX, event.pos.getY() - distY, event.pos.getZ() - distZ, event.pos.getX() + distX, event.pos.getY() + distY, event.pos.getZ() + distZ)).isEmpty()) && Settings.nearbyMobsCancelSleep[1])
    {
        //We manually set it because it may be safe with vanilla code
        event.result = EntityPlayer.EnumStatus.NOT_SAFE;
        return;
    }

    //This checks if if its day time or not sleeping overworld and returns if it should continue to cancel sleep
    if ((player.worldObj.isDaytime() && Settings.dayCancelsSleep[1]) || (!player.worldObj.provider.isSurfaceWorld()))
    {
        //We let vanilla handle setting the result as of this time
        return;
    }

    //If sleep is disabled then we say there is a problem and we check if the bed should set a spawn
    if (!Settings.sleepIsEnabled[1])
    {
        event.result = EntityPlayer.EnumStatus.OTHER_PROBLEM;
        if (Settings.bedSetsSpawn[1])
        {
            BlockPos blockPos = new BlockPos(event.pos.getX(), event.pos.getY(), event.pos.getZ());
            BlockPos bedCoordinates = player.worldObj.getBlockState(event.pos).getBlock().getBedSpawnPosition(player.worldObj, blockPos, player);
            if (bedCoordinates == null) {
                bedCoordinates = new BlockPos(blockPos);
            }

            player.setSpawnChunk(blockPos, false, player.dimension); //!Settings.playerChecksBedRespawn[1]);
        }
        return;
    }

    boolean wouldSleep = wouldSleepInVanilla(player, event.pos.getX(), event.pos.getY(), event.pos.getZ());
    //If the tests would be failed in vanilla then we sleep using our own method
    if (!wouldSleep)
    {
        sleep(player, event.pos.getX(), event.pos.getY(), event.pos.getZ());
        event.result = EntityPlayer.EnumStatus.OK;
    }
    if (!Settings.bedSetsSpawn[1])
    {
        playersToNotSetSpawn.put(player.getUniqueID(), new SpawnPoint(player.getBedLocation(player.dimension), player.isSpawnForced(player.dimension)));
    }
}
项目:Insomnia    文件:Insomnia.java   
@SubscribeEvent
public void onPlayerSleep(PlayerSleepInBedEvent event) {
    EntityPlayer entityPlayer = event.entityPlayer;
    EntityPlayer.EnumStatus enumStatus = EntityPlayer.EnumStatus.OK;

    if (!entityPlayer.worldObj.isRemote) {
        if (entityPlayer.isPlayerSleeping() || !entityPlayer.isEntityAlive()) {
            enumStatus = EntityPlayer.EnumStatus.OTHER_PROBLEM;
        }

        if (!entityPlayer.worldObj.provider.isSurfaceWorld()) {
            enumStatus = EntityPlayer.EnumStatus.NOT_POSSIBLE_HERE;
        }

        if (entityPlayer.worldObj.isDaytime()) {
            enumStatus = EntityPlayer.EnumStatus.NOT_POSSIBLE_NOW;
        }

        if (Math.abs(entityPlayer.posX - (double) event.x) > 3.0D || Math.abs(entityPlayer.posY - (double) event.y) > 2.0D || Math.abs(entityPlayer.posZ - (double) event.z) > 3.0D) {
            enumStatus = EntityPlayer.EnumStatus.TOO_FAR_AWAY;
        }

        double d0 = 8.0D;
        double d1 = 5.0D;
        List list = entityPlayer.worldObj.getEntitiesWithinAABB(EntityMob.class, AxisAlignedBB.getBoundingBox((double) event.x - d0, (double) event.y - d1, (double) event.z - d0, (double) event.x + d0, (double) event.y + d1, (double) event.z + d0));

        if (!list.isEmpty()) {
            enumStatus = EntityPlayer.EnumStatus.NOT_SAFE;
        }
    }

    if (enumStatus == EntityPlayer.EnumStatus.OK) {
        ChunkCoordinates chunkCoordinates = new ChunkCoordinates(event.x, event.y, event.z);
        ChunkCoordinates bedCoordinates = entityPlayer.worldObj.getBlock(event.x, event.y, event.z).getBedSpawnPosition(entityPlayer.worldObj, chunkCoordinates.posX, chunkCoordinates.posY, chunkCoordinates.posZ, entityPlayer);
        if (bedCoordinates == null) {
            bedCoordinates = new ChunkCoordinates(chunkCoordinates.posX, chunkCoordinates.posY + 1, chunkCoordinates.posZ);
        }

        ChunkCoordinates verifiedCoordinates = EntityPlayer.verifyRespawnCoordinates(entityPlayer.worldObj, bedCoordinates, false);

        if (verifiedCoordinates == null) {
            verifiedCoordinates = new ChunkCoordinates(chunkCoordinates.posX, chunkCoordinates.posY, chunkCoordinates.posZ);
        }

        entityPlayer.setSpawnChunk(verifiedCoordinates, false);

        // To hide any possible chat message
        event.result = EntityPlayer.EnumStatus.OTHER_PROBLEM;

        // Then send our own
        entityPlayer.addChatComponentMessage(new ChatComponentTranslation("tile.bed.insomnia"));
    } else {
        event.result = enumStatus;
    }
}
项目:JLPModJam    文件:EventHookHandler.java   
@ForgeSubscribe
public void onSleepyTime(PlayerSleepInBedEvent event)
{
   event.result  = event.result;
}