Started by
Le lance Flamer
on
Topic category: Help with Minecraft modding (Java Edition)
Hi, I need to know the method to spawn an entity with a command argument. I tried adding a variable and then in the code making it act to spawner the entity but it tells me that an unexpected error occurred. The code for the procedure:
Entity entityThatWillBeSpawned = null;
entityThatWillBeSpawned = new Object() {
public Entity getEntity() {
try {
return EntityArgument.getEntity(arguments, "entity");
} catch (CommandSyntaxException e) {
e.printStackTrace();
return null;
}
}
}.getEntity();
Entity entityToSpawn = entityThatWillBeSpawned;
entityToSpawn.moveTo((new Object() {
public double getX() {
try {
return BlockPosArgument.getLoadedBlockPos(arguments, "pos").getX();
} catch (CommandSyntaxException e) {
e.printStackTrace();
return 0;
}
}
}.getX())
Don't tell me that you can't see more after .getX()) because it is useless.
Normally, you don't need the code below but if you want it.
if (entityToSpawn instanceof Mob _mobToSpawn)
_mobToSpawn.finalizeSpawn(_level, world.getCurrentDifficultyAt(entityToSpawn.blockPosition()), MobSpawnType.MOB_SUMMONED, null, null);
world.addFreshEntity(entityToSpawn);
Thanks for your help because for time I am hard thinking to remove the error.
Edited by Le lance Flamer on Thu, 06/30/2022 - 20:15
Oh, I found how to do it:
1. In the command's procedure, open its code and put under the "execute" method (If you copy & paste, check each classes if they are imported. If not, re-enter the name of the class):
2. In the "execute" method, remove all code except the "execute" method and its parameters and then put a try-catch with the private method you created (spawnEntity) (see code below):
Tell me if any errors occur, I can fix them for you. AND ALSO DON'T FORGET TO SAVE AND LOCK THE CODE FOR MCREATOR OR THE CODE WON'T BE CHANGED!!!!