Search in sources :

Example 11 with JobEntry

use of com.minecolonies.api.colony.jobs.registry.JobEntry in project minecolonies by Minecolonies.

the class BuildingCook method buildingRequiresCertainAmountOfItem.

@Override
public int buildingRequiresCertainAmountOfItem(final ItemStack stack, final List<ItemStorage> localAlreadyKept, final boolean inventory, final JobEntry jobEntry) {
    if (stack.isEmpty()) {
        return 0;
    }
    if (inventory && getFirstModuleOccurance(MinimumStockModule.class).isStocked(stack)) {
        return stack.getCount();
    }
    // Neither like the cook does here, nor how the average worker does in the super call.
    if (jobEntry == ModJobs.cookassistant) {
        return stack.getCount();
    }
    if (isAllowedFood(stack) && (localAlreadyKept.stream().filter(storage -> ISFOOD.test(storage.getItemStack())).mapToInt(ItemStorage::getAmount).sum() < STACKSIZE || !inventory)) {
        final ItemStorage kept = new ItemStorage(stack);
        if (localAlreadyKept.contains(kept)) {
            kept.setAmount(localAlreadyKept.remove(localAlreadyKept.indexOf(kept)).getAmount());
        }
        localAlreadyKept.add(kept);
        return 0;
    }
    final Predicate<ItemStack> allowedFuel = theStack -> getModuleMatching(ItemListModule.class, m -> m.getId().equals(FUEL_LIST)).isItemInList(new ItemStorage(theStack));
    if (allowedFuel.test(stack) && (localAlreadyKept.stream().filter(storage -> allowedFuel.test(storage.getItemStack())).mapToInt(ItemStorage::getAmount).sum() < STACKSIZE || !inventory)) {
        final ItemStorage kept = new ItemStorage(stack);
        if (localAlreadyKept.contains(kept)) {
            kept.setAmount(localAlreadyKept.remove(localAlreadyKept.indexOf(kept)).getAmount());
        }
        localAlreadyKept.add(kept);
        return 0;
    }
    return super.buildingRequiresCertainAmountOfItem(stack, localAlreadyKept, inventory, jobEntry);
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) java.util(java.util) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) Item(net.minecraft.item.Item) IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) ICitizenData(com.minecolonies.api.colony.ICitizenData) ISFOOD(com.minecolonies.api.util.ItemStackUtils.ISFOOD) AbstractJobCrafter(com.minecolonies.coremod.colony.jobs.AbstractJobCrafter) IGenericRecipe(com.minecolonies.api.crafting.IGenericRecipe) CRAFTING_COOK(com.minecolonies.api.util.constant.TagConstants.CRAFTING_COOK) MinecoloniesAPIProxy(com.minecolonies.api.MinecoloniesAPIProxy) ItemStack(net.minecraft.item.ItemStack) TAG_SITTING(com.minecolonies.api.util.constant.SchematicTagConstants.TAG_SITTING) GenericRecipe(com.minecolonies.api.crafting.GenericRecipe) MinimumStockModule(com.minecolonies.coremod.colony.buildings.modules.MinimumStockModule) CraftingWorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.CraftingWorkerBuildingModule) ModJobs(com.minecolonies.api.colony.jobs.ModJobs) JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) CraftingType(com.minecolonies.api.crafting.registry.CraftingType) OptionalPredicate(com.minecolonies.api.util.OptionalPredicate) FUEL_LIST(com.minecolonies.api.util.constant.BuildingConstants.FUEL_LIST) ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) ImmutableSet(com.google.common.collect.ImmutableSet) ModTags(com.minecolonies.api.items.ModTags) STACKSIZE(com.minecolonies.api.util.constant.Constants.STACKSIZE) Predicate(java.util.function.Predicate) CraftingUtils(com.minecolonies.api.util.CraftingUtils) FurnaceRecipes(com.minecolonies.coremod.util.FurnaceRecipes) Tuple(net.minecraft.util.Tuple) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) Nullable(org.jetbrains.annotations.Nullable) OVERRIDE_EQUALS(com.minecolonies.api.util.constant.Suppression.OVERRIDE_EQUALS) AbstractCraftingBuildingModule(com.minecolonies.coremod.colony.buildings.modules.AbstractCraftingBuildingModule) IColony(com.minecolonies.api.colony.IColony) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) ItemStack(net.minecraft.item.ItemStack) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Example 12 with JobEntry

use of com.minecolonies.api.colony.jobs.registry.JobEntry in project minecolonies by Minecolonies.

the class PrivateWorkerCraftingProductionResolverFactory method deserialize.

