| 1 | package net.minecraft.command;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import java.util.List;
|
| 5 | import net.minecraft.block.Block;
|
| 6 | import net.minecraft.block.state.IBlockState;
|
| 7 | import net.minecraft.init.Blocks;
|
| 8 | import net.minecraft.inventory.IInventory;
|
| 9 | import net.minecraft.nbt.JsonToNBT;
|
| 10 | import net.minecraft.nbt.NBTException;
|
| 11 | import net.minecraft.nbt.NBTTagCompound;
|
| 12 | import net.minecraft.tileentity.TileEntity;
|
| 13 | import net.minecraft.util.BlockPos;
|
| 14 | import net.minecraft.world.World;
|
| 15 |
|
| 16 | public class CommandFill extends CommandBase
|
| 17 | {
|
| 18 | /**
|
| 19 | * Gets the name of the command
|
| 20 | */
|
| 21 | public String getCommandName()
|
| 22 | {
|
| 23 | return "fill";
|
| 24 | }
|
| 25 |
|
| 26 | /**
|
| 27 | * Return the required permission level for this command.
|
| 28 | */
|
| 29 | public int getRequiredPermissionLevel()
|
| 30 | {
|
| 31 | return 2;
|
| 32 | }
|
| 33 |
|
| 34 | /**
|
| 35 | * Gets the usage string for the command.
|
| 36 | */
|
| 37 | public String getCommandUsage(ICommandSender sender)
|
| 38 | {
|
| 39 | return "commands.fill.usage";
|
| 40 | }
|
| 41 |
|
| 42 | /**
|
| 43 | * Callback when the command is invoked
|
| 44 | */
|
| 45 | public void processCommand(ICommandSender sender, String[] args) throws CommandException
|
| 46 | {
|
| 47 | if (args.length < 7)
|
| 48 | {
|
| 49 | throw new WrongUsageException("commands.fill.usage", new Object[0]);
|
| 50 | }
|
| 51 | else
|
| 52 | {
|
| 53 | sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
|
| 54 | BlockPos blockpos = parseBlockPos(sender, args, 0, false);
|
| 55 | BlockPos blockpos1 = parseBlockPos(sender, args, 3, false);
|
| 56 | Block block = CommandBase.getBlockByText(sender, args[6]);
|
| 57 | int i = 0;
|
| 58 |
|
| 59 | if (args.length >= 8)
|
| 60 | {
|
| 61 | i = parseInt(args[7], 0, 15);
|
| 62 | }
|
| 63 |
|
| 64 | BlockPos blockpos2 = new BlockPos(Math.min(blockpos.getX(), blockpos1.getX()), Math.min(blockpos.getY(), blockpos1.getY()), Math.min(blockpos.getZ(), blockpos1.getZ()));
|
| 65 | BlockPos blockpos3 = new BlockPos(Math.max(blockpos.getX(), blockpos1.getX()), Math.max(blockpos.getY(), blockpos1.getY()), Math.max(blockpos.getZ(), blockpos1.getZ()));
|
| 66 | int j = (blockpos3.getX() - blockpos2.getX() + 1) * (blockpos3.getY() - blockpos2.getY() + 1) * (blockpos3.getZ() - blockpos2.getZ() + 1);
|
| 67 |
|
| 68 | if (j > 32768)
|
| 69 | {
|
| 70 | throw new CommandException("commands.fill.tooManyBlocks", new Object[] {Integer.valueOf(j), Integer.valueOf(32768)});
|
| 71 | }
|
| 72 | else if (blockpos2.getY() >= 0 && blockpos3.getY() < 256)
|
| 73 | {
|
| 74 | World world = sender.getEntityWorld();
|
| 75 |
|
| 76 | for (int k = blockpos2.getZ(); k < blockpos3.getZ() + 16; k += 16)
|
| 77 | {
|
| 78 | for (int l = blockpos2.getX(); l < blockpos3.getX() + 16; l += 16)
|
| 79 | {
|
| 80 | if (!world.isBlockLoaded(new BlockPos(l, blockpos3.getY() - blockpos2.getY(), k)))
|
| 81 | {
|
| 82 | throw new CommandException("commands.fill.outOfWorld", new Object[0]);
|
| 83 | }
|
| 84 | }
|
| 85 | }
|
| 86 |
|
| 87 | NBTTagCompound nbttagcompound = new NBTTagCompound();
|
| 88 | boolean flag = false;
|
| 89 |
|
| 90 | if (args.length >= 10 && block.hasTileEntity())
|
| 91 | {
|
| 92 | String s = getChatComponentFromNthArg(sender, args, 9).getUnformattedText();
|
| 93 |
|
| 94 | try
|
| 95 | {
|
| 96 | nbttagcompound = JsonToNBT.getTagFromJson(s);
|
| 97 | flag = true;
|
| 98 | }
|
| 99 | catch (NBTException nbtexception)
|
| 100 | {
|
| 101 | throw new CommandException("commands.fill.tagError", new Object[] {nbtexception.getMessage()});
|
| 102 | }
|
| 103 | }
|
| 104 |
|
| 105 | List<BlockPos> list = Lists.<BlockPos>newArrayList();
|
| 106 | j = 0;
|
| 107 |
|
| 108 | for (int i1 = blockpos2.getZ(); i1 <= blockpos3.getZ(); ++i1)
|
| 109 | {
|
| 110 | for (int j1 = blockpos2.getY(); j1 <= blockpos3.getY(); ++j1)
|
| 111 | {
|
| 112 | for (int k1 = blockpos2.getX(); k1 <= blockpos3.getX(); ++k1)
|
| 113 | {
|
| 114 | BlockPos blockpos4 = new BlockPos(k1, j1, i1);
|
| 115 |
|
| 116 | if (args.length >= 9)
|
| 117 | {
|
| 118 | if (!args[8].equals("outline") && !args[8].equals("hollow"))
|
| 119 | {
|
| 120 | if (args[8].equals("destroy"))
|
| 121 | {
|
| 122 | world.destroyBlock(blockpos4, true);
|
| 123 | }
|
| 124 | else if (args[8].equals("keep"))
|
| 125 | {
|
| 126 | if (!world.isAirBlock(blockpos4))
|
| 127 | {
|
| 128 | continue;
|
| 129 | }
|
| 130 | }
|
| 131 | else if (args[8].equals("replace") && !block.hasTileEntity())
|
| 132 | {
|
| 133 | if (args.length > 9)
|
| 134 | {
|
| 135 | Block block1 = CommandBase.getBlockByText(sender, args[9]);
|
| 136 |
|
| 137 | if (world.getBlockState(blockpos4).getBlock() != block1)
|
| 138 | {
|
| 139 | continue;
|
| 140 | }
|
| 141 | }
|
| 142 |
|
| 143 | if (args.length > 10)
|
| 144 | {
|
| 145 | int l1 = CommandBase.parseInt(args[10]);
|
| 146 | IBlockState iblockstate = world.getBlockState(blockpos4);
|
| 147 |
|
| 148 | if (iblockstate.getBlock().getMetaFromState(iblockstate) != l1)
|
| 149 | {
|
| 150 | continue;
|
| 151 | }
|
| 152 | }
|
| 153 | }
|
| 154 | }
|
| 155 | else if (k1 != blockpos2.getX() && k1 != blockpos3.getX() && j1 != blockpos2.getY() && j1 != blockpos3.getY() && i1 != blockpos2.getZ() && i1 != blockpos3.getZ())
|
| 156 | {
|
| 157 | if (args[8].equals("hollow"))
|
| 158 | {
|
| 159 | world.setBlockState(blockpos4, Blocks.air.getDefaultState(), 2);
|
| 160 | list.add(blockpos4);
|
| 161 | }
|
| 162 |
|
| 163 | continue;
|
| 164 | }
|
| 165 | }
|
| 166 |
|
| 167 | TileEntity tileentity1 = world.getTileEntity(blockpos4);
|
| 168 |
|
| 169 | if (tileentity1 != null)
|
| 170 | {
|
| 171 | if (tileentity1 instanceof IInventory)
|
| 172 | {
|
| 173 | ((IInventory)tileentity1).clear();
|
| 174 | }
|
| 175 |
|
| 176 | world.setBlockState(blockpos4, Blocks.barrier.getDefaultState(), block == Blocks.barrier ? 2 : 4);
|
| 177 | }
|
| 178 |
|
| 179 | IBlockState iblockstate1 = block.getStateFromMeta(i);
|
| 180 |
|
| 181 | if (world.setBlockState(blockpos4, iblockstate1, 2))
|
| 182 | {
|
| 183 | list.add(blockpos4);
|
| 184 | ++j;
|
| 185 |
|
| 186 | if (flag)
|
| 187 | {
|
| 188 | TileEntity tileentity = world.getTileEntity(blockpos4);
|
| 189 |
|
| 190 | if (tileentity != null)
|
| 191 | {
|
| 192 | nbttagcompound.setInteger("x", blockpos4.getX());
|
| 193 | nbttagcompound.setInteger("y", blockpos4.getY());
|
| 194 | nbttagcompound.setInteger("z", blockpos4.getZ());
|
| 195 | tileentity.readFromNBT(nbttagcompound);
|
| 196 | }
|
| 197 | }
|
| 198 | }
|
| 199 | }
|
| 200 | }
|
| 201 | }
|
| 202 |
|
| 203 | for (BlockPos blockpos5 : list)
|
| 204 | {
|
| 205 | Block block2 = world.getBlockState(blockpos5).getBlock();
|
| 206 | world.notifyNeighborsRespectDebug(blockpos5, block2);
|
| 207 | }
|
| 208 |
|
| 209 | if (j <= 0)
|
| 210 | {
|
| 211 | throw new CommandException("commands.fill.failed", new Object[0]);
|
| 212 | }
|
| 213 | else
|
| 214 | {
|
| 215 | sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, j);
|
| 216 | notifyOperators(sender, this, "commands.fill.success", new Object[] {Integer.valueOf(j)});
|
| 217 | }
|
| 218 | }
|
| 219 | else
|
| 220 | {
|
| 221 | throw new CommandException("commands.fill.outOfWorld", new Object[0]);
|
| 222 | }
|
| 223 | }
|
| 224 | }
|
| 225 |
|
| 226 | public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
|
| 227 | {
|
| 228 | return args.length > 0 && args.length <= 3 ? func_175771_a(args, 0, pos) : (args.length > 3 && args.length <= 6 ? func_175771_a(args, 3, pos) : (args.length == 7 ? getListOfStringsMatchingLastWord(args, Block.blockRegistry.getKeys()) : (args.length == 9 ? getListOfStringsMatchingLastWord(args, new String[] {"replace", "destroy", "keep", "hollow", "outline"}): (args.length == 10 && "replace".equals(args[8]) ? getListOfStringsMatchingLastWord(args, Block.blockRegistry.getKeys()) : null))));
|
| 229 | }
|
| 230 | }
|
| 231 |
|