Exemple #1
0
        private void OnTeleport(IServerPlayer fromPlayer, ForTeleportingData data)
        {
            Entity[] tpEntities;
            Vec3d    currCenterPos;

            if (data.TargetPos == null)
            {
                return;
            }

            if (data.SourcePos == null)
            {
                if (fromPlayer.Entity == null)
                {
                    return;
                }

                tpEntities = new Entity[1] {
                    fromPlayer.Entity
                };
                currCenterPos = fromPlayer.Entity.Pos.XYZ;
            }
            else
            {
                BlockEntityTeleport bet = sapi.World.BlockAccessor.GetBlockEntity(data.SourcePos.AsBlockPos) as BlockEntityTeleport;
                if (bet == null)
                {
                    return;
                }

                tpEntities    = bet.GetInCircleEntities();
                currCenterPos = bet.Pos.ToVec3d().Add(0.5, 1, 0.5);
            }

            if (tpEntities == null)
            {
                return;
            }


            string name = Teleports[data.TargetPos.AsBlockPos]?.Name;

            foreach (var entity in tpEntities)
            {
                double x = data.TargetPos.X + (entity.Pos.X - currCenterPos.X) + 0.5;
                double y = data.TargetPos.Y + (entity.Pos.Y - currCenterPos.Y) + 2;
                double z = data.TargetPos.Z + (entity.Pos.Z - currCenterPos.Z) + 0.5;

                entity.TeleportToDouble(x, y, z);

                if (entity is EntityPlayer player)
                {
                    player.SetActivityRunning("teleportCooldown", 5000);
                }

                sapi.World.Logger.ModNotification($"{entity?.GetName()} teleported to {x}, {y}, {z} ({name})");
            }
        }
Exemple #2
0
        //public MeshData[] meshes = new MeshData[2];

        public override void OnEntityCollide(IWorldAccessor world, Entity entity, BlockPos pos, BlockFacing facing, Vec3d collideSpeed, bool isImpact)
        {
            BlockEntityTeleport be = api.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityTeleport;

            if (be == null)
            {
                return;
            }

            be.OnEntityCollide(entity);
        }
Exemple #3
0
        public override bool DoPlaceBlock(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ItemStack byItemStack)
        {
            bool flag = base.DoPlaceBlock(world, byPlayer, blockSel, byItemStack);

            if (flag && byPlayer.WorldData.CurrentGameMode == EnumGameMode.Creative)
            {
                BlockEntityTeleport bet = api.World.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityTeleport;

                if (bet != null && bet.State == EnumTeleportState.Normal && api.Side == EnumAppSide.Server)
                {
                    TPNetManager.AddAvailableTeleport(byPlayer as IServerPlayer, blockSel.Position);
                }
            }

            return(flag);
        }
Exemple #4
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            BlockEntityTeleport be = api.World.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityTeleport;

            if (be == null)
            {
                //api.World.BlockAccessor.SetBlock(BlockId, blockSel.Position);
                return(false);
            }

            if (be.Repaired && byPlayer.WorldData.EntityControls.Sneak)
            {
                be.OnShiftRightClick();
                return(true);
            }

            ItemSlot slot = byPlayer.InventoryManager.ActiveHotbarSlot;

            if (slot.Empty)
            {
                return(base.OnBlockInteractStart(world, byPlayer, blockSel));
            }

            if (!be.Repaired && slot.Itemstack.Collectible is ItemTemporalGear)
            {
                be.Repaired = true;

                if (byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative)
                {
                    slot.TakeOut(1);
                    slot.MarkDirty();
                }
                if (api.Side == EnumAppSide.Server)
                {
                    TPNetManager.AddAvailableTeleport(byPlayer as IServerPlayer, be.Pos);
                }

                world.PlaySoundAt(new AssetLocation("sounds/effect/latch"), blockSel.Position.X + 0.5, blockSel.Position.Y, blockSel.Position.Z + 0.5, byPlayer, true, 16);

                return(true);
            }

            return(false);
        }