@NotNull
@Override
public PrivateWorkerCraftingProductionResolver deserialize(@NotNull final IFactoryController controller, @NotNull final CompoundNBT nbt) {
    final IToken<?> token = controller.deserialize(nbt.getCompound(NBT_TOKEN));
    final ILocation location = controller.deserialize(nbt.getCompound(NBT_LOCATION));
    final JobEntry entry = IJobRegistry.getInstance().getValue(new ResourceLocation(nbt.getString(NBT_JOB)));
    return new PrivateWorkerCraftingProductionResolver(location, token, entry);
}
Also used : JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) PrivateWorkerCraftingProductionResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.PrivateWorkerCraftingProductionResolver) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) ResourceLocation(net.minecraft.util.ResourceLocation) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with JobEntry

use of com.minecolonies.api.colony.jobs.registry.JobEntry in project minecolonies by Minecolonies.

the class PublicWorkerCraftingProductionResolverFactory method deserialize.

@Override
public PublicWorkerCraftingProductionResolver deserialize(IFactoryController controller, PacketBuffer buffer) throws Throwable {
    final IToken<?> token = controller.deserialize(buffer);
    final ILocation location = controller.deserialize(buffer);
    final JobEntry entry = buffer.readRegistryId();
    return new PublicWorkerCraftingProductionResolver(location, token, entry);
}
Also used : JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) PublicWorkerCraftingProductionResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.PublicWorkerCraftingProductionResolver)

Example 14 with JobEntry

use of com.minecolonies.api.colony.jobs.registry.JobEntry in project minecolonies by Minecolonies.

the class PublicWorkerCraftingRequestResolverFactory method deserialize.

@Override
public PublicWorkerCraftingRequestResolver deserialize(IFactoryController controller, PacketBuffer buffer) throws Throwable {
    final IToken<?> token = controller.deserialize(buffer);
    final ILocation location = controller.deserialize(buffer);
    final JobEntry entry = buffer.readRegistryId();
    return new PublicWorkerCraftingRequestResolver(location, token, entry);
}
Also used : JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) PublicWorkerCraftingRequestResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.PublicWorkerCraftingRequestResolver)

Example 15 with JobEntry

use of com.minecolonies.api.colony.jobs.registry.JobEntry in project minecolonies by Minecolonies.

the class PublicWorkerCraftingRequestResolverFactory method deserialize.

@NotNull
@Override
public PublicWorkerCraftingRequestResolver deserialize(@NotNull final IFactoryController controller, @NotNull final CompoundNBT nbt) {
    final IToken<?> token = controller.deserialize(nbt.getCompound(NBT_TOKEN));
    final ILocation location = controller.deserialize(nbt.getCompound(NBT_LOCATION));
    final JobEntry entry = IJobRegistry.getInstance().getValue(new ResourceLocation(nbt.getString(NBT_JOB)));
    return new PublicWorkerCraftingRequestResolver(location, token, entry);
}
Also used : JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) ResourceLocation(net.minecraft.util.ResourceLocation) PublicWorkerCraftingRequestResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.PublicWorkerCraftingRequestResolver) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

JobEntry (com.minecolonies.api.colony.jobs.registry.JobEntry)37 ResourceLocation (net.minecraft.util.ResourceLocation)18 ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)16 NotNull (org.jetbrains.annotations.NotNull)13 Nullable (org.jetbrains.annotations.Nullable)7 PublicWorkerCraftingRequestResolver (com.minecolonies.coremod.colony.requestsystem.resolvers.PublicWorkerCraftingRequestResolver)6 ICitizenData (com.minecolonies.api.colony.ICitizenData)5 IColony (com.minecolonies.api.colony.IColony)5 PublicWorkerCraftingProductionResolver (com.minecolonies.coremod.colony.requestsystem.resolvers.PublicWorkerCraftingProductionResolver)5 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)4 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)3 RaiderType (com.minecolonies.api.entity.mobs.RaiderType)3 PrivateWorkerCraftingRequestResolver (com.minecolonies.coremod.colony.requestsystem.resolvers.PrivateWorkerCraftingRequestResolver)3 PacketBuffer (net.minecraft.network.PacketBuffer)3 IColonyManager (com.minecolonies.api.colony.IColonyManager)2 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)2 com.minecolonies.api.colony.buildings.modules (com.minecolonies.api.colony.buildings.modules)2 ISettingKey (com.minecolonies.api.colony.buildings.modules.settings.ISettingKey)2 BuildingEntry (com.minecolonies.api.colony.buildings.registry.BuildingEntry)2 IWareHouse (com.minecolonies.api.colony.buildings.workerbuildings.IWareHouse)2