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 "net.minecraft.network.packet.h"
3#include "net.minecraft.world.level.h"
4#include "net.minecraft.commands.h"
5#include "..\Minecraft.Client\MinecraftServer.h"
6#include "CommandBlockEntity.h"
7
8CommandBlockEntity::CommandBlockEntity()
9{
10 successCount = 0;
11 command = L"";
12 name = L"@";
13}
14
15void CommandBlockEntity::setCommand(const wstring &command)
16{
17 this->command = command;
18 setChanged();
19}
20
21wstring CommandBlockEntity::getCommand()
22{
23 return command;
24}
25
26int CommandBlockEntity::performCommand(Level *level)
27{
28#if 0
29 if (level->isClientSide)
30 {
31 return 0;
32 }
33
34 MinecraftServer *instance = MinecraftServer::getInstance();
35 if (instance != NULL && instance->isCommandBlockEnabled())
36 {
37 CommandDispatcher *commandDispatcher = instance->getCommandDispatcher();
38 return commandDispatcher->performCommand(dynamic_pointer_cast<CommandSender>(shared_from_this()), command, byteArray() );
39 }
40 return 0;
41#else
42 // 4J-JEV: Cannot decide what to do with the command field.
43 assert(false);
44 return 0;
45#endif
46}
47
48wstring CommandBlockEntity::getName()
49{
50 return name;
51}
52
53void CommandBlockEntity::setName(const wstring &name)
54{
55 this->name = name;
56}
57
58void CommandBlockEntity::sendMessage(const wstring& message, ChatPacket::EChatPacketMessage type, int customData , const wstring& additionalMessage)
59{
60}
61
62bool CommandBlockEntity::hasPermission(EGameCommand command)
63{
64 return false;
65}
66
67void CommandBlockEntity::save(CompoundTag *tag)
68{
69 TileEntity::save(tag);
70 tag->putString(L"Command", command);
71 tag->putInt(L"SuccessCount", successCount);
72 tag->putString(L"CustomName", name);
73}
74
75void CommandBlockEntity::load(CompoundTag *tag)
76{
77 TileEntity::load(tag);
78 command = tag->getString(L"Command");
79 successCount = tag->getInt(L"SuccessCount");
80 if (tag->contains(L"CustomName")) name = tag->getString(L"CustomName");
81}
82
83Pos *CommandBlockEntity::getCommandSenderWorldPosition()
84{
85 return new Pos(x, y, z);
86}
87
88Level *CommandBlockEntity::getCommandSenderWorld()
89{
90 return getLevel();
91}
92
93shared_ptr<Packet> CommandBlockEntity::getUpdatePacket()
94{
95 CompoundTag *tag = new CompoundTag();
96 save(tag);
97 return shared_ptr<TileEntityDataPacket>( new TileEntityDataPacket(x, y, z, TileEntityDataPacket::TYPE_ADV_COMMAND, tag) );
98}
99
100int CommandBlockEntity::getSuccessCount()
101{
102 return successCount;
103}
104
105void CommandBlockEntity::setSuccessCount(int successCount)
106{
107 this->successCount = successCount;
108}
109
110// 4J Added
111shared_ptr<TileEntity> CommandBlockEntity::clone()
112{
113 shared_ptr<CommandBlockEntity> result = shared_ptr<CommandBlockEntity>( new CommandBlockEntity() );
114 TileEntity::clone(result);
115
116 result->successCount = successCount;
117 result->command = command;
118 result->name = name;
119
120 return result;
121}