public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel) { if (!world.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.Use)) { return(false); } BlockFacing facing = BlockFacing.FromCode(LastCodePart()).Opposite; BlockEntityBed beBed = world.BlockAccessor.GetBlockEntity(LastCodePart(1) == "feet" ? blockSel.Position.AddCopy(facing) : blockSel.Position) as BlockEntityBed; if (beBed == null) { return(false); } if (beBed.MountedBy != null) { return(false); } EntityBehaviorTiredness ebt = byPlayer.Entity.GetBehavior("tiredness") as EntityBehaviorTiredness; if (ebt != null && ebt.Tiredness <= 8) { if (world.Side == EnumAppSide.Client) { (api as ICoreClientAPI).TriggerIngameError(this, "nottiredenough", Lang.Get("not-tired-enough")); } return(false); } return(byPlayer.Entity.TryMount(beBed)); }
public void DidUnmount(EntityAgent entityAgent) { EntityBehaviorTiredness ebt = MountedBy?.GetBehavior("tiredness") as EntityBehaviorTiredness; if (ebt != null) { ebt.IsSleeping = false; } MountedBy = null; if (!blockBroken) { foreach (BlockFacing facing in BlockFacing.HORIZONTALS) { Vec3d placepos = Pos.ToVec3d().AddCopy(facing).Add(0.5, 0.001, 0.5); if (!Api.World.CollisionTester.IsColliding(Api.World.BlockAccessor, entityAgent.SelectionBox, placepos, false)) { entityAgent.TeleportTo(placepos); break; } } } base.OnBlockRemoved(); }
private void RestPlayer(float dt) { double hoursPassed = Api.World.Calendar.TotalHours - hoursTotal; // Since waking up takes an hour, we take away one hour from the sleepEfficiency float sleepEff = sleepEfficiency - 1f / 12; if (hoursPassed > 0) { int tempStormSleep = Api.World.Config.GetString("temporalStormSleeping", "0").ToInt(); if (tempStormSleep == 0 && Api.ModLoader.GetModSystem <SystemTemporalStability>().StormStrength > 0) { MountedBy.TryUnmount(); return; } EntityBehaviorTiredness ebt = MountedBy?.GetBehavior("tiredness") as EntityBehaviorTiredness; if (ebt != null) { float newval = Math.Max(0, ebt.Tiredness - (float)hoursPassed / sleepEff); ebt.Tiredness = newval; if (newval <= 0) { MountedBy.TryUnmount(); } } hoursTotal = Api.World.Calendar.TotalHours; } }
public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel) { BlockFacing facing = BlockFacing.FromCode(LastCodePart()).GetOpposite(); BlockEntityBed beBed = world.BlockAccessor.GetBlockEntity(LastCodePart(1) == "feet" ? blockSel.Position.AddCopy(facing) : blockSel.Position) as BlockEntityBed; if (beBed == null) { return(false); } if (beBed.MountedBy != null) { return(false); } EntityBehaviorTiredness ebt = byPlayer.Entity.GetBehavior("tiredness") as EntityBehaviorTiredness; if (ebt != null && ebt.Tiredness <= 8) { if (world.Side == EnumAppSide.Client) { (byPlayer as IClientPlayer).ShowChatNotification("I'm not tired enough to sleep."); } return(false); } return(byPlayer.Entity.TryMount(beBed)); }
public void DidUnmount(EntityAgent entityAgent) { EntityBehaviorTiredness ebt = MountedBy?.GetBehavior("tiredness") as EntityBehaviorTiredness; if (ebt != null) { ebt.IsSleeping = false; } MountedBy = null; base.OnBlockRemoved(); }
public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel) { if (!world.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.Use)) { return(false); } BlockFacing facing = BlockFacing.FromCode(LastCodePart()).Opposite; BlockEntityBed beBed = world.BlockAccessor.GetBlockEntity(LastCodePart(1) == "feet" ? blockSel.Position.AddCopy(facing) : blockSel.Position) as BlockEntityBed; if (beBed == null) { return(false); } if (beBed.MountedBy != null) { return(false); } EntityBehaviorTiredness ebt = byPlayer.Entity.GetBehavior("tiredness") as EntityBehaviorTiredness; if (ebt != null && ebt.Tiredness <= 8) { if (world.Side == EnumAppSide.Client) { (api as ICoreClientAPI).TriggerIngameError(this, "nottiredenough", Lang.Get("not-tired-enough")); } return(false); } int tempStormSleep = api.World.Config.GetString("temporalStormSleeping", "0").ToInt(); if (tempStormSleep == 0 && api.ModLoader.GetModSystem <SystemTemporalStability>().StormStrength > 0) { if (world.Side == EnumAppSide.Client) { (api as ICoreClientAPI).TriggerIngameError(this, "cantsleep-tempstorm", Lang.Get("cantsleep-tempstorm")); } return(false); } return(byPlayer.Entity.TryMount(beBed)); }
public void DidMount(EntityAgent entityAgent) { if (MountedBy != null) { return; } MountedBy = entityAgent; if (api.Side == EnumAppSide.Server) { RegisterGameTickListener(RestPlayer, 200); hoursTotal = api.World.Calendar.TotalHours; } EntityBehaviorTiredness ebt = MountedBy?.GetBehavior("tiredness") as EntityBehaviorTiredness; if (ebt != null) { ebt.IsSleeping = true; } }
private void RestPlayer(float dt) { double hoursPassed = api.World.Calendar.TotalHours - hoursTotal; // Since waking up takes an hour, we take away one hour from the sleepEfficiency float sleepEff = sleepEfficiency - 1f / 12; if (hoursPassed > 0) { EntityBehaviorTiredness ebt = MountedBy?.GetBehavior("tiredness") as EntityBehaviorTiredness; if (ebt != null) { float newval = Math.Max(0, ebt.Tiredness - (float)hoursPassed / sleepEff); ebt.Tiredness = newval; if (newval <= 0) { MountedBy.TryUnmount(); } } hoursTotal = api.World.Calendar.TotalHours; } }