Search in sources :

Example 1 with IFactoryController

use of com.minecolonies.api.colony.requestsystem.factory.IFactoryController in project minecolonies by Minecolonies.

the class StandardRetryingRequestResolverFactory method deserialize.

@NotNull
@Override
public StandardRetryingRequestResolver deserialize(@NotNull final IFactoryController controller, @NotNull final NBTTagCompound nbt) {
    final Map<IToken<?>, Integer> assignments = NBTUtils.streamCompound(nbt.getTagList(NBT_TRIES, Constants.NBT.TAG_COMPOUND)).map(assignmentCompound -> {
        IToken token = controller.deserialize(assignmentCompound.getCompoundTag(NBT_TOKEN));
        Integer tries = assignmentCompound.getInteger(NBT_VALUE);
        return new HashMap.SimpleEntry<>(token, tries);
    }).collect(Collectors.toMap(HashMap.SimpleEntry::getKey, HashMap.SimpleEntry::getValue));
    final Map<IToken<?>, Integer> delays = NBTUtils.streamCompound(nbt.getTagList(NBT_DELAYS, Constants.NBT.TAG_COMPOUND)).map(assignmentCompound -> {
        IToken token = controller.deserialize(assignmentCompound.getCompoundTag(NBT_TOKEN));
        Integer tries = assignmentCompound.getInteger(NBT_VALUE);
        return new HashMap.SimpleEntry<>(token, tries);
    }).collect(Collectors.toMap(HashMap.SimpleEntry::getKey, HashMap.SimpleEntry::getValue));
    final IToken<?> token = controller.deserialize(nbt.getCompoundTag(NBT_TOKEN));
    final ILocation location = controller.deserialize(nbt.getCompoundTag(NBT_LOCATION));
    final StandardRetryingRequestResolver retryingRequestResolver = new StandardRetryingRequestResolver(token, location);
    retryingRequestResolver.updateData(assignments, delays);
    return retryingRequestResolver;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) Constants(net.minecraftforge.common.util.Constants) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) HashMap(java.util.HashMap) TypeToken(com.google.common.reflect.TypeToken) IFactoryController(com.minecolonies.api.colony.requestsystem.factory.IFactoryController) Collectors(java.util.stream.Collectors) IRequestManager(com.minecolonies.api.colony.requestsystem.manager.IRequestManager) IFactory(com.minecolonies.api.colony.requestsystem.factory.IFactory) Map(java.util.Map) NBTUtils(com.minecolonies.api.util.NBTUtils) StandardRetryingRequestResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.StandardRetryingRequestResolver) NotNull(org.jetbrains.annotations.NotNull) StandardRetryingRequestResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.StandardRetryingRequestResolver) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) HashMap(java.util.HashMap) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with IFactoryController

use of com.minecolonies.api.colony.requestsystem.factory.IFactoryController in project minecolonies by Minecolonies.

the class StandardPlayerRequestResolverFactory method deserialize.

@NotNull
@Override
public StandardPlayerRequestResolver deserialize(@NotNull final IFactoryController controller, @NotNull final NBTTagCompound nbt) {
    final IToken token = controller.deserialize(nbt.getCompoundTag(NBT_TOKEN));
    final ILocation location = controller.deserialize(nbt.getCompoundTag(NBT_LOCATION));
    final Set<IToken<?>> assignedRequests = NBTUtils.streamCompound(nbt.getTagList(NBT_ASSIGNED_REQUESTS, Constants.NBT.TAG_COMPOUND)).map(c -> (IToken<?>) controller.deserialize(c)).collect(Collectors.toSet());
    final StandardPlayerRequestResolver resolver = new StandardPlayerRequestResolver(location, token);
    resolver.setAllAssignedRequests(assignedRequests);
    return resolver;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) StandardPlayerRequestResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.StandardPlayerRequestResolver) Constants(net.minecraftforge.common.util.Constants) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) Set(java.util.Set) TypeToken(com.google.common.reflect.TypeToken) IFactoryController(com.minecolonies.api.colony.requestsystem.factory.IFactoryController) Collectors(java.util.stream.Collectors) IRequestManager(com.minecolonies.api.colony.requestsystem.manager.IRequestManager) IFactory(com.minecolonies.api.colony.requestsystem.factory.IFactory) TypeConstants(com.minecolonies.api.util.constant.TypeConstants) NBTUtils(com.minecolonies.api.util.NBTUtils) NotNull(org.jetbrains.annotations.NotNull) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) StandardPlayerRequestResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.StandardPlayerRequestResolver) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

TypeToken (com.google.common.reflect.TypeToken)2 IFactory (com.minecolonies.api.colony.requestsystem.factory.IFactory)2 IFactoryController (com.minecolonies.api.colony.requestsystem.factory.IFactoryController)2 ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)2 IRequestManager (com.minecolonies.api.colony.requestsystem.manager.IRequestManager)2 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)2 NBTUtils (com.minecolonies.api.util.NBTUtils)2 Collectors (java.util.stream.Collectors)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 Constants (net.minecraftforge.common.util.Constants)2 NotNull (org.jetbrains.annotations.NotNull)2 TypeConstants (com.minecolonies.api.util.constant.TypeConstants)1 StandardPlayerRequestResolver (com.minecolonies.coremod.colony.requestsystem.resolvers.StandardPlayerRequestResolver)1 StandardRetryingRequestResolver (com.minecolonies.coremod.colony.requestsystem.resolvers.StandardRetryingRequestResolver)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1