diff options
Diffstat (limited to 'Minecraft.World/FallingTile.cpp')
| -rw-r--r-- | Minecraft.World/FallingTile.cpp | 57 |
1 files changed, 49 insertions, 8 deletions
diff --git a/Minecraft.World/FallingTile.cpp b/Minecraft.World/FallingTile.cpp index 254631ff..28248014 100644 --- a/Minecraft.World/FallingTile.cpp +++ b/Minecraft.World/FallingTile.cpp @@ -24,6 +24,7 @@ void FallingTile::_init() hurtEntities = false; fallDamageMax = 40; fallDamageAmount = 2; + tileData = NULL; // 4J Added so that client-side falling tiles can fall through blocks // This fixes a bug on the host where the tile update from the server comes in before the client-side falling tile @@ -62,6 +63,11 @@ FallingTile::FallingTile(Level *level, double x, double y, double z, int tile, i zOld = z; } +FallingTile::~FallingTile() +{ + delete tileData; +} + bool FallingTile::makeStepSound() { return false; @@ -105,7 +111,7 @@ void FallingTile::tick() { if (level->getTile(xt, yt, zt) == tile) { - level->setTile(xt, yt, zt, 0); + level->removeTile(xt, yt, zt); } else { @@ -120,17 +126,36 @@ void FallingTile::tick() zd *= 0.7f; yd *= -0.5f; - // if (HeavyTile.isFree(level, xt, yt, zt)) { if (level->getTile(xt, yt, zt) != Tile::pistonMovingPiece_Id) { remove(); - if (!cancelDrop && level->mayPlace(tile, xt, yt, zt, true, 1, nullptr) && !HeavyTile::isFree(level, xt, yt - 1, zt) && level->setTileAndData(xt, yt, zt, tile, data)) + if (!cancelDrop && level->mayPlace(tile, xt, yt, zt, true, 1, nullptr, nullptr) && !HeavyTile::isFree(level, xt, yt - 1, zt) && level->setTileAndData(xt, yt, zt, tile, data, Tile::UPDATE_ALL)) { HeavyTile *hv = dynamic_cast<HeavyTile *>(Tile::tiles[tile]); if (hv) { hv->onLand(level, xt, yt, zt, data); } + if (tileData != NULL && Tile::tiles[tile]->isEntityTile()) + { + shared_ptr<TileEntity> tileEntity = level->getTileEntity(xt, yt, zt); + + if (tileEntity != NULL) + { + CompoundTag *swap = new CompoundTag(); + tileEntity->save(swap); + vector<Tag *> *allTags = tileData->getAllTags(); + for(AUTO_VAR(it, allTags->begin()); it != allTags->end(); ++it) + { + Tag *tag = *it; + if (tag->getName().compare(L"x") == 0 || tag->getName().compare(L"y") == 0 || tag->getName().compare(L"z") == 0) continue; + swap->put(tag->getName(), tag->copy()); + } + delete allTags; + tileEntity->load(swap); + tileEntity->setChanged(); + } + } } else { @@ -140,7 +165,7 @@ void FallingTile::tick() } else if ( (time > 20 * 5 && !level->isClientSide && (yt < 1 || yt > Level::maxBuildHeight)) || (time > 20 * 30)) { - if(dropItem) spawnAtLocation(tile, 1); + if(dropItem) spawnAtLocation( shared_ptr<ItemInstance>( new ItemInstance(tile, 1, Tile::tiles[tile]->getSpawnResourcesAuxValue(data) )), 0); remove(); } } @@ -153,14 +178,16 @@ void FallingTile::causeFallDamage(float distance) int dmg = Mth::ceil(distance - 1); if (dmg > 0) { - vector<shared_ptr<Entity> > *entities = level->getEntities(shared_from_this(), bb); + // 4J: Copy vector since it might be modified when we hurt the entities (invalidating our iterator) + vector<shared_ptr<Entity> > *entities = new vector<shared_ptr<Entity> >(*level->getEntities(shared_from_this(), bb)); DamageSource *source = tile == Tile::anvil_Id ? DamageSource::anvil : DamageSource::fallingBlock; - //for (Entity entity : entities) - for(AUTO_VAR(it,entities->begin()); it != entities->end(); ++it) + for(AUTO_VAR(it, entities->begin()); it != entities->end(); ++it) { (*it)->hurt(source, min(Mth::floor(dmg * fallDamageAmount), fallDamageMax)); } + delete entities; + if (tile == Tile::anvil_Id && random->nextFloat() < 0.05f + (dmg * 0.05)) { int damage = data >> 2; @@ -182,17 +209,26 @@ void FallingTile::causeFallDamage(float distance) void FallingTile::addAdditonalSaveData(CompoundTag *tag) { tag->putByte(L"Tile", (byte) tile); + tag->putInt(L"TileID", tile); tag->putByte(L"Data", (byte) data); tag->putByte(L"Time", (byte) time); tag->putBoolean(L"DropItem", dropItem); tag->putBoolean(L"HurtEntities", hurtEntities); tag->putFloat(L"FallHurtAmount", fallDamageAmount); tag->putInt(L"FallHurtMax", fallDamageMax); + if (tileData != NULL) tag->putCompound(L"TileEntityData", tileData); } void FallingTile::readAdditionalSaveData(CompoundTag *tag) { - tile = tag->getByte(L"Tile") & 0xff; + if (tag->contains(L"TileID")) + { + tile = tag->getInt(L"TileID"); + } + else + { + tile = tag->getByte(L"Tile") & 0xff; + } data = tag->getByte(L"Data") & 0xff; time = tag->getByte(L"Time") & 0xff; @@ -212,6 +248,11 @@ void FallingTile::readAdditionalSaveData(CompoundTag *tag) dropItem = tag->getBoolean(L"DropItem"); } + if (tag->contains(L"TileEntityData")) + { + tileData = tag->getCompound(L"TileEntityData"); + } + if (tile == 0) { tile = Tile::sand_Id; |
