Skip to content

Commit

Permalink
Fixed 2 more bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Thodor12 committed Jan 14, 2025
1 parent d1ab51f commit 82a3fdd
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
*/
public interface IExpedition
{
/**
* Get all the leader of the expedition.
*
* @return the expedition leader.
*/
@NotNull
IExpeditionMember<?> getLeader();

/**
* Get all the members of the expedition.
*
Expand Down Expand Up @@ -81,4 +89,4 @@ public interface IExpedition
* @param compound the compound tag.
*/
void write(final CompoundTag compound);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.minecolonies.api.colony.expeditions.IExpeditionMember;
import com.minecolonies.core.colony.expeditions.AbstractExpedition;
import com.minecolonies.core.colony.expeditions.ExpeditionStage;
import com.minecolonies.core.colony.expeditions.ExpeditionVisitorMember;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -126,24 +125,6 @@ public void write(final CompoundTag compound)
compound.putString(TAG_EXPEDITION_TYPE, expeditionTypeId.toString());
}

/**
* Get the expeditionary visitor that is leading this expedition.
*
* @return the member instance.
*/
@NotNull
public ExpeditionVisitorMember getLeader()
{
for (final IExpeditionMember<?> member : members.values())
{
if (member instanceof ExpeditionVisitorMember visitorMember)
{
return visitorMember;
}
}
throw new IllegalStateException("Visitor leader from expedition is missing.");
}

/**
* Comparator class for sorting guards in a predictable order in the window.
*/
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/com/minecolonies/core/colony/CitizenData.java
Original file line number Diff line number Diff line change
Expand Up @@ -922,16 +922,6 @@ public void updateEntityIfNecessary()
return;
}

// Okay we are either just done traveling or the entity disappeared, lets check if we just finished traveling.
final Optional<BlockPos> travelingTargetCandidate = getColony().getTravelingManager().getTravellingTargetFor(this);
if (travelingTargetCandidate.isPresent())
{
// We just finished traveling, lets spawn the entity by setting the nextRespawnPosition.
getColony().getTravelingManager().finishTravellingFor(this);
nextRespawnPos = travelingTargetCandidate.get();
lastPosition = nextRespawnPos;
}

if (nextRespawnPos != null)
{
respawnAfterUpdate(nextRespawnPos);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.minecolonies.core.colony.events;

import com.minecolonies.api.colony.ICitizenData;
import com.minecolonies.api.colony.ICivilianData;
import com.minecolonies.api.colony.IColony;
import com.minecolonies.api.colony.IVisitorData;
Expand All @@ -16,13 +17,13 @@
import com.minecolonies.api.util.MessageUtils.MessagePriority;
import com.minecolonies.api.util.constant.Constants;
import com.minecolonies.core.colony.expeditions.ExpeditionCitizenMember;
import com.minecolonies.core.colony.expeditions.ExpeditionVisitorMember;
import com.minecolonies.core.colony.expeditions.colony.types.ColonyExpeditionType;
import com.minecolonies.core.colony.expeditions.encounters.ExpeditionEncounter;
import com.minecolonies.core.datalistener.ColonyExpeditionTypeListener;
import com.minecolonies.core.datalistener.ExpeditionEncounterListener;
import com.minecolonies.core.entity.visitor.ExpeditionaryVisitorType.DespawnTimeData.DespawnTime;
import com.minecolonies.core.items.ItemAdventureToken;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -319,7 +320,7 @@ private IExpeditionMember<?> getNextAttacker(final ColonyExpedition expedition)
}
}

