Search in sources :

Example 1 with SleepingLocationCheckEvent

use of net.minecraftforge.event.entity.player.SleepingLocationCheckEvent in project MinecraftForge by MinecraftForge.

the class ForgeEventFactory method fireSleepingLocationCheck.

public static boolean fireSleepingLocationCheck(EntityPlayer player, BlockPos sleepingLocation) {
    SleepingLocationCheckEvent evt = new SleepingLocationCheckEvent(player, sleepingLocation);
    MinecraftForge.EVENT_BUS.post(evt);
    Result canContinueSleep = evt.getResult();
    if (canContinueSleep == Result.DEFAULT) {
        IBlockState state = player.world.getBlockState(player.bedLocation);
        return state.getBlock().isBed(state, player.world, player.bedLocation, player);
    } else
        return canContinueSleep == Result.ALLOW;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) SleepingLocationCheckEvent(net.minecraftforge.event.entity.player.SleepingLocationCheckEvent) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) RayTraceResult(net.minecraft.util.math.RayTraceResult) Result(net.minecraftforge.fml.common.eventhandler.Event.Result) SleepResult(net.minecraft.entity.player.EntityPlayer.SleepResult)

Example 2 with SleepingLocationCheckEvent

use of net.minecraftforge.event.entity.player.SleepingLocationCheckEvent in project MinecraftForge by MinecraftForge.

the class ForgeEventFactory method fireSleepingLocationCheck.

