Skip to content

Commit

Permalink
Fixes (#10479)
Browse files Browse the repository at this point in the history
Make sure guards also flee while not fighting
Unloaded warehouse no longer errors
Nethermine now uses the correct AI state to gather resources
Make sure to reset pose when walking similarly to dismounting
Fix clipboard crashing on opening on unresolvable request tokens
  • Loading branch information
someaddons authored Nov 24, 2024
1 parent 34e7ec1 commit a50b7ad
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 39 deletions.
53 changes: 32 additions & 21 deletions src/main/java/com/minecolonies/core/client/gui/WindowClipBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.minecolonies.api.colony.requestsystem.resolver.player.IPlayerRequestResolver;
import com.minecolonies.api.colony.requestsystem.resolver.retrying.IRetryingRequestResolver;
import com.minecolonies.api.colony.requestsystem.token.IToken;
import com.minecolonies.api.util.Log;
import com.minecolonies.api.util.constant.Constants;
import com.minecolonies.core.Network;
import com.minecolonies.core.network.messages.server.colony.UpdateRequestStateMessage;
Expand All @@ -20,6 +21,7 @@
import org.jetbrains.annotations.NotNull;

import java.util.*;

import static com.minecolonies.api.util.constant.WindowConstants.CLIPBOARD_TOGGLE;

/**
Expand Down Expand Up @@ -88,38 +90,47 @@ public ImmutableList<IRequest<?>> getOpenRequestsFromBuilding(final IBuildingVie
return ImmutableList.of();
}

final IPlayerRequestResolver resolver = requestManager.getPlayerResolver();
final IRetryingRequestResolver retryingRequestResolver = requestManager.getRetryingRequestResolver();

final Set<IToken<?>> requestTokens = new HashSet<>();
requestTokens.addAll(resolver.getAllAssignedRequests());
requestTokens.addAll(retryingRequestResolver.getAllAssignedRequests());

for (final IToken<?> token : requestTokens)
try
{
IRequest<?> request = requestManager.getRequestForToken(token);
final IPlayerRequestResolver resolver = requestManager.getPlayerResolver();
final IRetryingRequestResolver retryingRequestResolver = requestManager.getRetryingRequestResolver();

while (request != null && request.hasParent())
final Set<IToken<?>> requestTokens = new HashSet<>();
requestTokens.addAll(resolver.getAllAssignedRequests());
requestTokens.addAll(retryingRequestResolver.getAllAssignedRequests());

for (final IToken<?> token : requestTokens)
{
request = requestManager.getRequestForToken(request.getParent());
IRequest<?> request = requestManager.getRequestForToken(token);

while (request != null && request.hasParent())
{
request = requestManager.getRequestForToken(request.getParent());
}

if (request != null && !requests.contains(request))
{
requests.add(request);
}
}

if (request != null && !requests.contains(request))
if (hide)
{
requests.add(request);
requests.removeIf(req -> asyncRequest.contains(req.getId()));
}
}

if (hide)
final BlockPos playerPos = Minecraft.getInstance().player.blockPosition();
requests.sort(Comparator.comparing((IRequest<?> request) -> request.getRequester().getLocation().getInDimensionLocation()
.distSqr(new Vec3i(playerPos.getX(), playerPos.getY(), playerPos.getZ())))
.thenComparingInt((IRequest<?> request) -> request.getId().hashCode()));
}
catch (Exception e)
{
requests.removeIf(req -> asyncRequest.contains(req.getId()));
Log.getLogger().warn("Exception trying to retreive requests:", e);
requestManager.reset();
return ImmutableList.of();
}

final BlockPos playerPos = Minecraft.getInstance().player.blockPosition();
requests.sort(Comparator.comparing((IRequest<?> request) -> request.getRequester().getLocation().getInDimensionLocation()
.distSqr(new Vec3i(playerPos.getX(), playerPos.getY(), playerPos.getZ())))
.thenComparingInt((IRequest<?> request) -> request.getId().hashCode()));

return ImmutableList.copyOf(requests);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@
import com.minecolonies.core.colony.buildings.modules.BuildingModules;
import com.minecolonies.core.colony.buildings.workerbuildings.BuildingWareHouse;
import com.minecolonies.core.tileentities.TileEntityWareHouse;
import net.minecraft.world.item.ItemStack;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.minecolonies.api.colony.requestsystem.requestable.deliveryman.AbstractDeliverymanRequestable.getDefaultDeliveryPriority;
import static com.minecolonies.api.util.constant.RSConstants.CONST_WAREHOUSE_RESOLVER_PRIORITY;
Expand Down Expand Up @@ -216,6 +218,11 @@ public List<IRequest<?>> getFollowupRequestForCompletion(@NotNull final IRequest
final Colony colony = (Colony) manager.getColony();
final TileEntityWareHouse wareHouse = (TileEntityWareHouse) colony.getBuildingManager().getBuilding(getLocation().getInDimensionLocation()).getTileEntity();

if (wareHouse == null)
{
return null;
}

List<IRequest<?>> deliveries = Lists.newArrayList();
int remainingCount = completedRequest.getRequest().getCount();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.minecolonies.api.util.SoundUtils;
import com.minecolonies.api.util.constant.translation.RequestSystemTranslationConstants;
import com.minecolonies.core.Network;
import com.minecolonies.core.colony.buildings.modules.BuildingModules;
import com.minecolonies.core.colony.buildings.modules.FurnaceUserModule;
import com.minecolonies.core.colony.buildings.modules.ItemListModule;
import com.minecolonies.core.colony.buildings.workerbuildings.BuildingSmeltery;
Expand All @@ -25,21 +26,20 @@
import com.minecolonies.core.entity.ai.workers.AbstractEntityAIUsesFurnace;
import com.minecolonies.core.network.messages.client.LocalizedParticleEffectMessage;
import com.minecolonies.core.util.WorkerUtil;

import net.minecraft.network.chat.Component;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.FurnaceBlockEntity;
import net.minecraft.network.chat.Component;
import net.minecraft.sounds.SoundEvents;
import net.minecraftforge.items.wrapper.InvWrapper;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.stream.Collectors;

import static com.minecolonies.api.util.constant.Constants.*;
import static com.minecolonies.api.util.constant.TranslationConstants.*;
import static com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState.*;
import static com.minecolonies.api.util.constant.Constants.*;
import static com.minecolonies.api.util.constant.TranslationConstants.FURNACE_USER_NO_ORE;

/**
* Smelter AI class.
Expand Down Expand Up @@ -75,7 +75,7 @@ public EntityAIWorkSmelter(@NotNull final JobSmelter job)
*/
private IAIState breakOres()
{
final ICraftingBuildingModule module = building.getFirstModuleOccurance(BuildingSmeltery.OreBreakingModule.class);
final BuildingSmeltery.OreBreakingModule module = building.getModule(BuildingModules.SMELTER_OREBREAK);
final IRecipeStorage currentRecipeStorage = module.getFirstFulfillableRecipe(ItemStackUtils::isEmpty, 1, false);

if (currentRecipeStorage == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public AbstractEntityAIGuard(@NotNull final J job)
new AITarget(GUARD_REGEN, this::regen, GUARD_REGEN_INTERVAL),
new AITarget(GUARD_FLEE, this::flee, 20),
new AITarget(CombatAIStates.ATTACKING, this::shouldFlee, () -> GUARD_FLEE, GUARD_REGEN_INTERVAL),
new AITarget(CombatAIStates.NO_TARGET, this::shouldFlee, () -> GUARD_FLEE, GUARD_REGEN_INTERVAL),
new AITarget(CombatAIStates.NO_TARGET, this::decide, GUARD_TASK_INTERVAL),
new AITarget(GUARD_WAKE, this::wakeUpGuard, TICKS_SECOND),

Expand Down Expand Up @@ -593,6 +594,15 @@ public void setNextPatrolTarget(final BlockPos target)
{
worker.isWorkerAtSiteWithMove(currentPatrolPoint, 2);
}

registerTarget(new AIOneTimeEventTarget(() ->
{
if (getState() == CombatAIStates.NO_TARGET)
{
return decide();
}
return getState();
}));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import com.minecolonies.api.compatibility.tinkers.TinkersToolHelper;
import com.minecolonies.api.crafting.IRecipeStorage;
import com.minecolonies.api.crafting.ItemStorage;
import com.minecolonies.api.entity.ai.workers.util.GuardGear;
import com.minecolonies.api.entity.ai.workers.util.GuardGearBuilder;
import com.minecolonies.api.entity.ai.statemachine.AITarget;
import com.minecolonies.api.entity.ai.statemachine.states.IAIState;
import com.minecolonies.api.entity.ai.workers.util.GuardGear;
import com.minecolonies.api.entity.ai.workers.util.GuardGearBuilder;
import com.minecolonies.api.entity.citizen.AbstractEntityCitizen;
import com.minecolonies.api.equipment.ModEquipmentTypes;
import com.minecolonies.api.equipment.registry.EquipmentTypeEntry;
Expand Down Expand Up @@ -54,11 +54,12 @@
import java.util.stream.Collectors;

import static com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState.*;
import static com.minecolonies.api.research.util.ResearchConstants.*;
import static com.minecolonies.api.research.util.ResearchConstants.REGENERATION;
import static com.minecolonies.api.research.util.ResearchConstants.SATLIMIT;
import static com.minecolonies.api.util.constant.CitizenConstants.*;
import static com.minecolonies.api.util.constant.EquipmentLevelConstants.*;
import static com.minecolonies.api.util.constant.GuardConstants.*;
import static com.minecolonies.api.util.constant.NbtTagConstants.*;
import static com.minecolonies.api.util.constant.EquipmentLevelConstants.*;
import static com.minecolonies.core.colony.buildings.modules.BuildingModules.NETHERMINER_MENU;
import static com.minecolonies.core.entity.ai.workers.production.EntityAIStructureMiner.*;

Expand Down Expand Up @@ -992,7 +993,7 @@ protected IAIState checkAndRequestFood()
if (InventoryUtils.hasBuildingEnoughElseCount(building, stack -> building.getModule(NETHERMINER_MENU).getMenu().contains(new ItemStorage(stack)), 1) >= 1)
{
needsCurrently = new Tuple<>(stack -> building.getModule(NETHERMINER_MENU).getMenu().contains(new ItemStorage(stack)), 16);
return PICK_UP;
return GATHERING_REQUIRED_MATERIALS;
}
return getState();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.Pose;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.ChunkPos;
Expand Down Expand Up @@ -499,6 +500,11 @@ protected PathFinder createPathFinder(final int p_179679_1_)
@Override
protected boolean canUpdatePath()
{
if (ourEntity.getPose() != Pose.STANDING)
{
ourEntity.setPose(Pose.STANDING);
}

// Auto dismount when trying to path.
if (ourEntity.vehicle != null)
{
Expand Down Expand Up @@ -873,16 +879,16 @@ private boolean handlePathPointOnLadder(final PathPointExtended pEx)
{
// Any of these values is climbing, so adjust our direction of travel towards the ladder
case NORTH:
vec3 = vec3.add(0, 0, 0.4);
vec3 = vec3.add(0, 0, 0.8);
break;
case SOUTH:
vec3 = vec3.add(0, 0, -0.4);
vec3 = vec3.add(0, 0, -0.8);
break;
case WEST:
vec3 = vec3.add(0.4, 0, 0);
vec3 = vec3.add(0.8, 0.8, 0);
break;
case EAST:
vec3 = vec3.add(-0.4, 0, 0);
vec3 = vec3.add(-0.8, 0, 0);
break;
case UP:
vec3 = vec3.add(0, 1, 0);
Expand All @@ -896,6 +902,7 @@ private boolean handlePathPointOnLadder(final PathPointExtended pEx)
isSneaking = true;
}
this.ourEntity.getMoveControl().setWantedPosition(vec3.x, vec3.y, vec3.z, 0.2);
wantedPosition = vec3;
break;
}

Expand All @@ -906,6 +913,7 @@ private boolean handlePathPointOnLadder(final PathPointExtended pEx)
this.ourEntity.setDeltaMovement(this.ourEntity.getDeltaMovement().add(0, 0.1D, 0));
}
this.ourEntity.getMoveControl().setWantedPosition(vec3.x, vec3.y, vec3.z, newSpeed);
wantedPosition = vec3;
}
else
{
Expand Down Expand Up @@ -957,6 +965,7 @@ private boolean handleEntityInWater(int oldIndex, final PathPointExtended pEx)
}

this.ourEntity.getMoveControl().setWantedPosition(Vector3d.x, Vector3d.y, Vector3d.z, getSpeedFactor());
wantedPosition = Vector3d;
return false;
}

Expand Down

0 comments on commit a50b7ad

Please sign in to comment.