|
@@ -36,25 +36,19 @@ public class EntityCommands {
|
|
|
@SuppressWarnings("unchecked")
|
|
|
public static void registerFunctions(ScriptManager sm, SnuviScheduler scheduler) {
|
|
|
sm.registerConsumer("entity.setnopickup", (sc, in) -> {
|
|
|
- ((AbstractArrowEntity) in[0].get(sc)).pickupStatus =
|
|
|
- AbstractArrowEntity.PickupStatus.DISALLOWED;
|
|
|
+ ((AbstractArrowEntity) in[0].get(sc)).pickupStatus = AbstractArrowEntity.PickupStatus.DISALLOWED;
|
|
|
});
|
|
|
- sm.registerFunction("entity.shootprojectile",
|
|
|
- (sc, in) -> launchProjectile((LivingEntity) in[0].get(sc),
|
|
|
- getNamedClass(in[1].getString(sc)), in[2].getDouble(sc),
|
|
|
- in.length >= 4 ? in[3].get(sc) : null));
|
|
|
+ sm.registerFunction("entity.shootprojectile", (sc, in) -> launchProjectile((LivingEntity) in[0].get(sc),
|
|
|
+ getNamedClass(in[1].getString(sc)), in[2].getDouble(sc), in.length >= 4 ? in[3].get(sc) : null));
|
|
|
sm.registerFunction("entity.isblocking",
|
|
|
(sc, in) -> ((LivingEntity) in[0].get(sc)).isActiveItemStackBlocking());
|
|
|
- sm.registerFunction("entity.getarmorthoughness", (sc, in) -> ((LivingEntity) in[0].get(sc))
|
|
|
- .getAttribute(Attributes.ARMOR_TOUGHNESS).getValue());
|
|
|
+ sm.registerFunction("entity.getarmorthoughness",
|
|
|
+ (sc, in) -> ((LivingEntity) in[0].get(sc)).getAttribute(Attributes.ARMOR_TOUGHNESS).getValue());
|
|
|
sm.registerFunction("entity.getarmor",
|
|
|
(sc, in) -> (double) ((LivingEntity) in[0].get(sc)).getTotalArmorValue());
|
|
|
- sm.registerFunction("entity.getenchantmentmodifier",
|
|
|
- (sc, in) -> EnchantmentHelper.getEnchantmentModifierDamage(
|
|
|
- ((LivingEntity) in[0].get(sc)).getArmorInventoryList(),
|
|
|
- (DamageSource) in[1].get(sc)));
|
|
|
- sm.registerConsumer("entity.setburning",
|
|
|
- (sc, in) -> ((Entity) in[0].get(sc)).forceFireTicks(in[1].getInt(sc)));
|
|
|
+ sm.registerFunction("entity.getenchantmentmodifier", (sc, in) -> EnchantmentHelper.getEnchantmentModifierDamage(
|
|
|
+ ((LivingEntity) in[0].get(sc)).getArmorInventoryList(), (DamageSource) in[1].get(sc)));
|
|
|
+ sm.registerConsumer("entity.setburning", (sc, in) -> ((Entity) in[0].get(sc)).forceFireTicks(in[1].getInt(sc)));
|
|
|
sm.registerFunction("entity.isburning", (sc, in) -> ((Entity) in[0].get(sc)).isBurning());
|
|
|
sm.registerFunction("entity.getlook", (sc, in) -> {
|
|
|
Object[] o = new Object[3];
|
|
@@ -64,6 +58,14 @@ public class EntityCommands {
|
|
|
o[2] = v.z;
|
|
|
return o;
|
|
|
});
|
|
|
+ sm.registerFunction("entity.getmotion", (sc, in) -> {
|
|
|
+ Object[] o = new Object[3];
|
|
|
+ Vector3d v = ((Entity) in[0].get(sc)).getMotion();
|
|
|
+ o[0] = v.x;
|
|
|
+ o[1] = v.y;
|
|
|
+ o[2] = v.z;
|
|
|
+ return o;
|
|
|
+ });
|
|
|
sm.registerFunction("entity.getlocation", (sc, in) -> new Location((Entity) in[0].get(sc)));
|
|
|
sm.registerConsumer("entity.heal", (sc, in) -> {
|
|
|
LivingEntity liv = (LivingEntity) in[0].get(sc);
|
|
@@ -73,36 +75,32 @@ public class EntityCommands {
|
|
|
sm.registerConsumer("entity.damage", (sc, in) -> {
|
|
|
LivingEntity liv = (LivingEntity) in[0].get(sc);
|
|
|
float damage = in[1].getFloat(sc);
|
|
|
- DamageSource damageSource =
|
|
|
- (in.length >= 3) ? (DamageSource) in[2].get(sc) : DamageSource.GENERIC;
|
|
|
+ DamageSource damageSource = (in.length >= 3) ? (DamageSource) in[2].get(sc) : DamageSource.GENERIC;
|
|
|
scheduler.scheduleTask(() -> liv.attackEntityFrom(damageSource, damage));
|
|
|
});
|
|
|
sm.registerFunction("entity.fromsource", (sc, in) -> {
|
|
|
DamageSource ds = (DamageSource) in[0].get(sc);
|
|
|
Entity ent = ds.getTrueSource();
|
|
|
- if(ent == null) {
|
|
|
+ if (ent == null) {
|
|
|
return ds.getImmediateSource();
|
|
|
}
|
|
|
return ent;
|
|
|
});
|
|
|
sm.registerAlias("damage.get", "entity.getdamagesource");
|
|
|
- sm.registerFunction("entity.getmaxhealth",
|
|
|
- (sc, in) -> (double) ((LivingEntity) in[0].get(sc)).getMaxHealth());
|
|
|
- sm.registerFunction("entity.gethealth",
|
|
|
- (sc, in) -> (double) ((LivingEntity) in[0].get(sc)).getHealth());
|
|
|
+ sm.registerFunction("entity.getmaxhealth", (sc, in) -> (double) ((LivingEntity) in[0].get(sc)).getMaxHealth());
|
|
|
+ sm.registerFunction("entity.gethealth", (sc, in) -> (double) ((LivingEntity) in[0].get(sc)).getHealth());
|
|
|
sm.registerConsumer("entity.sethealth",
|
|
|
(sc, in) -> ((LivingEntity) in[0].get(sc)).setHealth(in[1].getFloat(sc)));
|
|
|
sm.registerConsumer("entity.setname", (sc, in) -> {
|
|
|
Entity ent = (Entity) in[0].get(sc);
|
|
|
ent.setCustomName(new StringTextComponent(in[1].getString(sc)));
|
|
|
- if(in.length >= 3) {
|
|
|
+ if (in.length >= 3) {
|
|
|
ent.setCustomNameVisible(in[2].getBoolean(sc));
|
|
|
return;
|
|
|
}
|
|
|
ent.setCustomNameVisible(false);
|
|
|
});
|
|
|
- sm.registerFunction("entity.getname",
|
|
|
- (sc, in) -> ((Entity) in[0].get(sc)).getDisplayName().getString());
|
|
|
+ sm.registerFunction("entity.getname", (sc, in) -> ((Entity) in[0].get(sc)).getDisplayName().getString());
|
|
|
sm.registerConsumer("entity.throw", (sc, in) -> {
|
|
|
Entity ent = (Entity) in[0].get(sc);
|
|
|
ent.setMotion(in[1].getDouble(sc), in[2].getDouble(sc), in[3].getDouble(sc));
|
|
@@ -111,14 +109,14 @@ public class EntityCommands {
|
|
|
sm.registerConsumer("entity.teleport", (sc, in) -> {
|
|
|
Entity ent = (Entity) in[0].get(sc);
|
|
|
Location l = (Location) in[1].get(sc);
|
|
|
- if(l.getWorld() == null) {
|
|
|
+ if (l.getWorld() == null) {
|
|
|
throw new IllegalArgumentException("world must not be null");
|
|
|
}
|
|
|
- if(ent instanceof ServerPlayerEntity) {
|
|
|
+ if (ent instanceof ServerPlayerEntity) {
|
|
|
ServerPlayerEntity p = (ServerPlayerEntity) ent;
|
|
|
|
|
|
p.stopRiding();
|
|
|
- if(p.isSleeping()) {
|
|
|
+ if (p.isSleeping()) {
|
|
|
p.stopSleepInBed(true, true);
|
|
|
}
|
|
|
|
|
@@ -126,7 +124,7 @@ public class EntityCommands {
|
|
|
float pitch = l.getPitch() != 0.0f ? l.getPitch() : ent.rotationPitch;
|
|
|
p.teleport((ServerWorld) l.getWorld(), l.getX(), l.getY(), l.getZ(), yaw, pitch);
|
|
|
} else {
|
|
|
- if(ent.world != l.getWorld()) {
|
|
|
+ if (ent.world != l.getWorld()) {
|
|
|
ServerWorld ws = (ServerWorld) l.getWorld();
|
|
|
ent.changeDimension(ws);
|
|
|
}
|
|
@@ -177,14 +175,13 @@ public class EntityCommands {
|
|
|
return ItemStack.EMPTY;
|
|
|
});
|
|
|
sm.registerConsumer("entity.removeall", (sc, in) -> {
|
|
|
- Class<? extends Entity> c =
|
|
|
- (Class<? extends Entity>) getNamedClass(in[0].getString(sc));
|
|
|
- if(c == Entity.class) {
|
|
|
+ Class<? extends Entity> c = (Class<? extends Entity>) getNamedClass(in[0].getString(sc));
|
|
|
+ if (c == Entity.class) {
|
|
|
return;
|
|
|
}
|
|
|
Location l = (Location) in[1].get(sc);
|
|
|
- Utils.getEntities(l.getWorld(), l.getX(), l.getY(), l.getZ(), in[2].getDouble(sc), c)
|
|
|
- .stream().forEach(ent -> {
|
|
|
+ Utils.getEntities(l.getWorld(), l.getX(), l.getY(), l.getZ(), in[2].getDouble(sc), c).stream()
|
|
|
+ .forEach(ent -> {
|
|
|
ent.remove();
|
|
|
});
|
|
|
});
|
|
@@ -207,15 +204,14 @@ public class EntityCommands {
|
|
|
sm.registerConsumer("entity.addeffect", (sc, in) -> {
|
|
|
LivingEntity base = (LivingEntity) in[0].get(sc);
|
|
|
Effect potion = Mapper.getPotion(in[1].getString(sc));
|
|
|
- if(potion == null) { // doing this only to prevent EffectInstance doing shit
|
|
|
+ if (potion == null) { // doing this only to prevent EffectInstance doing shit
|
|
|
throw new IllegalArgumentException("potion does not exist");
|
|
|
}
|
|
|
- if(base.isPotionActive(potion)) {
|
|
|
+ if (base.isPotionActive(potion)) {
|
|
|
base.removePotionEffect(potion);
|
|
|
}
|
|
|
boolean showParticles = in.length >= 5 ? in[4].getBoolean(sc) : true;
|
|
|
- base.addPotionEffect(new EffectInstance(potion, in[2].getInt(sc), in[3].getInt(sc),
|
|
|
- false, showParticles));
|
|
|
+ base.addPotionEffect(new EffectInstance(potion, in[2].getInt(sc), in[3].getInt(sc), false, showParticles));
|
|
|
});
|
|
|
sm.registerConsumer("entity.cleareffects", (sc, in) -> {
|
|
|
((LivingEntity) in[0].get(sc)).clearActivePotions();
|
|
@@ -239,9 +235,8 @@ public class EntityCommands {
|
|
|
return Utils.getEntity(l.getWorld(), l.getX(), l.getY(), l.getZ(), in[1].getDouble(sc),
|
|
|
(Class<? extends Entity>) getNamedClass(in[2].getString(sc)));
|
|
|
});
|
|
|
- sm.registerFunction("entity.getpotiontype",
|
|
|
- (sc, in) -> PotionUtils.getPotionFromItem(((PotionEntity) in[0].get(sc)).getItem())
|
|
|
- .getRegistryName().toString());
|
|
|
+ sm.registerFunction("entity.getpotiontype", (sc, in) -> PotionUtils
|
|
|
+ .getPotionFromItem(((PotionEntity) in[0].get(sc)).getItem()).getRegistryName().toString());
|
|
|
sm.registerConsumer("entity.setgravity", (sc, in) -> {
|
|
|
((Entity) in[0].get(sc)).setNoGravity(!in[1].getBoolean(sc));
|
|
|
});
|
|
@@ -252,121 +247,109 @@ public class EntityCommands {
|
|
|
sm.registerFunction("entity.spawn", (sc, in) -> {
|
|
|
ResourceLocation type = new ResourceLocation(in[0].getString(sc));
|
|
|
Location l = (Location) in[1].get(sc);
|
|
|
- if(!World.isInvalidPosition(l.getBlockPos())) {
|
|
|
+ if (!World.isInvalidPosition(l.getBlockPos())) {
|
|
|
return null;
|
|
|
}
|
|
|
- CompoundNBT nbt = in.length >= 3 ? JsonToNBT.getTagFromJson(in[2].getString(sc))
|
|
|
- : new CompoundNBT();
|
|
|
+ CompoundNBT nbt = in.length >= 3 ? JsonToNBT.getTagFromJson(in[2].getString(sc)) : new CompoundNBT();
|
|
|
nbt.putString("id", type.toString());
|
|
|
ServerWorld sw = (ServerWorld) l.getWorld();
|
|
|
Entity ent = EntityType.loadEntityAndExecute(nbt, sw, (e) -> {
|
|
|
- e.setLocationAndAngles(l.getX(), l.getY(), l.getZ(), e.rotationYaw,
|
|
|
- e.rotationPitch);
|
|
|
+ e.setLocationAndAngles(l.getX(), l.getY(), l.getZ(), e.rotationYaw, e.rotationPitch);
|
|
|
return e;
|
|
|
});
|
|
|
- if(ent == null) {
|
|
|
+ if (ent == null) {
|
|
|
return ent;
|
|
|
}
|
|
|
- if(ent instanceof MobEntity) {
|
|
|
+ if (ent instanceof MobEntity) {
|
|
|
((MobEntity) ent).onInitialSpawn(sw, sw.getDifficultyForLocation(ent.getPosition()),
|
|
|
SpawnReason.COMMAND, null, null);
|
|
|
}
|
|
|
- if(!sw.func_242106_g(ent)) {
|
|
|
+ if (!sw.func_242106_g(ent)) {
|
|
|
return null;
|
|
|
}
|
|
|
return ent;
|
|
|
});
|
|
|
sm.registerFunction("entity.near", (sc, in) -> {
|
|
|
Object o = in[0].get(sc);
|
|
|
- if(o instanceof Location) {
|
|
|
+ if (o instanceof Location) {
|
|
|
return Utils.getEntities((Location) o, in[1].getDouble(sc));
|
|
|
}
|
|
|
return Utils.getEntities((Entity) o, in[1].getDouble(sc));
|
|
|
});
|
|
|
sm.registerConsumer("entity.setspeed", (sc, in) -> {
|
|
|
- ((LivingEntity) in[0].get(sc)).getAttribute(Attributes.MOVEMENT_SPEED)
|
|
|
- .setBaseValue(in[1].getDouble(sc));
|
|
|
+ ((LivingEntity) in[0].get(sc)).getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(in[1].getDouble(sc));
|
|
|
});
|
|
|
sm.registerConsumer("entity.setgrowingage", (sc, in) -> {
|
|
|
((AgeableEntity) in[0].get(sc)).setGrowingAge(in[1].getInt(sc));
|
|
|
});
|
|
|
sm.registerFunction("entity.gettype",
|
|
|
(sc, in) -> ((Entity) in[0].get(sc)).getType().getRegistryName().getPath());
|
|
|
- sm.registerFunction("entity.issneaking",
|
|
|
- (sc, in) -> ((Entity) in[0].get(sc)).isCrouching());
|
|
|
- sm.registerFunction("entity.issneaking",
|
|
|
- (sc, in) -> ((Entity) in[0].get(sc)).isCrouching());
|
|
|
- sm.registerFunction("sheep.issheared",
|
|
|
- (sc, in) -> ((SheepEntity) in[0].get(sc)).getSheared());
|
|
|
- sm.registerFunction("sheep.getcolor",
|
|
|
- (sc, in) -> ((SheepEntity) in[0].get(sc)).getFleeceColor().toString());
|
|
|
- sm.registerConsumer("creeper.explode",
|
|
|
- (sc, in) -> ((CreeperEntity) in[0].get(sc)).ignite());
|
|
|
+ sm.registerFunction("entity.issneaking", (sc, in) -> ((Entity) in[0].get(sc)).isCrouching());
|
|
|
+ sm.registerFunction("entity.issneaking", (sc, in) -> ((Entity) in[0].get(sc)).isCrouching());
|
|
|
+ sm.registerFunction("sheep.issheared", (sc, in) -> ((SheepEntity) in[0].get(sc)).getSheared());
|
|
|
+ sm.registerFunction("sheep.getcolor", (sc, in) -> ((SheepEntity) in[0].get(sc)).getFleeceColor().toString());
|
|
|
+ sm.registerConsumer("creeper.explode", (sc, in) -> ((CreeperEntity) in[0].get(sc)).ignite());
|
|
|
sm.registerFunction("pet.istamed", (sc, in) -> ((TameableEntity) in[0].get(sc)).isTamed());
|
|
|
sm.registerConsumer("pet.settamed", (sc, in) -> {
|
|
|
TameableEntity t = (TameableEntity) in[0].get(sc);
|
|
|
boolean b = in[1].getBoolean(sc);
|
|
|
- if(b) {
|
|
|
+ if (b) {
|
|
|
t.setTamedBy((PlayerEntity) in[2].get(sc));
|
|
|
}
|
|
|
t.setTamed(b);
|
|
|
});
|
|
|
- sm.registerFunction("pet.getowner",
|
|
|
- (sc, in) -> ((TameableEntity) in[0].get(sc)).getOwner());
|
|
|
+ sm.registerFunction("pet.getowner", (sc, in) -> ((TameableEntity) in[0].get(sc)).getOwner());
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
- private static <T> T launchProjectile(LivingEntity liv, Class<? extends T> projectile,
|
|
|
- double scale, Object data) {
|
|
|
+ private static <T> T launchProjectile(LivingEntity liv, Class<? extends T> projectile, double scale, Object data) {
|
|
|
World w = liv.world;
|
|
|
Entity launch = null;
|
|
|
|
|
|
- if(EntityItemProjectile.class == projectile) {
|
|
|
- if(data == null) {
|
|
|
+ if (EntityItemProjectile.class == projectile) {
|
|
|
+ if (data == null) {
|
|
|
throw new NullPointerException("Data musn't be null for EntityItemProjectile");
|
|
|
}
|
|
|
ItemStack stack = (ItemStack) data;
|
|
|
- if(stack.isEmpty()) {
|
|
|
+ if (stack.isEmpty()) {
|
|
|
throw new IllegalArgumentException("Empty ItemStack not allowed here");
|
|
|
}
|
|
|
launch = new EntityItemProjectile(liv, stack.copy());
|
|
|
- ((EntityItemProjectile) launch).setHeadingFromThrower(liv, liv.rotationPitch,
|
|
|
- liv.rotationYaw, 0.0f, 1.5f, 1.0f);
|
|
|
- } else if(SnowballEntity.class == projectile) {
|
|
|
+ ((EntityItemProjectile) launch).setHeadingFromThrower(liv, liv.rotationPitch, liv.rotationYaw, 0.0f, 1.5f,
|
|
|
+ 1.0f);
|
|
|
+ } else if (SnowballEntity.class == projectile) {
|
|
|
launch = new SnowballEntity(w, liv);
|
|
|
((SnowballEntity) launch).shoot(liv.rotationPitch, liv.rotationYaw, 0.0f, 1.5f, 1.0f);
|
|
|
- } else if(EggEntity.class == projectile) {
|
|
|
+ } else if (EggEntity.class == projectile) {
|
|
|
launch = new EggEntity(w, liv);
|
|
|
((EggEntity) launch).shoot(liv.rotationPitch, liv.rotationYaw, 0.0f, 1.5f, 1.0f);
|
|
|
- } else if(EnderPearlEntity.class == projectile) {
|
|
|
+ } else if (EnderPearlEntity.class == projectile) {
|
|
|
launch = new EnderPearlEntity(w, liv);
|
|
|
((EnderPearlEntity) launch).shoot(liv.rotationPitch, liv.rotationYaw, 0.0f, 1.5f, 1.0f);
|
|
|
- } else if(PotionEntity.class == projectile) {
|
|
|
+ } else if (PotionEntity.class == projectile) {
|
|
|
launch = new PotionEntity(w, liv);
|
|
|
((PotionEntity) launch).setItem((ItemStack) data);
|
|
|
((PotionEntity) launch).shoot(liv.rotationPitch, liv.rotationYaw, -20.0f, 0.5f, 1.0f);
|
|
|
- } else if(ExperienceBottleEntity.class == projectile) {
|
|
|
+ } else if (ExperienceBottleEntity.class == projectile) {
|
|
|
launch = new ExperienceBottleEntity(w, liv);
|
|
|
- ((ExperienceBottleEntity) launch).shoot(liv.rotationPitch, liv.rotationYaw, -20.0f,
|
|
|
- 0.7f, 1.0f);
|
|
|
- } else if(AbstractArrowEntity.class.isAssignableFrom(projectile)) {
|
|
|
- if(SpectralArrowEntity.class == projectile) {
|
|
|
+ ((ExperienceBottleEntity) launch).shoot(liv.rotationPitch, liv.rotationYaw, -20.0f, 0.7f, 1.0f);
|
|
|
+ } else if (AbstractArrowEntity.class.isAssignableFrom(projectile)) {
|
|
|
+ if (SpectralArrowEntity.class == projectile) {
|
|
|
launch = new SpectralArrowEntity(w, liv);
|
|
|
} else {
|
|
|
launch = new ArrowEntity(w, liv);
|
|
|
- if(data != null) {
|
|
|
+ if (data != null) {
|
|
|
((ArrowEntity) launch).setPotionEffect((ItemStack) data);
|
|
|
}
|
|
|
}
|
|
|
- ((AbstractArrowEntity) launch).shoot(liv.rotationPitch, liv.rotationYaw, 0.0F, 3.0F,
|
|
|
- 1.0F);
|
|
|
- } else if(DamagingProjectileEntity.class.isAssignableFrom(projectile)) {
|
|
|
+ ((AbstractArrowEntity) launch).shoot(liv.rotationPitch, liv.rotationYaw, 0.0F, 3.0F, 1.0F);
|
|
|
+ } else if (DamagingProjectileEntity.class.isAssignableFrom(projectile)) {
|
|
|
Vector3d v = liv.getLookVec().scale(10);
|
|
|
- if(SmallFireballEntity.class == projectile) {
|
|
|
+ if (SmallFireballEntity.class == projectile) {
|
|
|
launch = new SmallFireballEntity(w, liv, v.x, v.y, v.z);
|
|
|
- } else if(WitherSkullEntity.class == projectile) {
|
|
|
+ } else if (WitherSkullEntity.class == projectile) {
|
|
|
launch = new WitherSkullEntity(w, liv, v.x, v.y, v.z);
|
|
|
- } else if(DragonFireballEntity.class == projectile) {
|
|
|
+ } else if (DragonFireballEntity.class == projectile) {
|
|
|
launch = new DragonFireballEntity(w, liv, v.x, v.y, v.z);
|
|
|
} else {
|
|
|
launch = new FireballEntity(w, liv, v.x, v.y, v.z);
|