How to make a procedure when you eat a food, it teleport the player to a random location, similar to a chorus fruit

Started by Canadian_Gamer23 on

Topic category: Help with Minecraft modding (Java Edition)

Joined Jul 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to make a procedure when you eat a food, it teleport the player to a random location, similar to a chorus fruit

In my mod, I made item called Chorus Salad, and I want to know how do I make a procedure where when eaten by the player, it teleport the to a random location. Like a chorus fruit. I tried looking for the code of the chorus fruit, couldn't find it. I really need some help with this. Thank you!

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
maybe the /spreadplayers…
Thu, 08/06/2020 - 03:57

maybe the /spreadplayers command (I think that's what it is)

Joined Jul 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
It did not work, so I still…
Fri, 08/14/2020 - 00:45

It did not work, so I still need some help 

 

Joined Jun 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I found the code chorus…
Sun, 08/16/2020 - 09:53

I found the code chorus fruit uses:

   public ItemStack onItemUseFinish(ItemStack stack, World worldIn, LivingEntity entityLiving) {
      ItemStack itemstack = super.onItemUseFinish(stack, worldIn, entityLiving);
      if (!worldIn.isRemote) {
         double d0 = entityLiving.getPosX();
         double d1 = entityLiving.getPosY();
         double d2 = entityLiving.getPosZ();

         for(int i = 0; i < 16; ++i) {
            double d3 = entityLiving.getPosX() + (entityLiving.getRNG().nextDouble() - 0.5D) * 16.0D;
            double d4 = MathHelper.clamp(entityLiving.getPosY() + (double)(entityLiving.getRNG().nextInt(16) - 8), 0.0D, (double)(worldIn.getActualHeight() - 1));
            double d5 = entityLiving.getPosZ() + (entityLiving.getRNG().nextDouble() - 0.5D) * 16.0D;
            if (entityLiving.isPassenger()) {
               entityLiving.stopRiding();
            }

            if (entityLiving.attemptTeleport(d3, d4, d5, true)) {
               worldIn.playSound((PlayerEntity)null, d0, d1, d2, SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, SoundCategory.PLAYERS, 1.0F, 1.0F);
               entityLiving.playSound(SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, 1.0F, 1.0F);
               break;
            }
         }

         if (entityLiving instanceof PlayerEntity) {
            ((PlayerEntity)entityLiving).getCooldownTracker().setCooldown(this, 20);
         }
      }

      return itemstack;
   }

 

Joined Jun 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
how would this be…
Wed, 08/19/2020 - 00:17

how would this be implemented into a mod? would u create a procedure and then and the code into it?