Skip to content

Commit

Permalink
No more teams
Browse files Browse the repository at this point in the history
  • Loading branch information
Raycoms committed Nov 12, 2024
1 parent c196070 commit 3d798a7
Show file tree
Hide file tree
Showing 65 changed files with 266 additions and 414 deletions.
19 changes: 0 additions & 19 deletions src/main/java/com/minecolonies/api/colony/IColony.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.scores.PlayerTeam;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.common.capabilities.CapabilityToken;
Expand Down Expand Up @@ -119,17 +118,6 @@ public interface IColony
*/
boolean hasBuilding(final String building, final int level, final boolean singleBuilding);

/**
* Defines the team name for all colonies (both Colony and ColonyView)
*
* @return The team name
*/
static String getTeamName(final Level level, final int id)
{
final String dim = level.dimension().location().getPath();
return TEAM_COLONY_NAME + "_" + (dim.length() > 10 ? dim.hashCode() : dim) + "_" + id;
}

/**
* Getter for the team colony color.
*
Expand All @@ -151,13 +139,6 @@ static String getTeamName(final Level level, final int id)
*/
boolean isDay();

/**
* Retrieves the team of the colony
*
* @return Team of the colony
*/
PlayerTeam getTeam();

/**
* Get the last contact of a player to the colony in hours.
*
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/com/minecolonies/api/colony/IColonyView.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.scores.PlayerTeam;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -343,9 +342,6 @@ public interface IColonyView extends IColony
@Override
boolean hasWarehouse();

@Override
PlayerTeam getTeam();

@Override
int getLastContactInHours();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
import com.minecolonies.core.entity.pathfinding.navigation.AbstractAdvancedPathNavigate;
import com.minecolonies.core.entity.pathfinding.navigation.PathingStuckHandler;
import com.mojang.datafixers.util.Pair;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
Expand All @@ -46,7 +49,6 @@
import net.minecraft.world.item.ShieldItem;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.scores.PlayerTeam;
import net.minecraftforge.items.IItemHandler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -235,18 +237,6 @@ public boolean isNoAi()
return false;
}

@Override
@Nullable
protected PlayerTeam getAssignedTeam()
{
final ICitizenColonyHandler citizenColonyHandler = getCitizenColonyHandler();
if (citizenColonyHandler == null)
{
return null;
}
return citizenColonyHandler.getTeam(level);
}

/**
* Sets the textures of all citizens and distinguishes between male and female.
*/
Expand Down Expand Up @@ -782,4 +772,29 @@ public boolean isSleeping()
{
return getCitizenSleepHandler().isAsleep();
}

@Override
public int getTeamColor()
{
if (getCitizenColonyHandler().getColony() == null)
{
return super.getTeamColor();
}
return getCitizenColonyHandler().getColony().getTeamColonyColor().getColor();
}

@Override
@NotNull
public Component getDisplayName()
{
if (getCitizenColonyHandler().getColony() == null)
{
return super.getDisplayName();
}
if (getName() instanceof MutableComponent mutableComponent)
{
return mutableComponent.withStyle(getCitizenColonyHandler().getColony().getTeamColonyColor()).withStyle((style) -> style.withHoverEvent(this.createHoverEvent()).withInsertion(this.getStringUUID()));
}
return super.getDisplayName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
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 @@ -46,7 +44,7 @@ public interface ICitizenColonyHandler
* @return the colony of the citizen or null.
*/
@Nullable
IColony getColony();
IColony getColonyOrRegister();

/**
* Getter for the colony id.
Expand Down Expand Up @@ -77,8 +75,8 @@ public interface ICitizenColonyHandler
boolean registered();

/**
* Get the citizen team.
* @return the team.
* Unsafe colony getter, doesn't run registration.
* @return the colony.
*/
PlayerTeam getTeam(final Level level);
IColony getColony();
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.scores.PlayerTeam;
import net.minecraftforge.common.util.ITeleporter;
import org.jetbrains.annotations.NotNull;

Expand All @@ -52,7 +51,6 @@
import static com.minecolonies.api.util.constant.ColonyManagerConstants.NO_COLONY_ID;
import static com.minecolonies.api.util.constant.NbtTagConstants.*;
import static com.minecolonies.api.util.constant.RaiderConstants.*;
import static com.minecolonies.core.util.TeamUtils.checkOrCreateTeam;

/**
* Abstract for all raider entities.
Expand Down Expand Up @@ -732,13 +730,6 @@ public void initStatsFor(final double baseHealth, final double difficulty, final
this.setHealth(this.getMaxHealth());
}

@Override
@Nullable
protected PlayerTeam getAssignedTeam()
{
return checkOrCreateTeam(level, RAID_TEAM);
}

/**
* Get the mobs difficulty
*
Expand Down Expand Up @@ -774,4 +765,11 @@ public ITickRateStateMachine<IState> getAI()
{
return ai;
}

@Override
public String getTeamName()
{
// All raiders are in the same team. You're doomed!
return "raider";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.minecolonies.api.util.constant.ColonyConstants;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
Expand All @@ -15,15 +16,12 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.entity.EntityTypeTest;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.scores.PlayerTeam;
import net.minecraft.world.scores.Team;
import net.minecraftforge.common.util.ITeleporter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
* Special abstract minecolonies mob that overrides laggy vanilla behaviour.
Expand Down Expand Up @@ -320,78 +318,6 @@ public void updateSwimAmount()

}

/**
* Get the team this entity is assigned to.
*
* @return the team instance.
*/
@Nullable
protected abstract PlayerTeam getAssignedTeam();

@Override
@Nullable
public final Team getTeam()
{
final PlayerTeam assignedTeam = getAssignedTeam();
registerToTeamInternal(assignedTeam);
return assignedTeam;
}

/**
* Register this entity to its own assigned team.
*/
public void registerToTeam()
{
registerToTeamInternal(getAssignedTeam());
}

/**
* Internal method for team registration.
*
* @param team the team to register to.
*/
private void registerToTeamInternal(@Nullable final PlayerTeam team)
{
if (team != null && !isInTeam(team))
{
level.getScoreboard().addPlayerToTeam(getScoreboardName(), team);
}
}

/**
* Remove the entity from its own assigned team.
*/
public void removeFromTeam()
{
final PlayerTeam team = getAssignedTeam();
if (team != null && isInTeam(team))
{
level.getScoreboard().removePlayerFromTeam(getScoreboardName(), team);
}
}

/**
* Check if the current entity is assigned to the provided team.
*
* @param team the input team.
* @return true if so.
*/
private boolean isInTeam(@NotNull final PlayerTeam team)
{
return Objects.equals(level.getScoreboard().getPlayersTeam(getScoreboardName()), team);
}

@Override
public void remove(@NotNull final RemovalReason reason)
{
super.remove(reason);
final PlayerTeam playersTeam = level.getScoreboard().getPlayersTeam(getScoreboardName());
if (playersTeam != null)
{
level.getScoreboard().removePlayerFromTeam(getScoreboardName(), playersTeam);
}
}

/**
* Static Byte values to avoid frequent autoboxing
*/
Expand Down Expand Up @@ -426,4 +352,20 @@ public void knockback(double power, double xRatio, double zRatio)
super.knockback(power, xRatio, zRatio);
}
}

