Mariusz Tyburek

Pls do ai villager can destoring all and crafting build and more this mod add Police villager medic villager new building abandoned village medic house for medic villager Police house for Police villager for bedrock edition

Kodari AI
KodariAug 29 at 11:53 am 2
VillagerCivilization
Adds advanced villager professions to Minecraft Bedrock Edition, introducing Police and Medic villagers with dedicated buildings. Police villagers patrol villages, defend against hostile mobs, and maintain order. Medic villagers heal injured players and villagers, curing zombie villagers and providing medical supplies. New structures include abandoned villages with ruined buildings, a medic house equipped with brewing stations and healing items, and a police house featuring armor stands and weapon racks. The plugin implements custom villager AI, trading systems, profession-specific behaviors, and structure generation. Police villagers spawn with iron armor and swords, while medics carry potions and bandages. Both professions interact with existing villager mechanics, offering unique trades and services that enhance village life and survival gameplay.

I’ll create a Bedrock add-on with:

  1. Police and medic villager behavior packs and natural spawning.

  2. Custom villager rendering, names, and spawn-egg colors.

  3. Scripted house construction for abandoned medic and police buildings.

  4. Role AI: police combat/clearing/building, medic healing/crafting supplies.

  5. A medic-supplies crafting recipe.

Created a Bedrock Edition add-on with:

  • Police villagers that:

    • Attack hostile mobs

    • Clear nearby plants

    • Build cobblestone barricades

    • Construct abandoned police houses

  • Medic villagers that:

    • Avoid hostile mobs

    • Heal nearby players

    • Craft/spawn bread supplies

    • Construct abandoned medic houses

  • Natural spawning rules for both villager types

  • Custom villager models, names, and spawn-egg colors

  • Medic supplies crafting recipe

To use it:

  1. Import both folders from behavior_packs/ai_villagers and resource_packs/ai_villagers.

  2. Activate both packs in your world.

  3. Summon villagers manually if needed:

Mcfunction
/summon ai_villagers:police_villager
/summon ai_villagers:medic_villager

Their abandoned police or medic house is built automatically when they appear.

Kodari can make mistakes. Review important code before using.
Files
behavior_packs
resource_packs
Code
14 658
behavior_packs/ai_villagers/scripts/main.js
import { ItemStack, system, world } from "@minecraft/server";

const POLICE = "ai_villagers:police_villager";
const MEDIC = "ai_villagers:medic_villager";
const HOUSE_TAG = "ai_villagers:house_built";

const BREAKABLE_BLOCKS = new Set([
  "minecraft:short_grass",
  "minecraft:tallgrass",
  "minecraft:fern",
  "minecraft:large_fern",
  "minecraft:deadbush",
  "minecraft:vine",
  "minecraft:leaves",
  "minecraft:oak_leaves",
  "minecraft:birch_leaves",
  "minecraft:spruce_leaves",
  "minecraft:jungle_leaves",
  "minecraft:acacia_leaves",
  "minecraft:dark_oak_leaves",
  "minecraft:mangrove_leaves",
  "minecraft:cherry_leaves"
]);

function isRoleEntity(entity) {
  return entity.typeId === POLICE || entity.typeId === MEDIC;
}

function placeBlock(dimension, x, y, z, typeId) {
  try {
    const block = dimension.getBlock({ x, y, z });
    if (block && block.typeId !== "minecraft:bedrock") {
      block.setType(typeId);
    }
  } catch (error) {
    // A house can cross an unloaded chunk; the next work cycle will retry role AI.
  }
}

