aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/JukeboxTile.cpp
diff options
context:
space:
mode:
authordaoge <3523206925@qq.com>2026-03-03 03:04:10 +0800
committerGitHub <noreply@github.com>2026-03-03 03:04:10 +0800
commitb3feddfef372618c8a9d7a0abcaf18cfad866c18 (patch)
tree267761c3bb39241ba5c347bfbe2254d06686e287 /Minecraft.World/JukeboxTile.cpp
parent84c31a2331f7a0ec85b9d438992e244f60e5020f (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/JukeboxTile.cpp')
-rw-r--r--Minecraft.World/JukeboxTile.cpp167
1 files changed, 167 insertions, 0 deletions
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<ItemInstance>( 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<TileEntity> JukeboxTile::Entity::clone()
+{
+ shared_ptr<JukeboxTile::Entity> result = shared_ptr<JukeboxTile::Entity>( new JukeboxTile::Entity() );
+ TileEntity::clone(result);
+
+ result->record = record;
+
+ return result;
+}
+
+shared_ptr<ItemInstance> JukeboxTile::Entity::getRecord()
+{
+ return record;
+}
+
+void JukeboxTile::Entity::setRecord(shared_ptr<ItemInstance> 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> 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> 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<ItemInstance> record)
+{
+ if (level->isClientSide) return;
+
+ shared_ptr<JukeboxTile::Entity> rte = dynamic_pointer_cast<JukeboxTile::Entity>( 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<JukeboxTile::Entity> rte = dynamic_pointer_cast<JukeboxTile::Entity>( level->getTileEntity(x, y, z) );
+ if( rte == NULL ) return;
+
+ shared_ptr<ItemInstance> 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> itemInstance = oldRecord->copy();
+
+ shared_ptr<ItemEntity> item = shared_ptr<ItemEntity>( 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<TileEntity> JukeboxTile::newTileEntity(Level *level)
+{
+ return shared_ptr<JukeboxTile::Entity>( 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<ItemInstance> record = dynamic_pointer_cast<JukeboxTile::Entity>( 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