CommandTestForBlock .java

net.minecraft.command.server.CommandTestForBlock (class): members: addTabCompletionOptions, getRequiredPermissionLevel, getCommandUsage, getCommandName.

net.minecraft.command.serverclass150 linesserverextends CommandBase5.7 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 (10)

"testforblock"
"commands.testforblock.usage"
"commands.setblock.notFound"
"commands.testforblock.outOfWorld"
"commands.setblock.tagError"
"commands.testforblock.failed.tile"
"commands.testforblock.failed.data"
"commands.testforblock.failed.tileEntity"
"commands.testforblock.failed.nbt"
"commands.testforblock.success"

Full Source

CommandTestForBlock.java150 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.command.server;
2
3
import java.util.List;
4
import net.minecraft.block.Block;
5
import net.minecraft.block.state.IBlockState;
6
import net.minecraft.command.CommandBase;
7
import net.minecraft.command.CommandException;
8
import net.minecraft.command.CommandResultStats;
9
import net.minecraft.command.ICommandSender;
10
import net.minecraft.command.NumberInvalidException;
11
import net.minecraft.command.WrongUsageException;
12
import net.minecraft.nbt.JsonToNBT;
13
import net.minecraft.nbt.NBTException;
14
import net.minecraft.nbt.NBTTagCompound;
15
import net.minecraft.nbt.NBTUtil;
16
import net.minecraft.tileentity.TileEntity;
17
import net.minecraft.util.BlockPos;
18
import net.minecraft.world.World;
19
20
public class CommandTestForBlock extends CommandBase
21
{
22
    /**
23
     * Gets the name of the command
24
     */
25
    public String getCommandName()
26
    {
27
        return "testforblock";
28
    }
29
30
    /**
31
     * Return the required permission level for this command.
32
     */
33
    public int getRequiredPermissionLevel()
34
    {
35
        return 2;
36
    }
37
38
    /**
39
     * Gets the usage string for the command.
40
     */
41
    public String getCommandUsage(ICommandSender sender)
42
    {
43
        return "commands.testforblock.usage";
44
    }
45
46
    /**
47
     * Callback when the command is invoked
48
     */
49
    public void processCommand(ICommandSender sender, String[] args) throws CommandException
50
    {
51
        if (args.length < 4)
52
        {
53
            throw new WrongUsageException("commands.testforblock.usage", new Object[0]);
54
        }
55
        else
56
        {
57
            sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
58
            BlockPos blockpos = parseBlockPos(sender, args, 0, false);
59
            Block block = Block.getBlockFromName(args[3]);
60
61
            if (block == null)
62
            {
63
                throw new NumberInvalidException("commands.setblock.notFound", new Object[] {args[3]});
64
            }
65
            else
66
            {
67
                int i = -1;
68
69
                if (args.length >= 5)
70
                {
71
                    i = parseInt(args[4], -1, 15);
72
                }
73
74
                World world = sender.getEntityWorld();
75
76
                if (!world.isBlockLoaded(blockpos))
77
                {
78
                    throw new CommandException("commands.testforblock.outOfWorld", new Object[0]);
79
                }
80
                else
81
                {
82
                    NBTTagCompound nbttagcompound = new NBTTagCompound();
83
                    boolean flag = false;
84
85
                    if (args.length >= 6 && block.hasTileEntity())
86
                    {
87
                        String s = getChatComponentFromNthArg(sender, args, 5).getUnformattedText();
88
89
                        try
90
                        {
91
                            nbttagcompound = JsonToNBT.getTagFromJson(s);
92
                            flag = true;
93
                        }
94
                        catch (NBTException nbtexception)
95
                        {
96
                            throw new CommandException("commands.setblock.tagError", new Object[] {nbtexception.getMessage()});
97
                        }
98
                    }
99
100
                    IBlockState iblockstate = world.getBlockState(blockpos);
101
                    Block block1 = iblockstate.getBlock();
102
103
                    if (block1 != block)
104
                    {
105
                        throw new CommandException("commands.testforblock.failed.tile", new Object[] {Integer.valueOf(blockpos.getX()), Integer.valueOf(blockpos.getY()), Integer.valueOf(blockpos.getZ()), block1.getLocalizedName(), block.getLocalizedName()});
106
                    }
107
                    else
108
                    {
109
                        if (i > -1)
110
                        {
111
                            int j = iblockstate.getBlock().getMetaFromState(iblockstate);
112
113
                            if (j != i)
114
                            {
115
                                throw new CommandException("commands.testforblock.failed.data", new Object[] {Integer.valueOf(blockpos.getX()), Integer.valueOf(blockpos.getY()), Integer.valueOf(blockpos.getZ()), Integer.valueOf(j), Integer.valueOf(i)});
116
                            }
117
                        }
118
119
                        if (flag)
120
                        {
121
                            TileEntity tileentity = world.getTileEntity(blockpos);
122
123
                            if (tileentity == null)
124
                            {
125
                                throw new CommandException("commands.testforblock.failed.tileEntity", new Object[] {Integer.valueOf(blockpos.getX()), Integer.valueOf(blockpos.getY()), Integer.valueOf(blockpos.getZ())});
126
                            }
127
128
                            NBTTagCompound nbttagcompound1 = new NBTTagCompound();
129
                            tileentity.writeToNBT(nbttagcompound1);
130
131
                            if (!NBTUtil.func_181123_a(nbttagcompound, nbttagcompound1, true))
132
                            {
133
                                throw new CommandException("commands.testforblock.failed.nbt", new Object[] {Integer.valueOf(blockpos.getX()), Integer.valueOf(blockpos.getY()), Integer.valueOf(blockpos.getZ())});
134
                            }
135
                        }
136
137
                        sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 1);
138
                        notifyOperators(sender, this, "commands.testforblock.success", new Object[] {Integer.valueOf(blockpos.getX()), Integer.valueOf(blockpos.getY()), Integer.valueOf(blockpos.getZ())});
139
                    }
140
                }
141
            }
142
        }
143
    }
144
145
    public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
146
    {
147
        return args.length > 0 && args.length <= 3 ? func_175771_a(args, 0, pos) : (args.length == 4 ? getListOfStringsMatchingLastWord(args, Block.blockRegistry.getKeys()) : null);
148
    }
149
}
150

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