diff --git a/src/main/java/com/minecolonies/api/entity/citizen/citizenhandlers/ICitizenColonyHandler.java b/src/main/java/com/minecolonies/api/entity/citizen/citizenhandlers/ICitizenColonyHandler.java index 82bb845eb9a..9894600f529 100755 --- a/src/main/java/com/minecolonies/api/entity/citizen/citizenhandlers/ICitizenColonyHandler.java +++ b/src/main/java/com/minecolonies/api/entity/citizen/citizenhandlers/ICitizenColonyHandler.java @@ -71,4 +71,6 @@ public interface ICitizenColonyHandler * @param dataAccessor */ void onSyncDataUpdate(EntityDataAccessor dataAccessor); + + boolean registered(); } diff --git a/src/main/java/com/minecolonies/core/colony/CitizenData.java b/src/main/java/com/minecolonies/core/colony/CitizenData.java index 605452da0d1..e0276347d15 100755 --- a/src/main/java/com/minecolonies/core/colony/CitizenData.java +++ b/src/main/java/com/minecolonies/core/colony/CitizenData.java @@ -63,9 +63,9 @@ import static com.minecolonies.api.util.constant.ColonyConstants.UPDATE_SUBSCRIBERS_INTERVAL; import static com.minecolonies.api.util.constant.Constants.TAG_STRING; import static com.minecolonies.api.util.constant.Constants.TICKS_SECOND; -import static com.minecolonies.api.util.constant.NbtTagConstants.*; import static com.minecolonies.api.util.constant.NbtTagConstants.TAG_ID; import static com.minecolonies.api.util.constant.NbtTagConstants.TAG_NAME; +import static com.minecolonies.api.util.constant.NbtTagConstants.*; import static com.minecolonies.api.util.constant.TranslationConstants.*; /** @@ -512,6 +512,7 @@ public void initEntityValues() { if (!getEntity().isPresent()) { + Log.getLogger().warn("Missing entity upon adding data to that entity!" + this.toString(), new Exception()); return; } diff --git a/src/main/java/com/minecolonies/core/colony/managers/CitizenManager.java b/src/main/java/com/minecolonies/core/colony/managers/CitizenManager.java index 87a5e160677..994b6009dfa 100755 --- a/src/main/java/com/minecolonies/core/colony/managers/CitizenManager.java +++ b/src/main/java/com/minecolonies/core/colony/managers/CitizenManager.java @@ -297,6 +297,7 @@ private ICitizenData spawnCitizenOnPosition( colony.getEventDescriptionManager().addEventDescription(new CitizenSpawnedEvent(spawnPoint, citizenData.getName())); } + final EntityCitizen entity = (EntityCitizen) ModEntities.CITIZEN.create(world); entity.setUUID(citizenData.getUUID()); diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIStructure.java b/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIStructure.java index 268d37c798b..055ae8670ce 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIStructure.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIStructure.java @@ -797,7 +797,7 @@ public static , B extends AbstractBuildingS return RECALC; } } - + // TODO: Why predicate based search when we got our ItemStorages we look for already? final List foundStacks = InventoryUtils.filterItemHandler(placer.getWorker().getInventoryCitizen(), itemStack -> requestedMap.keySet().stream().anyMatch(storage -> ItemStackUtils.compareItemStacksIgnoreStackSize(storage.getItemStack(), itemStack))); diff --git a/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java b/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java index ce2cc794db7..6f3b45848e7 100755 --- a/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java +++ b/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java @@ -430,9 +430,10 @@ public InteractionResult checkAndHandleImportantInteractions(final Player player if (citizenData.getJob() != null) { ((AbstractEntityAIBasic) citizenData.getJob().getWorkerAI()).setDelay(TICKS_SECOND * 3); - getNavigation().stop(); - getLookControl().setLookAt(player); } + + getNavigation().stop(); + getLookControl().setLookAt(player); } return InteractionResult.SUCCESS; @@ -1302,6 +1303,25 @@ public void setCitizenExperienceHandler(final ICitizenExperienceHandler citizenE @Override public boolean hurt(@NotNull final DamageSource damageSource, final float damage) { + // TODO: temporary debug data + if (damageSource.getEntity() instanceof Player player && player.isCreative() && player.getMainHandItem().getItem() == ModItems.scanAnalyzer) + { + CompoundTag tag = new CompoundTag(); + try + { + save(tag); + } + catch (Exception e) + { + Log.getLogger().warn("Error while saving:", e); + } + + Log.getLogger() + .warn("Entity:" + getName().toString() + " uuid:" + getUUID() + " id:" + getId() + " removed:" + isRemoved() + " colonyid:" + citizenColonyHandler.getColonyId() + + " entitydata colony id:" + getEntityData().get(DATA_COLONY_ID) + " hascolony:" + (citizenColonyHandler.getColony() != null) + + " registered:" + citizenColonyHandler.registered() + " world:" + level + " saved data:" + tag); + } + if (handleInWallDamage(damageSource)) { return false; diff --git a/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenColonyHandler.java b/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenColonyHandler.java index 34c5ff82f7e..0f8725b14dd 100755 --- a/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenColonyHandler.java +++ b/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenColonyHandler.java @@ -134,6 +134,12 @@ public void updateColonyClient() colonyId = citizen.getEntityData().get(DATA_COLONY_ID); } + if (colonyId == 0) + { + citizen.discard(); + return; + } + if (citizen.getCivilianID() == 0) { citizen.setCitizenId(citizen.getEntityData().get(DATA_CITIZEN_ID)); @@ -161,6 +167,12 @@ public void onSyncDataUpdate(final EntityDataAccessor data) } } + @Override + public boolean registered() + { + return registered; + } + /** * Get the amount the worker should decrease its saturation by each action done or x blocks traveled. * 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 c1cb06f5ae9..d9057ad23a6 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 @@ -106,6 +106,11 @@ public class MinecoloniesAdvancedPathNavigate extends AbstractAdvancedPathNaviga */ private int pauseTicks = 0; + /** + * Temporary block position + */ + private BlockPos.MutableBlockPos tempPos = new BlockPos.MutableBlockPos(); + /** * Instantiates the navigation of an ourEntity. * @@ -366,13 +371,12 @@ else if (this.path != null && !this.path.isDone()) if (!this.isDone()) { Vec3 vector3d2 = path.getNextEntityPos(mob); - BlockPos blockpos = BlockPos.containing(vector3d2); - - if (ChunkPos.asLong(blockpos) == mob.chunkPosition().toLong() || WorldUtil.isEntityBlockLoaded(level, blockpos)) + tempPos.set(Mth.floor(vector3d2.x), Mth.floor(vector3d2.y) - 1, Mth.floor(vector3d2.z)); + if (ChunkPos.asLong(tempPos) == mob.chunkPosition().toLong() || WorldUtil.isEntityBlockLoaded(level, tempPos)) { mob.getMoveControl() .setWantedPosition(vector3d2.x, - level.getBlockState(blockpos.below()).isAir() ? vector3d2.y : getSmartGroundY(this.level, blockpos), + getSmartGroundY(this.level, tempPos, vector3d2.y), vector3d2.z, speedModifier); } @@ -394,18 +398,24 @@ else if (this.path != null && !this.path.isDone()) * * @param world the world. * @param pos the position to check. + * @param y * @return the next y level to go to. */ - public static double getSmartGroundY(final BlockGetter world, final BlockPos pos) + public static double getSmartGroundY(final BlockGetter world, final BlockPos pos, final double orgY) { - final BlockPos blockpos = pos.below(); - final VoxelShape voxelshape = world.getBlockState(blockpos).getCollisionShape(world, blockpos); + final BlockState state = world.getBlockState(pos); + if (state.isAir()) + { + return orgY; + } + + final VoxelShape voxelshape = state.getCollisionShape(world, pos); final double maxY = ShapeUtil.max(voxelshape, Direction.Axis.Y); if (maxY < 1.0) { return pos.getY(); } - return blockpos.getY() + maxY; + return pos.getY() + maxY; } @Nullable @@ -974,6 +984,7 @@ protected void followThePath() // Look at multiple points, incase we're too fast for (int i = this.path.getNextNodeIndex(); i < Math.min(this.path.getNodeCount(), this.path.getNextNodeIndex() + 4); i++) { + // TODO: Only keep advancing if distance gets closer, instead of looping many points, check if entity pos at node is even needed, normal pos probably fine Vec3 next = this.path.getEntityPosAtNode(this.mob, i); if (Math.abs(this.mob.getX() - next.x) < (double) this.maxDistanceToWaypoint - Math.abs(this.mob.getY() - (next.y)) * 0.1 && Math.abs(this.mob.getZ() - next.z) < (double) this.maxDistanceToWaypoint - Math.abs(this.mob.getY() - (next.y)) * 0.1 && diff --git a/src/main/java/com/minecolonies/core/event/EventHandler.java b/src/main/java/com/minecolonies/core/event/EventHandler.java index 8a7061df56d..e721eadd06f 100755 --- a/src/main/java/com/minecolonies/core/event/EventHandler.java +++ b/src/main/java/com/minecolonies/core/event/EventHandler.java @@ -143,6 +143,11 @@ public static void onEntityAdded(@NotNull final EntityJoinLevelEvent event) { event.setCanceled(true); } + + if (event.getEntity() instanceof EntityCitizen citizen && citizen.getCitizenColonyHandler().getColonyId() == 0) + { + event.setCanceled(true); + } } }