diff --git a/ClassicalSharp/Game/Game.cs b/ClassicalSharp/Game/Game.cs
index dcceaff0f..eac579821 100644
--- a/ClassicalSharp/Game/Game.cs
+++ b/ClassicalSharp/Game/Game.cs
@@ -43,9 +43,9 @@ namespace ClassicalSharp {
public bool ChangeTerrainAtlas(Bitmap atlas) {
if (!ValidateBitmap("terrain.png", atlas)) return false;
- if (atlas.Width != atlas.Height && (atlas.Width * 2 != atlas.Height)) {
+ if (atlas.Height < atlas.Width) {
Chat.Add("&cUnable to use terrain.png from the texture pack.");
- Chat.Add("&c Its width is not the same as its height.");
+ Chat.Add("&c Its height is less than its width.");
return false;
}
if (Graphics.LostContext) return false;
@@ -190,7 +190,7 @@ namespace ClassicalSharp {
public bool UpdateTexture(ref int texId, string file, byte[] data, ref SkinType type) {
bool calc = type != SkinType.Invalid;
using (Bitmap bmp = Platform.ReadBmp(Drawer2D, data)) {
- if (!ValidateBitmap(file, bmp)) return false;
+ if (!ValidateBitmap(file, bmp)) return false;
if (calc) type = Utils.GetSkinType(bmp);
Graphics.DeleteTexture(ref texId);
diff --git a/ClassicalSharp/Network/Protocols/CPE.cs b/ClassicalSharp/Network/Protocols/CPE.cs
index 018977b30..aa797f8f1 100644
--- a/ClassicalSharp/Network/Protocols/CPE.cs
+++ b/ClassicalSharp/Network/Protocols/CPE.cs
@@ -421,9 +421,7 @@ namespace ClassicalSharp.Network.Protocols {
BlockID order = reader.ReadBlock();
game.Inventory.Remove(block);
- // TODO: kinda hacky, get rid of 255 completely when servers updated
- bool hidden = order == 0 || (order == 255 && !net.cpeData.extTexs);
- if (!hidden) { game.Inventory.Map[order - 1] = block; }
+ if (order != 0) { game.Inventory.Map[order - 1] = block; }
}
#endregion
diff --git a/ClassicalSharp/Particles/ParticleManager.cs b/ClassicalSharp/Particles/ParticleManager.cs
index 6d92c58b9..d5ca8e9a0 100644
--- a/ClassicalSharp/Particles/ParticleManager.cs
+++ b/ClassicalSharp/Particles/ParticleManager.cs
@@ -40,7 +40,7 @@ namespace ClassicalSharp.Particles {
void TextureChanged(object sender, TextureEventArgs e) {
if (e.Name == "particles.png")
- game.Loadtexture(ref ParticlesTexId, e.Name, e.Data);
+ game.LoadTexture(ref ParticlesTexId, e.Name, e.Data);
}
diff --git a/ClassicalSharp/TexturePack/TerrainAtlas.cs b/ClassicalSharp/TexturePack/TerrainAtlas.cs
index 995a2974c..23f4c6158 100644
--- a/ClassicalSharp/TexturePack/TerrainAtlas.cs
+++ b/ClassicalSharp/TexturePack/TerrainAtlas.cs
@@ -1,118 +1,119 @@
-// Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
-using System;
-using System.Drawing;
-using ClassicalSharp.GraphicsAPI;
-#if ANDROID
-using Android.Graphics;
-#endif
-
-namespace ClassicalSharp.Textures {
-
- /// Represents a 2D packed texture atlas, specifically for terrain.png.
- public static class Atlas2D {
- public const int TilesPerRow = 16, MaxRowsCount = 32;
- public static Bitmap Atlas;
- public static int TileSize, RowsCount;
- internal static Game game;
-
- public static void UpdateState(Bitmap bmp) {
- Atlas = bmp;
- TileSize = bmp.Width / TilesPerRow;
- RowsCount = bmp.Height / TileSize;
- BlockInfo.RecalculateSpriteBB();
- }
-
- public static int LoadTile(int texLoc) {
- int size = TileSize, x = texLoc % TilesPerRow, y = texLoc / TilesPerRow;
- if (y >= RowsCount) return 0;
-
- using (FastBitmap atlas = new FastBitmap(Atlas, true, true))
- using (Bitmap bmp = Platform.CreateBmp(size, size))
- using (FastBitmap dst = new FastBitmap(bmp, true, false))
- {
- FastBitmap.MovePortion(x * size, y * size, 0, 0, atlas, dst, size);
- return game.Graphics.CreateTexture(dst, false, game.Graphics.Mipmaps);
- }
- }
-
- public static void Dispose() {
- if (Atlas != null) Atlas.Dispose();
- }
- }
-
- /// Represents a 2D packed texture atlas that has been converted into an array of 1D atlases.
- public static class Atlas1D {
- public static int TilesPerAtlas, AtlasesCount;
- public static float invTileSize;
- internal static Game game;
- public const int MaxAtlases = Atlas2D.MaxRowsCount * Atlas2D.TilesPerRow;
- public static int[] TexIds = new int[MaxAtlases];
-
- public static TextureRec GetTexRec(int texLoc, int uCount, out int index) {
- index = texLoc / TilesPerAtlas;
- int y = texLoc % TilesPerAtlas;
- // Adjust coords to be slightly inside - fixes issues with AMD/ATI cards.
- return new TextureRec(0, y * invTileSize, (uCount - 1) + 15.99f/16f, (15.99f/16f) * invTileSize);
- }
-
- /// Returns the index of the 1D texture within the array of 1D textures
- /// containing the given texture id.
- public static int Get1DIndex(int texLoc) { return texLoc / TilesPerAtlas; }
-
- /// Returns the index of the given texture id within a 1D texture.
- public static int Get1DRowId(int texLoc) { return texLoc % TilesPerAtlas; }
-
- public static void UpdateState() {
- int tileSize = Atlas2D.TileSize;
- int maxTiles = Atlas2D.RowsCount * Atlas2D.TilesPerRow;
- int maxAtlasHeight = Math.Min(4096, game.Graphics.MaxTextureDimensions);
- int maxTilesPerAtlas = maxAtlasHeight / tileSize;
-
- TilesPerAtlas = Math.Min(maxTilesPerAtlas, maxTiles);
- AtlasesCount = Utils.CeilDiv(maxTiles, TilesPerAtlas);
- invTileSize = 1f / TilesPerAtlas;
-
- Utils.LogDebug("Loaded new atlas: {0} bmps, {1} per bmp", AtlasesCount, TilesPerAtlas);
- int index = 0, atlasHeight = TilesPerAtlas * tileSize;
-
- using (FastBitmap atlas = new FastBitmap(Atlas2D.Atlas, true, true)) {
- for (int i = 0; i < AtlasesCount; i++) {
- Make1DTexture(i, atlas, atlasHeight, ref index);
- }
- }
- }
-
- static void Make1DTexture(int i, FastBitmap atlas, int atlas1DHeight, ref int index) {
- int tileSize = Atlas2D.TileSize;
- using (Bitmap atlas1d = Platform.CreateBmp(tileSize, atlas1DHeight))
- using (FastBitmap dst = new FastBitmap(atlas1d, true, false))
- {
- for (int index1D = 0; index1D < TilesPerAtlas; index1D++) {
- int atlasX = (index % Atlas2D.TilesPerRow) * tileSize;
- int atlasY = (index / Atlas2D.TilesPerRow) * tileSize;
-
- FastBitmap.MovePortion(atlasX, atlasY,
- 0, index1D * tileSize, atlas, dst, tileSize);
- index++;
- }
- TexIds[i] = game.Graphics.CreateTexture(dst, true, game.Graphics.Mipmaps);
- }
- }
-
- public static int UsedAtlasesCount() {
- int maxTexLoc = 0;
- for (int i = 0; i < BlockInfo.textures.Length; i++) {
- maxTexLoc = Math.Max(maxTexLoc, BlockInfo.textures[i]);
- }
- return Get1DIndex(maxTexLoc) + 1;
- }
-
- public static void Dispose() {
- if (TexIds == null) return;
-
- for (int i = 0; i < AtlasesCount; i++) {
- game.Graphics.DeleteTexture(ref TexIds[i]);
- }
- }
- }
+// Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
+using System;
+using System.Drawing;
+using ClassicalSharp.GraphicsAPI;
+#if ANDROID
+using Android.Graphics;
+#endif
+
+namespace ClassicalSharp.Textures {
+
+ /// Represents a 2D packed texture atlas, specifically for terrain.png.
+ public static class Atlas2D {
+ public const int TilesPerRow = 16, MaxRowsCount = 32;
+ public static Bitmap Atlas;
+ public static int TileSize, RowsCount;
+ internal static Game game;
+
+ public static void UpdateState(Bitmap bmp) {
+ Atlas = bmp;
+ TileSize = bmp.Width / TilesPerRow;
+ RowsCount = bmp.Height / TileSize;
+ RowsCount = Math.Min(RowsCount, MaxRowsCount);
+ BlockInfo.RecalculateSpriteBB();
+ }
+
+ public static int LoadTile(int texLoc) {
+ int size = TileSize, x = texLoc % TilesPerRow, y = texLoc / TilesPerRow;
+ if (y >= RowsCount) return 0;
+
+ using (FastBitmap atlas = new FastBitmap(Atlas, true, true))
+ using (Bitmap bmp = Platform.CreateBmp(size, size))
+ using (FastBitmap dst = new FastBitmap(bmp, true, false))
+ {
+ FastBitmap.MovePortion(x * size, y * size, 0, 0, atlas, dst, size);
+ return game.Graphics.CreateTexture(dst, false, game.Graphics.Mipmaps);
+ }
+ }
+
+ public static void Dispose() {
+ if (Atlas != null) Atlas.Dispose();
+ }
+ }
+
+ /// Represents a 2D packed texture atlas that has been converted into an array of 1D atlases.
+ public static class Atlas1D {
+ public static int TilesPerAtlas, AtlasesCount;
+ public static float invTileSize;
+ internal static Game game;
+ public const int MaxAtlases = Atlas2D.MaxRowsCount * Atlas2D.TilesPerRow;
+ public static int[] TexIds = new int[MaxAtlases];
+
+ public static TextureRec GetTexRec(int texLoc, int uCount, out int index) {
+ index = texLoc / TilesPerAtlas;
+ int y = texLoc % TilesPerAtlas;
+ // Adjust coords to be slightly inside - fixes issues with AMD/ATI cards.
+ return new TextureRec(0, y * invTileSize, (uCount - 1) + 15.99f/16f, (15.99f/16f) * invTileSize);
+ }
+
+ /// Returns the index of the 1D texture within the array of 1D textures
+ /// containing the given texture id.
+ public static int Get1DIndex(int texLoc) { return texLoc / TilesPerAtlas; }
+
+ /// Returns the index of the given texture id within a 1D texture.
+ public static int Get1DRowId(int texLoc) { return texLoc % TilesPerAtlas; }
+
+ public static void UpdateState() {
+ int tileSize = Atlas2D.TileSize;
+ int maxTiles = Atlas2D.RowsCount * Atlas2D.TilesPerRow;
+ int maxAtlasHeight = Math.Min(4096, game.Graphics.MaxTextureDimensions);
+ int maxTilesPerAtlas = maxAtlasHeight / tileSize;
+
+ TilesPerAtlas = Math.Min(maxTilesPerAtlas, maxTiles);
+ AtlasesCount = Utils.CeilDiv(maxTiles, TilesPerAtlas);
+ invTileSize = 1f / TilesPerAtlas;
+
+ Utils.LogDebug("Loaded new atlas: {0} bmps, {1} per bmp", AtlasesCount, TilesPerAtlas);
+ int index = 0, atlasHeight = TilesPerAtlas * tileSize;
+
+ using (FastBitmap atlas = new FastBitmap(Atlas2D.Atlas, true, true)) {
+ for (int i = 0; i < AtlasesCount; i++) {
+ Make1DTexture(i, atlas, atlasHeight, ref index);
+ }
+ }
+ }
+
+ static void Make1DTexture(int i, FastBitmap atlas, int atlas1DHeight, ref int index) {
+ int tileSize = Atlas2D.TileSize;
+ using (Bitmap atlas1d = Platform.CreateBmp(tileSize, atlas1DHeight))
+ using (FastBitmap dst = new FastBitmap(atlas1d, true, false))
+ {
+ for (int index1D = 0; index1D < TilesPerAtlas; index1D++) {
+ int atlasX = (index % Atlas2D.TilesPerRow) * tileSize;
+ int atlasY = (index / Atlas2D.TilesPerRow) * tileSize;
+
+ FastBitmap.MovePortion(atlasX, atlasY,
+ 0, index1D * tileSize, atlas, dst, tileSize);
+ index++;
+ }
+ TexIds[i] = game.Graphics.CreateTexture(dst, true, game.Graphics.Mipmaps);
+ }
+ }
+
+ public static int UsedAtlasesCount() {
+ int maxTexLoc = 0;
+ for (int i = 0; i < BlockInfo.textures.Length; i++) {
+ maxTexLoc = Math.Max(maxTexLoc, BlockInfo.textures[i]);
+ }
+ return Get1DIndex(maxTexLoc) + 1;
+ }
+
+ public static void Dispose() {
+ if (TexIds == null) return;
+
+ for (int i = 0; i < AtlasesCount; i++) {
+ game.Graphics.DeleteTexture(ref TexIds[i]);
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/src/Client/Game.c b/src/Client/Game.c
index 2a3074939..86fc307bc 100644
--- a/src/Client/Game.c
+++ b/src/Client/Game.c
@@ -139,9 +139,9 @@ bool Game_ChangeTerrainAtlas(struct Bitmap* atlas) {
String terrain = String_FromConst("terrain.png");
if (!Game_ValidateBitmap(&terrain, atlas)) return false;
- if (atlas->Width != atlas->Height) {
+ if (atlas->Height < atlas->Width) {
String m1 = String_FromConst("&cUnable to use terrain.png from the texture pack."); Chat_Add(&m1);
- String m2 = String_FromConst("&c Its width is not the same as its height."); Chat_Add(&m2);
+ String m2 = String_FromConst("&c Its height is less than its width."); Chat_Add(&m2);
return false;
}
if (Gfx_LostContext) return false;
diff --git a/src/Client/Menus.c b/src/Client/Menus.c
index d9b11f49f..ff11f797f 100644
--- a/src/Client/Menus.c
+++ b/src/Client/Menus.c
@@ -2941,12 +2941,12 @@ static void TexIdsOverlay_ContextRecreated(void* obj) {
String prefix = String_FromConst("f");
TextAtlas_Make(&screen->IdAtlas, &chars, &screen->TextFont, &prefix);
- Int32 size = Game_Height / ATLAS2D_ROWS_COUNT;
+ Int32 size = Game_Height / ATLAS2D_TILES_PER_ROW;
size = (size / 8) * 8;
Math_Clamp(size, 8, 40);
- screen->XOffset = Gui_CalcPos(ANCHOR_CENTRE, 0, size * ATLAS2D_TILES_PER_ROW, Game_Width);
- screen->YOffset = Gui_CalcPos(ANCHOR_CENTRE, 0, size * ATLAS2D_ROWS_COUNT, Game_Height);
+ screen->XOffset = Gui_CalcPos(ANCHOR_CENTRE, 0, size * ATLAS2D_ROWS_COUNT, Game_Width);
+ screen->YOffset = Gui_CalcPos(ANCHOR_CENTRE, 0, size * ATLAS2D_TILES_PER_ROW, Game_Height);
screen->TileSize = size;
String title = String_FromConst("Texture ID reference sheet");
diff --git a/src/Client/PacketHandlers.c b/src/Client/PacketHandlers.c
index 7ceade667..b507e2198 100644
--- a/src/Client/PacketHandlers.c
+++ b/src/Client/PacketHandlers.c
@@ -1145,9 +1145,7 @@ static void CPE_SetInventoryOrder(struct Stream* stream) {
BlockID order = Handlers_ReadBlock(stream);
Inventory_Remove(block);
- if (order != 255 && order != 0) {
- Inventory_Map[order - 1] = block;
- }
+ if (order) { Inventory_Map[order - 1] = block; }
}
static void CPE_Reset(void) {