Skip to content

Commit

Permalink
Only deserialize valid requestresolveidentities (#10140)
Browse files Browse the repository at this point in the history
Only deserialize valid requestresolveidentities
  • Loading branch information
Raycoms committed Aug 20, 2024
1 parent c7e59c9 commit e185b01
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 10 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 @@ -17,13 +17,11 @@
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.util.Tuple;

import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

import static com.minecolonies.api.util.constant.NbtTagConstants.*;

Expand Down Expand Up @@ -118,15 +116,18 @@ public StandardRequestResolversIdentitiesDataStore deserialize(@NotNull final IF
{
final IToken<?> token = controller.deserialize(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.deserialize(CompoundTag.getCompound(TAG_TOKEN));
final IRequestResolver<?> resolver = controller.deserialize(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.deserialize(mapCompound.getCompound(TAG_TOKEN));
final IRequestResolver<?> resolver = controller.deserialize(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.translatable(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 e185b01

Please sign in to comment.