public static boolean fireSleepingLocationCheck(LivingEntity player, BlockPos sleepingLocation) {
    SleepingLocationCheckEvent evt = new SleepingLocationCheckEvent(player, sleepingLocation);
    MinecraftForge.EVENT_BUS.post(evt);
    Result canContinueSleep = evt.getResult();
    if (canContinueSleep == Result.DEFAULT) {
        return player.getSleepingPos().map(pos -> {
            BlockState state = player.level.getBlockState(pos);
            return state.getBlock().isBed(state, player.level, pos, player);
        }).orElse(false);
    } else
        return canContinueSleep == Result.ALLOW;
}
Also used : EntityTeleportEvent(net.minecraftforge.event.entity.EntityTeleportEvent) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) ProjectileImpactEvent(net.minecraftforge.event.entity.ProjectileImpactEvent) GameProfile(com.mojang.authlib.GameProfile) FurnaceFuelBurnTimeEvent(net.minecraftforge.event.furnace.FurnaceFuelBurnTimeEvent) UseHoeEvent(net.minecraftforge.event.entity.player.UseHoeEvent) PlayerList(net.minecraft.server.players.PlayerList) Dist(net.minecraftforge.api.distmarker.Dist) FireworkRocketEntity(net.minecraft.world.entity.projectile.FireworkRocketEntity) Zombie(net.minecraft.world.entity.monster.Zombie) Pose(net.minecraft.world.entity.Pose) MobSpawnSettings(net.minecraft.world.level.biome.MobSpawnSettings) CapabilityDispatcher(net.minecraftforge.common.capabilities.CapabilityDispatcher) EntityPlaceEvent(net.minecraftforge.event.world.BlockEvent.EntityPlaceEvent) Projectile(net.minecraft.world.entity.projectile.Projectile) PreparableReloadListener(net.minecraft.server.packs.resources.PreparableReloadListener) FillBucketEvent(net.minecraftforge.event.entity.player.FillBucketEvent) BonemealEvent(net.minecraftforge.event.entity.player.BonemealEvent) OverlayType(net.minecraftforge.client.event.RenderBlockOverlayEvent.OverlayType) RecipeType(net.minecraft.world.item.crafting.RecipeType) EntityItemPickupEvent(net.minecraftforge.event.entity.player.EntityItemPickupEvent) RenderBlockOverlayEvent(net.minecraftforge.client.event.RenderBlockOverlayEvent) LogicalSide(net.minecraftforge.fml.LogicalSide) PlayerEvent(net.minecraftforge.event.entity.player.PlayerEvent) LivingHealEvent(net.minecraftforge.event.entity.living.LivingHealEvent) BlockEvent(net.minecraftforge.event.world.BlockEvent) ThrownEnderpearl(net.minecraft.world.entity.projectile.ThrownEnderpearl) InteractionResult(net.minecraft.world.InteractionResult) LivingConversionEvent(net.minecraftforge.event.entity.living.LivingConversionEvent) BaseSpawner(net.minecraft.world.level.BaseSpawner) ItemTooltipEvent(net.minecraftforge.event.entity.player.ItemTooltipEvent) PistonEvent(net.minecraftforge.event.world.PistonEvent) ItemStack(net.minecraft.world.item.ItemStack) SoundSource(net.minecraft.sounds.SoundSource) java.util(java.util) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) CommandSourceStack(net.minecraft.commands.CommandSourceStack) ICapabilityProvider(net.minecraftforge.common.capabilities.ICapabilityProvider) EntityType(net.minecraft.world.entity.EntityType) SleepingLocationCheckEvent(net.minecraftforge.event.entity.player.SleepingLocationCheckEvent) BlockState(net.minecraft.world.level.block.state.BlockState) ArrowLooseEvent(net.minecraftforge.event.entity.player.ArrowLooseEvent) EntityMobGriefingEvent(net.minecraftforge.event.entity.EntityMobGriefingEvent) CreateFluidSourceEvent(net.minecraftforge.event.world.BlockEvent.CreateFluidSourceEvent) ServerPlayer(net.minecraft.server.level.ServerPlayer) Container(net.minecraft.world.Container) ClientChatEvent(net.minecraftforge.client.event.ClientChatEvent) ToolAction(net.minecraftforge.common.ToolAction) PlaySoundAtEntityEvent(net.minecraftforge.event.entity.PlaySoundAtEntityEvent) PlayerDestroyItemEvent(net.minecraftforge.event.entity.player.PlayerDestroyItemEvent) UseOnContext(net.minecraft.world.item.context.UseOnContext) Nullable(javax.annotation.Nullable) ExplosionEvent(net.minecraftforge.event.world.ExplosionEvent) LightningBolt(net.minecraft.world.entity.LightningBolt) Component(net.minecraft.network.chat.Component) PlayerSetSpawnEvent(net.minecraftforge.event.entity.player.PlayerSetSpawnEvent) Animal(net.minecraft.world.entity.animal.Animal) LivingDestroyBlockEvent(net.minecraftforge.event.entity.living.LivingDestroyBlockEvent) File(java.io.File) SaplingGrowTreeEvent(net.minecraftforge.event.world.SaplingGrowTreeEvent) ArrowNockEvent(net.minecraftforge.event.entity.player.ArrowNockEvent) ChunkPos(net.minecraft.world.level.ChunkPos) MinecraftForge(net.minecraftforge.common.MinecraftForge) Result(net.minecraftforge.eventbus.api.Event.Result) AnimalTameEvent(net.minecraftforge.event.entity.living.AnimalTameEvent) EntityDimensions(net.minecraft.world.entity.EntityDimensions) TooltipFlag(net.minecraft.world.item.TooltipFlag) AllowDespawn(net.minecraftforge.event.entity.living.LivingSpawnEvent.AllowDespawn) InteractionHand(net.minecraft.world.InteractionHand) EntityEvent(net.minecraftforge.event.entity.EntityEvent) Mob(net.minecraft.world.entity.Mob) ResourceLocation(net.minecraft.resources.ResourceLocation) LivingEntity(net.minecraft.world.entity.LivingEntity) PlayerWakeUpEvent(net.minecraftforge.event.entity.player.PlayerWakeUpEvent) InteractionResultHolder(net.minecraft.world.InteractionResultHolder) Direction(net.minecraft.core.Direction) ItemExpireEvent(net.minecraftforge.event.entity.item.ItemExpireEvent) MinecraftForgeClient(net.minecraftforge.client.MinecraftForgeClient) PortalShape(net.minecraft.world.level.portal.PortalShape) LootTables(net.minecraft.world.level.storage.loot.LootTables) NeighborNotifyEvent(net.minecraftforge.event.world.BlockEvent.NeighborNotifyEvent) PlayerDataStorage(net.minecraft.world.level.storage.PlayerDataStorage) LivingExperienceDropEvent(net.minecraftforge.event.entity.living.LivingExperienceDropEvent) PlayerSleepInBedEvent(net.minecraftforge.event.entity.player.PlayerSleepInBedEvent) Event(net.minecraftforge.eventbus.api.Event) NonNullList(net.minecraft.core.NonNullList) LivingPackSizeEvent(net.minecraftforge.event.entity.living.LivingPackSizeEvent) WorldEvent(net.minecraftforge.event.world.WorldEvent) PlayerFlyableFallEvent(net.minecraftforge.event.entity.player.PlayerFlyableFallEvent) Commands(net.minecraft.commands.Commands) BedSleepingProblem(net.minecraft.world.entity.player.Player.BedSleepingProblem) GameRules(net.minecraft.world.level.GameRules) PermissionsChangedEvent(net.minecraftforge.event.entity.player.PermissionsChangedEvent) ChatType(net.minecraft.network.chat.ChatType) LevelReader(net.minecraft.world.level.LevelReader) Player(net.minecraft.world.entity.player.Player) Blocks(net.minecraft.world.level.block.Blocks) PotionBrewEvent(net.minecraftforge.event.brewing.PotionBrewEvent) ItemEntity(net.minecraft.world.entity.item.ItemEntity) SoundEvent(net.minecraft.sounds.SoundEvent) BlockPos(net.minecraft.core.BlockPos) BlockToolInteractEvent(net.minecraftforge.event.world.BlockEvent.BlockToolInteractEvent) LevelAccessor(net.minecraft.world.level.LevelAccessor) ClientChatReceivedEvent(net.minecraftforge.client.event.ClientChatReceivedEvent) Level(net.minecraft.world.level.Level) SummonAidEvent(net.minecraftforge.event.entity.living.ZombieEvent.SummonAidEvent) MobSpawnType(net.minecraft.world.entity.MobSpawnType) ServerLevelData(net.minecraft.world.level.storage.ServerLevelData) ServerLevel(net.minecraft.server.level.ServerLevel) EntityMountEvent(net.minecraftforge.event.entity.EntityMountEvent) PoseStack(com.mojang.blaze3d.vertex.PoseStack) MobCategory(net.minecraft.world.entity.MobCategory) LivingEntityUseItemEvent(net.minecraftforge.event.entity.living.LivingEntityUseItemEvent) LootTable(net.minecraft.world.level.storage.loot.LootTable) ServerResources(net.minecraft.server.ServerResources) SleepingTimeCheckEvent(net.minecraftforge.event.entity.player.SleepingTimeCheckEvent) Nonnull(javax.annotation.Nonnull) BlockSnapshot(net.minecraftforge.common.util.BlockSnapshot) EntityMultiPlaceEvent(net.minecraftforge.event.world.BlockEvent.EntityMultiPlaceEvent) ResourceKey(net.minecraft.resources.ResourceKey) Explosion(net.minecraft.world.level.Explosion) EntityStruckByLightningEvent(net.minecraftforge.event.entity.EntityStruckByLightningEvent) Consumer(java.util.function.Consumer) HitResult(net.minecraft.world.phys.HitResult) Entity(net.minecraft.world.entity.Entity) LivingSpawnEvent(net.minecraftforge.event.entity.living.LivingSpawnEvent) SleepFinishedTimeEvent(net.minecraftforge.event.world.SleepFinishedTimeEvent) PlayerBrewedPotionEvent(net.minecraftforge.event.brewing.PlayerBrewedPotionEvent) ChunkWatchEvent(net.minecraftforge.event.world.ChunkWatchEvent) BlockState(net.minecraft.world.level.block.state.BlockState) SleepingLocationCheckEvent(net.minecraftforge.event.entity.player.SleepingLocationCheckEvent) InteractionResult(net.minecraft.world.InteractionResult) Result(net.minecraftforge.eventbus.api.Event.Result) HitResult(net.minecraft.world.phys.HitResult)

Aggregations

GameProfile (com.mojang.authlib.GameProfile)1 PoseStack (com.mojang.blaze3d.vertex.PoseStack)1 CommandDispatcher (com.mojang.brigadier.CommandDispatcher)1 File (java.io.File)1 java.util (java.util)1 Consumer (java.util.function.Consumer)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 IBlockState (net.minecraft.block.state.IBlockState)1 CommandSourceStack (net.minecraft.commands.CommandSourceStack)1 Commands (net.minecraft.commands.Commands)1 BlockPos (net.minecraft.core.BlockPos)1 Direction (net.minecraft.core.Direction)1 NonNullList (net.minecraft.core.NonNullList)1 SleepResult (net.minecraft.entity.player.EntityPlayer.SleepResult)1 ChatType (net.minecraft.network.chat.ChatType)1 Component (net.minecraft.network.chat.Component)1 ResourceKey (net.minecraft.resources.ResourceKey)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 ServerResources (net.minecraft.server.ServerResources)1