Skip to content

Commit

Permalink
Only deserialize valid requestresolveidentities
Browse files Browse the repository at this point in the history
  • Loading branch information
Raycoms committed Aug 19, 2024
1 parent bd03c76 commit cd9a5fe
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,10 @@ default int getSuitabilityMetric(@NotNull final IRequestManager manager, @NotNul
* @return The priority of this resolver.
*/
int getPriority();

/**
* If this resolver has valid data in it.
* @return true if so.
*/
boolean isValid();
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,18 @@ public StandardRequestResolversIdentitiesDataStore deserialize(@NotNull final Ho
{
final IToken<?> token = controller.deserializeTag(provider, nbt.getCompound(TAG_TOKEN));
final ListTag list = nbt.getList(TAG_LIST, Tag.TAG_COMPOUND);
final BiMap<IToken<?>, IRequestResolver<?>> biMap = HashBiMap.create();

final Map<IToken<?>, IRequestResolver<?>> map = NBTUtils.streamCompound(list).map(CompoundTag -> {
final IToken<?> id = controller.deserializeTag(provider, CompoundTag.getCompound(TAG_TOKEN));
final IRequestResolver<?> resolver = controller.deserializeTag(provider, CompoundTag.getCompound(TAG_RESOLVER));

return new Tuple<IToken<?>, IRequestResolver<?>>(id, resolver);
}).collect(Collectors.toMap((Tuple<IToken<?>, IRequestResolver<?>> t) -> t.getA(), (Tuple<IToken<?>, IRequestResolver<?>> t) -> t.getB()));

final BiMap<IToken<?>, IRequestResolver<?>> biMap = HashBiMap.create(map);
for (int i = 0; i < list.size(); i++)
{
final CompoundTag mapCompound = list.getCompound(i);
final IToken<?> id = controller.deserializeTag(provider, mapCompound.getCompound(TAG_TOKEN));
final IRequestResolver<?> resolver = controller.deserializeTag(provider, mapCompound.getCompound(TAG_RESOLVER));
if (resolver.isValid())
{
biMap.put(id, resolver);
}
}

return new StandardRequestResolversIdentitiesDataStore(token, biMap);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,11 @@ public MutableComponent getRequesterDisplayName(
{
return Component.translatableEscape(TranslationConstants.COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN);
}

@Override
public boolean isValid()
{
// Always valid
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,11 @@ public void setAllAssignedRequests(final Set<IToken<?>> assignedRequests)
this.assignedRequests.clear();
this.assignedRequests.addAll(assignedRequests);
}

@Override
public boolean isValid()
{
// Always valid
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,11 @@ public void onColonyUpdate(@NotNull final IRequestManager manager, @NotNull fina
}
});
}

@Override
public boolean isValid()
{
// Always valid
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,11 @@ protected boolean internalCanResolve(final List<TileEntityWareHouse> wareHouses,
}
return false;
}

@Override
public boolean isValid()
{
// Always valid
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,11 @@ public void resolveRequest(@NotNull final IRequestManager manager, @NotNull fina
}

public abstract void resolveForBuilding(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends R> request, @NotNull final AbstractBuilding building);

@Override
public boolean isValid()
{
// Always valid.
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,10 @@ public void resolveForBuilding(@NotNull final IRequestManager manager, @NotNull

manager.updateRequestState(request.getId(), RequestState.RESOLVED);
}

@Override
public boolean isValid()
{
return jobEntry != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -369,4 +369,10 @@ public void resolveForBuilding(@NotNull final IRequestManager manager, @NotNull
{
manager.updateRequestState(request.getId(), RequestState.RESOLVED);
}

@Override
public boolean isValid()
{
return jobEntry != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,11 @@ public int getPriority()
{
return CONST_WAREHOUSE_RESOLVER_PRIORITY;
}

@Override
public boolean isValid()
{
// Always valid
return true;
}
}

0 comments on commit cd9a5fe

Please sign in to comment.