@Override
public boolean hurt(final DamageSource dmgSource, final float dmg)
{
if (dmgSource.getEntity() instanceof AbstractFastMinecoloniesEntity otherFastMinecolEntity && otherFastMinecolEntity.getTeamName().equals(getTeamName()))
{
return false;
}
return super.hurt(dmgSource, dmg);
}

/**
* Get the team name of this entity.
* @return the team name.
*/
public abstract String getTeamName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private Optional<Boolean> test(@NotNull final LootContext lootContext, @Nullable
{
return Optional.ofNullable(entity)
.map(e -> e instanceof AbstractEntityCitizen citizen ? citizen : null)
.flatMap(c -> test(lootContext, c.getCitizenColonyHandler().getColony()));
.flatMap(c -> test(lootContext, c.getCitizenColonyHandler().getColonyOrRegister()));
}

private Optional<Boolean> test(@NotNull final LootContext lootContext, @Nullable Vec3 origin)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/minecolonies/api/util/FoodUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static double getFoodValue(final ItemStack foodStack, final AbstractEntit
{
final FoodProperties itemFood = foodStack.getItem().getFoodProperties(foodStack, citizen);
final int housingLevel = citizen.getCitizenData().getHomeBuilding() == null ? 0 : citizen.getCitizenData().getHomeBuilding().getBuildingLevel();
final double researchBonus = citizen.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(SATURATION);
final double researchBonus = citizen.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(SATURATION);
return getFoodValue(foodStack, itemFood, housingLevel, researchBonus);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ else if (foodStack.getItem() instanceof ItemBowlFood)
citizen.getCitizenData().getCitizenHappinessHandler().addModifier(new ExpirationBasedHappinessModifier(HADGREATFOOD, 2.0, new StaticHappinessSupplier(2.0), 5));
}

IColony citizenColony = citizen.getCitizenColonyHandler().getColony();
IColony citizenColony = citizen.getCitizenColonyHandler().getColonyOrRegister();
if (citizenColony != null)
{
AdvancementUtils.TriggerAdvancementPlayersForColony(citizenColony, playerMP -> AdvancementTriggers.CITIZEN_EAT_FOOD.trigger(playerMP, foodStack));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/minecolonies/api/util/MessageUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static MessageBuilder forCitizen(final AbstractEntityCitizen citizen, fin
*/
public static MessageBuilder forCitizen(final AbstractEntityCitizen citizen, Component component)
{
if (citizen.getCitizenColonyHandler().getColony() != null)
if (citizen.getCitizenColonyHandler().getColonyOrRegister() != null)
{
final IJob<?> job = citizen.getCitizenJobHandler().getColonyJob();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ private static VertexBuffer draw(final BufferBuilder bufferbuilder,
final Color colour = colonyColours.computeIfAbsent(colonyId, id ->
{
final IColonyView colony = IMinecoloniesAPI.getInstance().getColonyManager().getColonyView(id, Minecraft.getInstance().level.dimension());
final ChatFormatting team = colony != null ? colony.getTeamColonyColor()
: id == playerColonyId ? ChatFormatting.WHITE : ChatFormatting.RED;
final ChatFormatting team = colony != null ? colony.getTeamColonyColor() : id == playerColonyId ? ChatFormatting.WHITE : ChatFormatting.RED;
return new Color(team.getColor());
});

Expand Down
Loading

0 comments on commit 3d798a7

Please sign in to comment.