Jump to content

[1.10.2] Entity that riding player doesn't work?


lamp3345

Recommended Posts

I've make a block that will spawn entity and ride to the player when destroy it, but this seem to not work anymore.

 

Code :

    @Override
    public void onBlockDestroyedByPlayer(World world, BlockPos pos, IBlockState state)
    {
        if (!world.isRemote)
        {
            if (world.rand.nextInt(5) == 0)
            {
                EntityJuicer juicer = new EntityJuicer(world);
                juicer.setLocationAndAngles(pos.getX() + 0.5D, pos.getY() + 1.0D, pos.getZ() + 0.5D, 0.0F, 0.0F);
                world.spawnEntityInWorld(juicer);
            }
            if (world.rand.nextInt(10) == 0)
            {
                double radiusPlayer = 5.0D;
                List<EntityPlayer> playerList = world.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(pos.getX() - radiusPlayer, pos.getY() - radiusPlayer, pos.getZ() - radiusPlayer, pos.getX() + radiusPlayer, pos.getY() + radiusPlayer, pos.getZ() + radiusPlayer));

                if (!playerList.isEmpty())
                {
                    for (EntityPlayer player : playerList)
                    {
                        EntityJuicer juicer = new EntityJuicer(world);
                        juicer.setLocationAndAngles(pos.getX() + 0.5D, pos.getY() + 1.0D, pos.getZ() + 0.5D, 0.0F, 0.0F);
                        world.spawnEntityInWorld(juicer);
                        juicer.startRiding(player);
                    }
                }
            }
        }
    }

 

Edited by lamp3345
Link to comment
Share on other sites

  • 4 weeks later...

When break the block, EntityJuicer will ride to the nearby player. This work perfectly in 1.8.9 but its broken in 1.10.2.

 

Current method that I used.

    @Override
    public void onBlockDestroyedByPlayer(World world, BlockPos pos, IBlockState state)
    {
        EntityPlayer player = world.getClosestPlayer(pos.getX(), pos.getY(), pos.getZ(), 5, false);
        
        if (!world.isRemote)
        {
//            if (world.rand.nextInt(5) == 0)
//            {
//                EntityJuicer juicer = new EntityJuicer(world);
//                juicer.setLocationAndAngles(pos.getX() + 0.5D, pos.getY() + 1.0D, pos.getZ() + 0.5D, 0.0F, 0.0F);
//                world.spawnEntityInWorld(juicer);
//            }
            //if (world.rand.nextInt(10) == 0)
            {
//                double radiusPlayer = 5.0D;
//                List<EntityPlayer> playerList = world.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(pos.getX() - radiusPlayer, pos.getY() - radiusPlayer, pos.getZ() - radiusPlayer, pos.getX() + radiusPlayer, pos.getY() + radiusPlayer, pos.getZ() + radiusPlayer));
//
//                if (!playerList.isEmpty())
//                {
//                    for (EntityPlayer player : playerList)
//                    {
//                        EntityJuicer juicer = new EntityJuicer(world);
//                        juicer.setLocationAndAngles(pos.getX() + 0.5D, pos.getY() + 1.0D, pos.getZ() + 0.5D, 0.0F, 0.0F);
//                        world.spawnEntityInWorld(juicer);
//                        juicer.startRiding(player, true);
//                    }
//                }
              EntityJuicer juicer = new EntityJuicer(world);
              juicer.setLocationAndAngles(pos.getX() + 0.5D, pos.getY() + 1.0D, pos.getZ() + 0.5D, 0.0F, 0.0F);
              juicer.startRiding(player, true);
              world.spawnEntityInWorld(juicer);

              //juicer.startRiding(player, true);
            }
        }
    }

 

Link to comment
Share on other sites

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.