Jump to content

Recommended Posts

Posted

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;
                    }
                }
            }
        }
    }
}

Posted

Check out what the levitation potion does.

 

I tried looking for that, but I could not find the class for it in the vanilla library.

Posted

There is no class. The Potion instance is stored in

MobEffects.LEVITATION

. Search for where that is used.

 

I realized that after following the usages in the potion class. Thank you.

Posted

Stop using static variables any class-level variables at all inside your item class.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Stop using static variables any class-level variables at all inside your item class.

 

I was using some of the variables for tick calculations in some other class and never set them back. Thank you for reminding me.

 

Now that I look at it again, all your code is only running client side. This is bad.

 

Would you mind explaining to me how to make things run server side? I took some recommendations from a friend while writing this -- mostly on checking if the world is remote, which is what I am assuming is the issue.

EDIT: I changed world.isRemote to !world.isRemote and everything works as intended now.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.