pmmp / PocketMine-MP

A server software for Minecraft: Bedrock Edition in PHP
https://pmmp.io
GNU Lesser General Public License v3.0
3.26k stars 1.55k forks source link

Beds (without tiles) don't appear #997

Closed moskadev closed 2 years ago

moskadev commented 7 years ago

Issue description

Not sure if this is an issue but anyway, I will see. I'm trying to update my server to PMMP 1.1.

When I was testing my game and others things on my server, I saw all beds invisible. (These beds where placed on MC:PE 1.0 - when there weren't beds' tiles.

I cancelled BlockBreakEvent and tried to break these beds to see what happens - Beds reappeared but have random color.

To fix that, I tried to do this code :

$pointA = new Vector3(x, y, z);
$pointB = new Vector3(x, y, z);
$color = mt_rand(0, 15);

for($z = $pointA->z; $z <= $pointB->z; ++$z){
    for($y = $pointA->y; $y <= $pointB->y; ++$y){
        for($x = $pointA->x; $x <= $pointB->x; ++$x){
            $block = $levelArena->getBlock(new Vector3($x, $y, $z));
            if($block->getId() == Block::BED_BLOCK){
                echo "Placed bed" . PHP_EOL; //echo are sent 2 times, so bed's blocks are there
                $levelArena->setBlock(new Vector3($x, $y, $z), Block::get(Block::BED_BLOCK, $block->getDamage())); //Tried without setBlock() too
                $nbt = new CompoundTag("", [
                    new StringTag("id", Tile::BED),
                    new ByteTag("color", $color & 0x0f), //Tried without "& 0x0f" too
                    new IntTag("x", $block->x),
                    new IntTag("y", $block->y),
                    new IntTag("z", $block->z),
                ]);

                Tile::createTile(Tile::BED, $levelArena, $nbt);
            }
        }
    }
}

I have done exactly the same steps I mentioned above. Beds still invisible but tiles & blocks are there now, and we need again to break it to see the bed again. The colors are no longer random and and are correctly set.

[[So, this code doesn't fix the problem but just the color.]] EDIT : This code fixes beds but I need to unload & load chunk of where is the bed.

Thanks for reading, and sorry for my bad english.

Steps to reproduce the issue

  1. Use a old world who wasn't generated or used on MC:PE 1.1.
  2. Place some bed blocks.
  3. Try this world on MC:PE 1.1.
  4. Beds are invisible.

OS and versions

I'm actually using the api3/blocks branch, not the master. (I'll post more informations (Jenkins, etc..) there when I'll come back to my home.)

Crashdump, backtrace or other files

dktapps commented 7 years ago

Newly placed beds on api3/blocks will not have an issue, but PocketMine doesn't scan for existing old beds without tiles due to performance considerations and no suitable method currently in place to do this.

moskadev commented 7 years ago

That's really perturbing. :/

inxomnyaa commented 7 years ago

Create a plugin cycling through all blocks when a chunk is loaded as example, then place a red tile at all beds. I think i'll create a plugin for that soon, fixing all tiles that are missing. https://github.com/thebigsmileXD/TileFixer will be the future repo. And yes, indeed, this is pretty memory/cpu consuming.

0x15f commented 7 years ago

Why do we call them "tiles"? They are block entities.

Sandertv commented 7 years ago

Because blame shoghi. Changing that would break a huge amount of plugins. Perhaps it would be a good idea though as it's still 3.0.0-ALPHA... It would require lots of changes in PMMP too.

dktapps commented 7 years ago

"Block entity" is also somewhat misleading... they aren't entities at all, merely blocks with some extra data/behaviour. For backwards-compatibility's sake, we stick with the old Tile name (they used to be called tiles in vanilla PC a few years ago).

SOF3 commented 7 years ago

We already have three distinct nouns "Block", "Entity" and "Tile" referring to entirely different things. Why try to increase the confusion?

inxomnyaa commented 7 years ago

Added a chunk fixing command to tilefixer, fixing the tiles in the current chunk. This should help you for now.

moskadev commented 7 years ago

^^^^ EDIT ^^^^ The code on the description of this issue is working, but to see the bed, you need to unload & load the chunk.

jojoe77777 commented 7 years ago

@SuperMaXAleX forgot to spawnToAll()? ;)

moskadev commented 7 years ago

@jojoe77777 eh ? The player ?

JackNoordhuis commented 7 years ago

@SuperMaXAleX He means changing Tile::createTile(Tile::BED, $levelArena, $nbt); to

$tile = Tile::createTile(Tile::BED, $levelArena, $nbt);
$tile->spawnToAll();
inxomnyaa commented 7 years ago

@jojoe77777 He did indeed.

I know that furnaces, brewing stands and chests appear when you click on them, because the code rechecks if there is a chest and if not, it spawns it.

in my oppinion getSpawnCompound should be statically accessible, so you can pass it as default nbt tag on createTile(). Looks like the function is not used otherwise..

example: Tile::createTile(Tile::BED, $level, Bed::getSpawnCompound());

moskadev commented 7 years ago

@JackNoordhuis Just tried this code but nothing changes

inxomnyaa commented 7 years ago

Note: Extends #880

dktapps commented 5 years ago

The general issue of missing and invalid tiles for blocks is planned for resolution in 4.0.

inxomnyaa commented 5 years ago

Right now beds without or with invalid tiles crash the client when clicked

dktapps commented 3 years ago

This should be cheap to fix with paletted chunks. (Previously the obstacle to implementing this has been performance, but with palettes it's very cheap to check if a chunk needs to be scanned for tile fixing.)

dktapps commented 2 years ago

Since some version in the past (I'm not sure exactly when) the client now renders beds without tiles as a default red bed (instead of being invisible), so no further action is needed on this.

inxomnyaa commented 2 years ago

The general issue of missing and invalid tiles for blocks is planned for resolution in 4.0.

This still persists, should it be moved into a new issue? Plugins might expect a tile when clicking a bed - or similar, causing unexpected crashes.

dktapps commented 2 years ago

In PM4 it's not expected that plugins will directly interact with tiles anyway. Most APIs are provided directly by the Block now, so I don't consider that an issue.

The general issue of missing tiles has been removed from PM4 milestone due to low priority and high time cost.