From 132967bf9dc724297485091bdc1fc282d49f9842 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 10 Feb 2017 23:54:08 +1100 Subject: [PATCH] Now hold air instead of 255 in survival, fixes invalid block type 255 --- ClassicalSharp/Game/PickingHandler.cs | 5 ++--- ClassicalSharp/GraphicsAPI/IGraphicsApi.cs | 1 + ClassicalSharp/Mode/Survival.cs | 6 +++--- ClassicalSharp/Network/Protocols/CPE.cs | 6 ++++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/ClassicalSharp/Game/PickingHandler.cs b/ClassicalSharp/Game/PickingHandler.cs index 13123726f..063d778df 100644 --- a/ClassicalSharp/Game/PickingHandler.cs +++ b/ClassicalSharp/Game/PickingHandler.cs @@ -32,9 +32,8 @@ namespace ClassicalSharp { input.ButtonStateChanged(MouseButton.Middle, middle); } - int buttonsDown = (left ? 1 : 0) + (right ? 1 : 0) + (middle ? 1 : 0); - if (buttonsDown > 1 || game.Gui.ActiveScreen.HandlesAllInput || - inv.HeldBlock == Block.Air) return; + int btns = (left ? 1 : 0) + (right ? 1 : 0) + (middle ? 1 : 0); + if (btns > 1 || game.Gui.ActiveScreen.HandlesAllInput || inv.HeldBlock == Block.Invalid) return; // always play delete animations, even if we aren't picking a block. if (left) { diff --git a/ClassicalSharp/GraphicsAPI/IGraphicsApi.cs b/ClassicalSharp/GraphicsAPI/IGraphicsApi.cs index 31a8f5dcf..00babb88c 100644 --- a/ClassicalSharp/GraphicsAPI/IGraphicsApi.cs +++ b/ClassicalSharp/GraphicsAPI/IGraphicsApi.cs @@ -58,6 +58,7 @@ namespace ClassicalSharp.GraphicsAPI { if (!Utils.IsPowerOf2(bmp.Width) || !Utils.IsPowerOf2(bmp.Height)) { throw new ArgumentOutOfRangeException("Bitmap must have power of two dimensions"); } + if (LostContext) throw new InvalidOperationException("Cannot create texture when context lost"); if (!bmp.IsLocked) bmp.LockBits(); int texId = CreateTexture(bmp.Width, bmp.Height, bmp.Scan0, managedPool); diff --git a/ClassicalSharp/Mode/Survival.cs b/ClassicalSharp/Mode/Survival.cs index 29295077a..31c4fdb80 100644 --- a/ClassicalSharp/Mode/Survival.cs +++ b/ClassicalSharp/Mode/Survival.cs @@ -39,7 +39,7 @@ namespace ClassicalSharp.Mode { if (invCount[index] != 0) return; // bypass HeldBlock's normal behaviour - game.Inventory.Hotbar[index] = Block.Invalid; + game.Inventory.Hotbar[index] = Block.Air; game.Events.RaiseHeldBlockChanged(); } @@ -83,7 +83,7 @@ namespace ClassicalSharp.Mode { } if (index == -1) { for (int i = hotbar.Length - 1; i >= 0; i--) { - if (hotbar[i] == Block.Invalid) index = i; + if (hotbar[i] == Block.Air) index = i; } } if (index == -1) return; // no free slots @@ -116,7 +116,7 @@ namespace ClassicalSharp.Mode { this.game = game; byte[] hotbar = game.Inventory.Hotbar; for (int i = 0; i < hotbar.Length; i++) - hotbar[i] = Block.Invalid; + hotbar[i] = Block.Air; hotbar[hotbar.Length - 1] = Block.TNT; } diff --git a/ClassicalSharp/Network/Protocols/CPE.cs b/ClassicalSharp/Network/Protocols/CPE.cs index f76e4e513..3ea4a6929 100644 --- a/ClassicalSharp/Network/Protocols/CPE.cs +++ b/ClassicalSharp/Network/Protocols/CPE.cs @@ -83,10 +83,12 @@ namespace ClassicalSharp.Network.Protocols { } void HandleHoldThis() { - byte blockType = reader.ReadUInt8(); + byte block = reader.ReadUInt8(); + if (block == Block.Air) block = Block.Invalid; bool canChange = reader.ReadUInt8() == 0; + game.Inventory.CanChangeHeldBlock = true; - game.Inventory.HeldBlock = blockType; + game.Inventory.HeldBlock = block; game.Inventory.CanChangeHeldBlock = canChange; }