Skip to content

Commit

Permalink
Team fix (#10403)
Browse files Browse the repository at this point in the history
Calculate team via colony handler, no need to get colony for it
  • Loading branch information
Raycoms committed Nov 4, 2024
1 parent ef15650 commit 4a93822
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
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 @@ -125,10 +125,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 @@ -245,11 +245,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 @@ -375,7 +375,7 @@ public class Colony implements IColony
this.colonyFlag = new BannerPatternLayers.Builder().add(Utils.getRegistryValue(BannerPatterns.BASE, world), DyeColor.WHITE).build();
this.dimensionId = world.dimension();
onWorldLoad(world);
checkOrCreateTeam(world, getTeamName(), false);
checkOrCreateTeam(world, IColony.getTeamName(world, id), false);
}

colonyStateMachine = new TickRateStateMachine<>(INACTIVE, e ->
Expand Down Expand Up @@ -640,7 +640,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 @@ -1258,7 +1258,7 @@ public boolean isDay()
@Override
public PlayerTeam getTeam()
{
return getWorld().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);
}
}

0 comments on commit 4a93822

Please sign in to comment.