| 1 | package net.minecraft.command.server;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import net.minecraft.command.CommandBase;
|
| 5 | import net.minecraft.command.CommandException;
|
| 6 | import net.minecraft.command.ICommandSender;
|
| 7 | import net.minecraft.command.WrongUsageException;
|
| 8 | import net.minecraft.entity.Entity;
|
| 9 | import net.minecraft.entity.EntityList;
|
| 10 | import net.minecraft.entity.EntityLiving;
|
| 11 | import net.minecraft.entity.IEntityLivingData;
|
| 12 | import net.minecraft.entity.effect.EntityLightningBolt;
|
| 13 | import net.minecraft.nbt.JsonToNBT;
|
| 14 | import net.minecraft.nbt.NBTException;
|
| 15 | import net.minecraft.nbt.NBTTagCompound;
|
| 16 | import net.minecraft.util.BlockPos;
|
| 17 | import net.minecraft.util.IChatComponent;
|
| 18 | import net.minecraft.util.Vec3;
|
| 19 | import net.minecraft.world.World;
|
| 20 |
|
| 21 | public class CommandSummon extends CommandBase
|
| 22 | {
|
| 23 | /**
|
| 24 | * Gets the name of the command
|
| 25 | */
|
| 26 | public String getCommandName()
|
| 27 | {
|
| 28 | return "summon";
|
| 29 | }
|
| 30 |
|
| 31 | /**
|
| 32 | * Return the required permission level for this command.
|
| 33 | */
|
| 34 | public int getRequiredPermissionLevel()
|
| 35 | {
|
| 36 | return 2;
|
| 37 | }
|
| 38 |
|
| 39 | /**
|
| 40 | * Gets the usage string for the command.
|
| 41 | */
|
| 42 | public String getCommandUsage(ICommandSender sender)
|
| 43 | {
|
| 44 | return "commands.summon.usage";
|
| 45 | }
|
| 46 |
|
| 47 | /**
|
| 48 | * Callback when the command is invoked
|
| 49 | */
|
| 50 | public void processCommand(ICommandSender sender, String[] args) throws CommandException
|
| 51 | {
|
| 52 | if (args.length < 1)
|
| 53 | {
|
| 54 | throw new WrongUsageException("commands.summon.usage", new Object[0]);
|
| 55 | }
|
| 56 | else
|
| 57 | {
|
| 58 | String s = args[0];
|
| 59 | BlockPos blockpos = sender.getPosition();
|
| 60 | Vec3 vec3 = sender.getPositionVector();
|
| 61 | double d0 = vec3.xCoord;
|
| 62 | double d1 = vec3.yCoord;
|
| 63 | double d2 = vec3.zCoord;
|
| 64 |
|
| 65 | if (args.length >= 4)
|
| 66 | {
|
| 67 | d0 = parseDouble(d0, args[1], true);
|
| 68 | d1 = parseDouble(d1, args[2], false);
|
| 69 | d2 = parseDouble(d2, args[3], true);
|
| 70 | blockpos = new BlockPos(d0, d1, d2);
|
| 71 | }
|
| 72 |
|
| 73 | World world = sender.getEntityWorld();
|
| 74 |
|
| 75 | if (!world.isBlockLoaded(blockpos))
|
| 76 | {
|
| 77 | throw new CommandException("commands.summon.outOfWorld", new Object[0]);
|
| 78 | }
|
| 79 | else if ("LightningBolt".equals(s))
|
| 80 | {
|
| 81 | world.addWeatherEffect(new EntityLightningBolt(world, d0, d1, d2));
|
| 82 | notifyOperators(sender, this, "commands.summon.success", new Object[0]);
|
| 83 | }
|
| 84 | else
|
| 85 | {
|
| 86 | NBTTagCompound nbttagcompound = new NBTTagCompound();
|
| 87 | boolean flag = false;
|
| 88 |
|
| 89 | if (args.length >= 5)
|
| 90 | {
|
| 91 | IChatComponent ichatcomponent = getChatComponentFromNthArg(sender, args, 4);
|
| 92 |
|
| 93 | try
|
| 94 | {
|
| 95 | nbttagcompound = JsonToNBT.getTagFromJson(ichatcomponent.getUnformattedText());
|
| 96 | flag = true;
|
| 97 | }
|
| 98 | catch (NBTException nbtexception)
|
| 99 | {
|
| 100 | throw new CommandException("commands.summon.tagError", new Object[] {nbtexception.getMessage()});
|
| 101 | }
|
| 102 | }
|
| 103 |
|
| 104 | nbttagcompound.setString("id", s);
|
| 105 | Entity entity2;
|
| 106 |
|
| 107 | try
|
| 108 | {
|
| 109 | entity2 = EntityList.createEntityFromNBT(nbttagcompound, world);
|
| 110 | }
|
| 111 | catch (RuntimeException var19)
|
| 112 | {
|
| 113 | throw new CommandException("commands.summon.failed", new Object[0]);
|
| 114 | }
|
| 115 |
|
| 116 | if (entity2 == null)
|
| 117 | {
|
| 118 | throw new CommandException("commands.summon.failed", new Object[0]);
|
| 119 | }
|
| 120 | else
|
| 121 | {
|
| 122 | entity2.setLocationAndAngles(d0, d1, d2, entity2.rotationYaw, entity2.rotationPitch);
|
| 123 |
|
| 124 | if (!flag && entity2 instanceof EntityLiving)
|
| 125 | {
|
| 126 | ((EntityLiving)entity2).onInitialSpawn(world.getDifficultyForLocation(new BlockPos(entity2)), (IEntityLivingData)null);
|
| 127 | }
|
| 128 |
|
| 129 | world.spawnEntityInWorld(entity2);
|
| 130 | Entity entity = entity2;
|
| 131 |
|
| 132 | for (NBTTagCompound nbttagcompound1 = nbttagcompound; entity != null && nbttagcompound1.hasKey("Riding", 10); nbttagcompound1 = nbttagcompound1.getCompoundTag("Riding"))
|
| 133 | {
|
| 134 | Entity entity1 = EntityList.createEntityFromNBT(nbttagcompound1.getCompoundTag("Riding"), world);
|
| 135 |
|
| 136 | if (entity1 != null)
|
| 137 | {
|
| 138 | entity1.setLocationAndAngles(d0, d1, d2, entity1.rotationYaw, entity1.rotationPitch);
|
| 139 | world.spawnEntityInWorld(entity1);
|
| 140 | entity.mountEntity(entity1);
|
| 141 | }
|
| 142 |
|
| 143 | entity = entity1;
|
| 144 | }
|
| 145 |
|
| 146 | notifyOperators(sender, this, "commands.summon.success", new Object[0]);
|
| 147 | }
|
| 148 | }
|
| 149 | }
|
| 150 | }
|
| 151 |
|
| 152 | public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
|
| 153 | {
|
| 154 | return args.length == 1 ? getListOfStringsMatchingLastWord(args, EntityList.getEntityNameList()) : (args.length > 1 && args.length <= 4 ? func_175771_a(args, 1, pos) : null);
|
| 155 | }
|
| 156 | }
|
| 157 |
|