Skip to content

Commit

Permalink
Various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
someaddons committed Oct 16, 2024
1 parent 7f4e6ef commit 0c5ad64
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,6 @@ public interface ICitizenColonyHandler
* @param dataAccessor
*/
void onSyncDataUpdate(EntityDataAccessor<?> dataAccessor);

boolean registered();
}
3 changes: 2 additions & 1 deletion src/main/java/com/minecolonies/core/colony/CitizenData.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

/**
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ public static <J extends AbstractJobStructure<?, J>, B extends AbstractBuildingS
return RECALC;
}
}

// TODO: Why predicate based search when we got our ItemStorages we look for already?
final List<ItemStack> foundStacks = InventoryUtils.filterItemHandler(placer.getWorker().getInventoryCitizen(),
itemStack -> requestedMap.keySet().stream().anyMatch(storage -> ItemStackUtils.compareItemStacksIgnoreStackSize(storage.getItemStack(), itemStack)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
}
Expand All @@ -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
Expand Down Expand Up @@ -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 &&
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/minecolonies/core/event/EventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit 0c5ad64

Please sign in to comment.