public void PickBlocks(bool cooldown, bool left, bool middle, bool right) { DateTime now = DateTime.UtcNow; double delta = (now - lastClick).TotalMilliseconds; if (cooldown && delta < 250) { return; // 4 times per second } lastClick = now; Inventory inv = game.Inventory; SurvivalInventory SurvInv = game.SurvInv; if (game.Server.UsingPlayerClick && !game.Gui.ActiveScreen.HandlesAllInput) { input.pickingId = -1; input.ButtonStateChanged(MouseButton.Left, left); input.ButtonStateChanged(MouseButton.Right, right); input.ButtonStateChanged(MouseButton.Middle, middle); } if (game.Gui.ActiveScreen.HandlesAllInput || !inv.CanPick) { return; } if (left) { if (game.Mode.PickingLeft()) { return; } Vector3I pos = game.SelectedPos.BlockPos; if (!game.SelectedPos.Valid || !game.World.IsValidPos(pos)) { return; } BlockID old = game.World.GetBlock(pos); if (BlockInfo.Draw[old] == DrawType.Gas || !BlockInfo.CanDelete[old]) { return; } game.Mode.PickLeft(old); } else if (right) { if (game.Mode.PickingRight()) { return; } Vector3I pos = game.SelectedPos.TranslatedPos; Vector3I pos2 = game.SelectedPos.BlockPos; BlockID sel = Block.Air; if (game.World.IsValidPos(pos2)) { sel = game.World.GetBlock(pos2); } if (!game.SelectedPos.Valid || !game.World.IsValidPos(pos)) { game.Mode.SelRight(sel); return; } BlockID old = game.World.GetBlock(pos); BlockID block; if (game.Mode is ClassicalSharp.Mode.CreativeGameMode) { block = inv.Selected; } else { block = SurvInv.Selected; } if (game.AutoRotate) { block = AutoRotate.RotateBlock(game, block); } if (game.CanPick(old) || !BlockInfo.CanPlace[block]) { game.Mode.SelRight(sel); return; } // air-ish blocks can only replace over other air-ish blocks if (BlockInfo.Draw[block] == DrawType.Gas && BlockInfo.Draw[old] != DrawType.Gas) { game.Mode.SelRight(sel); return; } if (!PickingHandler.CheckIsFree(game, block)) { game.Mode.SelRight(sel); return; } game.Mode.PickRight(old, block, sel); } else if (middle) { Vector3I pos = game.SelectedPos.BlockPos; if (!game.SelectedPos.Valid || !game.World.IsValidPos(pos)) { return; } BlockID old = game.World.GetBlock(pos); game.Mode.PickMiddle(old); } }
internal void OnLoad() { Mouse = window.Mouse; Keyboard = window.Keyboard; #if ANDROID Graphics = new OpenGLESApi(); #elif !USE_DX Graphics = new OpenGLApi(); #else Graphics = new Direct3D9Api(this); #endif Graphics.MakeApiInfo(); ErrorHandler.AdditionalInfo = Graphics.ApiInfo; #if ANDROID Drawer2D = new CanvasDrawer2D(Graphics); #else Drawer2D = new GdiPlusDrawer2D(Graphics); #endif Entities = new EntityList(this); AcceptedUrls.Load(); DeniedUrls.Load(); ETags.Load(); LastModified.Load(); if (Options.GetBool(OptionsKey.SurvivalMode, false)) { Mode = new SurvivalGameMode(); } else { Mode = new CreativeGameMode(); } Components.Add(Mode); Input = new InputHandler(this); defaultIb = Graphics.MakeDefaultIb(); ParticleManager = new ParticleManager(); Components.Add(ParticleManager); TabList = new TabList(); Components.Add(TabList); LoadOptions(); LoadGuiOptions(); Chat = new Chat(); Components.Add(Chat); WorldEvents.OnNewMap += OnNewMapCore; WorldEvents.OnNewMapLoaded += OnNewMapLoadedCore; Events.TextureChanged += TextureChangedCore; BlockInfo.Allocate(256); BlockInfo.Init(); ModelCache = new ModelCache(this); ModelCache.InitCache(); Downloader = new AsyncDownloader(Drawer2D); Components.Add(Downloader); Lighting = new BasicLighting(); Components.Add(Lighting); Drawer2D.UseBitmappedChat = ClassicMode || !Options.GetBool(OptionsKey.UseChatFont, false); Drawer2D.BlackTextShadows = Options.GetBool(OptionsKey.BlackText, false); Graphics.Mipmaps = Options.GetBool(OptionsKey.Mipmaps, false); TerrainAtlas1D.game = this; TerrainAtlas2D.game = this; Animations = new Animations(); Components.Add(Animations); Inventory = new Inventory(); Components.Add(Inventory); SurvInv = new SurvivalInventory(); Components.Add(SurvInv); Inventory.Map = new BlockID[BlockInfo.Count]; RecipeList = Recipes.MakeRecipeList(); BlockInfo.SetDefaultPerms(); World = new World(this); LocalPlayer = new LocalPlayer(this); Components.Add(LocalPlayer); Entities.List[EntityList.SelfID] = LocalPlayer; Width = window.Width; Height = window.Height; MapRenderer = new MapRenderer(this); string renType = Options.Get(OptionsKey.RenderType) ?? "normal"; if (!SetRenderType(renType)) { SetRenderType("normal"); } if (IPAddress == null) { Server = new Singleplayer.SinglePlayerServer(this); } else { Server = new Network.NetworkProcessor(this); } Graphics.LostContextFunction = Server.Tick; Cameras.Add(new FirstPersonCamera(this)); Cameras.Add(new ThirdPersonCamera(this, false)); Cameras.Add(new ThirdPersonCamera(this, true)); Camera = Cameras[0]; UpdateProjection(); Gui = new GuiInterface(this); Components.Add(Gui); CommandList = new CommandList(); Components.Add(CommandList); SelectionManager = new SelectionManager(); Components.Add(SelectionManager); WeatherRenderer = new WeatherRenderer(); Components.Add(WeatherRenderer); HeldBlockRenderer = new HeldBlockRenderer(); Components.Add(HeldBlockRenderer); Graphics.DepthTest = true; Graphics.DepthTestFunc(CompareFunc.LessEqual); //Graphics.DepthWrite = true; Graphics.AlphaBlendFunc(BlendFunc.SourceAlpha, BlendFunc.InvSourceAlpha); Graphics.AlphaTestFunc(CompareFunc.Greater, 0.5f); Culling = new FrustumCulling(); Picking = new PickedPosRenderer(); Components.Add(Picking); AudioPlayer = new AudioPlayer(); Components.Add(AudioPlayer); AxisLinesRenderer = new AxisLinesRenderer(); Components.Add(AxisLinesRenderer); SkyboxRenderer = new SkyboxRenderer(); Components.Add(SkyboxRenderer); CelestialRenderer = new CelestialRenderer(); Components.Add(CelestialRenderer); PluginLoader.game = this; List <string> nonLoaded = PluginLoader.LoadAll(); for (int i = 0; i < Components.Count; i++) { Components[i].Init(this); } ExtractInitialTexturePack(); for (int i = 0; i < Components.Count; i++) { Components[i].Ready(this); } InitScheduledTasks(); if (nonLoaded != null) { for (int i = 0; i < nonLoaded.Count; i++) { Overlay warning = new PluginOverlay(this, nonLoaded[i]); Gui.ShowOverlay(warning, false); } } window.LoadIcon(); string connectString = "Connecting to " + IPAddress + ":" + Port + ".."; if (Graphics.WarnIfNecessary(Chat)) { //MapBordersRenderer.UseLegacyMode(true); EnvRenderer.UseLegacyMode(true); } Gui.SetNewScreen(new LoadingMapScreen(this, connectString, "")); Server.Connect(IPAddress, Port); }