| 1 | package net.minecraft.command;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import java.util.LinkedList;
|
| 5 | import java.util.List;
|
| 6 | import net.minecraft.block.Block;
|
| 7 | import net.minecraft.block.state.IBlockState;
|
| 8 | import net.minecraft.init.Blocks;
|
| 9 | import net.minecraft.inventory.IInventory;
|
| 10 | import net.minecraft.nbt.NBTTagCompound;
|
| 11 | import net.minecraft.tileentity.TileEntity;
|
| 12 | import net.minecraft.util.BlockPos;
|
| 13 | import net.minecraft.world.NextTickListEntry;
|
| 14 | import net.minecraft.world.World;
|
| 15 | import net.minecraft.world.gen.structure.StructureBoundingBox;
|
| 16 |
|
| 17 | public class CommandClone extends CommandBase
|
| 18 | {
|
| 19 | /**
|
| 20 | * Gets the name of the command
|
| 21 | */
|
| 22 | public String getCommandName()
|
| 23 | {
|
| 24 | return "clone";
|
| 25 | }
|
| 26 |
|
| 27 | /**
|
| 28 | * Return the required permission level for this command.
|
| 29 | */
|
| 30 | public int getRequiredPermissionLevel()
|
| 31 | {
|
| 32 | return 2;
|
| 33 | }
|
| 34 |
|
| 35 | /**
|
| 36 | * Gets the usage string for the command.
|
| 37 | */
|
| 38 | public String getCommandUsage(ICommandSender sender)
|
| 39 | {
|
| 40 | return "commands.clone.usage";
|
| 41 | }
|
| 42 |
|
| 43 | /**
|
| 44 | * Callback when the command is invoked
|
| 45 | */
|
| 46 | public void processCommand(ICommandSender sender, String[] args) throws CommandException
|
| 47 | {
|
| 48 | if (args.length < 9)
|
| 49 | {
|
| 50 | throw new WrongUsageException("commands.clone.usage", new Object[0]);
|
| 51 | }
|
| 52 | else
|
| 53 | {
|
| 54 | sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
|
| 55 | BlockPos blockpos = parseBlockPos(sender, args, 0, false);
|
| 56 | BlockPos blockpos1 = parseBlockPos(sender, args, 3, false);
|
| 57 | BlockPos blockpos2 = parseBlockPos(sender, args, 6, false);
|
| 58 | StructureBoundingBox structureboundingbox = new StructureBoundingBox(blockpos, blockpos1);
|
| 59 | StructureBoundingBox structureboundingbox1 = new StructureBoundingBox(blockpos2, blockpos2.add(structureboundingbox.func_175896_b()));
|
| 60 | int i = structureboundingbox.getXSize() * structureboundingbox.getYSize() * structureboundingbox.getZSize();
|
| 61 |
|
| 62 | if (i > 32768)
|
| 63 | {
|
| 64 | throw new CommandException("commands.clone.tooManyBlocks", new Object[] {Integer.valueOf(i), Integer.valueOf(32768)});
|
| 65 | }
|
| 66 | else
|
| 67 | {
|
| 68 | boolean flag = false;
|
| 69 | Block block = null;
|
| 70 | int j = -1;
|
| 71 |
|
| 72 | if ((args.length < 11 || !args[10].equals("force") && !args[10].equals("move")) && structureboundingbox.intersectsWith(structureboundingbox1))
|
| 73 | {
|
| 74 | throw new CommandException("commands.clone.noOverlap", new Object[0]);
|
| 75 | }
|
| 76 | else
|
| 77 | {
|
| 78 | if (args.length >= 11 && args[10].equals("move"))
|
| 79 | {
|
| 80 | flag = true;
|
| 81 | }
|
| 82 |
|
| 83 | if (structureboundingbox.minY >= 0 && structureboundingbox.maxY < 256 && structureboundingbox1.minY >= 0 && structureboundingbox1.maxY < 256)
|
| 84 | {
|
| 85 | World world = sender.getEntityWorld();
|
| 86 |
|
| 87 | if (world.isAreaLoaded(structureboundingbox) && world.isAreaLoaded(structureboundingbox1))
|
| 88 | {
|
| 89 | boolean flag1 = false;
|
| 90 |
|
| 91 | if (args.length >= 10)
|
| 92 | {
|
| 93 | if (args[9].equals("masked"))
|
| 94 | {
|
| 95 | flag1 = true;
|
| 96 | }
|
| 97 | else if (args[9].equals("filtered"))
|
| 98 | {
|
| 99 | if (args.length < 12)
|
| 100 | {
|
| 101 | throw new WrongUsageException("commands.clone.usage", new Object[0]);
|
| 102 | }
|
| 103 |
|
| 104 | block = getBlockByText(sender, args[11]);
|
| 105 |
|
| 106 | if (args.length >= 13)
|
| 107 | {
|
| 108 | j = parseInt(args[12], 0, 15);
|
| 109 | }
|
| 110 | }
|
| 111 | }
|
| 112 |
|
| 113 | List<CommandClone.StaticCloneData> list = Lists.<CommandClone.StaticCloneData>newArrayList();
|
| 114 | List<CommandClone.StaticCloneData> list1 = Lists.<CommandClone.StaticCloneData>newArrayList();
|
| 115 | List<CommandClone.StaticCloneData> list2 = Lists.<CommandClone.StaticCloneData>newArrayList();
|
| 116 | LinkedList<BlockPos> linkedlist = Lists.<BlockPos>newLinkedList();
|
| 117 | BlockPos blockpos3 = new BlockPos(structureboundingbox1.minX - structureboundingbox.minX, structureboundingbox1.minY - structureboundingbox.minY, structureboundingbox1.minZ - structureboundingbox.minZ);
|
| 118 |
|
| 119 | for (int k = structureboundingbox.minZ; k <= structureboundingbox.maxZ; ++k)
|
| 120 | {
|
| 121 | for (int l = structureboundingbox.minY; l <= structureboundingbox.maxY; ++l)
|
| 122 | {
|
| 123 | for (int i1 = structureboundingbox.minX; i1 <= structureboundingbox.maxX; ++i1)
|
| 124 | {
|
| 125 | BlockPos blockpos4 = new BlockPos(i1, l, k);
|
| 126 | BlockPos blockpos5 = blockpos4.add(blockpos3);
|
| 127 | IBlockState iblockstate = world.getBlockState(blockpos4);
|
| 128 |
|
| 129 | if ((!flag1 || iblockstate.getBlock() != Blocks.air) && (block == null || iblockstate.getBlock() == block && (j < 0 || iblockstate.getBlock().getMetaFromState(iblockstate) == j)))
|
| 130 | {
|
| 131 | TileEntity tileentity = world.getTileEntity(blockpos4);
|
| 132 |
|
| 133 | if (tileentity != null)
|
| 134 | {
|
| 135 | NBTTagCompound nbttagcompound = new NBTTagCompound();
|
| 136 | tileentity.writeToNBT(nbttagcompound);
|
| 137 | list1.add(new CommandClone.StaticCloneData(blockpos5, iblockstate, nbttagcompound));
|
| 138 | linkedlist.addLast(blockpos4);
|
| 139 | }
|
| 140 | else if (!iblockstate.getBlock().isFullBlock() && !iblockstate.getBlock().isFullCube())
|
| 141 | {
|
| 142 | list2.add(new CommandClone.StaticCloneData(blockpos5, iblockstate, (NBTTagCompound)null));
|
| 143 | linkedlist.addFirst(blockpos4);
|
| 144 | }
|
| 145 | else
|
| 146 | {
|
| 147 | list.add(new CommandClone.StaticCloneData(blockpos5, iblockstate, (NBTTagCompound)null));
|
| 148 | linkedlist.addLast(blockpos4);
|
| 149 | }
|
| 150 | }
|
| 151 | }
|
| 152 | }
|
| 153 | }
|
| 154 |
|
| 155 | if (flag)
|
| 156 | {
|
| 157 | for (BlockPos blockpos6 : linkedlist)
|
| 158 | {
|
| 159 | TileEntity tileentity1 = world.getTileEntity(blockpos6);
|
| 160 |
|
| 161 | if (tileentity1 instanceof IInventory)
|
| 162 | {
|
| 163 | ((IInventory)tileentity1).clear();
|
| 164 | }
|
| 165 |
|
| 166 | world.setBlockState(blockpos6, Blocks.barrier.getDefaultState(), 2);
|
| 167 | }
|
| 168 |
|
| 169 | for (BlockPos blockpos7 : linkedlist)
|
| 170 | {
|
| 171 | world.setBlockState(blockpos7, Blocks.air.getDefaultState(), 3);
|
| 172 | }
|
| 173 | }
|
| 174 |
|
| 175 | List<CommandClone.StaticCloneData> list3 = Lists.<CommandClone.StaticCloneData>newArrayList();
|
| 176 | list3.addAll(list);
|
| 177 | list3.addAll(list1);
|
| 178 | list3.addAll(list2);
|
| 179 | List<CommandClone.StaticCloneData> list4 = Lists.<CommandClone.StaticCloneData>reverse(list3);
|
| 180 |
|
| 181 | for (CommandClone.StaticCloneData commandclone$staticclonedata : list4)
|
| 182 | {
|
| 183 | TileEntity tileentity2 = world.getTileEntity(commandclone$staticclonedata.pos);
|
| 184 |
|
| 185 | if (tileentity2 instanceof IInventory)
|
| 186 | {
|
| 187 | ((IInventory)tileentity2).clear();
|
| 188 | }
|
| 189 |
|
| 190 | world.setBlockState(commandclone$staticclonedata.pos, Blocks.barrier.getDefaultState(), 2);
|
| 191 | }
|
| 192 |
|
| 193 | i = 0;
|
| 194 |
|
| 195 | for (CommandClone.StaticCloneData commandclone$staticclonedata1 : list3)
|
| 196 | {
|
| 197 | if (world.setBlockState(commandclone$staticclonedata1.pos, commandclone$staticclonedata1.blockState, 2))
|
| 198 | {
|
| 199 | ++i;
|
| 200 | }
|
| 201 | }
|
| 202 |
|
| 203 | for (CommandClone.StaticCloneData commandclone$staticclonedata2 : list1)
|
| 204 | {
|
| 205 | TileEntity tileentity3 = world.getTileEntity(commandclone$staticclonedata2.pos);
|
| 206 |
|
| 207 | if (commandclone$staticclonedata2.compound != null && tileentity3 != null)
|
| 208 | {
|
| 209 | commandclone$staticclonedata2.compound.setInteger("x", commandclone$staticclonedata2.pos.getX());
|
| 210 | commandclone$staticclonedata2.compound.setInteger("y", commandclone$staticclonedata2.pos.getY());
|
| 211 | commandclone$staticclonedata2.compound.setInteger("z", commandclone$staticclonedata2.pos.getZ());
|
| 212 | tileentity3.readFromNBT(commandclone$staticclonedata2.compound);
|
| 213 | tileentity3.markDirty();
|
| 214 | }
|
| 215 |
|
| 216 | world.setBlockState(commandclone$staticclonedata2.pos, commandclone$staticclonedata2.blockState, 2);
|
| 217 | }
|
| 218 |
|
| 219 | for (CommandClone.StaticCloneData commandclone$staticclonedata3 : list4)
|
| 220 | {
|
| 221 | world.notifyNeighborsRespectDebug(commandclone$staticclonedata3.pos, commandclone$staticclonedata3.blockState.getBlock());
|
| 222 | }
|
| 223 |
|
| 224 | List<NextTickListEntry> list5 = world.func_175712_a(structureboundingbox, false);
|
| 225 |
|
| 226 | if (list5 != null)
|
| 227 | {
|
| 228 | for (NextTickListEntry nextticklistentry : list5)
|
| 229 | {
|
| 230 | if (structureboundingbox.isVecInside(nextticklistentry.position))
|
| 231 | {
|
| 232 | BlockPos blockpos8 = nextticklistentry.position.add(blockpos3);
|
| 233 | world.scheduleBlockUpdate(blockpos8, nextticklistentry.getBlock(), (int)(nextticklistentry.scheduledTime - world.getWorldInfo().getWorldTotalTime()), nextticklistentry.priority);
|
| 234 | }
|
| 235 | }
|
| 236 | }
|
| 237 |
|
| 238 | if (i <= 0)
|
| 239 | {
|
| 240 | throw new CommandException("commands.clone.failed", new Object[0]);
|
| 241 | }
|
| 242 | else
|
| 243 | {
|
| 244 | sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, i);
|
| 245 | notifyOperators(sender, this, "commands.clone.success", new Object[] {Integer.valueOf(i)});
|
| 246 | }
|
| 247 | }
|
| 248 | else
|
| 249 | {
|
| 250 | throw new CommandException("commands.clone.outOfWorld", new Object[0]);
|
| 251 | }
|
| 252 | }
|
| 253 | else
|
| 254 | {
|
| 255 | throw new CommandException("commands.clone.outOfWorld", new Object[0]);
|
| 256 | }
|
| 257 | }
|
| 258 | }
|
| 259 | }
|
| 260 | }
|
| 261 |
|
| 262 | public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
|
| 263 | {
|
| 264 | 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 > 6 && args.length <= 9 ? func_175771_a(args, 6, pos) : (args.length == 10 ? getListOfStringsMatchingLastWord(args, new String[] {"replace", "masked", "filtered"}): (args.length == 11 ? getListOfStringsMatchingLastWord(args, new String[] {"normal", "force", "move"}): (args.length == 12 && "filtered".equals(args[9]) ? getListOfStringsMatchingLastWord(args, Block.blockRegistry.getKeys()) : null)))));
|
| 265 | }
|
| 266 |
|
| 267 | static class StaticCloneData
|
| 268 | {
|
| 269 | public final BlockPos pos;
|
| 270 | public final IBlockState blockState;
|
| 271 | public final NBTTagCompound compound;
|
| 272 |
|
| 273 | public StaticCloneData(BlockPos posIn, IBlockState stateIn, NBTTagCompound compoundIn)
|
| 274 | {
|
| 275 | this.pos = posIn;
|
| 276 | this.blockState = stateIn;
|
| 277 | this.compound = compoundIn;
|
| 278 | }
|
| 279 | }
|
| 280 | }
|
| 281 |
|