use of com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule in project minecolonies by Minecolonies.
the class CraftingTagAuditor method doRecipeAudit.
private static void doRecipeAudit(@NotNull final BufferedWriter writer, @NotNull final MinecraftServer server, @NotNull final CustomRecipeManager customRecipeManager) throws IOException {
final Map<CraftingType, List<IGenericRecipe>> vanillaRecipesMap = RecipeAnalyzer.buildVanillaRecipesMap(server.getRecipeManager(), server.overworld());
final List<ICraftingBuildingModule> crafters = getCraftingModules().stream().sorted(Comparator.comparing(m -> m instanceof SimpleCraftingModule).reversed()).collect(// sort the simple modules first (2x2 crafting, personal only)
Collectors.toList());
final Map<ItemStorage, Map<ICraftingBuildingModule, List<IGenericRecipe>>> craftingMap = new HashMap<>();
// initially map every vanilla craftable
for (final List<IGenericRecipe> recipeList : vanillaRecipesMap.values()) {
for (final IGenericRecipe recipe : recipeList) {
add(customRecipeManager, craftingMap, null, recipe);
}
}
writeItemHeaders(writer);
writer.write(",player");
for (final ICraftingBuildingModule crafter : crafters) {
writer.write(',');
writer.write(crafter.getCustomRecipeKey());
final List<IGenericRecipe> recipes = RecipeAnalyzer.findRecipes(vanillaRecipesMap, crafter);
for (final IGenericRecipe recipe : recipes) {
add(customRecipeManager, craftingMap, crafter, recipe);
}
}
writer.newLine();
for (final ItemStack item : getAllItems()) {
writeItemData(writer, item);
final Map<ICraftingBuildingModule, List<IGenericRecipe>> crafterMap = craftingMap.getOrDefault(new ItemStorage(item, true, false), Collections.emptyMap());
writeCrafterValue(writer, crafterMap, null);
for (final ICraftingBuildingModule crafter : crafters) {
writeCrafterValue(writer, crafterMap, crafter);
}
writer.newLine();
}
}
use of com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule in project minecolonies by Minecolonies.
the class JEIPlugin method registerCategories.
@Override
public void registerCategories(@NotNull final IRecipeCategoryRegistration registration) {
final IJeiHelpers jeiHelpers = registration.getJeiHelpers();
final IGuiHelper guiHelper = jeiHelpers.getGuiHelper();
final IModIdHelper modIdHelper = jeiHelpers.getModIdHelper();
registration.addRecipeCategories(new CompostRecipeCategory(guiHelper));
registration.addRecipeCategories(new FishermanRecipeCategory(guiHelper));
categories.clear();
for (final BuildingEntry building : IMinecoloniesAPI.getInstance().getBuildingRegistry()) {
for (final Supplier<IBuildingModule> producer : building.getModuleProducers()) {
final IBuildingModule module = producer.get();
if (module instanceof ICraftingBuildingModule) {
final ICraftingBuildingModule crafting = (ICraftingBuildingModule) module;
final IJob<?> job = crafting.getCraftingJob();
if (job != null) {
registerCategory(registration, new GenericRecipeCategory(building, job, crafting, guiHelper, modIdHelper));
}
}
if (module instanceof AnimalHerdingModule) {
final AnimalHerdingModule herding = (AnimalHerdingModule) module;
registerCategory(registration, new HerderRecipeCategory(building, herding.getHerdingJob(), herding, guiHelper));
}
}
}
}
use of com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule in project minecolonies by Minecolonies.
the class AbstractCraftingProductionResolver method attemptResolveForBuildingAndStack.
@Nullable
protected List<IToken<?>> attemptResolveForBuildingAndStack(@NotNull final IRequestManager manager, @NotNull final AbstractBuilding building, final ItemStack stack, final int count, final int minCount, final IToken<?> recipeId) {
final ICraftingBuildingModule module = building.getCraftingModuleForRecipe(recipeId);
if (module == null) {
return null;
}
if (!canBuildingCraftStack(manager, building, stack)) {
return null;
}
final IRecipeStorage fullfillableCrafting = module.getFirstFulfillableRecipe(itemStack -> ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, stack), count, true);
if (fullfillableCrafting != null) {
return ImmutableList.of();
}
final IRecipeStorage craftableCrafting = module.getFirstRecipe(stack);
if (craftableCrafting == null) {
return null;
}
return createRequestsForRecipe(manager, building, count, minCount, craftableCrafting);
}
use of com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule in project minecolonies by ldtteam.
the class EntityAIWorkNether method decide.
@Override
protected IAIState decide() {
if (job.isInNether()) {
if (!worker.isInvisible()) {
goToVault();
}
return NETHER_AWAY;
}
if (worker.isInvisible()) {
returnFromVault();
}
IAIState crafterState = super.decide();
if (crafterState != IDLE && crafterState != START_WORKING) {
return crafterState;
}
// Get Armor if available.
// This is async, so we could go to the nether without it.
checkAndRequestArmor();
// Check for materials needed to go to the Nether:
IRecipeStorage rs = getOwnBuilding().getFirstModuleOccurance(BuildingNetherWorker.CraftingModule.class).getFirstRecipe(ItemStack::isEmpty);
if (rs != null) {
for (ItemStorage item : rs.getInput()) {
checkAndRequestMaterials(item.getItemStack(), item.getAmount());
}
}
// Make sure we have a stash of some food
checkAndRequestFood(16);
// Get other adventuring supplies. These are required.
// Done this way to get all the requests in parallel
boolean haveAxe = checkForToolOrWeapon(ToolType.AXE);
boolean havePick = checkForToolOrWeapon(ToolType.PICKAXE);
boolean haveShovel = checkForToolOrWeapon(ToolType.SHOVEL);
boolean haveSword = checkForToolOrWeapon(ToolType.SWORD);
boolean haveLighter = checkForToolOrWeapon(ToolType.FLINT_N_STEEL);
if (haveAxe || havePick || haveShovel || haveSword || haveLighter) {
worker.getCitizenData().setIdleAtJob(true);
return IDLE;
}
if (currentRecipeStorage == null) {
final ICraftingBuildingModule module = getOwnBuilding().getFirstModuleOccurance(BuildingNetherWorker.CraftingModule.class);
currentRecipeStorage = module.getFirstFulfillableRecipe(ItemStackUtils::isEmpty, 1, false);
if (getOwnBuilding().isReadyForTrip()) {
worker.getCitizenData().setIdleAtJob(true);
}
final BlockPos portal = getOwnBuilding().getPortalLocation();
if (portal != null && currentRecipeStorage == null && getOwnBuilding().shallClosePortalOnReturn()) {
final BlockState block = world.getBlockState(portal);
if (block.is(Blocks.NETHER_PORTAL)) {
return NETHER_CLOSEPORTAL;
}
}
return getState();
} else {
if (!getOwnBuilding().isReadyForTrip()) {
worker.getCitizenData().setIdleAtJob(false);
return IDLE;
}
if (walkTo != null || walkToBuilding()) {
return getState();
}
if (InventoryUtils.isItemHandlerFull(worker.getInventoryCitizen())) {
return INVENTORY_FULL;
}
IAIState checkResult = checkForItems(currentRecipeStorage);
if (checkResult == GET_RECIPE) {
currentRecipeStorage = null;
worker.getCitizenData().setIdleAtJob(true);
return IDLE;
}
if (checkResult != CRAFT) {
return checkResult;
}
}
return NETHER_LEAVE;
}
use of com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule in project minecolonies by ldtteam.
the class AbstractCraftingProductionResolver method attemptResolveForBuildingAndStack.
@Nullable
protected List<IToken<?>> attemptResolveForBuildingAndStack(@NotNull final IRequestManager manager, @NotNull final AbstractBuilding building, final ItemStack stack, final int count, final int minCount, final IToken<?> recipeId) {
final ICraftingBuildingModule module = building.getCraftingModuleForRecipe(recipeId);
if (module == null) {
return null;
}
if (!canBuildingCraftStack(manager, building, stack)) {
return null;
}
final IRecipeStorage fullfillableCrafting = module.getFirstFulfillableRecipe(itemStack -> ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, stack), count, true);
if (fullfillableCrafting != null) {
return ImmutableList.of();
}
final IRecipeStorage craftableCrafting = module.getFirstRecipe(stack);
if (craftableCrafting == null) {
return null;
}
return createRequestsForRecipe(manager, building, count, minCount, craftableCrafting);
}
Aggregations