the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "..\..\..\Minecraft.World\StringHelpers.h"
3#include "XboxStructureActionPlaceSpawner.h"
4#include "..\..\..\Minecraft.World\net.minecraft.world.level.levelgen.structure.h"
5#include "..\..\..\Minecraft.World\net.minecraft.world.level.h"
6#include "..\..\..\Minecraft.World\net.minecraft.world.level.tile.entity.h"
7
8XboxStructureActionPlaceSpawner::XboxStructureActionPlaceSpawner()
9{
10 m_tile = Tile::mobSpawner_Id;
11 m_entityId = L"Pig";
12}
13
14XboxStructureActionPlaceSpawner::~XboxStructureActionPlaceSpawner()
15{
16}
17
18void XboxStructureActionPlaceSpawner::writeAttributes(DataOutputStream *dos, UINT numAttrs)
19{
20 XboxStructureActionPlaceBlock::writeAttributes(dos, numAttrs + 1);
21
22 ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_entity);
23 dos->writeUTF(m_entityId);
24}
25
26void XboxStructureActionPlaceSpawner::addAttribute(const wstring &attributeName, const wstring &attributeValue)
27{
28 if(attributeName.compare(L"entity") == 0)
29 {
30 m_entityId = attributeValue;
31#ifndef _CONTENT_PACKAGE
32 wprintf(L"XboxStructureActionPlaceSpawner: Adding parameter entity=%ls\n",m_entityId.c_str());
33#endif
34 }
35 else
36 {
37 XboxStructureActionPlaceBlock::addAttribute(attributeName, attributeValue);
38 }
39}
40
41bool XboxStructureActionPlaceSpawner::placeSpawnerInLevel(StructurePiece *structure, Level *level, BoundingBox *chunkBB)
42{
43 int worldX = structure->getWorldX( m_x, m_z );
44 int worldY = structure->getWorldY( m_y );
45 int worldZ = structure->getWorldZ( m_x, m_z );
46
47 if ( chunkBB->isInside( worldX, worldY, worldZ ) )
48 {
49 if ( level->getTileEntity( worldX, worldY, worldZ ) != NULL )
50 {
51 // Remove the current tile entity
52 level->removeTileEntity( worldX, worldY, worldZ );
53 level->setTileAndData( worldX, worldY, worldZ, 0, 0, Tile::UPDATE_ALL );
54 }
55
56 level->setTileAndData( worldX, worldY, worldZ, m_tile, 0, Tile::UPDATE_ALL );
57 shared_ptr<MobSpawnerTileEntity> entity = dynamic_pointer_cast<MobSpawnerTileEntity>(level->getTileEntity( worldX, worldY, worldZ ));
58
59#ifndef _CONTENT_PACKAGE
60 wprintf(L"XboxStructureActionPlaceSpawner - placing a %ls spawner at (%d,%d,%d)\n", m_entityId.c_str(), worldX, worldY, worldZ);
61#endif
62 if( entity != NULL )
63 {
64 entity->setEntityId(m_entityId);
65 }
66 return true;
67 }
68 return false;
69}