CommandBlockData .java

net.minecraft.command.CommandBlockData (class, 107 lines): members: addTabCompletionOptions, getRequiredPermissionLevel, getCommandUsage, getCommandName.

net.minecraft.commandclass107 linescommonextends CommandBase3.6 KB

API Surface (5)

String getCommandName()
int getRequiredPermissionLevel()
String getCommandUsage(ICommandSender sender)
void processCommand(ICommandSender sender, String[] args)
List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)

String literals (7)

"blockdata"
"commands.blockdata.usage"
"commands.blockdata.outOfWorld"
"commands.blockdata.notValid"
"commands.blockdata.tagError"
"commands.blockdata.failed"
"commands.blockdata.success"

Full Source

CommandBlockData.java107 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.command;
2
3
import java.util.List;
4
import net.minecraft.nbt.JsonToNBT;
5
import net.minecraft.nbt.NBTException;
6
import net.minecraft.nbt.NBTTagCompound;
7
import net.minecraft.tileentity.TileEntity;
8
import net.minecraft.util.BlockPos;
9
import net.minecraft.world.World;
10
11
public class CommandBlockData extends CommandBase
12
{
13
    /**
14
     * Gets the name of the command
15
     */
16
    public String getCommandName()
17
    {
18
        return "blockdata";
19
    }
20
21
    /**
22
     * Return the required permission level for this command.
23
     */
24
    public int getRequiredPermissionLevel()
25
    {
26
        return 2;
27
    }
28
29
    /**
30
     * Gets the usage string for the command.
31
     */
32
    public String getCommandUsage(ICommandSender sender)
33
    {
34
        return "commands.blockdata.usage";
35
    }
36
37
    /**
38
     * Callback when the command is invoked
39
     */
40
    public void processCommand(ICommandSender sender, String[] args) throws CommandException
41
    {
42
        if (args.length < 4)
43
        {
44
            throw new WrongUsageException("commands.blockdata.usage", new Object[0]);
45
        }
46
        else
47
        {
48
            sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
49
            BlockPos blockpos = parseBlockPos(sender, args, 0, false);
50
            World world = sender.getEntityWorld();
51
52
            if (!world.isBlockLoaded(blockpos))
53
            {
54
                throw new CommandException("commands.blockdata.outOfWorld", new Object[0]);
55
            }
56
            else
57
            {
58
                TileEntity tileentity = world.getTileEntity(blockpos);
59
60
                if (tileentity == null)
61
                {
62
                    throw new CommandException("commands.blockdata.notValid", new Object[0]);
63
                }
64
                else
65
                {
66
                    NBTTagCompound nbttagcompound = new NBTTagCompound();
67
                    tileentity.writeToNBT(nbttagcompound);
68
                    NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttagcompound.copy();
69
                    NBTTagCompound nbttagcompound2;
70
71
                    try
72
                    {
73
                        nbttagcompound2 = JsonToNBT.getTagFromJson(getChatComponentFromNthArg(sender, args, 3).getUnformattedText());
74
                    }
75
                    catch (NBTException nbtexception)
76
                    {
77
                        throw new CommandException("commands.blockdata.tagError", new Object[] {nbtexception.getMessage()});
78
                    }
79
80
                    nbttagcompound.merge(nbttagcompound2);
81
                    nbttagcompound.setInteger("x", blockpos.getX());
82
                    nbttagcompound.setInteger("y", blockpos.getY());
83
                    nbttagcompound.setInteger("z", blockpos.getZ());
84
85
                    if (nbttagcompound.equals(nbttagcompound1))
86
                    {
87
                        throw new CommandException("commands.blockdata.failed", new Object[] {nbttagcompound.toString()});
88
                    }
89
                    else
90
                    {
91
                        tileentity.readFromNBT(nbttagcompound);
92
                        tileentity.markDirty();
93
                        world.markBlockForUpdate(blockpos);
94
                        sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 1);
95
                        notifyOperators(sender, this, "commands.blockdata.success", new Object[] {nbttagcompound.toString()});
96
                    }
97
                }
98
            }
99
        }
100
    }
101
102
    public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
103
    {
104
        return args.length > 0 && args.length <= 3 ? func_175771_a(args, 0, pos) : null;
105
    }
106
}
107

Deobfuscated MCP 1.8.9 source of CommandBlockData from Marcelektro/MavenMCP-1.8.9 (net/minecraft/command/CommandBlockData.java), stored verbatim.