diff options
| author | daoge <3523206925@qq.com> | 2026-03-03 03:04:10 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-03 03:04:10 +0800 |
| commit | b3feddfef372618c8a9d7a0abcaf18cfad866c18 (patch) | |
| tree | 267761c3bb39241ba5c347bfbe2254d06686e287 /Minecraft.World/DyePowderItem.cpp | |
| parent | 84c31a2331f7a0ec85b9d438992e244f60e5020f (diff) | |
feat: TU19 (Dec 2014) Features & Content (#155)
* try to resolve merge conflict
* feat: TU19 (Dec 2014) Features & Content (#32)
* December 2014 files
* Working release build
* Fix compilation issues
* Add sound to Windows64Media
* Add DLC content and force Tutorial DLC
* Revert "Add DLC content and force Tutorial DLC"
This reverts commit 97a43994725008e35fceb984d5549df9c8cea470.
* Disable broken light packing
* Disable breakpoint during DLC texture map load
Allows DLC loading but the DLC textures are still broken
* Fix post build not working
* ...
* fix vs2022 build
* fix cmake build
---------
Co-authored-by: Loki <lokirautio@gmail.com>
Diffstat (limited to 'Minecraft.World/DyePowderItem.cpp')
| -rw-r--r-- | Minecraft.World/DyePowderItem.cpp | 277 |
1 files changed, 154 insertions, 123 deletions
diff --git a/Minecraft.World/DyePowderItem.cpp b/Minecraft.World/DyePowderItem.cpp index a05b8354..b4ab86fa 100644 --- a/Minecraft.World/DyePowderItem.cpp +++ b/Minecraft.World/DyePowderItem.cpp @@ -62,8 +62,8 @@ const unsigned int DyePowderItem::COLOR_USE_DESCS[] = }; const wstring DyePowderItem::COLOR_TEXTURES[] = -{ L"dyePowder_black", L"dyePowder_red", L"dyePowder_green", L"dyePowder_brown", L"dyePowder_blue", L"dyePowder_purple", L"dyePowder_cyan", L"dyePowder_silver", L"dyePowder_gray", L"dyePowder_pink", -L"dyePowder_lime", L"dyePowder_yellow", L"dyePowder_lightBlue", L"dyePowder_magenta", L"dyePowder_orange", L"dyePowder_white"}; +{ L"black", L"red", L"green", L"brown", L"blue", L"purple", L"cyan", L"silver", L"gray", L"pink", +L"lime", L"yellow", L"light_blue", L"magenta", L"orange", L"white"}; const int DyePowderItem::COLOR_RGB[] = { @@ -73,8 +73,8 @@ const int DyePowderItem::COLOR_RGB[] = 0x51301a, 0x253192, 0x7b2fbe, - 0xababab, 0x287697, + 0xababab, 0x434343, 0xd88198, 0x41cd34, @@ -121,33 +121,42 @@ unsigned int DyePowderItem::getUseDescriptionId(shared_ptr<ItemInstance> itemIns bool DyePowderItem::useOn(shared_ptr<ItemInstance> itemInstance, shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly) { - if (!player->mayBuild(x, y, z)) return false; + if (!player->mayUseItemAt(x, y, z, face, itemInstance)) return false; // 4J-PB - Adding a test only version to allow tooltips to be displayed if (itemInstance->getAuxValue() == WHITE) { // bone meal is a fertilizer, so instantly grow trees and stuff - int tile = level->getTile(x, y, z); - if (tile == Tile::sapling_Id) + if (growCrop(itemInstance, level, x, y, z, bTestUseOnOnly)) { - if(!bTestUseOnOnly) - { - if (!level->isClientSide) - { - ((Sapling *) Tile::sapling)->growTree(level, x, y, z, level->random); - itemInstance->count--; - } - } + if (!level->isClientSide) level->levelEvent(LevelEvent::PARTICLES_PLANT_GROWTH, x, y, z, 0); return true; } - else if (tile == Tile::mushroom1_Id || tile == Tile::mushroom2_Id) + } + else if (itemInstance->getAuxValue() == BROWN) + { + // plant cocoa + + int tile = level->getTile(x, y, z); + int data = level->getData(x, y, z); + + if (tile == Tile::treeTrunk_Id && TreeTile::getWoodType(data) == TreeTile::JUNGLE_TRUNK) { + if (face == 0) return false; + if (face == 1) return false; + if (face == 2) z--; + if (face == 3) z++; + if (face == 4) x--; + if (face == 5) x++; + if(!bTestUseOnOnly) { - if (!level->isClientSide) + if (level->isEmptyTile(x, y, z)) { - if (((Mushroom *) Tile::tiles[tile])->growTree(level, x, y, z, level->random)) + int cocoaData = Tile::tiles[Tile::cocoa_Id]->getPlacedOnFaceDataValue(level, x, y, z, face, clickX, clickY, clickZ, 0); + level->setTileAndData(x, y, z, Tile::cocoa_Id, cocoaData, Tile::UPDATE_CLIENTS); + if (!player->abilities.instabuild) { itemInstance->count--; } @@ -155,147 +164,169 @@ bool DyePowderItem::useOn(shared_ptr<ItemInstance> itemInstance, shared_ptr<Play } return true; } - else if (tile == Tile::melonStem_Id || tile == Tile::pumpkinStem_Id) - { - if (level->getData(x, y, z) == 7) return false; - if(!bTestUseOnOnly) + } + return false; +} + +bool DyePowderItem::growCrop(shared_ptr<ItemInstance> itemInstance, Level *level, int x, int y, int z, bool bTestUseOnOnly) +{ + int tile = level->getTile(x, y, z); + if (tile == Tile::sapling_Id) + { + if(!bTestUseOnOnly) + { + if (!level->isClientSide) { - if (!level->isClientSide) - { - ((StemTile *) Tile::tiles[tile])->growCropsToMax(level, x, y, z); - itemInstance->count--; - } + if (level->random->nextFloat() < 0.45) ((Sapling *) Tile::sapling)->advanceTree(level, x, y, z, level->random); + itemInstance->count--; } - return true; - } - else if (tile == Tile::carrots_Id || tile == Tile::potatoes_Id) + } + return true; + } + else if (tile == Tile::mushroom_brown_Id || tile == Tile::mushroom_red_Id) + { + if(!bTestUseOnOnly) { - if (level->getData(x, y, z) == 7) return false; - if(!bTestUseOnOnly) + if (!level->isClientSide) { - if (!level->isClientSide) - { - ((CropTile *) Tile::tiles[tile])->growCropsToMax(level, x, y, z); - itemInstance->count--; - } + if (level->random->nextFloat() < 0.4) ((Mushroom *) Tile::tiles[tile])->growTree(level, x, y, z, level->random); + itemInstance->count--; } - return true; } - else if (tile == Tile::crops_Id) + return true; + } + else if (tile == Tile::melonStem_Id || tile == Tile::pumpkinStem_Id) + { + if (level->getData(x, y, z) == 7) return false; + if(!bTestUseOnOnly) { - if (level->getData(x, y, z) == 7) return false; - if(!bTestUseOnOnly) - { - if (!level->isClientSide) - { - ((CropTile *) Tile::crops)->growCropsToMax(level, x, y, z); - itemInstance->count--; - } + if (!level->isClientSide) + { + ((StemTile *) Tile::tiles[tile])->growCrops(level, x, y, z); + itemInstance->count--; } - return true; } - else if (tile == Tile::cocoa_Id) + return true; + } + else if (tile == Tile::carrots_Id || tile == Tile::potatoes_Id) + { + if (level->getData(x, y, z) == 7) return false; + if(!bTestUseOnOnly) { - if(!bTestUseOnOnly) + if (!level->isClientSide) { - if (!level->isClientSide) - { - level->setData(x, y, z, (2 << 2) | DirectionalTile::getDirection(level->getData(x, y, z))); - itemInstance->count--; - } + ((CropTile *) Tile::tiles[tile])->growCrops(level, x, y, z); + itemInstance->count--; } - return true; - } - else if (tile == Tile::grass_Id) + } + return true; + } + else if (tile == Tile::wheat_Id) + { + if (level->getData(x, y, z) == 7) return false; + if(!bTestUseOnOnly) + { + if (!level->isClientSide) + { + ((CropTile *) Tile::tiles[tile])->growCrops(level, x, y, z); + itemInstance->count--; + } + } + return true; + } + else if (tile == Tile::cocoa_Id) + { + if(!bTestUseOnOnly) { - if(!bTestUseOnOnly) - { - if (!level->isClientSide) - { - itemInstance->count--; + int data = level->getData(x, y, z); + int direction = DirectionalTile::getDirection(data); + int age = CocoaTile::getAge(data); + if (age >= 2) return false; + if (!level->isClientSide) + { + age++; + level->setData(x, y, z, (age << 2) | direction, Tile::UPDATE_CLIENTS); + itemInstance->count--; + } + } + return true; + } + else if (tile == Tile::grass_Id) + { + if(!bTestUseOnOnly) + { + if (!level->isClientSide) + { + itemInstance->count--; - for (int j = 0; j < 128; j++) + for (int j = 0; j < 128; j++) + { + int xx = x; + int yy = y + 1; + int zz = z; + for (int i = 0; i < j / 16; i++) { - int xx = x; - int yy = y + 1; - int zz = z; - for (int i = 0; i < j / 16; i++) + xx += random->nextInt(3) - 1; + yy += (random->nextInt(3) - 1) * random->nextInt(3) / 2; + zz += random->nextInt(3) - 1; + if (level->getTile(xx, yy - 1, zz) != Tile::grass_Id || level->isSolidBlockingTile(xx, yy, zz)) { - xx += random->nextInt(3) - 1; - yy += (random->nextInt(3) - 1) * random->nextInt(3) / 2; - zz += random->nextInt(3) - 1; - if (level->getTile(xx, yy - 1, zz) != Tile::grass_Id || level->isSolidBlockingTile(xx, yy, zz)) - { - goto mainloop; - } + goto mainloop; } + } - if (level->getTile(xx, yy, zz) == 0) + if (level->getTile(xx, yy, zz) == 0) + { + if (random->nextInt(10) != 0) + { + if (Tile::tallgrass->canSurvive(level, xx, yy, zz)) level->setTileAndData(xx, yy, zz, Tile::tallgrass_Id, TallGrass::TALL_GRASS, Tile::UPDATE_ALL); + } + else if (random->nextInt(3) != 0) { - if (random->nextInt(10) != 0) - { - if (Tile::tallgrass->canSurvive(level, xx, yy, zz)) level->setTileAndData(xx, yy, zz, Tile::tallgrass_Id, TallGrass::TALL_GRASS); - } - else if (random->nextInt(3) != 0) - { - if (Tile::flower->canSurvive(level, xx, yy, zz)) level->setTile(xx, yy, zz, Tile::flower_Id); - } - else - { - if (Tile::rose->canSurvive(level, xx, yy, zz)) level->setTile(xx, yy, zz, Tile::rose_Id); - } + if (Tile::flower->canSurvive(level, xx, yy, zz)) level->setTileAndUpdate(xx, yy, zz, Tile::flower_Id); + } + else + { + if (Tile::rose->canSurvive(level, xx, yy, zz)) level->setTileAndUpdate(xx, yy, zz, Tile::rose_Id); } + } - // 4J - Stops infinite loops. + // 4J - Stops infinite loops. mainloop: continue; - } } } - - return true; } + + return true; } - else if (itemInstance->getAuxValue() == BROWN) - { - // plant cocoa + return false; +} - int tile = level->getTile(x, y, z); - int data = level->getData(x, y, z); +void DyePowderItem::addGrowthParticles(Level *level, int x, int y, int z, int count) +{ + int id = level->getTile(x, y, z); + if (count == 0) count = 15; + Tile *tile = id > 0 && id < Tile::TILE_NUM_COUNT ? Tile::tiles[id] : NULL; - if (tile == Tile::treeTrunk_Id && TreeTile::getWoodType(data) == TreeTile::JUNGLE_TRUNK) - { - if (face == 0) return false; - if (face == 1) return false; - if (face == 2) z--; - if (face == 3) z++; - if (face == 4) x--; - if (face == 5) x++; + if (tile == NULL) return; + tile->updateShape(level, x, y, z); - if(!bTestUseOnOnly) - { - if (level->isEmptyTile(x, y, z)) - { - int cocoaData = Tile::tiles[Tile::cocoa_Id]->getPlacedOnFaceDataValue(level, x, y, z, face, clickX, clickY, clickZ, 0); - level->setTileAndData(x, y, z, Tile::cocoa_Id, cocoaData); - if (!player->abilities.instabuild) - { - itemInstance->count--; - } - } - } - return true; - } - } - return false; + for (int i = 0; i < count; i++) + { + double xa = level->random->nextGaussian() * 0.02; + double ya = level->random->nextGaussian() * 0.02; + double za = level->random->nextGaussian() * 0.02; + level->addParticle(eParticleType_happyVillager, x + level->random->nextFloat(), y + level->random->nextFloat() * tile->getShapeY1(), z + level->random->nextFloat(), xa, ya, za); + } } -bool DyePowderItem::interactEnemy(shared_ptr<ItemInstance> itemInstance, shared_ptr<Mob> mob) +bool DyePowderItem::interactEnemy(shared_ptr<ItemInstance> itemInstance, shared_ptr<Player> player, shared_ptr<LivingEntity> mob) { if (dynamic_pointer_cast<Sheep>( mob ) != NULL) { shared_ptr<Sheep> sheep = dynamic_pointer_cast<Sheep>(mob); // convert to tile-based color value (0 is white instead of black) - int newColor = ClothTile::getTileDataForItemAuxValue(itemInstance->getAuxValue()); + int newColor = ColoredTile::getTileDataForItemAuxValue(itemInstance->getAuxValue()); if (!sheep->isSheared() && sheep->getColor() != newColor) { sheep->setColor(newColor); @@ -312,6 +343,6 @@ void DyePowderItem::registerIcons(IconRegister *iconRegister) for (int i = 0; i < DYE_POWDER_ITEM_TEXTURE_COUNT; i++) { - icons[i] = iconRegister->registerIcon(COLOR_TEXTURES[i]); + icons[i] = iconRegister->registerIcon(getIconName() + L"_" + COLOR_TEXTURES[i]); } }
\ No newline at end of file |
