From 8e871aaffe36f58f09c20076d9d67c502bc71381 Mon Sep 17 00:00:00 2001 From: someaddons Date: Sat, 23 Nov 2024 23:41:05 +0100 Subject: [PATCH 1/2] 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 --- .../core/client/gui/WindowClipBoard.java | 53 +++++++++++-------- .../AbstractWarehouseRequestResolver.java | 13 +++-- .../workers/crafting/EntityAIWorkSmelter.java | 12 ++--- .../workers/guard/AbstractEntityAIGuard.java | 10 ++++ .../production/EntityAIWorkNether.java | 11 ++-- .../MinecoloniesAdvancedPathNavigate.java | 6 +++ 6 files changed, 70 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/minecolonies/core/client/gui/WindowClipBoard.java b/src/main/java/com/minecolonies/core/client/gui/WindowClipBoard.java index 086b1af64cd..cc74f9a7a35 100755 --- a/src/main/java/com/minecolonies/core/client/gui/WindowClipBoard.java +++ b/src/main/java/com/minecolonies/core/client/gui/WindowClipBoard.java @@ -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; @@ -20,6 +21,7 @@ import org.jetbrains.annotations.NotNull; import java.util.*; + import static com.minecolonies.api.util.constant.WindowConstants.CLIPBOARD_TOGGLE; /** @@ -88,38 +90,47 @@ public ImmutableList> getOpenRequestsFromBuilding(final IBuildingVie return ImmutableList.of(); } - final IPlayerRequestResolver resolver = requestManager.getPlayerResolver(); - final IRetryingRequestResolver retryingRequestResolver = requestManager.getRetryingRequestResolver(); - - final Set> 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> 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); } diff --git a/src/main/java/com/minecolonies/core/colony/requestsystem/resolvers/core/AbstractWarehouseRequestResolver.java b/src/main/java/com/minecolonies/core/colony/requestsystem/resolvers/core/AbstractWarehouseRequestResolver.java index c4fe32d5ea5..41cc42d98a7 100755 --- a/src/main/java/com/minecolonies/core/colony/requestsystem/resolvers/core/AbstractWarehouseRequestResolver.java +++ b/src/main/java/com/minecolonies/core/colony/requestsystem/resolvers/core/AbstractWarehouseRequestResolver.java @@ -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; @@ -216,6 +218,11 @@ public List> 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> deliveries = Lists.newArrayList(); int remainingCount = completedRequest.getRequest().getCount(); diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIWorkSmelter.java b/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIWorkSmelter.java index 2f13ee0bd10..8a3211938e8 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIWorkSmelter.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIWorkSmelter.java @@ -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; @@ -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. @@ -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) diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/AbstractEntityAIGuard.java b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/AbstractEntityAIGuard.java index 449e3cd1adc..2bdbcfe7d56 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/AbstractEntityAIGuard.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/AbstractEntityAIGuard.java @@ -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), @@ -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(); + })); } /** diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkNether.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkNether.java index 29be030759e..92b04690989 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkNether.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkNether.java @@ -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; @@ -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.*; @@ -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(); } diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/MinecoloniesAdvancedPathNavigate.java b/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/MinecoloniesAdvancedPathNavigate.java index e16e6085c5e..570cd0a4759 100644 --- a/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/MinecoloniesAdvancedPathNavigate.java +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/MinecoloniesAdvancedPathNavigate.java @@ -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; @@ -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) { From 3eb8123810916b97c4357bd33a9fae2df8455a02 Mon Sep 17 00:00:00 2001 From: someaddons Date: Sun, 24 Nov 2024 00:42:45 +0100 Subject: [PATCH 2/2] ladder movement fixes --- .../navigation/MinecoloniesAdvancedPathNavigate.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/MinecoloniesAdvancedPathNavigate.java b/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/MinecoloniesAdvancedPathNavigate.java index 570cd0a4759..6e09ed3e275 100644 --- a/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/MinecoloniesAdvancedPathNavigate.java +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/MinecoloniesAdvancedPathNavigate.java @@ -879,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); @@ -902,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; } @@ -912,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 { @@ -963,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; }