Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Team fix #10403

Merged
merged 6 commits into from
Nov 4, 2024
Merged

Team fix #10403

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/com/minecolonies/api/colony/IColony.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ public interface IColony
*
* @return The team name
*/
default String getTeamName()
static String getTeamName(final Level level, final int id)
{
final String dim = getDimension().location().getPath();
return TEAM_COLONY_NAME + "_" + (dim.length() > 10 ? dim.hashCode() : dim) + "_" + getID();
final String dim = level.dimension().location().getPath();
return TEAM_COLONY_NAME + "_" + (dim.length() > 10 ? dim.hashCode() : dim) + "_" + id;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,11 @@ public boolean isNoAi()
protected PlayerTeam getAssignedTeam()
{
final ICitizenColonyHandler citizenColonyHandler = getCitizenColonyHandler();
if (citizenColonyHandler == null || citizenColonyHandler.getColony() == null)
if (citizenColonyHandler == null)
{
return null;
}
return citizenColonyHandler.getColony().getTeam();
return citizenColonyHandler.getTeam(level);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.minecolonies.api.colony.IColony;
import com.minecolonies.api.colony.buildings.IBuilding;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.world.level.Level;
import net.minecraft.world.scores.PlayerTeam;
import org.jetbrains.annotations.Nullable;

public interface ICitizenColonyHandler
Expand Down Expand Up @@ -73,4 +75,10 @@ public interface ICitizenColonyHandler
void onSyncDataUpdate(EntityDataAccessor<?> dataAccessor);

boolean registered();

/**
* Get the citizen team.
* @return the team.
*/
PlayerTeam getTeam(final Level level);
}
4 changes: 2 additions & 2 deletions src/main/java/com/minecolonies/core/colony/Colony.java
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ protected Colony(final int id, @Nullable final Level world)
{
this.dimensionId = world.dimension();
onWorldLoad(world);
checkOrCreateTeam(world, getTeamName(), false);
checkOrCreateTeam(world, IColony.getTeamName(world, id), false);
}
this.permissions = new Permissions(this);
researchManager = new ResearchManager(this);
Expand Down Expand Up @@ -632,7 +632,7 @@ public void updateAttackingPlayers()
public PlayerTeam getTeam()
{
// This getter will create the team if it doesn't exist. Could do something different though in the future.
return checkOrCreateTeam(world, getTeamName(), false);
return checkOrCreateTeam(world, IColony.getTeamName(world, id), false);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/minecolonies/core/colony/ColonyView.java
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ public boolean isDay()
@Override
public PlayerTeam getTeam()
{
return world.getScoreboard().getPlayerTeam(getTeamName());
return world.getScoreboard().getPlayerTeam(IColony.getTeamName(world, id));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.scores.PlayerTeam;
import org.jetbrains.annotations.Nullable;

import static com.minecolonies.api.entity.citizen.AbstractEntityCitizen.*;
import static com.minecolonies.api.util.constant.CitizenConstants.SATURATION_DECREASE_FACTOR;
import static com.minecolonies.core.util.TeamUtils.checkOrCreateTeam;

/**
* Handles all colony related methods for the citizen.
Expand Down Expand Up @@ -233,4 +236,10 @@ public void onCitizenRemoved()
citizen.getCitizenData().setLastPosition(citizen.blockPosition());
}
}

@Override
public PlayerTeam getTeam(final Level level)
{
return checkOrCreateTeam(level, IColony.getTeamName(level, colonyId), false);
}
}