Guest User

Code

a guest
Apr 22nd, 2023
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.01 KB | None | 0 0
  1.     @Override
  2.     public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
  3.         long currentTime = System.currentTimeMillis();
  4.         if (currentTime - lastUsedTime < 30000) { // 30-second delay
  5.             return new InteractionResultHolder<>(InteractionResult.FAIL, player.getItemInHand(hand));
  6.         }
  7.  
  8.         // Get all entities in the world
  9.         List<Entity> entities = world.getEntities(player, new AABB(player.getX() - 10.0, player.getY() - 10.0, player.getZ() - 10.0, player.getX() + 10.0, player.getY() + 10.0, player.getZ() + 10.0));
  10.  
  11.         Entity nearestEntity = null;
  12.         double nearestDistance = Double.MAX_VALUE;
  13.  
  14.         // Iterate through the entities to find the nearest one to the player
  15.         for (Entity entity : entities) {
  16.             double distance = player.distanceTo(entity);
  17.             if (distance < nearestDistance) {
  18.                 nearestEntity = entity;
  19.                 nearestDistance = distance;
  20.             }
  21.         }
  22.  
  23.         if (nearestEntity != null) {
  24.             // Get the position of the nearest entity
  25.             Vec3 entityPos = nearestEntity.position();
  26.  
  27.             // Spawn green, purple, and blue smoke particles at the position of the nearest entity
  28.             for (int i = 0; i < 50; i++) {
  29.                 world.addParticle(ParticleTypes.ENTITY_EFFECT,
  30.                         entityPos.x(), entityPos.y(), entityPos.z(),
  31.                         Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5
  32.                 );
  33.             }
  34.  
  35.             // Apply damage to the nearest entity
  36.             if (nearestEntity instanceof LivingEntity) {
  37.                 nearestEntity.hurt(DamageSource.playerAttack(player).bypassArmor(), 15f);
  38.             }
  39.  
  40.             // Update the last used time
  41.             lastUsedTime = currentTime;
  42.             return new InteractionResultHolder<>(InteractionResult.SUCCESS, player.getItemInHand(hand));
  43.         }
  44.  
  45.         return super.use(world, player, hand);
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment