@SuppressWarnings("rawtypes")
  @Override
  public void overwriteVillagerAI(LivingEntity villager) {
    try {
      EntityVillager ev = ((CraftVillager) villager).getHandle();

      Field goalsField = EntityInsentient.class.getDeclaredField("goalSelector");
      goalsField.setAccessible(true);
      PathfinderGoalSelector goals = (PathfinderGoalSelector) goalsField.get(ev);

      Field listField = PathfinderGoalSelector.class.getDeclaredField("a");
      listField.setAccessible(true);
      List list = (List) listField.get(goals);
      list.clear();
      listField = PathfinderGoalSelector.class.getDeclaredField("b");
      listField.setAccessible(true);
      list = (List) listField.get(goals);
      list.clear();

      goals.a(0, new PathfinderGoalFloat(ev));
      goals.a(1, new PathfinderGoalTradeWithPlayer(ev));
      goals.a(1, new PathfinderGoalLookAtTradingPlayer(ev));
      goals.a(2, new PathfinderGoalLookAtPlayer(ev, EntityHuman.class, 12.0F, 1.0F));
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  @SuppressWarnings("unchecked")
  @Override
  public boolean openTradeWindow(String name, List<ItemStack[]> recipes, Player player) {
    try {
      EntityVillager villager = new EntityVillager(((CraftPlayer) player).getHandle().world, 0);
      if (name != null && !name.isEmpty()) {
        villager.setCustomName(name);
      }

      Field recipeListField = EntityVillager.class.getDeclaredField("bu");
      recipeListField.setAccessible(true);
      MerchantRecipeList recipeList = (MerchantRecipeList) recipeListField.get(villager);
      if (recipeList == null) {
        recipeList = new MerchantRecipeList();
        recipeListField.set(villager, recipeList);
      }
      recipeList.clear();
      for (ItemStack[] recipe : recipes) {
        recipeList.add(createMerchantRecipe(recipe[0], recipe[1], recipe[2]));
      }

      villager.a(((CraftPlayer) player).getHandle());

      return true;
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
  }
コード例 #3
0
 @Override
 public void setupStandardGoals() {
   try {
     Mind mind = this.getRemoteEntity().getMind();
     mind.addMovementDesires(getDefaultMovementDesires());
     mind.addTargetingDesires(getDefaultTargetingDesires());
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
コード例 #4
0
 public static DesireItem[] getDefaultMovementDesires() {
   try {
     return new DesireItem[] {
       new DesireItem(new DesireSwim(), 0),
       new DesireItem(new DesireAvoidSpecific(8f, 0.6D, 0.6D, EntityZombie.class), 1),
       new DesireItem(new DesireTradeWithPlayer(), 1),
       new DesireItem(new DesireLookAtTrader(8), 1),
       new DesireItem(new DesireMoveIndoors(), 2),
       new DesireItem(new DesireRestrictOpenDoor(), 3),
       new DesireItem(new DesireOpenDoor(true, false), 4),
       new DesireItem(new DesireMoveTowardsRestriction(), 5),
       new DesireItem(new DesireMakeLove(), 6),
       new DesireItem(new DesireAcceptFlower(), 7),
       new DesireItem(new DesirePlay(0.32D), 8),
       new DesireItem(new DesireInteract(EntityHuman.class, 3, 1f), 9),
       new DesireItem(new DesireInteract(EntityVillager.class, 5, 0.2f), 9),
       new DesireItem(new DesireWanderAround(), 9),
       new DesireItem(new DesireLookAtNearest(EntityInsentient.class, 8), 10)
     };
   } catch (Exception e) {
     e.printStackTrace();
     return new DesireItem[0];
   }
 }