Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reached and prevent too long underwaterpathing #10146

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public interface IDeliverable extends IRetryable
*/
IDeliverable copyWithCount(final int newCount);


/**
* Can this type of request be resolved by the building, or only by external resolvers.
* @return true if so.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public boolean matchDamage()
@Override
public IDeliverable copyWithCount(final int newCount)
{
return new Stack(this.theStack, this.matchDamage, this.matchNBT, this.matchOreDic, this.result, newCount, this.minCount);
return new Stack(this.theStack, this.matchDamage, this.matchNBT, this.matchOreDic, this.result, newCount, Math.min(newCount, this.minCount));
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public AbstractAdvancedPathNavigate getNavigation()
this.navigation = newNavigator;
newNavigator.setSwimSpeedFactor(getSwimSpeedFactor());
newNavigator.setSpeedModifier(0.5);
newNavigator.getPathingOptions().withStartSwimCost(2.5D).withSwimCost(1.0D).withCanEnterDoors(true).withDropCost(1D).withJumpCost(1D).withWalkUnderWater(true).withNonLadderClimbableCost(1D).setPassDanger(true);
newNavigator.getPathingOptions().withStartSwimCost(2.5D).withSwimCost(1.0D).withDivingCost(1.0D).withCanEnterDoors(true).withDropCost(1D).withJumpCost(1D).withWalkUnderWater(true).withNonLadderClimbableCost(1D).setPassDanger(true);
PathingStuckHandler stuckHandler = PathingStuckHandler.createStuckHandler()
.withTakeDamageOnStuck(0.4f)
.withBuildLeafBridges()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.minecolonies.api.tileentities;

import com.minecolonies.api.crafting.ItemStorage;
import com.minecolonies.api.inventory.InventoryCitizen;
import com.minecolonies.api.util.Tuple;
import com.minecolonies.core.tileentities.TileEntityColonyBuilding;
Expand Down Expand Up @@ -69,6 +70,14 @@ public AbstractTileEntityWareHouse(final BlockEntityType<? extends AbstractTileE
@NotNull
public abstract List<Tuple<ItemStack, BlockPos>> getMatchingItemStacksInWarehouse(@NotNull Predicate<ItemStack> itemStackSelectionPredicate);

/**
* Get the count up to some maxCount for some itemstorage in the warehouse.
* @param storage the storage.
* @param maxCount the count.
* @return the maxCount or less.
*/
public abstract int getCountInWarehouse(@NotNull final ItemStorage storage, int maxCount);

