From b3feddfef372618c8a9d7a0abcaf18cfad866c18 Mon Sep 17 00:00:00 2001 From: daoge <3523206925@qq.com> Date: Tue, 3 Mar 2026 03:04:10 +0800 Subject: 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 --- Minecraft.World/JukeboxTile.cpp | 167 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 Minecraft.World/JukeboxTile.cpp (limited to 'Minecraft.World/JukeboxTile.cpp') diff --git a/Minecraft.World/JukeboxTile.cpp b/Minecraft.World/JukeboxTile.cpp new file mode 100644 index 00000000..cf53a751 --- /dev/null +++ b/Minecraft.World/JukeboxTile.cpp @@ -0,0 +1,167 @@ +#include "stdafx.h" +#include "net.minecraft.world.level.redstone.h" +#include "net.minecraft.world.entity.item.h" +#include "net.minecraft.world.item.h" +#include "net.minecraft.world.level.h" +#include "net.minecraft.h" +#include "net.minecraft.world.h" +#include "JukeboxTile.h" +#include "LevelEvent.h" + +JukeboxTile::Entity::Entity() : TileEntity() +{ + record = nullptr; +} + +void JukeboxTile::Entity::load(CompoundTag *tag) +{ + TileEntity::load(tag); + + if (tag->contains(L"RecordItem")) + { + setRecord(ItemInstance::fromTag(tag->getCompound(L"RecordItem"))); + } + else if (tag->getInt(L"Record") > 0) + { + setRecord(shared_ptr( new ItemInstance(tag->getInt(L"Record"), 1, 0))); + } +} + +void JukeboxTile::Entity::save(CompoundTag *tag) +{ + TileEntity::save(tag); + + if (getRecord() != NULL) + { + tag->putCompound(L"RecordItem", getRecord()->save(new CompoundTag())); + + tag->putInt(L"Record", getRecord()->id); + } +} + +// 4J Added +shared_ptr JukeboxTile::Entity::clone() +{ + shared_ptr result = shared_ptr( new JukeboxTile::Entity() ); + TileEntity::clone(result); + + result->record = record; + + return result; +} + +shared_ptr JukeboxTile::Entity::getRecord() +{ + return record; +} + +void JukeboxTile::Entity::setRecord(shared_ptr record) +{ + this->record = record; + setChanged(); +} + +JukeboxTile::JukeboxTile(int id) : BaseEntityTile(id, Material::wood) +{ + iconTop = NULL; +} + +Icon *JukeboxTile::getTexture(int face, int data) +{ + if (face == Facing::UP) + { + return iconTop; + } + return icon; +} + +// 4J-PB - Adding a TestUse for tooltip display +bool JukeboxTile::TestUse(Level *level, int x, int y, int z, shared_ptr player) +{ + // if the jukebox is empty, return true + if (level->getData(x, y, z) == 0) return false; + return true; +} + +bool JukeboxTile::use(Level *level, int x, int y, int z, shared_ptr player, int clickedFace, float clickX, float clickY, float clickZ, bool soundOnly/*=false*/) // 4J added soundOnly param +{ + if (soundOnly) return false; + if (level->getData(x, y, z) == 0) return false; + dropRecording(level, x, y, z); + return true; +} + +void JukeboxTile::setRecord(Level *level, int x, int y, int z, shared_ptr record) +{ + if (level->isClientSide) return; + + shared_ptr rte = dynamic_pointer_cast( level->getTileEntity(x, y, z) ); + rte->setRecord(record->copy()); + rte->setChanged(); + + level->setData(x, y, z, 1, Tile::UPDATE_CLIENTS); +} + +void JukeboxTile::dropRecording(Level *level, int x, int y, int z) +{ + if (level->isClientSide) return; + + shared_ptr rte = dynamic_pointer_cast( level->getTileEntity(x, y, z) ); + if( rte == NULL ) return; + + shared_ptr oldRecord = rte->getRecord(); + if (oldRecord == NULL) return; + + + level->levelEvent(LevelEvent::SOUND_PLAY_RECORDING, x, y, z, 0); + // 4J-PB- the level event will play the music + //level->playStreamingMusic(L"", x, y, z); + rte->setRecord(nullptr); + rte->setChanged(); + level->setData(x, y, z, 0, Tile::UPDATE_CLIENTS); + + float s = 0.7f; + double xo = level->random->nextFloat() * s + (1 - s) * 0.5; + double yo = level->random->nextFloat() * s + (1 - s) * 0.2 + 0.6; + double zo = level->random->nextFloat() * s + (1 - s) * 0.5; + + shared_ptr itemInstance = oldRecord->copy(); + + shared_ptr item = shared_ptr( new ItemEntity(level, x + xo, y + yo, z + zo, itemInstance ) ); + item->throwTime = 10; + level->addEntity(item); +} + +void JukeboxTile::onRemove(Level *level, int x, int y, int z, int id, int data) +{ + dropRecording(level, x, y, z); + Tile::onRemove(level, x, y, z, id, data); +} + +void JukeboxTile::spawnResources(Level *level, int x, int y, int z, int data, float odds, int playerBonus) +{ + if (level->isClientSide) return; + Tile::spawnResources(level, x, y, z, data, odds, 0); +} + +shared_ptr JukeboxTile::newTileEntity(Level *level) +{ + return shared_ptr( new JukeboxTile::Entity() ); +} + +void JukeboxTile::registerIcons(IconRegister *iconRegister) +{ + icon = iconRegister->registerIcon(getIconName() + L"_side"); + iconTop = iconRegister->registerIcon(getIconName() + L"_top"); +} + +bool JukeboxTile::hasAnalogOutputSignal() +{ + return true; +} + +int JukeboxTile::getAnalogOutputSignal(Level *level, int x, int y, int z, int dir) +{ + shared_ptr record = dynamic_pointer_cast( level->getTileEntity(x, y, z))->getRecord(); + return record == NULL ? Redstone::SIGNAL_NONE : record->id + 1 - Item::record_01_Id; +} \ No newline at end of file -- cgit v1.2.3