final ExpeditionVisitorMember leader = expedition.getLeader();
final IExpeditionMember<?> leader = expedition.getLeader();
if (selected == null && !leader.isDead())
{
selected = leader;
Expand Down Expand Up @@ -497,10 +498,10 @@ public void onFinish()

// Update the respawn time for the leader
finishMember(expedition.getLeader());
final IVisitorData leaderData = expedition.getLeader().resolveCivilianData(colony);
if (leaderData != null)
final ICivilianData leaderData = expedition.getLeader().resolveCivilianData(colony);
if (leaderData instanceof IVisitorData visitorData)
{
leaderData.setExtraDataValue(EXTRA_DATA_DESPAWN_TIME, DespawnTime.fromNow(colony.getWorld(), DEFAULT_DESPAWN_TIME));
visitorData.setExtraDataValue(EXTRA_DATA_DESPAWN_TIME, DespawnTime.fromNow(colony.getWorld(), DEFAULT_DESPAWN_TIME));
}

// Remove all members to the travelling manager and respawn them and update their inventories.
Expand All @@ -514,28 +515,35 @@ public void onFinish()
*/
private void finishMember(final IExpeditionMember<?> member)
{
// Remove the member from the travelling manager.
colony.getTravelingManager().finishTravellingFor(member.getId());

if (member.isDead())
final ICivilianData civilianData = member.resolveCivilianData(colony);
if (civilianData instanceof ICitizenData citizenData)
{
// Remove the member from the colony silently in case they died
member.removeFromColony(colony);
}
else
{
// Apply usage damage to all armor of all members.
final ArmorList armor = getArmor(member);
damageArmor(armor,
armor.getTotalArmor() * Mth.randomBetween(random, MIN_PERCENTAGE_USAGE_DAMAGE, MAX_PERCENTAGE_USAGE_DAMAGE),
slot -> member.getInventory().forceArmorStackToSlot(slot, ItemStack.EMPTY));

// Write over the updated inventory
final CompoundTag inventoryTag = new CompoundTag();
member.getInventory().write(inventoryTag);
final ICivilianData data = member.resolveCivilianData(colony);
data.getInventory().read(inventoryTag);
data.getInventory().markDirty();
// Get the traveling target and set the respawn position
final Optional<BlockPos> travelingTarget = colony.getTravelingManager().getTravellingTargetFor(citizenData);
travelingTarget.ifPresent(citizenData::setNextRespawnPosition);

// Remove the member from the travelling manager.
colony.getTravelingManager().finishTravellingFor(member.getId());

if (member.isDead())
{
// Remove the member from the colony silently in case they died
member.removeFromColony(colony);
}
else
{
// Apply usage damage to all armor of all members.
final ArmorList armor = getArmor(member);
damageArmor(armor,
armor.getTotalArmor() * Mth.randomBetween(random, MIN_PERCENTAGE_USAGE_DAMAGE, MAX_PERCENTAGE_USAGE_DAMAGE),
slot -> member.getInventory().forceArmorStackToSlot(slot, ItemStack.EMPTY));

// Write over the updated inventory
final CompoundTag inventoryTag = new CompoundTag();
member.getInventory().write(inventoryTag);
citizenData.getInventory().read(inventoryTag);
citizenData.getInventory().markDirty();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ else if (member instanceof ExpeditionVisitorMember)
member.write(compound);
}

@Override
@NotNull
public IExpeditionMember<?> getLeader()
{
return leader;
}

@Override
@NotNull
public List<IExpeditionMember<?>> getMembers()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ private void tryStartExpedition(final IVisitorData visitorData, final Player pla
// Add all members to the travelling manager and de-spawn them.
final BlockPos townHallReturnPosition =
BlockPosUtil.findSpawnPosAround(colony.getWorld(), colony.getBuildingManager().getTownHall().getPosition());
for (final IExpeditionMember<?> member : expedition.getMembers())
for (final IExpeditionMember<?> member : expedition.getActiveMembers())
{
colony.getTravelingManager().startTravellingTo(member.getId(), townHallReturnPosition, TICKS_HOUR, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private boolean isEntityLoaded()
*/
private VisitorState wander()
{
EntityNavigationUtils.walkToRandomPos(this.visitor, 10, DEFAULT_SPEED);
EntityNavigationUtils.walkToRandomPosWithin(this.visitor, 10, DEFAULT_SPEED, visitor.getCitizenColonyHandler().getColony().getBuildingManager().getTownHall().getCorners());

return VisitorState.WANDERING;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.minecolonies.core.entity.visitor;

import com.minecolonies.api.colony.IColony;
import com.minecolonies.api.colony.IVisitorData;
import com.minecolonies.api.colony.expeditions.ExpeditionStatus;
import com.minecolonies.api.entity.ModEntities;
Expand All @@ -12,6 +13,7 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
Expand Down Expand Up @@ -75,6 +77,17 @@ public InteractionResult onPlayerInteraction(final AbstractEntityVisitor visitor
return InteractionResult.PASS;
}

@Override
public void onDied(final VisitorCitizen visitor, final DamageSource cause)
{
final IColony colony = visitor.getCitizenColonyHandler().getColony();
if (colony != null && visitor.getCitizenData() != null)
{
colony.getVisitorManager().removeCivilian(visitor.getCitizenData());
colony.getExpeditionManager().removeCreatedExpedition(visitor.getCivilianID());
}
}

@Override
public void update(final IVisitorData visitor)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,19 @@
import com.minecolonies.core.entity.ai.minimal.EntityAIInteractToggleAble;
import com.minecolonies.core.entity.ai.minimal.LookAtEntityGoal;
import com.minecolonies.core.entity.ai.minimal.LookAtEntityInteractGoal;
import com.minecolonies.core.entity.ai.visitor.EntityAIVisitor;
import com.minecolonies.core.entity.citizen.EntityCitizen;
import com.minecolonies.core.entity.citizen.citizenhandlers.CitizenExperienceHandler;
import com.minecolonies.core.entity.citizen.citizenhandlers.CitizenInventoryHandler;
import com.minecolonies.core.entity.citizen.citizenhandlers.CitizenJobHandler;
import com.minecolonies.core.entity.citizen.citizenhandlers.CitizenSleepHandler;
import com.minecolonies.core.entity.pathfinding.navigation.MovementHandler;
import com.minecolonies.core.network.messages.client.ItemParticleEffectMessage;
import com.minecolonies.core.network.messages.server.colony.OpenInventoryMessage;
import com.minecolonies.core.util.citizenutils.CitizenItemUtils;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
Expand All @@ -55,12 +52,10 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static com.minecolonies.api.util.ItemStackUtils.ISFOOD;
import static com.minecolonies.api.util.constant.CitizenConstants.TICKS_20;
import static com.minecolonies.api.util.constant.Constants.*;
import static com.minecolonies.api.util.constant.NbtTagConstants.TAG_CITIZEN;
import static com.minecolonies.api.util.constant.NbtTagConstants.TAG_COLONY_ID;
import static com.minecolonies.api.util.constant.TranslationConstants.MESSAGE_INTERACTION_VISITOR_FOOD;
import static com.minecolonies.core.entity.ai.minimal.EntityAIInteractToggleAble.*;

/**
Expand Down Expand Up @@ -551,7 +546,7 @@ public void readAdditionalSaveData(final CompoundTag compound)
}

@Override
public void die(DamageSource cause)
public void die(@NotNull DamageSource cause)
{
super.die(cause);
if (!level.isClientSide())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2879,7 +2879,7 @@
"com.minecolonies.core.expedition.gui.guards.subheader.met": "Enough guards",
"com.minecolonies.core.expedition.gui.guards.subheader.not_met": "Guards needed: %d",
"com.minecolonies.core.expedition.start": "[%s]: Thanks for the help, we will be leaving soon to start the expedition!",
"com.minecolonies.core.expedition.start.fail": "[%s]: You don't have all of the required items yet, please gather all the items and come back!",
"com.minecolonies.core.expedition.start.fail": "[%s]: You don't have all of the required items or enough guards, please make sure all requirements are met and come back to me!",
"com.minecolonies.core.expedition.finish": "[%s]: We've returned from our expedition! Come visit me at the Town Hall to claim your loot.",
"com.minecolonies.core.expedition.failure": "The expedition lead by %s has not returned in time, they either got lost or died on the way.",
"com.minecolonies.core.expedition.finished.leaving": "[%s]: I will be leaving because you have claimed all of your rewards, goodbye!",
Expand Down

0 comments on commit 82a3fdd

Please sign in to comment.