Search in sources :

Example 1 with ILocation

use of com.minecolonies.api.colony.requestsystem.location.ILocation in project minecolonies by Minecolonies.

the class DeliveryRequestResolverFactory method deserialize.

@NotNull
@Override
public DeliveryRequestResolver 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));
    return new DeliveryRequestResolver(location, token);
}
Also used : DeliveryRequestResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.DeliveryRequestResolver) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ILocation

use of com.minecolonies.api.colony.requestsystem.location.ILocation 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 3 with ILocation

use of com.minecolonies.api.colony.requestsystem.location.ILocation in project minecolonies by Minecolonies.

the class BuildingBasedRequester method deserialize.

public static BuildingBasedRequester deserialize(final IFactoryController controller, final NBTTagCompound compound) {
    final ILocation location = controller.deserialize(compound.getCompoundTag(NBT_LOCATION));
    final IToken<?> token = controller.deserialize(compound.getCompoundTag(NBT_ID));
    return new BuildingBasedRequester(location, token);
}
Also used : ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation)

Example 4 with ILocation

use of com.minecolonies.api.colony.requestsystem.location.ILocation in project minecolonies by Minecolonies.

the class BuildingBasedRequesterFactory method getNewInstance.

@NotNull
@Override
public BuildingBasedRequester getNewInstance(@NotNull final IFactoryController factoryController, @NotNull final AbstractBuilding building, @NotNull final Object... context) throws IllegalArgumentException {
    if (context.length != 0) {
        throw new IllegalArgumentException("To many context elements. Only 0 supported.");
    }
    final ILocation location = factoryController.getNewInstance(TypeConstants.ILOCATION, building.getLocation(), building.getColony().getWorld().provider.getDimension());
    final IToken token = factoryController.getNewInstance(TypeConstants.ITOKEN);
    return new BuildingBasedRequester(location, token);
}
Also used : BuildingBasedRequester(com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with ILocation

use of com.minecolonies.api.colony.requestsystem.location.ILocation in project minecolonies by Minecolonies.

the class Delivery method deserialize.

@NotNull
public static Delivery deserialize(@NotNull final IFactoryController controller, @NotNull final NBTTagCompound compound) {
    final ILocation start = controller.deserialize(compound.getCompoundTag(NBT_START));
    final ILocation target = controller.deserialize(compound.getCompoundTag(NBT_TARGET));
    final ItemStack stack = ItemStackUtils.deserializeFromNBT(compound.getCompoundTag(NBT_STACK));
    return new Delivery(start, target, stack);
}
Also used : ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) ItemStack(net.minecraft.item.ItemStack) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)14 NotNull (org.jetbrains.annotations.NotNull)10 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)7 Collectors (java.util.stream.Collectors)3 ItemStack (net.minecraft.item.ItemStack)3 Nullable (org.jetbrains.annotations.Nullable)3 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 IRequestManager (com.minecolonies.api.colony.requestsystem.manager.IRequestManager)2 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)2 Delivery (com.minecolonies.api.colony.requestsystem.requestable.Delivery)2 NBTUtils (com.minecolonies.api.util.NBTUtils)2 Colony (com.minecolonies.coremod.colony.Colony)2 BuildingBasedRequester (com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester)2 StandardPlayerRequestResolver (com.minecolonies.coremod.colony.requestsystem.resolvers.StandardPlayerRequestResolver)2 TileEntityColonyBuilding (com.minecolonies.coremod.tileentities.TileEntityColonyBuilding)2 TileEntity (net.minecraft.tileentity.TileEntity)2 TileEntityChest (net.minecraft.tileentity.TileEntityChest)2 BlockPos (net.minecraft.util.math.BlockPos)2