Skip to content

Commit

Permalink
use static util to get team without needing the colony.
Browse files Browse the repository at this point in the history
  • Loading branch information
Raycoms committed Nov 4, 2024
1 parent cca3f2b commit f270db8
Showing 5 changed files with 24 additions and 7 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
@@ -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;
}

/**
Original file line number Diff line number Diff line change
@@ -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);
}

/**
Original file line number Diff line number Diff line change
@@ -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);
}
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
@@ -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);
}

/**
Original file line number Diff line number Diff line change
@@ -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));
}
}

0 comments on commit f270db8

Please sign in to comment.