Search in sources :

Example 1 with RequestState

use of com.minecolonies.api.colony.requestsystem.request.RequestState in project minecolonies by Minecolonies.

the class StandardRequestFactories method deserializeFromNBT.

public static <T extends IRequestable, R extends IRequest<T>> R deserializeFromNBT(final IFactoryController controller, final NBTTagCompound compound, final INBTToObjectConverter<T> typeDeserialization, final IObjectConstructor<T, R> objectConstructor) {
    final IRequester requester = controller.deserialize(compound.getCompoundTag(NBT_REQUESTER));
    final IToken token = controller.deserialize(compound.getCompoundTag(NBT_TOKEN));
    final RequestState state = RequestState.deserializeNBT((NBTTagInt) compound.getTag(NBT_STATE));
    final T requested = typeDeserialization.apply(controller, compound.getCompoundTag(NBT_REQUESTED));
    final List<IToken> childTokens = new ArrayList<>();
    final NBTTagList childCompound = compound.getTagList(NBT_CHILDREN, Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < childCompound.tagCount(); i++) {
        childTokens.add(controller.deserialize(childCompound.getCompoundTagAt(i)));
    }
    @SuppressWarnings(Suppression.LEFT_CURLY_BRACE) final R request = objectConstructor.construct(requested, token, requester, state);
    request.addChildren(childTokens);
    if (compound.hasKey(NBT_PARENT)) {
        request.setParent(controller.deserialize(compound.getCompoundTag(NBT_PARENT)));
    }
    if (compound.hasKey(NBT_RESULT)) {
        request.setResult(typeDeserialization.apply(controller, compound.getCompoundTag(NBT_RESULT)));
    }
    return request;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) RequestState(com.minecolonies.api.colony.requestsystem.request.RequestState) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) ArrayList(java.util.ArrayList) IRequester(com.minecolonies.api.colony.requestsystem.requester.IRequester)

Example 2 with RequestState

use of com.minecolonies.api.colony.requestsystem.request.RequestState in project minecolonies by Minecolonies.

the class StandardRequestManagerTest method testUpdateRequestState.

@Test
public void testUpdateRequestState() throws Exception {
    requestManager.onProviderAddedToColony(provider);
    final StringRequestable hello = new StringRequestable(LOG);
    final IToken<?> token = requestManager.createAndAssignRequest(TestRequester.INSTANCE, hello);
    final RequestState originalState = requestManager.getRequestForToken(token).getState();
    assertEquals(RequestState.COMPLETED, originalState);
    requestManager.updateRequestState(token, RequestState.RECEIVED);
    assertNull(requestManager.getRequestForToken(token));
}
Also used : RequestState(com.minecolonies.api.colony.requestsystem.request.RequestState) Test(org.junit.Test)

Aggregations

RequestState (com.minecolonies.api.colony.requestsystem.request.RequestState)2 IRequester (com.minecolonies.api.colony.requestsystem.requester.IRequester)1 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)1 ArrayList (java.util.ArrayList)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 Test (org.junit.Test)1