void DrawCounts() { SurvivalGameMode surv = (SurvivalGameMode)game.Mode; VertexP3fT2fC4b[] vertices = game.ModelCache.vertices; int index = 0; posAtlas.tex.Y = (short)(game.Height - barHeight + 10 * (elemSize / 16)); int offset = game.Inventory.Offset; for (int i = 0; i < Inventory.BlocksPerRow; i++) { int x = (int)(X + (elemSize + borderSize) * i); if (survivalinventory.invCount[offset + i] > 9) { posAtlas.curX = (int)(x + 7 * (elemSize / 16)); } else { posAtlas.curX = (int)(x + 14 * (elemSize / 16)); } if (survivalinventory.invCount[offset + i] > 1) { posAtlas.AddInt(survivalinventory.invCount[offset + i], vertices, ref index); } } gfx.BindTexture(posAtlas.tex.ID); gfx.UpdateDynamicIndexedVb(DrawMode.Triangles, game.ModelCache.vb, game.ModelCache.vertices, index); }
void DrawCounts() { SurvivalGameMode surv = (SurvivalGameMode)game.Mode; VertexP3fT2fC4bN1v[] vertices = game.ModelCache.vertices; int index = 0; posAtlas.tex.Y = (short)(Y + (Height - (int)(12 * game.GuiHotbarScale))); int xAdj = (int)(14 * game.GuiHotbarScale); int xAdj2 = (int)(7 * game.GuiHotbarScale); int offset = 0; for (int i = 0; i < Inventory.BlocksPerRow; i++) { if (game.SurvInv.ItemList[i] == null) { continue; } int x = (int)(X + (elemSize + borderSize) * i + xAdj); int count = 0; if (game.SurvInv.ItemList[i] != null) { count = game.SurvInv.ItemList[i].Count; } int xAdj3 = (count.ToString().Length - 1) * xAdj2; if (xAdj3 < 0) { xAdj3 = 0; } x -= xAdj3; posAtlas.curX = x; if (count > 1) { posAtlas.AddInt(count, vertices, ref index); } } game.Graphics.BindTexture(posAtlas.tex.ID); game.Graphics.UpdateDynamicVb_IndexedTris(game.ModelCache.vb, game.ModelCache.vertices, index); }
void DrawCounts() { SurvivalGameMode surv = (SurvivalGameMode)game.Mode; VertexP3fT2fC4b[] vertices = game.ModelCache.vertices; int index = 0; posAtlas.tex.Y = (short)(Y + (Height - barHeight)); int offset = game.Inventory.Offset; for (int i = 0; i < Inventory.BlocksPerRow; i++) { int x = (int)(X + (elemSize + borderSize) * i); posAtlas.curX = x; if (surv.invCount[offset + i] > 1) { posAtlas.AddInt(surv.invCount[offset + i], vertices, ref index); } } game.Graphics.BindTexture(posAtlas.tex.ID); game.Graphics.UpdateDynamicVb_IndexedTris(game.ModelCache.vb, game.ModelCache.vertices, index); }
internal void OnLoad() { #if ANDROID Graphics = new OpenGLESApi(); #elif !USE_DX Graphics = new OpenGLApi(window); #else Graphics = new Direct3D9Api(window); #endif Graphics.MakeApiInfo(); ErrorHandler.ExtraInfo = Graphics.ApiInfo; #if ANDROID Drawer2D = new CanvasDrawer2D(Graphics); #else Drawer2D = new GdiPlusDrawer2D(Graphics); #endif UpdateClientSize(); Entities = new EntityList(this); TextureCache.Init(); #if SURVIVAL_TEST if (Options.GetBool(OptionsKey.SurvivalMode, false)) { Mode = new SurvivalGameMode(); } else { Mode = new CreativeGameMode(); } #endif Input = new InputHandler(this); ParticleManager = new ParticleManager(); Components.Add(ParticleManager); TabList = new TabList(); Components.Add(TabList); LoadOptions(); LoadGuiOptions(); Chat = new Chat(); Components.Add(Chat); Events.OnNewMap += OnNewMapCore; Events.OnNewMapLoaded += OnNewMapLoadedCore; Events.TextureChanged += TextureChangedCore; Events.LowVRAMDetected += OnLowVRAMDetected; 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); Atlas1D.game = this; Atlas2D.game = this; Animations = new Animations(); Components.Add(Animations); Inventory = new Inventory(); Components.Add(Inventory); Inventory.Map = new BlockID[BlockInfo.Count]; BlockInfo.SetDefaultPerms(); World = new World(this); LocalPlayer = new LocalPlayer(this); Components.Add(LocalPlayer); Entities.List[EntityList.SelfID] = LocalPlayer; MapRenderer = new MapRenderer(this); ChunkUpdater = new ChunkUpdater(this); EnvRenderer = new EnvRenderer(); Components.Add(EnvRenderer); MapBordersRenderer = new MapBordersRenderer(); Components.Add(MapBordersRenderer); string renType = Options.Get(OptionsKey.RenderType, "normal"); int flags = CalcRenderType(renType); if (flags == -1) { flags = 0; } MapBordersRenderer.legacy = (flags & 1) != 0; EnvRenderer.legacy = (flags & 1) != 0; EnvRenderer.minimal = (flags & 2) != 0; if (IPAddress == null) { Server = new Singleplayer.SinglePlayerServer(this); } else { Server = new Network.NetworkProcessor(this); } Components.Add(Server); 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); List <string> nonLoaded = PluginLoader.LoadAll(this); 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); } } LoadIcon(); string connectString = "Connecting to " + IPAddress + ":" + Port + ".."; if (Graphics.WarnIfNecessary(Chat)) { MapBordersRenderer.UseLegacyMode(true); EnvRenderer.UseLegacyMode(true); } Gui.SetNewScreen(new LoadingScreen(this, connectString, "")); Server.BeginConnect(); }
public override void Tick(double delta) { if (!game.World.HasBlocks) { return; } OldVelocity = Velocity; interp.AdvanceState(); physics.UpdateVelocityState(); bool sprite = BlockInfo.Draw[ItemId] == DrawType.Sprite; physics.PhysicsTick(Vector3.Zero); interp.next.Pos = Position; Position = interp.prev.Pos; //if (sprite) { // interp.prevRotY = RotY; interp.nextRotY = game.LocalPlayer.HeadY - 45f; //} anim.UpdateAnimState(interp.prev.Pos, interp.next.Pos, delta); SurvivalGameMode surv = null; if (game.Mode.GetType() == typeof(SurvivalGameMode)) { surv = (SurvivalGameMode)game.Mode; } for (int id = 0; id < EntityList.MaxCount; id++) { Entity other = game.Entities.List[id]; if (other != game.LocalPlayer) { continue; } if (other == null || other == this) { continue; } //if (!other.Model.Pushes) continue; bool yIntersects = this.Position.Y <= (other.Position.Y + other.Size.Y) && other.Position.Y <= (this.Position.Y + this.Size.Y); if (!yIntersects) { continue; } float dX = other.Position.X - this.Position.X; float dZ = other.Position.Z - this.Position.Z; float dist = dX * dX + dZ * dZ; if (dist > 1.5f) { continue; // TODO: range needs to be lower? } if (surv == null) { int changeInv = 0; changeInv = game.Inventory.SelectedIndex; game.Inventory[changeInv] = this.ItemId; int entId = game.Entities.GetEntityID(this); game.Entities.RemoveEntity((byte)entId); break; } else { //surv.AddToHotbar(ItemId, ItemCount); game.SurvInv.TryAddItem(ItemCount, ItemId); int entId = game.Entities.GetEntityID(this); game.Entities.RemoveEntity((byte)entId); break; } } }
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.Init(); ModelCache = new ModelCache(this); ModelCache.InitCache(); AsyncDownloader = new AsyncDownloader(Drawer2D); Components.Add(AsyncDownloader); 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 = new TerrainAtlas1D(this); TerrainAtlas = new TerrainAtlas2D(this); Animations = new Animations(); Components.Add(Animations); Inventory = new Inventory(); Components.Add(Inventory); 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); plugins = new PluginLoader(this); List <string> nonLoaded = plugins.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++) { plugins.MakeWarning(this, nonLoaded[i]); } } 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); }