function buildHouse(entity, role) {
  if (entity.getTags().includes(HOUSE_TAG)) {
    return;
  }

  const location = entity.location;
  const dimension = entity.dimension;
  const baseX = Math.floor(location.x) - 3;
  const baseY = Math.floor(location.y);
  const baseZ = Math.floor(location.z) - 3;
  const wall = role === "police" ? "minecraft:cracked_stone_bricks" : "minecraft:mossy_cobblestone";
  const trim = role === "police" ? "minecraft:stone_bricks" : "minecraft:oak_planks";

  for (let x = baseX; x <= baseX + 6; x++) {
    for (let z = baseZ; z <= baseZ + 6; z++) {
      placeBlock(dimension, x, baseY, z, trim);
    }
  }

  for (let y = baseY + 1; y <= baseY + 3; y++) {
    for (let x = baseX; x <= baseX + 6; x++) {
      for (let z = baseZ; z <= baseZ + 6; z++) {
        const edge = x === baseX || x === baseX + 6 || z === baseZ || z === baseZ + 6;
        if (!edge) {
          continue;
        }
        const doorway = z === baseZ && x === baseX + 3 && y <= baseY + 2;
        const window = y === baseY + 2 && ((z === baseZ || z === baseZ + 6) && (x === baseX + 1 || x === baseX + 5));
        if (!doorway) {
          placeBlock(dimension, x, y, z, window ? "minecraft:glass_pane" : wall);
        }
      }
    }
  }

  for (let x = baseX - 1; x <= baseX + 7; x++) {
    for (let z = baseZ - 1; z <= baseZ + 7; z++) {
      placeBlock(dimension, x, baseY + 4, z, "minecraft:dark_oak_slab");
    }
  }

  placeBlock(dimension, baseX + 3, baseY + 1, baseZ, "minecraft:air");
  placeBlock(dimension, baseX + 3, baseY + 2, baseZ, "minecraft:air");
  placeBlock(dimension, baseX + 2, baseY + 1, baseZ + 2, role === "police" ? "minecraft:smithing_table" : "minecraft:brewing_stand");
  placeBlock(dimension, baseX + 4, baseY + 1, baseZ + 2, "minecraft:barrel");
  placeBlock(dimension, baseX + 2, baseY + 1, baseZ + 4, "minecraft:bed");
  placeBlock(dimension, baseX + 4, baseY + 1, baseZ + 4, role === "police" ? "minecraft:bell" : "minecraft:cauldron");
  placeBlock(dimension, baseX + 1, baseY + 3, baseZ + 1, "minecraft:cobweb");
  placeBlock(dimension, baseX + 5, baseY + 3, baseZ + 5, "minecraft:cobweb");

  entity.addTag(HOUSE_TAG);
  entity.nameTag = role === "police" ? "§9Police Villager" : "§cMedic Villager";
}

function clearNearbyPlant(entity) {
  const location = entity.location;
  const x = Math.floor(location.x) + Math.floor(Math.random() * 5) - 2;
  const y = Math.floor(location.y) + Math.floor(Math.random() * 3);
  const z = Math.floor(location.z) + Math.floor(Math.random() * 5) - 2;
  try {
    const block = entity.dimension.getBlock({ x, y, z });
    if (block && BREAKABLE_BLOCKS.has(block.typeId)) {
      block.setType("minecraft:air");
    }
  } catch (error) {
    // The target may be outside the currently loaded area.
  }
}

function buildPoliceBarricade(entity) {
  const location = entity.location;
  const x = Math.floor(location.x) + (Math.random() > 0.5 ? 3 : -3);
  const y = Math.floor(location.y);
  const z = Math.floor(location.z);
  for (let height = 0; height < 2; height++) {
    placeBlock(entity.dimension, x, y + height, z, "minecraft:cobblestone_wall");
  }
}

function healNearestPlayer(entity) {
  const players = entity.dimension.getEntities({
    type: "minecraft:player",
    location: entity.location,
    maxDistance: 8
  });
  let closest = null;
  let closestDistance = Number.MAX_VALUE;
  for (const player of players) {
    const dx = player.location.x - entity.location.x;
    const dy = player.location.y - entity.location.y;
    const dz = player.location.z - entity.location.z;
    const distance = dx * dx + dy * dy + dz * dz;
    if (distance < closestDistance) {
      closest = player;
      closestDistance = distance;
    }
  }
  if (!closest) {
    return;
  }

  try {
    const health = closest.getComponent("minecraft:health");
    if (health && health.currentValue < health.effectiveMax) {
      health.resetToMax();
      entity.dimension.spawnItem(new ItemStack("minecraft:paper", 1), {
        x: entity.location.x,
        y: entity.location.y + 1,
        z: entity.location.z
      });
    }
  } catch (error) {
    // The player may leave the dimension between the query and the heal.
  }
}

function craftMedicSupplies(entity) {
  try {
    entity.dimension.spawnItem(new ItemStack("minecraft:bread", 2), {
      x: entity.location.x,
      y: entity.location.y + 1,
      z: entity.location.z
    });
  } catch (error) {
    // Item spawning is skipped if the entity is removed during this work cycle.
  }
}

function runRoleWork(entity) {
  if (!isRoleEntity(entity)) {
    return;
  }
  const role = entity.typeId === POLICE ? "police" : "medic";
  buildHouse(entity, role);
  if (role === "police") {
    clearNearbyPlant(entity);
    if (Math.random() > 0.45) {
      buildPoliceBarricade(entity);
    }
  } else {
    healNearestPlayer(entity);
    if (Math.random() > 0.35) {
      craftMedicSupplies(entity);
    }
  }
}

world.afterEvents.entitySpawn.subscribe((event) => {
  if (isRoleEntity(event.entity)) {
    system.run(() => runRoleWork(event.entity));
  }
});

system.runInterval(() => {
  for (const dimensionId of ["overworld", "nether", "the_end"]) {
    let dimension;
    try {
      dimension = world.getDimension(dimensionId);
    } catch (error) {
      continue;
    }