Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
- long currentTime = System.currentTimeMillis();
- if (currentTime - lastUsedTime < 30000) { // 30-second delay
- return new InteractionResultHolder<>(InteractionResult.FAIL, player.getItemInHand(hand));
- }
- // Get all entities in the world
- 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));
- Entity nearestEntity = null;
- double nearestDistance = Double.MAX_VALUE;
- // Iterate through the entities to find the nearest one to the player
- for (Entity entity : entities) {
- double distance = player.distanceTo(entity);
- if (distance < nearestDistance) {
- nearestEntity = entity;
- nearestDistance = distance;
- }
- }
- if (nearestEntity != null) {
- // Get the position of the nearest entity
- Vec3 entityPos = nearestEntity.position();
- // Spawn green, purple, and blue smoke particles at the position of the nearest entity
- for (int i = 0; i < 50; i++) {
- world.addParticle(ParticleTypes.ENTITY_EFFECT,
- entityPos.x(), entityPos.y(), entityPos.z(),
- Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5
- );
- }
- // Apply damage to the nearest entity
- if (nearestEntity instanceof LivingEntity) {
- nearestEntity.hurt(DamageSource.playerAttack(player).bypassArmor(), 15f);
- }
- // Update the last used time
- lastUsedTime = currentTime;
- return new InteractionResultHolder<>(InteractionResult.SUCCESS, player.getItemInHand(hand));
- }
- return super.use(world, player, hand);
- }
Advertisement
Add Comment
Please, Sign In to add comment