I am trying to levitate entities that are within a radius from the player when a related item is right clicked with (not yet implemented -- currently tries to levitate as soon as a mob is within the radius).
The idea is to gradually move them into a position that is two blocks above the player, but no mobs seem to be reacting to EntityMob#motionY.
If I use EntityMob#setPositionAndUpdate they will jerk between their original location and the new location every time the AI tries to preform a task.
Another implementation I am planning is to have any mobs that are being levitated to move synchronously with the player, if anyone has insight on that. Not necessarily the actual code, but a rough idea on how to accomplish it.
public class ItemFissuredLimiter extends Item
{
public ItemFissuredLimiter()
{
setMaxStackSize(1);
setCreativeTab(KinesisReference.KINESIS_TAB);
}
public static int grabRadius = 5; // Blocks.
public static int grabLimit = 5; // Mobs.
public static int grabDuration = 10; // Seconds.
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand)
{
return super.onItemRightClick(itemStackIn, worldIn, playerIn, hand);
}
@Override
public void onUpdate(ItemStack itemStackIn, World worldIn, Entity entity, int someInt, boolean someBoolean)
{
EntityPlayer playerIn = (EntityPlayer) entity;
if(worldIn.isRemote && playerIn.getHeldItemMainhand() == itemStackIn)
{
// Create bounds around the player, based on the grab radius of the limiter, to check for entities in.
double playerX = playerIn.getPosition().getX();
double playerY = playerIn.getPosition().getY();
double playerZ = playerIn.getPosition().getZ();
int radiusHeightDifference = grabRadius - KinesisReference.PLAYER_HEIGHT;
BlockPos posMin = new BlockPos(playerX - grabRadius, playerY - grabRadius, playerZ - grabRadius);
BlockPos posMax = new BlockPos(playerX + grabRadius, playerY + radiusHeightDifference, playerZ + grabRadius);
AxisAlignedBB radiusBox = new AxisAlignedBB(posMin, posMax);
// Check for entities that are both in the grab radius and are mobs.
List<EntityMob> mobsInRadius = worldIn.getEntitiesWithinAABB(EntityMob.class, radiusBox);
// Levitate entities that are within the required radius while restrictions are not yet met.
for(EntityMob mob : mobsInRadius)
{
// Don't levitate boss mobs, that is silly.
if(mob.isNonBoss())
{
double mobX = mob.getPosition().getX();
double mobY = mob.getPosition().getY();
double mobZ = mob.getPosition().getZ();
System.out.println(mob);
System.out.println(mob.motionY);
mob.fallDistance = 0;
if(mobY < playerY + 2)
{
mob.motionY = 0.2;
}
if(mobY > playerY + 2)
{
mob.motionY = -0.2;
}
}
}
}
}
}