diff --git a/src/main/java/com/minecolonies/api/colony/IColony.java b/src/main/java/com/minecolonies/api/colony/IColony.java index 4212bcd6795..8b49e882c6b 100755 --- a/src/main/java/com/minecolonies/api/colony/IColony.java +++ b/src/main/java/com/minecolonies/api/colony/IColony.java @@ -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; } /** diff --git a/src/main/java/com/minecolonies/api/entity/citizen/AbstractEntityCitizen.java b/src/main/java/com/minecolonies/api/entity/citizen/AbstractEntityCitizen.java index 6d631267eb1..8b6ffe83a0a 100755 --- a/src/main/java/com/minecolonies/api/entity/citizen/AbstractEntityCitizen.java +++ b/src/main/java/com/minecolonies/api/entity/citizen/AbstractEntityCitizen.java @@ -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); } /** 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 9894600f529..122a60d4711 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 @@ -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 @@ -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); } diff --git a/src/main/java/com/minecolonies/core/colony/Colony.java b/src/main/java/com/minecolonies/core/colony/Colony.java index 885c6ee1ba1..12bf606ccbb 100644 --- a/src/main/java/com/minecolonies/core/colony/Colony.java +++ b/src/main/java/com/minecolonies/core/colony/Colony.java @@ -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); @@ -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); } /** diff --git a/src/main/java/com/minecolonies/core/colony/ColonyView.java b/src/main/java/com/minecolonies/core/colony/ColonyView.java index 7365fba8fd1..d5ed603c49b 100644 --- a/src/main/java/com/minecolonies/core/colony/ColonyView.java +++ b/src/main/java/com/minecolonies/core/colony/ColonyView.java @@ -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 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 0f8725b14dd..0f17aa1c181 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 @@ -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. @@ -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); + } }