private void GetSelectedEntity() { if (_playerManager.ActiveTool == null) { return; } bool newpicking; Vector3D mouseWorldPosition; Vector3D mouseLookAtPosition; var distance = 10f; var thirdPersonCamera = _cameraManager.ActiveBaseCamera as ThirdPersonCameraWithFocus; if (thirdPersonCamera != null) { distance = thirdPersonCamera.Distance * 2; } if (_inputsManager.MouseManager.MouseCapture) { _inputsManager.MouseManager.UnprojectMouseCursor(_cameraManager.ActiveBaseCamera, out mouseWorldPosition, out mouseLookAtPosition, true); newpicking = RefreshPicking(ref mouseWorldPosition, mouseLookAtPosition.AsVector3(), distance); } else { _inputsManager.MouseManager.UnprojectMouseCursor(_cameraManager.ActiveBaseCamera, out mouseWorldPosition, out mouseLookAtPosition); newpicking = RefreshPicking(ref mouseWorldPosition, mouseLookAtPosition.AsVector3(), distance); if (newpicking) { if (PlayerManager.Player.EntityState.IsBlockPicked) { if (Vector3D.Distance(mouseWorldPosition, new Vector3D(PlayerManager.Player.EntityState.PickedBlockPosition)) > 10.0) { PlayerManager.Player.EntityState.IsBlockPicked = false; } } } } if (newpicking) { //A new Block has been pickedup if (PlayerManager.Player.EntityState.IsEntityPicked == false) { PickingRenderer.SetPickedBlock(ref PlayerManager.Player.EntityState.PickedBlockPosition, _worldConfiguration.BlockProfiles[_pickedCube.Cube.Id].YBlockOffset); } else { if (_cameraManager.ActiveBaseCamera.CameraType == CameraType.ThirdPerson && _pickedUpEntity.Entity == PlayerManager.Player) { return; } PickingRenderer.SetPickedEntity(_pickedUpEntity); } } }
protected override void OnLoad(EventArgs e) { #if !USE_DX Graphics = new OpenGLApi(); #else Graphics = new Direct3D9Api(this); #endif Graphics.MakeGraphicsInfo(); Players = new EntityList(this); Options.Load(); AcceptedUrls.Load(); DeniedUrls.Load(); ViewDistance = Options.GetInt(OptionsKey.ViewDist, 16, 4096, 512); UserViewDistance = ViewDistance; CameraClipping = Options.GetBool(OptionsKey.CameraClipping, true); InputHandler = new InputHandler(this); Chat = new ChatLog(this); ParticleManager = new ParticleManager(this); HudScale = Options.GetFloat(OptionsKey.HudScale, 0.25f, 5f, 1f); ChatScale = Options.GetFloat(OptionsKey.ChatScale, 0.35f, 5f, 1f); defaultIb = Graphics.MakeDefaultIb(); MouseSensitivity = Options.GetInt(OptionsKey.Sensitivity, 1, 100, 30); UseClassicGui = Options.GetBool(OptionsKey.UseClassicGui, false); BlockInfo = new BlockInfo(); BlockInfo.Init(); ChatLines = Options.GetInt(OptionsKey.ChatLines, 1, 30, 12); ClickableChat = Options.GetBool(OptionsKey.ClickableChat, true); ModelCache = new ModelCache(this); ModelCache.InitCache(); AsyncDownloader = new AsyncDownloader(skinServer); Drawer2D = new GdiPlusDrawer2D(Graphics); Drawer2D.UseBitmappedChat = !Options.GetBool(OptionsKey.ArialChatFont, false); ViewBobbing = Options.GetBool(OptionsKey.ViewBobbing, false); ShowBlockInHand = Options.GetBool(OptionsKey.ShowBlockInHand, true); InvertMouse = Options.GetBool(OptionsKey.InvertMouse, false); SimpleArmsAnim = Options.GetBool(OptionsKey.SimpleArmsAnim, false); TerrainAtlas1D = new TerrainAtlas1D(Graphics); TerrainAtlas = new TerrainAtlas2D(Graphics, Drawer2D); Animations = new Animations(this); defTexturePack = Options.Get(OptionsKey.DefaultTexturePack) ?? "default.zip"; TexturePackExtractor extractor = new TexturePackExtractor(); extractor.Extract("default.zip", this); // in case the user's default texture pack doesn't have all required textures if (defTexturePack != "default.zip") { extractor.Extract(DefaultTexturePack, this); } Inventory = new Inventory(this); BlockInfo.SetDefaultBlockPermissions(Inventory.CanPlace, Inventory.CanDelete); Map = new Map(this); LocalPlayer = new LocalPlayer(this); Players[255] = LocalPlayer; width = Width; height = Height; MapRenderer = new MapRenderer(this); MapBordersRenderer = new MapBordersRenderer(this); EnvRenderer = new StandardEnvRenderer(this); if (IPAddress == null) { Network = new Singleplayer.SinglePlayerServer(this); } else { Network = new NetworkProcessor(this); } Graphics.LostContextFunction = Network.Tick; firstPersonCam = new FirstPersonCamera(this); thirdPersonCam = new ThirdPersonCamera(this); forwardThirdPersonCam = new ForwardThirdPersonCamera(this); Camera = firstPersonCam; FieldOfView = Options.GetInt(OptionsKey.FieldOfView, 1, 150, 70); ZoomFieldOfView = FieldOfView; UpdateProjection(); CommandManager = new CommandManager(); CommandManager.Init(this); SelectionManager = new SelectionManager(this); WeatherRenderer = new WeatherRenderer(this); WeatherRenderer.Init(); BlockHandRenderer = new BlockHandRenderer(this); BlockHandRenderer.Init(); FpsLimitMethod method = Options.GetEnum(OptionsKey.FpsLimit, FpsLimitMethod.LimitVSync); SetFpsLimitMethod(method); Graphics.DepthTest = true; Graphics.DepthTestFunc(CompareFunc.LessEqual); //Graphics.DepthWrite = true; Graphics.AlphaBlendFunc(BlendFunc.SourceAlpha, BlendFunc.InvSourceAlpha); Graphics.AlphaTestFunc(CompareFunc.Greater, 0.5f); fpsScreen = new FpsScreen(this); fpsScreen.Init(); hudScreen = new HudScreen(this); hudScreen.Init(); Culling = new FrustumCulling(); EnvRenderer.Init(); MapBordersRenderer.Init(); Picking = new PickingRenderer(this); AudioPlayer = new AudioPlayer(this); LiquidsBreakable = Options.GetBool(OptionsKey.LiquidsBreakable, false); AxisLinesRenderer = new AxisLinesRenderer(this); LoadIcon(); string connectString = "Connecting to " + IPAddress + ":" + Port + ".."; Graphics.WarnIfNecessary(Chat); SetNewScreen(new LoadingMapScreen(this, connectString, "Waiting for handshake")); Network.Connect(IPAddress, Port); }