| 1 | package net.minecraft.command;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import net.minecraft.block.state.IBlockState;
|
| 5 | import net.minecraft.init.Blocks;
|
| 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 | import net.minecraft.world.gen.structure.StructureBoundingBox;
|
| 11 |
|
| 12 | public class CommandCompare extends CommandBase
|
| 13 | {
|
| 14 | /**
|
| 15 | * Gets the name of the command
|
| 16 | */
|
| 17 | public String getCommandName()
|
| 18 | {
|
| 19 | return "testforblocks";
|
| 20 | }
|
| 21 |
|
| 22 | /**
|
| 23 | * Return the required permission level for this command.
|
| 24 | */
|
| 25 | public int getRequiredPermissionLevel()
|
| 26 | {
|
| 27 | return 2;
|
| 28 | }
|
| 29 |
|
| 30 | /**
|
| 31 | * Gets the usage string for the command.
|
| 32 | */
|
| 33 | public String getCommandUsage(ICommandSender sender)
|
| 34 | {
|
| 35 | return "commands.compare.usage";
|
| 36 | }
|
| 37 |
|
| 38 | /**
|
| 39 | * Callback when the command is invoked
|
| 40 | */
|
| 41 | public void processCommand(ICommandSender sender, String[] args) throws CommandException
|
| 42 | {
|
| 43 | if (args.length < 9)
|
| 44 | {
|
| 45 | throw new WrongUsageException("commands.compare.usage", new Object[0]);
|
| 46 | }
|
| 47 | else
|
| 48 | {
|
| 49 | sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
|
| 50 | BlockPos blockpos = parseBlockPos(sender, args, 0, false);
|
| 51 | BlockPos blockpos1 = parseBlockPos(sender, args, 3, false);
|
| 52 | BlockPos blockpos2 = parseBlockPos(sender, args, 6, false);
|
| 53 | StructureBoundingBox structureboundingbox = new StructureBoundingBox(blockpos, blockpos1);
|
| 54 | StructureBoundingBox structureboundingbox1 = new StructureBoundingBox(blockpos2, blockpos2.add(structureboundingbox.func_175896_b()));
|
| 55 | int i = structureboundingbox.getXSize() * structureboundingbox.getYSize() * structureboundingbox.getZSize();
|
| 56 |
|
| 57 | if (i > 524288)
|
| 58 | {
|
| 59 | throw new CommandException("commands.compare.tooManyBlocks", new Object[] {Integer.valueOf(i), Integer.valueOf(524288)});
|
| 60 | }
|
| 61 | else if (structureboundingbox.minY >= 0 && structureboundingbox.maxY < 256 && structureboundingbox1.minY >= 0 && structureboundingbox1.maxY < 256)
|
| 62 | {
|
| 63 | World world = sender.getEntityWorld();
|
| 64 |
|
| 65 | if (world.isAreaLoaded(structureboundingbox) && world.isAreaLoaded(structureboundingbox1))
|
| 66 | {
|
| 67 | boolean flag = false;
|
| 68 |
|
| 69 | if (args.length > 9 && args[9].equals("masked"))
|
| 70 | {
|
| 71 | flag = true;
|
| 72 | }
|
| 73 |
|
| 74 | i = 0;
|
| 75 | BlockPos blockpos3 = new BlockPos(structureboundingbox1.minX - structureboundingbox.minX, structureboundingbox1.minY - structureboundingbox.minY, structureboundingbox1.minZ - structureboundingbox.minZ);
|
| 76 | BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
|
| 77 | BlockPos.MutableBlockPos blockpos$mutableblockpos1 = new BlockPos.MutableBlockPos();
|
| 78 |
|
| 79 | for (int j = structureboundingbox.minZ; j <= structureboundingbox.maxZ; ++j)
|
| 80 | {
|
| 81 | for (int k = structureboundingbox.minY; k <= structureboundingbox.maxY; ++k)
|
| 82 | {
|
| 83 | for (int l = structureboundingbox.minX; l <= structureboundingbox.maxX; ++l)
|
| 84 | {
|
| 85 | blockpos$mutableblockpos.set(l, k, j);
|
| 86 | blockpos$mutableblockpos1.set(l + blockpos3.getX(), k + blockpos3.getY(), j + blockpos3.getZ());
|
| 87 | boolean flag1 = false;
|
| 88 | IBlockState iblockstate = world.getBlockState(blockpos$mutableblockpos);
|
| 89 |
|
| 90 | if (!flag || iblockstate.getBlock() != Blocks.air)
|
| 91 | {
|
| 92 | if (iblockstate == world.getBlockState(blockpos$mutableblockpos1))
|
| 93 | {
|
| 94 | TileEntity tileentity = world.getTileEntity(blockpos$mutableblockpos);
|
| 95 | TileEntity tileentity1 = world.getTileEntity(blockpos$mutableblockpos1);
|
| 96 |
|
| 97 | if (tileentity != null && tileentity1 != null)
|
| 98 | {
|
| 99 | NBTTagCompound nbttagcompound = new NBTTagCompound();
|
| 100 | tileentity.writeToNBT(nbttagcompound);
|
| 101 | nbttagcompound.removeTag("x");
|
| 102 | nbttagcompound.removeTag("y");
|
| 103 | nbttagcompound.removeTag("z");
|
| 104 | NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
| 105 | tileentity1.writeToNBT(nbttagcompound1);
|
| 106 | nbttagcompound1.removeTag("x");
|
| 107 | nbttagcompound1.removeTag("y");
|
| 108 | nbttagcompound1.removeTag("z");
|
| 109 |
|
| 110 | if (!nbttagcompound.equals(nbttagcompound1))
|
| 111 | {
|
| 112 | flag1 = true;
|
| 113 | }
|
| 114 | }
|
| 115 | else if (tileentity != null)
|
| 116 | {
|
| 117 | flag1 = true;
|
| 118 | }
|
| 119 | }
|
| 120 | else
|
| 121 | {
|
| 122 | flag1 = true;
|
| 123 | }
|
| 124 |
|
| 125 | ++i;
|
| 126 |
|
| 127 | if (flag1)
|
| 128 | {
|
| 129 | throw new CommandException("commands.compare.failed", new Object[0]);
|
| 130 | }
|
| 131 | }
|
| 132 | }
|
| 133 | }
|
| 134 | }
|
| 135 |
|
| 136 | sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, i);
|
| 137 | notifyOperators(sender, this, "commands.compare.success", new Object[] {Integer.valueOf(i)});
|
| 138 | }
|
| 139 | else
|
| 140 | {
|
| 141 | throw new CommandException("commands.compare.outOfWorld", new Object[0]);
|
| 142 | }
|
| 143 | }
|
| 144 | else
|
| 145 | {
|
| 146 | throw new CommandException("commands.compare.outOfWorld", new Object[0]);
|
| 147 | }
|
| 148 | }
|
| 149 | }
|
| 150 |
|
| 151 | public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
|
| 152 | {
|
| 153 | 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[] {"masked", "all"}): null)));
|
| 154 | }
|
| 155 | }
|
| 156 |
|