/**
* Dump the inventory of a citizen into the warehouse. Go through all items and search the right chest to dump it in.
*
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/minecolonies/core/colony/ColonyView.java
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,10 @@ public void handleColonyViewMessage(@NotNull final RegistryFriendlyByteBuf buf,

if (buf.readBoolean())
{
this.requestManager = new StandardRequestManager(this);
if (this.requestManager == null)
{
this.requestManager = new StandardRequestManager(this);
}
this.requestManager.deserialize(StandardFactoryController.getInstance(), buf);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,15 @@ private IToken<?> resolve(
//TODO: Change this false to simulation.
resolver.onRequestAssigned(manager, request, false);

for (final IToken<?> childRequestToken :
attemptResult)
for (final IToken<?> childRequestToken : attemptResult)
{
final IRequest<?> childRequest = manager.getRequestHandler().getRequest(childRequestToken);

childRequest.setParent(request.getId());
request.addChild(childRequest.getId());
}

for (final IToken<?> childRequestToken :
attemptResult)
for (final IToken<?> childRequestToken : attemptResult)
{
final IRequest<?> childRequest = manager.getRequestHandler().getRequest(childRequestToken);

Expand Down Expand Up @@ -338,8 +336,7 @@ public void onRequestResolved(final IToken<?> token)
}

//Assign the followup request if need be
if (followupRequests != null && !followupRequests.isEmpty() &&
followupRequests.stream().anyMatch(followupRequest -> !isAssigned(followupRequest.getId())))
if (followupRequests != null && !followupRequests.isEmpty())
{
followupRequests.stream()
.filter(followupRequest -> !isAssigned(followupRequest.getId()))
Expand Down Expand Up @@ -614,8 +611,6 @@ public IRequest<?> getRequest(final IToken<?> token)
@Override
public IRequest<?> getRequestOrNull(final IToken<?> token)
{
manager.log("Retrieving the request for: " + token);

return manager.getRequestIdentitiesDataStore().getIdentities().get(token);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,6 @@ public IRequestResolver<? extends IRequestable> getResolver(final IToken<?> toke
throw new IllegalArgumentException("The given token for a resolver is not known to this manager!");
}

manager.log("Retrieving resolver for: " + token);

return manager.getRequestResolverIdentitiesDataStore().getIdentities().get(token);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.minecolonies.core.colony.buildings.modules.BuildingModules;
import com.minecolonies.core.colony.buildings.modules.CourierAssignmentModule;
import com.minecolonies.core.colony.buildings.modules.WarehouseRequestQueueModule;
import com.minecolonies.core.colony.buildings.workerbuildings.BuildingWareHouse;
import com.minecolonies.core.colony.jobs.JobDeliveryman;
import com.minecolonies.core.colony.requestsystem.resolvers.core.AbstractRequestResolver;
import net.minecraft.network.chat.MutableComponent;
Expand Down Expand Up @@ -43,6 +44,13 @@ public boolean canResolveRequest(@NotNull final IRequestManager manager, final I
{
return false;
}
final Colony colony = (Colony) manager.getColony();

if (colony.getBuildingManager().getBuilding(requestToCheck.getRequester().getLocation().getInDimensionLocation()) instanceof BuildingWareHouse buildingWareHouse
&& !buildingWareHouse.getID().equals(getLocation().getInDimensionLocation()))
{
return false;
}

return hasCouriers(manager);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import com.minecolonies.api.colony.requestsystem.requestable.INonExhaustiveDeliverable;
import com.minecolonies.api.colony.requestsystem.requestable.Stack;
import com.minecolonies.api.colony.requestsystem.token.IToken;
import com.minecolonies.api.crafting.ItemStorage;
import com.minecolonies.core.colony.buildings.workerbuildings.BuildingWareHouse;
import com.minecolonies.core.colony.requestsystem.resolvers.core.AbstractWarehouseRequestResolver;
import com.minecolonies.core.tileentities.TileEntityWareHouse;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;

import java.util.List;
Expand All @@ -27,42 +29,41 @@ public WarehouseConcreteRequestResolver(
}

@Override
protected boolean internalCanResolve(final List<TileEntityWareHouse> wareHouses, final IRequest<? extends IDeliverable> requestToCheck)
protected boolean internalCanResolve(final Level level, final List<BuildingWareHouse> wareHouses, final IRequest<? extends IDeliverable> requestToCheck)
{
final IDeliverable deliverable = requestToCheck.getRequest();

if(deliverable instanceof IConcreteDeliverable)
if (deliverable instanceof IConcreteDeliverable)
{
boolean ignoreNBT = false;
boolean ignoreDamage = false;
if (deliverable instanceof Stack)
if (deliverable instanceof Stack stack)
{
if (!((Stack) requestToCheck.getRequest()).matchNBT())
{
ignoreNBT = true;
}
if (!((Stack) requestToCheck.getRequest()).matchDamage())
{
ignoreDamage = true;
}
ignoreNBT = !stack.matchNBT();
ignoreDamage = !stack.matchDamage();
}
for(final ItemStack possible : ((IConcreteDeliverable) deliverable).getRequestedItems())
int totalCount = 0;
for (final ItemStack possible : ((IConcreteDeliverable) deliverable).getRequestedItems())
{
for (final TileEntityWareHouse wareHouse : wareHouses)
for (final BuildingWareHouse wareHouse : wareHouses)
{
if (requestToCheck.getRequest() instanceof INonExhaustiveDeliverable)
if (wareHouse.getTileEntity() == null)
{
continue;
}

if (requestToCheck.getRequest() instanceof INonExhaustiveDeliverable neDeliverable)
{
if (wareHouse.hasMatchingItemStackInWarehouse(possible, requestToCheck.getRequest().getMinimumCount(), ignoreNBT, ignoreDamage, ((INonExhaustiveDeliverable) requestToCheck.getRequest()).getLeftOver()))
{
return true;
}
totalCount += Math.max(0, wareHouse.getTileEntity().getCountInWarehouse(new ItemStorage(possible, requestToCheck.getRequest().getMinimumCount(), ignoreDamage, ignoreNBT), requestToCheck.getRequest().getMinimumCount()) - neDeliverable.getLeftOver());
}
else
{
if (wareHouse.hasMatchingItemStackInWarehouse(possible, requestToCheck.getRequest().getMinimumCount(), ignoreNBT, ignoreDamage, 0))
{
return true;
}
totalCount += wareHouse.getTileEntity().getCountInWarehouse(new ItemStorage(possible, requestToCheck.getRequest().getMinimumCount(), ignoreDamage, ignoreNBT), requestToCheck.getRequest().getMinimumCount());
}

if (totalCount >= requestToCheck.getRequest().getMinimumCount())
{
return true;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
import com.minecolonies.api.colony.requestsystem.requestable.IConcreteDeliverable;
import com.minecolonies.api.colony.requestsystem.requestable.IDeliverable;
import com.minecolonies.api.colony.requestsystem.token.IToken;
import com.minecolonies.api.util.WorldUtil;
import com.minecolonies.core.colony.buildings.workerbuildings.BuildingWareHouse;
import com.minecolonies.core.colony.requestsystem.resolvers.core.AbstractWarehouseRequestResolver;
import com.minecolonies.core.tileentities.TileEntityWareHouse;
import com.minecolonies.core.tileentities.TileEntityRack;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import org.jetbrains.annotations.NotNull;

import java.util.List;
Expand All @@ -24,18 +29,30 @@ public WarehouseRequestResolver(
}

@Override
protected boolean internalCanResolve(final List<TileEntityWareHouse> wareHouses, final IRequest<? extends IDeliverable> requestToCheck)
protected boolean internalCanResolve(final Level level, final List<BuildingWareHouse> wareHouses, final IRequest<? extends IDeliverable> requestToCheck)
{
if(requestToCheck.getRequest() instanceof IConcreteDeliverable)
if (requestToCheck.getRequest() instanceof IConcreteDeliverable)
{
return false;
return false;
}

for (final TileEntityWareHouse wareHouse : wareHouses)
int totalCount = 0;
for (final BuildingWareHouse wareHouse : wareHouses)
{
if (wareHouse.hasMatchingItemStackInWarehouse(itemStack -> requestToCheck.getRequest().matches(itemStack), requestToCheck.getRequest().getMinimumCount()))
for (@NotNull final BlockPos pos : wareHouse.getContainers())
{
return true;
if (WorldUtil.isBlockLoaded(level, pos))
{
final BlockEntity entity = level.getBlockEntity(pos);
if (entity instanceof final TileEntityRack rack && !rack.isEmpty())
{
totalCount += rack.getItemCount(itemStack -> requestToCheck.getRequest().matches(itemStack));
if (totalCount >= requestToCheck.getRequest().getMinimumCount())
{
return true;
}
}
}
}
}
return false;
Expand Down
Loading