2

I have installed a Minecraft Bukkit Plugin which saves inventories of players using MySQL.

The table looks like this:

My problem is that I want to display the items on the website, but there are these "BLOB" formats. I think, they should be the block IDs (I only found methods to convert "BLOB" into img).

The "Blob's" have following format:

EDIT

When I try to display it on the website with this code:

$conn = new mysqli("$host", "$user", "$pass", "auction");
$sql = "SELECT content FROM inventory";
$result = $conn->query($sql);

while($row = $result->fetch_assoc()) {
    echo base64_encode($row["content"]);
}

The solution looks like the following string:

H4sIAAAAAAAAAIuuViqpLEhVslJy9vcNcAwOVqrVgQs5egaNckc2NxYAYPN3OyECAAA=

3
  • 1
    Take a look at this phppot.com/php/mysql-blob-using-php Commented Dec 25, 2014 at 12:01
  • 1
    doesnt works for me :( Commented Dec 25, 2014 at 13:08
  • You need to know the mime type, since BLOB can be anything. Commented Dec 25, 2014 at 16:50

2 Answers 2

0

I recall that blocks had id's with numbers between 0 and 255. If they haven't extended it that would mean that every byte represents a block.

You will need to read the data, byte by byte and convert every byte to a number, representing the block id. Once you have that you will only have to display the appropriate picture, based on that id.

In the event where they actually extended the id system to two bytes, you will have to convert every two byte into a number between 0 and 65535.

Update:

This Question describes how to read binary data with PHP. After you converted it into a byte array you will only have to typecast every byte to an int.

Sign up to request clarification or add additional context in comments.

Comments

0

I know now, whats going on with this strange string. Minecraft uses "NBT Decoding". Does anyone here know, how i can decode / encode with nbt ? greets

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.