diff --git a/src/main/java/com/minecolonies/api/colony/IColony.java b/src/main/java/com/minecolonies/api/colony/IColony.java index b30f2377ad8..28adaab8e72 100755 --- a/src/main/java/com/minecolonies/api/colony/IColony.java +++ b/src/main/java/com/minecolonies/api/colony/IColony.java @@ -23,7 +23,6 @@ import net.minecraft.world.level.block.entity.BannerPatternLayers; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.LevelChunk; -import net.minecraft.world.scores.PlayerTeam; import net.neoforged.neoforge.event.tick.LevelTickEvent; import net.neoforged.neoforge.event.tick.ServerTickEvent; import org.jetbrains.annotations.NotNull; @@ -120,17 +119,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. * @@ -152,13 +140,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. * diff --git a/src/main/java/com/minecolonies/api/colony/IColonyView.java b/src/main/java/com/minecolonies/api/colony/IColonyView.java index ca3b93f4c8d..15d631bf978 100755 --- a/src/main/java/com/minecolonies/api/colony/IColonyView.java +++ b/src/main/java/com/minecolonies/api/colony/IColonyView.java @@ -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; @@ -334,9 +333,6 @@ public interface IColonyView extends IColony @Override boolean hasWarehouse(); - @Override - PlayerTeam getTeam(); - @Override int getLastContactInHours(); 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 d84ceaf319b..83ba052af95 100755 --- a/src/main/java/com/minecolonies/api/entity/citizen/AbstractEntityCitizen.java +++ b/src/main/java/com/minecolonies/api/entity/citizen/AbstractEntityCitizen.java @@ -26,8 +26,11 @@ 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.core.Direction; +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; @@ -52,7 +55,6 @@ import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.neoforged.neoforge.items.IItemHandler; -import net.minecraft.world.scores.PlayerTeam; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -240,18 +242,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. */ @@ -813,4 +803,29 @@ public IItemHandler getItemHandlerCap(final Direction facing) final ICitizenData data = getCitizenData(); return data == null ? null : data.getInventory(); } + + @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(); + } } 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 122a60d4711..88deaf9622b 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,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 @@ -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. @@ -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(); } diff --git a/src/main/java/com/minecolonies/api/entity/mobs/AbstractEntityRaiderMob.java b/src/main/java/com/minecolonies/api/entity/mobs/AbstractEntityRaiderMob.java index 5c824e0e495..6ca8a734303 100644 --- a/src/main/java/com/minecolonies/api/entity/mobs/AbstractEntityRaiderMob.java +++ b/src/main/java/com/minecolonies/api/entity/mobs/AbstractEntityRaiderMob.java @@ -39,7 +39,6 @@ import net.minecraft.world.level.ServerLevelAccessor; import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.portal.DimensionTransition; -import net.minecraft.world.scores.PlayerTeam; import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; @@ -49,7 +48,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. @@ -725,13 +723,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 * @@ -767,4 +758,11 @@ public ITickRateStateMachine getAI() { return ai; } + + @Override + public int getTeamId() + { + // All raiders are in the same team. You're doomed! + return -1; + } } diff --git a/src/main/java/com/minecolonies/api/entity/other/AbstractFastMinecoloniesEntity.java b/src/main/java/com/minecolonies/api/entity/other/AbstractFastMinecoloniesEntity.java index dfc756663b2..7cd51922a30 100644 --- a/src/main/java/com/minecolonies/api/entity/other/AbstractFastMinecoloniesEntity.java +++ b/src/main/java/com/minecolonies/api/entity/other/AbstractFastMinecoloniesEntity.java @@ -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; @@ -16,13 +17,10 @@ import net.minecraft.world.level.entity.EntityTypeTest; import net.minecraft.world.level.portal.DimensionTransition; import net.minecraft.world.phys.Vec3; -import net.minecraft.world.scores.PlayerTeam; -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. @@ -301,78 +299,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 PlayerTeam 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 */ @@ -407,4 +333,21 @@ 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.getTeamId() == getTeamId()) + { + return false; + } + return super.hurt(dmgSource, dmg); + } + + /** + * Get the team name of this entity. + * todo sam make colony ids unique across dimensions. + * @return the team name. + */ + public abstract int getTeamId(); } diff --git a/src/main/java/com/minecolonies/api/loot/ResearchUnlocked.java b/src/main/java/com/minecolonies/api/loot/ResearchUnlocked.java index 01da64cc525..4e6735c217f 100644 --- a/src/main/java/com/minecolonies/api/loot/ResearchUnlocked.java +++ b/src/main/java/com/minecolonies/api/loot/ResearchUnlocked.java @@ -95,7 +95,7 @@ private Optional 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 test(@NotNull final LootContext lootContext, @Nullable Vec3 origin) diff --git a/src/main/java/com/minecolonies/api/util/FoodUtils.java b/src/main/java/com/minecolonies/api/util/FoodUtils.java index fd668962804..111a3098814 100644 --- a/src/main/java/com/minecolonies/api/util/FoodUtils.java +++ b/src/main/java/com/minecolonies/api/util/FoodUtils.java @@ -70,7 +70,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); } } diff --git a/src/main/java/com/minecolonies/api/util/ItemStackUtils.java b/src/main/java/com/minecolonies/api/util/ItemStackUtils.java index 076ce3d2bdd..d310d70203b 100755 --- a/src/main/java/com/minecolonies/api/util/ItemStackUtils.java +++ b/src/main/java/com/minecolonies/api/util/ItemStackUtils.java @@ -919,7 +919,7 @@ public static void consumeFood(final ItemStack foodStack, final AbstractEntityCi } } - IColony citizenColony = citizen.getCitizenColonyHandler().getColony(); + IColony citizenColony = citizen.getCitizenColonyHandler().getColonyOrRegister(); if (citizenColony != null) { AdvancementUtils.TriggerAdvancementPlayersForColony(citizenColony, playerMP -> AdvancementTriggers.CITIZEN_EAT_FOOD.get().trigger(playerMP, foodStack)); diff --git a/src/main/java/com/minecolonies/api/util/MessageUtils.java b/src/main/java/com/minecolonies/api/util/MessageUtils.java index 07e8c071e31..c73ea17971b 100644 --- a/src/main/java/com/minecolonies/api/util/MessageUtils.java +++ b/src/main/java/com/minecolonies/api/util/MessageUtils.java @@ -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(); diff --git a/src/main/java/com/minecolonies/core/colony/Colony.java b/src/main/java/com/minecolonies/core/colony/Colony.java index 33b4bb90e05..15a0a3a78e6 100644 --- a/src/main/java/com/minecolonies/core/colony/Colony.java +++ b/src/main/java/com/minecolonies/core/colony/Colony.java @@ -65,7 +65,6 @@ import net.minecraft.world.level.block.entity.BannerPatterns; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.LevelChunk; -import net.minecraft.world.scores.PlayerTeam; import net.neoforged.neoforge.common.NeoForge; import net.neoforged.neoforge.event.tick.LevelTickEvent; import net.neoforged.neoforge.event.tick.ServerTickEvent; @@ -85,7 +84,6 @@ import static com.minecolonies.api.util.constant.NbtTagConstants.*; import static com.minecolonies.api.util.constant.TranslationConstants.*; import static com.minecolonies.core.MineColonies.getConfig; -import static com.minecolonies.core.util.TeamUtils.checkOrCreateTeam; /** * This class describes a colony and contains all the data and methods for manipulating a Colony. @@ -375,7 +373,6 @@ 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, IColony.getTeamName(world, id), false); } colonyStateMachine = new TickRateStateMachine<>(INACTIVE, e -> @@ -635,14 +632,6 @@ public void updateAttackingPlayers() } } - @Override - @Nullable - 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, IColony.getTeamName(world, id), false); - } - /** * Set up the colony color for team handling for pvp. * @@ -653,12 +642,6 @@ public void setColonyColor(final ChatFormatting colonyColor) if (this.world != null) { this.colonyTeamColor = colonyColor; - final PlayerTeam team = getTeam(); - if (team != null) - { - team.setColor(colonyColor); - team.setPlayerPrefix(Component.literal(colonyColor.toString())); - } } this.markDirty(); } diff --git a/src/main/java/com/minecolonies/core/colony/ColonyView.java b/src/main/java/com/minecolonies/core/colony/ColonyView.java index 22a9a36c3b1..cb62b8336a9 100644 --- a/src/main/java/com/minecolonies/core/colony/ColonyView.java +++ b/src/main/java/com/minecolonies/core/colony/ColonyView.java @@ -59,7 +59,6 @@ import net.minecraft.world.level.block.entity.BannerPatterns; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.LevelChunk; -import net.minecraft.world.scores.PlayerTeam; import net.neoforged.api.distmarker.Dist; import net.neoforged.api.distmarker.OnlyIn; import net.neoforged.neoforge.event.tick.LevelTickEvent; @@ -1255,12 +1254,6 @@ public boolean isDay() return false; } - @Override - public PlayerTeam getTeam() - { - return getWorld().getScoreboard().getPlayerTeam(IColony.getTeamName(getWorld(), id)); - } - @Override public int getLastContactInHours() { diff --git a/src/main/java/com/minecolonies/core/colony/managers/CitizenManager.java b/src/main/java/com/minecolonies/core/colony/managers/CitizenManager.java index f08e5e244b1..c774b5176cc 100755 --- a/src/main/java/com/minecolonies/core/colony/managers/CitizenManager.java +++ b/src/main/java/com/minecolonies/core/colony/managers/CitizenManager.java @@ -142,7 +142,6 @@ public void registerCivilian(final AbstractCivilianEntity entity) if (existingCitizen.isEmpty()) { data.setEntity(entity); - entity.registerToTeam(); return; } @@ -159,7 +158,6 @@ public void unregisterCivilian(final AbstractCivilianEntity entity) final ICitizenData data = citizens.get(entity.getCivilianID()); if (data != null && data.getEntity().isPresent() && data.getEntity().get() == entity) { - entity.removeFromTeam(); citizens.get(entity.getCivilianID()).setEntity(null); } } diff --git a/src/main/java/com/minecolonies/core/colony/pvp/AttackingPlayer.java b/src/main/java/com/minecolonies/core/colony/pvp/AttackingPlayer.java index 7b22ff46816..b53b3162442 100755 --- a/src/main/java/com/minecolonies/core/colony/pvp/AttackingPlayer.java +++ b/src/main/java/com/minecolonies/core/colony/pvp/AttackingPlayer.java @@ -54,7 +54,7 @@ public Player getPlayer() */ public static boolean isValidAttack(final AbstractEntityCitizen citizen, final Colony colony) { - final IColony guardColony = citizen.getCitizenColonyHandler().getColony(); + final IColony guardColony = citizen.getCitizenColonyHandler().getColonyOrRegister(); if (guardColony == null) { return false; diff --git a/src/main/java/com/minecolonies/core/entity/ai/combat/CombatUtils.java b/src/main/java/com/minecolonies/core/entity/ai/combat/CombatUtils.java index 961181dc913..1bcb42ede59 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/combat/CombatUtils.java +++ b/src/main/java/com/minecolonies/core/entity/ai/combat/CombatUtils.java @@ -101,7 +101,7 @@ public static void notifyGuardsOfTarget(final AbstractEntityCitizen user, final if (target instanceof AbstractEntityRaiderMob) { - for (final Map.Entry entry : user.getCitizenColonyHandler().getColony().getBuildingManager().getBuildings().entrySet()) + for (final Map.Entry entry : user.getCitizenColonyHandler().getColonyOrRegister().getBuildingManager().getBuildings().entrySet()) { if (entry.getValue() instanceof AbstractBuildingGuards && user.blockPosition().distSqr(entry.getKey()) < callRange) diff --git a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAICitizenChild.java b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAICitizenChild.java index 513adecd407..0c1d4fa9eb6 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAICitizenChild.java +++ b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAICitizenChild.java @@ -213,7 +213,7 @@ private IState followingEntity() private IState visitHuts() { // Find a hut to visit - if (visitingPath == null && child.getCitizenColonyHandler().getColony() != null) + if (visitingPath == null && child.getCitizenColonyHandler().getColonyOrRegister() != null) { // Visiting huts for 3min. if (actionTimer <= 0 && visitHutPos == null) @@ -221,11 +221,11 @@ private IState visitHuts() actionTimer = 3 * 60 * 20; } - int index = child.getCitizenColonyHandler().getColony().getBuildingManager().getBuildings().size(); + int index = child.getCitizenColonyHandler().getColonyOrRegister().getBuildingManager().getBuildings().size(); index = rand.nextInt(index); - final List buildings = new ArrayList<>(child.getCitizenColonyHandler().getColony().getBuildingManager().getBuildings().keySet()); + final List buildings = new ArrayList<>(child.getCitizenColonyHandler().getColonyOrRegister().getBuildingManager().getBuildings().keySet()); visitHutPos = buildings.get(index); visitingPath = child.getNavigation().moveToXYZ(visitHutPos.getX(), visitHutPos.getY(), visitHutPos.getZ(), 1.0d); @@ -264,9 +264,9 @@ private boolean tryGrowUp() return false; } - if (child.getCitizenColonyHandler().getColony() != null) + if (child.getCitizenColonyHandler().getColonyOrRegister() != null) { - if (child.getCitizenColonyHandler().getColony().useAdditionalChildTime(BONUS_TIME_COLONY)) + if (child.getCitizenColonyHandler().getColonyOrRegister().useAdditionalChildTime(BONUS_TIME_COLONY)) { aiActiveTime += BONUS_TIME_COLONY; } @@ -274,18 +274,18 @@ private boolean tryGrowUp() if (aiActiveTime >= MIN_ACTIVE_TIME) { - final double growthModifier = (1 + child.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(GROWTH)); + final double growthModifier = (1 + child.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(GROWTH)); // 1/144 Chance to grow up, every 25 seconds = avg 1h. Set to half since this AI isnt always active, e.g. sleeping. At 2h they directly grow if (rand.nextInt((int) (70 / growthModifier) + 1) == 0 || aiActiveTime > 70000 / growthModifier) { child.getCitizenColonyHandler() - .getColony() + .getColonyOrRegister() .getEventDescriptionManager() .addEventDescription(new CitizenGrownUpEvent(child.blockPosition(), child.getCitizenData().getName())); - if (child.getCitizenColonyHandler().getColony().getCitizenManager().getCitizens().size() <= GROW_UP_NOTIFY_LIMIT) + if (child.getCitizenColonyHandler().getColonyOrRegister().getCitizenManager().getCitizens().size() <= GROW_UP_NOTIFY_LIMIT) { - MessageUtils.format(MESSAGE_INFO_COLONY_CHILD_GREW_UP, child.getName().getString()).sendTo(child.getCitizenColonyHandler().getColony()).forAllPlayers(); + MessageUtils.format(MESSAGE_INFO_COLONY_CHILD_GREW_UP, child.getName().getString()).sendTo(child.getCitizenColonyHandler().getColonyOrRegister()).forAllPlayers(); } // Grow up child.setIsChild(false); diff --git a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAICitizenWander.java b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAICitizenWander.java index 569eb09d1b2..ddf6b7ec51c 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAICitizenWander.java +++ b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAICitizenWander.java @@ -203,7 +203,7 @@ private IState decide() final int randomBit = citizen.getRandom().nextInt(100); if (randomBit < LEISURE_CHANCE) { - leisureSite = citizen.getCitizenColonyHandler().getColony().getBuildingManager().getRandomLeisureSite(); + leisureSite = citizen.getCitizenColonyHandler().getColonyOrRegister().getBuildingManager().getRandomLeisureSite(); if (leisureSite == null) { if (citizen.getCitizenData().getHomeBuilding() != null) @@ -212,7 +212,7 @@ private IState decide() } else { - leisureSite = citizen.getCitizenColonyHandler().getColony().getCenter(); + leisureSite = citizen.getCitizenColonyHandler().getColonyOrRegister().getCenter(); } } diff --git a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAIEatTask.java b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAIEatTask.java index dee9fbeed79..90524d396d4 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAIEatTask.java +++ b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAIEatTask.java @@ -237,7 +237,7 @@ private EatingState getFoodYourself() return SEARCH_RESTAURANT; } - final IColony colony = citizen.getCitizenColonyHandler().getColony(); + final IColony colony = citizen.getCitizenColonyHandler().getColonyOrRegister(); final IBuilding cookBuilding = colony.getBuildingManager().getBuilding(restaurantPos); if (cookBuilding instanceof BuildingCook) { @@ -398,7 +398,7 @@ private EatingState goToRestaurant() { if (restaurantPos != null) { - final IBuilding building = citizen.getCitizenColonyHandler().getColony().getBuildingManager().getBuilding(restaurantPos); + final IBuilding building = citizen.getCitizenColonyHandler().getColonyOrRegister().getBuildingManager().getBuilding(restaurantPos); if (building != null) { if (building.isInBuilding(citizen.blockPosition())) diff --git a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAIMournCitizen.java b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAIMournCitizen.java index 5c5ac71880c..3daf3b2f70f 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAIMournCitizen.java +++ b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAIMournCitizen.java @@ -6,7 +6,6 @@ import com.minecolonies.api.entity.ai.statemachine.states.CitizenAIState; import com.minecolonies.api.entity.ai.statemachine.states.IState; import com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickingTransition; -import com.minecolonies.core.entity.pathfinding.navigation.AbstractAdvancedPathNavigate; import com.minecolonies.core.tileentities.TileEntityNamedGrave; import com.minecolonies.api.util.BlockPosUtil; import com.minecolonies.api.util.MathUtils; @@ -158,7 +157,7 @@ private IState wanderAtGraveyard() return MourningState.DECIDE; } - final IBuilding graveyardBuilding = citizen.getCitizenColonyHandler().getColony().getBuildingManager().getBuilding(graveyard); + final IBuilding graveyardBuilding = citizen.getCitizenColonyHandler().getColonyOrRegister().getBuildingManager().getBuilding(graveyard); if (!(graveyardBuilding instanceof BuildingGraveyard)) { graveyard = null; @@ -297,7 +296,7 @@ private IState decide() if (this.graveyard == null) { final IBuilding graveyardBuilding = - citizen.getCitizenColonyHandler().getColony().getBuildingManager().getFirstBuildingMatching(b -> b instanceof BuildingGraveyard && b.getFirstModuleOccurance( + citizen.getCitizenColonyHandler().getColonyOrRegister().getBuildingManager().getFirstBuildingMatching(b -> b instanceof BuildingGraveyard && b.getFirstModuleOccurance( GraveyardManagementModule.class).hasRestingCitizen(citizen.getCitizenData().getCitizenMournHandler().getDeceasedCitizens())); if (graveyardBuilding != null) { @@ -335,7 +334,7 @@ public void reset() */ protected BlockPos getMournLocation() { - final IColony colony = citizen.getCitizenColonyHandler().getColony(); + final IColony colony = citizen.getCitizenColonyHandler().getColonyOrRegister(); if (colony != null && colony.getBuildingManager().hasTownHall()) { return colony.getBuildingManager().getTownHall().getStandingPosition(); diff --git a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAISickTask.java b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAISickTask.java index a3d0e0f6185..b7d0f53dfe4 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAISickTask.java +++ b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAISickTask.java @@ -177,8 +177,8 @@ private DiseaseState findEmptyBed() } } - final BlockPos hospitalPos = citizen.getCitizenColonyHandler().getColony().getBuildingManager().getBestBuilding(citizen, BuildingHospital.class); - final IColony colony = citizen.getCitizenColonyHandler().getColony(); + final BlockPos hospitalPos = citizen.getCitizenColonyHandler().getColonyOrRegister().getBuildingManager().getBestBuilding(citizen, BuildingHospital.class); + final IColony colony = citizen.getCitizenColonyHandler().getColonyOrRegister(); final IBuilding hospital = colony.getBuildingManager().getBuilding(hospitalPos); if (hospital instanceof BuildingHospital) @@ -286,8 +286,8 @@ private void cure() if (usedBed != null) { - final BlockPos hospitalPos = citizen.getCitizenColonyHandler().getColony().getBuildingManager().getBestBuilding(citizen, BuildingHospital.class); - final IColony colony = citizen.getCitizenColonyHandler().getColony(); + final BlockPos hospitalPos = citizen.getCitizenColonyHandler().getColonyOrRegister().getBuildingManager().getBestBuilding(citizen, BuildingHospital.class); + final IColony colony = citizen.getCitizenColonyHandler().getColonyOrRegister(); final IBuilding hospital = colony.getBuildingManager().getBuilding(hospitalPos); ((BuildingHospital) hospital).registerPatient(usedBed, 0); usedBed = null; diff --git a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAISleep.java b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAISleep.java index 2af7e223b0e..ba4f366d785 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAISleep.java +++ b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAISleep.java @@ -164,7 +164,7 @@ private void findBedAndTryToSleep() } } - final IColony colony = citizen.getCitizenColonyHandler().getColony(); + final IColony colony = citizen.getCitizenColonyHandler().getColonyOrRegister(); if (colony != null && citizen.getCitizenData().getHomeBuilding() instanceof AbstractBuilding hut) { final BlockPos homePos = citizen.getCitizenData().getHomePosition(); diff --git a/src/main/java/com/minecolonies/core/entity/ai/visitor/EntityAIVisitor.java b/src/main/java/com/minecolonies/core/entity/ai/visitor/EntityAIVisitor.java index 47017be5a0c..7e23950942f 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/visitor/EntityAIVisitor.java +++ b/src/main/java/com/minecolonies/core/entity/ai/visitor/EntityAIVisitor.java @@ -96,7 +96,7 @@ private boolean reduceTime() citizen.getCitizenData().markDirty(20 * 20); if (citizen.getCitizenData().getSaturation() <= 0) { - citizen.getCitizenColonyHandler().getColony().getVisitorManager().removeCivilian(citizen.getCitizenData()); + citizen.getCitizenColonyHandler().getColonyOrRegister().getVisitorManager().removeCivilian(citizen.getCitizenData()); if (tavern != null) { tavern.getFirstModuleOccurance(TavernBuildingModule.class).removeCitizen(citizen.getCivilianID()); @@ -169,7 +169,7 @@ private VisitorState decide() } final int random = citizen.getRandom().nextInt(5); - if (tavern != null && (random == 0 || random == 1 && !citizen.getCitizenColonyHandler().getColony().isDay()) && tavern.hasModule(BuildingModules.TAVERN_VISITOR)) + if (tavern != null && (random == 0 || random == 1 && !citizen.getCitizenColonyHandler().getColonyOrRegister().isDay()) && tavern.hasModule(BuildingModules.TAVERN_VISITOR)) { final BlockPos pos = tavern.getModule(BuildingModules.TAVERN_VISITOR).getFreeSitPosition(); if (pos != null) @@ -183,7 +183,7 @@ private VisitorState decide() else if (random == 2) { citizen.getNavigation().moveToRandomPos(10, 0.6D); - actionTimeoutCounter = citizen.getCitizenColonyHandler().getColony().isDay() ? citizen.getRandom().nextInt(1000) + 1000 : 300; + actionTimeoutCounter = citizen.getCitizenColonyHandler().getColonyOrRegister().isDay() ? citizen.getRandom().nextInt(1000) + 1000 : 300; return VisitorState.WANDERING; } @@ -223,7 +223,7 @@ private boolean sit() */ private boolean isEntityLoaded() { - if (citizen.getCitizenColonyHandler().getColony() == null || citizen.getCitizenData() == null || citizen.getCitizenData().getHomeBuilding() == null) + if (citizen.getCitizenColonyHandler().getColonyOrRegister() == null || citizen.getCitizenData() == null || citizen.getCitizenData().getHomeBuilding() == null) { return false; } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIBasic.java b/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIBasic.java index 607bb502273..eba5a152338 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIBasic.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIBasic.java @@ -955,7 +955,7 @@ protected void checkForToolOrWeaponAsync(@NotNull final EquipmentTypeEntry toolT { if (req.getRequest().getMinLevel() < minLevel || req.getRequest().getMaxLevel() < maxLevel) { - worker.getCitizenColonyHandler().getColony().getRequestManager().updateRequestState(req.getId(), RequestState.CANCELLED); + worker.getCitizenColonyHandler().getColonyOrRegister().getRequestManager().updateRequestState(req.getId(), RequestState.CANCELLED); } else { @@ -981,7 +981,7 @@ protected void cancelAsynchRequestForArmor(final EquipmentTypeEntry armorType) building.getOpenRequestsOfTypeFiltered(worker.getCitizenData(), TypeConstants.TOOL, iRequest -> iRequest.getRequest().getEquipmentType() == armorType); for (final IRequest token : openRequests) { - worker.getCitizenColonyHandler().getColony().getRequestManager().updateRequestState(token.getId(), RequestState.CANCELLED); + worker.getCitizenColonyHandler().getColonyOrRegister().getRequestManager().updateRequestState(token.getId(), RequestState.CANCELLED); } } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIInteract.java b/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIInteract.java index c8b9f50f8c8..b76ad7c2282 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIInteract.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIInteract.java @@ -329,7 +329,7 @@ public int getBlockMiningTime(@NotNull final BlockState state, @NotNull final Bl */ private int calculateWorkerMiningDelay(@NotNull final BlockState state, @NotNull final BlockPos pos) { - final double reduction = 1 - worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(BLOCK_BREAK_SPEED); + final double reduction = 1 - worker.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(BLOCK_BREAK_SPEED); return (int) (((BLOCK_MINING_DELAY * Math.pow(LEVEL_MODIFIER, getBreakSpeedLevel() / 2.0)) * (double) world.getBlockState(pos).getDestroySpeed(world, pos) / (double) (worker.getMainHandItem() diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIStructure.java b/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIStructure.java index 07580f22796..ded27e694e8 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIStructure.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIStructure.java @@ -514,7 +514,7 @@ else if (result.getBlockResult().getResult() == BlockPlacementResult.Result.LIMI blockToMine = null; } - final double decrease = 1 - worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(BLOCK_PLACE_SPEED); + final double decrease = 1 - worker.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(BLOCK_PLACE_SPEED); setDelay((int) ((BUILD_BLOCK_DELAY * PROGRESS_MULTIPLIER / (getPlaceSpeedLevel() / 2 + PROGRESS_MULTIPLIER)) * decrease)); return getState(); @@ -704,7 +704,7 @@ public void loadStructure(@NotNull final IWorkOrder workOrder, final BlockPos po } final BuildingStructureHandler structure; - IBuilding colonyBuilding = worker.getCitizenColonyHandler().getColony().getBuildingManager().getBuilding(position); + IBuilding colonyBuilding = worker.getCitizenColonyHandler().getColonyOrRegister().getBuildingManager().getBuilding(position); final BlockEntity entity = world.getBlockEntity(position); if (removal) diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIStructureWithWorkOrder.java b/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIStructureWithWorkOrder.java index 24acee2930d..5687c975c81 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIStructureWithWorkOrder.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIStructureWithWorkOrder.java @@ -118,7 +118,7 @@ public IAIState loadRequirements() { Log.getLogger().error( String.format("Worker (%d:%d) ERROR - Starting and missing work order(%d)", - worker.getCitizenColonyHandler().getColony().getID(), + worker.getCitizenColonyHandler().getColonyOrRegister().getID(), worker.getCitizenData().getId(), job.getWorkOrderId()), new Exception()); job.setWorkOrder(null); return IDLE; @@ -131,12 +131,12 @@ public IAIState loadRequirements() { Log.getLogger().error( String.format("Worker (%d:%d) ERROR - Starting and missing building(%s)", - worker.getCitizenColonyHandler().getColony().getID(), worker.getCitizenData().getId(), wo.getLocation()), new Exception()); + worker.getCitizenColonyHandler().getColonyOrRegister().getID(), worker.getCitizenData().getId(), wo.getLocation()), new Exception()); return IDLE; } MessageUtils.forCitizen(worker, COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_BUILD_START, job.getWorkOrder().getDisplayName()) - .sendTo(worker.getCitizenColonyHandler().getColony().getMessagePlayerEntities()); + .sendTo(worker.getCitizenColonyHandler().getColonyOrRegister().getMessagePlayerEntities()); //Don't go through the CLEAR stage for repairs and upgrades if (building.getBuildingLevel() > 0) @@ -147,7 +147,7 @@ public IAIState loadRequirements() else if (!(wo instanceof WorkOrderMiner)) { MessageUtils.forCitizen(worker, COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_BUILD_START, job.getWorkOrder().getDisplayName()) - .sendTo(worker.getCitizenColonyHandler().getColony().getMessagePlayerEntities()); + .sendTo(worker.getCitizenColonyHandler().getColonyOrRegister().getMessagePlayerEntities()); ; } return getState(); @@ -176,10 +176,10 @@ private void loadStructure() } final BlockPos pos = workOrder.getLocation(); - if (workOrder instanceof WorkOrderBuilding && worker.getCitizenColonyHandler().getColony().getBuildingManager().getBuilding(pos) == null) + if (workOrder instanceof WorkOrderBuilding && worker.getCitizenColonyHandler().getColonyOrRegister().getBuildingManager().getBuilding(pos) == null) { Log.getLogger().warn("AbstractBuilding does not exist - removing build request"); - worker.getCitizenColonyHandler().getColony().getWorkManager().removeWorkOrder(workOrder); + worker.getCitizenColonyHandler().getColonyOrRegister().getWorkManager().removeWorkOrder(workOrder); return; } @@ -388,7 +388,7 @@ public void executeSpecificCompleteActions() if (wo == null) { Log.getLogger().error(String.format("Worker (%d:%d) ERROR - Finished, but missing work order(%d)", - worker.getCitizenColonyHandler().getColony().getID(), + worker.getCitizenColonyHandler().getColonyOrRegister().getID(), worker.getCitizenData().getId(), job.getWorkOrderId())); } @@ -402,19 +402,19 @@ public void executeSpecificCompleteActions() { case BUILD: colony.getEventDescriptionManager().addEventDescription(new BuildingBuiltEvent(wo.getLocation(), workOrderName)); - worker.getCitizenColonyHandler().getColony().getStatisticsManager().increment(BUILD_BUILT, colony.getDay()); + worker.getCitizenColonyHandler().getColonyOrRegister().getStatisticsManager().increment(BUILD_BUILT, colony.getDay()); break; case UPGRADE: colony.getEventDescriptionManager().addEventDescription(new BuildingUpgradedEvent(wo.getLocation(), workOrderName, wo.getTargetLevel())); - worker.getCitizenColonyHandler().getColony().getStatisticsManager().increment(BUILD_UPGRADED, colony.getDay()); + worker.getCitizenColonyHandler().getColonyOrRegister().getStatisticsManager().increment(BUILD_UPGRADED, colony.getDay()); break; case REPAIR: colony.getEventDescriptionManager().addEventDescription(new BuildingRepairedEvent(wo.getLocation(), workOrderName, wo.getCurrentLevel())); - worker.getCitizenColonyHandler().getColony().getStatisticsManager().increment(BUILD_REPAIRED, colony.getDay()); + worker.getCitizenColonyHandler().getColonyOrRegister().getStatisticsManager().increment(BUILD_REPAIRED, colony.getDay()); break; case REMOVE: colony.getEventDescriptionManager().addEventDescription(new BuildingDeconstructedEvent(wo.getLocation(), workOrderName, wo.getCurrentLevel())); - worker.getCitizenColonyHandler().getColony().getStatisticsManager().increment(BUILD_REMOVED, colony.getDay()); + worker.getCitizenColonyHandler().getColonyOrRegister().getStatisticsManager().increment(BUILD_REMOVED, colony.getDay()); break; } @@ -439,7 +439,7 @@ public void executeSpecificCompleteActions() if (building == null) { Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Finished, but missing building(%s)", - worker.getCitizenColonyHandler().getColony().getID(), + worker.getCitizenColonyHandler().getColonyOrRegister().getID(), worker.getCitizenData().getId(), wo.getLocation())); } @@ -458,7 +458,7 @@ public void executeSpecificCompleteActions() if (building == null) { Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Finished, but missing building(%s)", - worker.getCitizenColonyHandler().getColony().getID(), + worker.getCitizenColonyHandler().getColonyOrRegister().getID(), worker.getCitizenData().getId(), wo.getLocation())); } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/CitizenAI.java b/src/main/java/com/minecolonies/core/entity/ai/workers/CitizenAI.java index 4320c41f740..8d76b9c31be 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/CitizenAI.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/CitizenAI.java @@ -152,7 +152,7 @@ private IState calculateNextState() } // Raiding - if (citizen.getCitizenColonyHandler().getColony().getRaiderManager().isRaided()) + if (citizen.getCitizenColonyHandler().getColonyOrRegister().getRaiderManager().isRaided()) { citizen.getCitizenData().triggerInteraction(new StandardInteraction(Component.translatableEscape(COM_MINECOLONIES_COREMOD_ENTITY_CITIZEN_RAID), ChatPriority.IMPORTANT)); citizen.setVisibleStatusIfNone(RAIDED); @@ -295,7 +295,7 @@ private boolean shouldWorkWhileRaining() } final ICitizenColonyHandler colonyHandler = citizen.getCitizenColonyHandler(); - if (colonyHandler.getColony().getResearchManager().getResearchEffects().getEffectStrength(WORKING_IN_RAIN) > 0) + if (colonyHandler.getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(WORKING_IN_RAIN) > 0) { return true; } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/builder/EntityAIStructureBuilder.java b/src/main/java/com/minecolonies/core/entity/ai/workers/builder/EntityAIStructureBuilder.java index f76e4119c39..50e81665fb1 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/builder/EntityAIStructureBuilder.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/builder/EntityAIStructureBuilder.java @@ -160,7 +160,7 @@ private void killMobs() if (building.getBuildingLevel() >= LEVEL_TO_PURGE_MOBS && job.getWorkOrder() != null && job.getWorkOrder().getWorkOrderType() == WorkOrderType.BUILD) { final BlockPos buildingPos = job.getWorkOrder().getLocation(); - final IBuilding building = worker.getCitizenColonyHandler().getColony().getBuildingManager().getBuilding(buildingPos); + final IBuilding building = worker.getCitizenColonyHandler().getColonyOrRegister().getBuildingManager().getBuilding(buildingPos); if (building != null) { WorldUtil.getEntitiesWithinBuilding(world, Monster.class, building, null).forEach(e -> e.remove(Entity.RemovalReason.DISCARDED)); @@ -321,6 +321,6 @@ protected void sendCompletionMessage(final IWorkOrder wo) message.append(Component.translatableEscape(COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_MANUAL_SUFFIX)); } - MessageUtils.forCitizen(worker, message).sendTo(worker.getCitizenColonyHandler().getColony().getImportantMessageEntityPlayers()); + MessageUtils.forCitizen(worker, message).sendTo(worker.getCitizenColonyHandler().getColonyOrRegister().getImportantMessageEntityPlayers()); } } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/AbstractEntityAICrafting.java b/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/AbstractEntityAICrafting.java index 0757280185f..aa9ee490594 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/AbstractEntityAICrafting.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/AbstractEntityAICrafting.java @@ -536,9 +536,9 @@ public IAIState afterDump() if (currentRequest.getState() == RequestState.IN_PROGRESS) { worker.getCitizenColonyHandler() - .getColony() + .getColonyOrRegister() .getStatisticsManager() - .incrementBy(ITEMS_CRAFTED, currentRequest.getRequest().getCount(), worker.getCitizenColonyHandler().getColony().getDay()); + .incrementBy(ITEMS_CRAFTED, currentRequest.getRequest().getCount(), worker.getCitizenColonyHandler().getColonyOrRegister().getDay()); job.finishRequest(true); worker.getCitizenExperienceHandler().addExperience(currentRequest.getRequest().getCount() / 2.0); } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIWorkPupil.java b/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIWorkPupil.java index 9b458b94dc0..4d7873a7f8a 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIWorkPupil.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIWorkPupil.java @@ -188,7 +188,7 @@ private IAIState study() if (slot != -1) { InventoryUtils.reduceStackInItemHandler(worker.getInventoryCitizen(), new ItemStack(Items.PAPER), 1); - final double bonus = 50.0 * (1 + worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(TEACHING)); + final double bonus = 50.0 * (1 + worker.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(TEACHING)); worker.getCitizenData().getCitizenSkillHandler().addXpToSkill(Skill.Intelligence, bonus, worker.getCitizenData()); } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIWorkTeacher.java b/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIWorkTeacher.java index cd11ae3191d..cb8a5237f13 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIWorkTeacher.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIWorkTeacher.java @@ -157,7 +157,7 @@ private IAIState teach() // Intelligence + PrimarySkill(Knowledge) for amount gained per Teach state. double xp = 1.5 * (1.0 + worker.getCitizenData().getCitizenSkillHandler().getLevel(Skill.Intelligence) / 10.0); - xp *= (1 + worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(TEACHING)); + xp *= (1 + worker.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(TEACHING)); xp *= (1 + (getPrimarySkillLevel() / 10.0)); pupilToTeach.getCitizenData().getCitizenSkillHandler().addXpToSkill(Skill.Intelligence, xp, pupilToTeach.getCitizenData()); diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/AbstractEntityAIFight.java b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/AbstractEntityAIFight.java index 9c29ccc8ccc..8f66ef18067 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/AbstractEntityAIFight.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/AbstractEntityAIFight.java @@ -152,7 +152,7 @@ protected void atBuildingActions() continue; } if (item.getItemNeeded() == ModEquipmentTypes.shield.get() - && worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(SHIELD_USAGE) <= 0) + && worker.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(SHIELD_USAGE) <= 0) { continue; } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/AbstractEntityAIGuard.java b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/AbstractEntityAIGuard.java index e718c18b595..5d0df3edea7 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/AbstractEntityAIGuard.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/AbstractEntityAIGuard.java @@ -272,7 +272,7 @@ private boolean shouldSleep() return false; } - final double chance = 1 / (1 + worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(SLEEP_LESS)); + final double chance = 1 / (1 + worker.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(SLEEP_LESS)); // Chance to fall asleep every 10sec, Chance is 1 in (10 + level/2) = 1 in Level1:5,Level2:6 Level6:8 Level 12:11 etc if (worker.getRandom().nextInt((int) (worker.getCitizenData().getCitizenSkillHandler().getLevel(Skill.Adaptability) * 0.5) + 20) == 1 @@ -354,7 +354,7 @@ private boolean shouldFlee() { if (buildingGuards.shallRetrieveOnLowHealth() && worker.getHealth() < ((int) worker.getMaxHealth() * 0.2D) && worker.distanceToSqr(building.getID().getCenter()) > 20) { - return worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(RETREAT) > 0; + return worker.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(RETREAT) > 0; } return false; @@ -393,7 +393,7 @@ private IAIState flee() { if (!worker.hasEffect(MobEffects.MOVEMENT_SPEED)) { - final double effect = worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(FLEEING_SPEED); + final double effect = worker.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(FLEEING_SPEED); if (effect > 0) { worker.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SPEED, 200, (int) (0 + effect))); @@ -815,7 +815,7 @@ public static boolean isAttackableTarget(final AbstractEntityCitizen user, final return true; } - final IColony colony = user.getCitizenColonyHandler().getColony(); + final IColony colony = user.getCitizenColonyHandler().getColonyOrRegister(); if (colony == null) { return false; diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/DruidCombatAI.java b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/DruidCombatAI.java index 970f067beef..511bce9c548 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/DruidCombatAI.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/DruidCombatAI.java @@ -135,7 +135,7 @@ protected void doAttack(final LivingEntity target) final ItemStack stack = Items.SPLASH_POTION.getDefaultInstance(); boolean gotMaterial = false; BiPredicate predicate; - if (user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(DRUID_USE_POTIONS) > 0 + if (user.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(DRUID_USE_POTIONS) > 0 && InventoryUtils.hasItemInItemHandler(user.getInventoryCitizen(), item -> item.getItem() == ModItems.magicpotion)) { gotMaterial = true; diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/EntityAIDruid.java b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/EntityAIDruid.java index 99f9e09561b..2c84251e2ae 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/EntityAIDruid.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/EntityAIDruid.java @@ -47,7 +47,7 @@ protected void atBuildingActions() { super.atBuildingActions(); - if (worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(DRUID_USE_POTIONS) > 0) + if (worker.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(DRUID_USE_POTIONS) > 0) { // Mistletoes and water bottles InventoryUtils.transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandler(building, diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/EntityAIKnight.java b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/EntityAIKnight.java index b9b640bf8f3..e694aa3cf0c 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/EntityAIKnight.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/EntityAIKnight.java @@ -49,7 +49,7 @@ public EntityAIKnight(@NotNull final JobKnight job) protected List itemsNiceToHave() { final List list = super.itemsNiceToHave(); - if (worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(SHIELD_USAGE) > 0) + if (worker.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(SHIELD_USAGE) > 0) { list.add(new ItemStack(Items.SHIELD, 1)); } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/EntityAIRanger.java b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/EntityAIRanger.java index dbdc4bc63b8..1b0039eeeb6 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/EntityAIRanger.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/EntityAIRanger.java @@ -46,7 +46,7 @@ protected void atBuildingActions() { super.atBuildingActions(); - if (worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(ARCHER_USE_ARROWS) > 0) + if (worker.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(ARCHER_USE_ARROWS) > 0) { // Pickup arrows and request arrows InventoryUtils.transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandler(building, diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/KnightCombatAI.java b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/KnightCombatAI.java index f070a915be1..02e1357ebc1 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/KnightCombatAI.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/KnightCombatAI.java @@ -172,7 +172,7 @@ protected void doAttack(final LivingEntity target) target.hurt(source, (float) damageToBeDealt); target.setLastHurtByMob(user); - if (target instanceof Mob && user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(KNIGHT_TAUNT) > 0) + if (target instanceof Mob && user.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(KNIGHT_TAUNT) > 0) { ((Mob) target).setTarget(user); if (target instanceof IThreatTableEntity) @@ -195,7 +195,7 @@ protected void doAttack(final LivingEntity target) */ private void doAoeAttack(final DamageSource source, final double damageToBeDealt) { - if (user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(KNIGHT_WHIRLWIND) > 0 + if (user.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(KNIGHT_WHIRLWIND) > 0 && user.getRandom().nextInt(KNOCKBACK_CHANCE) == 0) { List entities = user.level().getEntitiesOfClass(LivingEntity.class, user.getBoundingBox().inflate(2.0D, 0.5D, 2.0D)); @@ -263,7 +263,7 @@ private double getAttackDamage() addDmg += EnchantmentHelper.modifyDamage((ServerLevel) user.level(), heldItem, target, user.level().damageSources().mobAttack(user), 1) / 2.5; } - addDmg += user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(MELEE_DAMAGE); + addDmg += user.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(MELEE_DAMAGE); // TODO: Recheck balancing, do we need this if (user.getHealth() <= user.getMaxHealth() * 0.2D) @@ -271,7 +271,7 @@ private double getAttackDamage() addDmg *= 2; } - if (ColonyConstants.rand.nextDouble() > 1 / (1 + user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(GUARD_CRIT))) + if (ColonyConstants.rand.nextDouble() > 1 / (1 + user.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(GUARD_CRIT))) { addDmg *= 1.5; ((ServerLevel) user.level()).getChunkSource().broadcastAndSend(user, new ClientboundAnimatePacket(target, 4)); @@ -361,7 +361,7 @@ protected void onTargetDied(final LivingEntity entity) { parentAI.incrementActionsDoneAndDecSaturation(); user.getCitizenExperienceHandler().addExperience(EXP_PER_MOB_DEATH); - user.getCitizenColonyHandler().getColony().getStatisticsManager().increment(MOBS_KILLED, user.getCitizenColonyHandler().getColony().getDay()); + user.getCitizenColonyHandler().getColonyOrRegister().getStatisticsManager().increment(MOBS_KILLED, user.getCitizenColonyHandler().getColonyOrRegister().getDay()); if (entity.getType().getDescription().getContents() instanceof TranslatableContents translatableContents) { parentAI.building.getModule(STATS_MODULE).increment(MOB_KILLED + ";" + translatableContents.getKey()); diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/RangerCombatAI.java b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/RangerCombatAI.java index 8f577a92c04..c0ccc72991b 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/RangerCombatAI.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/RangerCombatAI.java @@ -156,9 +156,9 @@ protected void doAttack(final LivingEntity target) user.stopUsingItem(); int amountOfArrows = 1; - if (user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(DOUBLE_ARROWS) > 0) + if (user.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(DOUBLE_ARROWS) > 0) { - if (user.getRandom().nextDouble() < user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(DOUBLE_ARROWS)) + if (user.getRandom().nextDouble() < user.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(DOUBLE_ARROWS)) { amountOfArrows++; } @@ -168,7 +168,7 @@ protected void doAttack(final LivingEntity target) { final AbstractArrow arrow = CombatUtils.createArrowForShooter(user); - if (user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(ARROW_PIERCE) > 0) + if (user.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(ARROW_PIERCE) > 0) { arrow.setPierceLevel((byte) 2); } @@ -248,7 +248,7 @@ private double calculateDamage(final AbstractArrow arrow) damage += heldItem.getEnchantmentLevel(Utils.getRegistryValue(Enchantments.POWER, user.level())); damage += user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(ARCHER_DAMAGE); - if (user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(ARCHER_USE_ARROWS) > 0) + if (user.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(ARCHER_USE_ARROWS) > 0) { int slot = InventoryUtils.findFirstSlotInItemHandlerWith(user.getInventoryCitizen(), item -> item.getItem() instanceof ArrowItem); if (slot != -1) @@ -278,7 +278,7 @@ private double calculateDamage(final AbstractArrow arrow) damage *= 2; } - if (ColonyConstants.rand.nextDouble() > 1 / (1 + user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(GUARD_CRIT))) + if (ColonyConstants.rand.nextDouble() > 1 / (1 + user.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(GUARD_CRIT))) { damage *= 1.5; } @@ -380,7 +380,7 @@ protected void onTargetDied(final LivingEntity entity) { parentAI.incrementActionsDoneAndDecSaturation(); user.getCitizenExperienceHandler().addExperience(EXP_PER_MOB_DEATH); - user.getCitizenColonyHandler().getColony().getStatisticsManager().increment(MOBS_KILLED, user.getCitizenColonyHandler().getColony().getDay()); + user.getCitizenColonyHandler().getColonyOrRegister().getStatisticsManager().increment(MOBS_KILLED, user.getCitizenColonyHandler().getColonyOrRegister().getDay()); if (entity.getType().getDescription().getContents() instanceof TranslatableContents translatableContents) { parentAI.building.getModule(STATS_MODULE).increment(MOB_KILLED + ";" + translatableContents.getKey()); diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIStructureMiner.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIStructureMiner.java index efc37160743..05219fdffe2 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIStructureMiner.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIStructureMiner.java @@ -8,8 +8,6 @@ import com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState; import com.minecolonies.api.entity.ai.statemachine.states.IAIState; import com.minecolonies.api.entity.citizen.VisibleCitizenStatus; -import com.minecolonies.core.entity.pathfinding.PathfindingUtils; -import com.minecolonies.core.entity.pathfinding.SurfaceType; import com.minecolonies.api.util.*; import com.minecolonies.api.util.constant.Constants; import com.minecolonies.core.colony.buildings.modules.MinerLevelManagementModule; @@ -955,7 +953,7 @@ protected void triggerMinedBlock(@NotNull final BlockState blockToMine) { super.triggerMinedBlock(blockToMine); - final double chance = 1 + worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(MORE_ORES); + final double chance = 1 + worker.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(MORE_ORES); if (IColonyManager.getInstance().getCompatibilityManager().isLuckyBlock(blockToMine.getBlock())) { diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkLumberjack.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkLumberjack.java index 37e14e881ab..1fa0bf9ddf1 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkLumberjack.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkLumberjack.java @@ -397,7 +397,7 @@ private IAIState findTree() 1.0D, building.getModuleMatching(ItemListModule.class, m -> m.getId().equals(SAPLINGS_LIST)).getList(), building.getSetting(BuildingLumberjack.DYNAMIC_TREES_SIZE).getValue(), - worker.getCitizenColonyHandler().getColony()); + worker.getCitizenColonyHandler().getColonyOrRegister()); } else { @@ -406,7 +406,7 @@ private IAIState findTree() 1.0D, building.getModuleMatching(ItemListModule.class, m -> m.getId().equals(SAPLINGS_LIST)).getList(), building.getSetting(BuildingLumberjack.DYNAMIC_TREES_SIZE).getValue(), - worker.getCitizenColonyHandler().getColony()); + worker.getCitizenColonyHandler().getColonyOrRegister()); } return getState(); } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkNether.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkNether.java index bc3ffc13fc8..6b60e373840 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkNether.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkNether.java @@ -980,11 +980,11 @@ private float checkHeal(AbstractEntityCitizen citizen) double healAmount = 0D; if (citizen.getHealth() < citizen.getMaxHealth()) { - final double limitDecrease = citizen.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(SATLIMIT); + final double limitDecrease = citizen.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(SATLIMIT); if (citizenData.getSaturation() >= FULL_SATURATION + limitDecrease) { - healAmount = 2 * (1.0 + citizen.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(REGENERATION)); + healAmount = 2 * (1.0 + citizen.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(REGENERATION)); } else if (citizenData.getSaturation() < LOW_SATURATION) { @@ -992,7 +992,7 @@ else if (citizenData.getSaturation() < LOW_SATURATION) } else { - healAmount = 1 * (1.0 + citizen.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(REGENERATION)); + healAmount = 1 * (1.0 + citizen.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(REGENERATION)); } citizen.heal((float) healAmount); diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkComposter.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkComposter.java index c814569b540..b1f0554c3ec 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkComposter.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkComposter.java @@ -315,7 +315,7 @@ private IAIState harvestBarrels() * Two researches to increase it to 10% and 15%, respectively. */ if (((worker.getRandom().nextInt(100)) + 1) <= (5 * (1 + worker.getCitizenColonyHandler() - .getColony() + .getColonyOrRegister() .getResearchManager() .getResearchEffects() .getEffectStrength(PODZOL_CHANCE)))) diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFarmer.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFarmer.java index bce6099acc5..113e59d4e7e 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFarmer.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFarmer.java @@ -590,7 +590,7 @@ private boolean hoeIfAble(BlockPos position, final FarmField farmField) createCorrectFarmlandForSeed(farmField.getSeed(), position); worker.getCitizenItemHandler().damageItemInHand(InteractionHand.MAIN_HAND, 1); worker.decreaseSaturationForContinuousAction(); - worker.getCitizenColonyHandler().getColony().getStatisticsManager().increment(LAND_TILLED, worker.getCitizenColonyHandler().getColony().getDay()); + worker.getCitizenColonyHandler().getColonyOrRegister().getStatisticsManager().increment(LAND_TILLED, worker.getCitizenColonyHandler().getColonyOrRegister().getDay()); return true; } @@ -649,14 +649,14 @@ private boolean harvestIfAble(BlockPos position) { worker.getCitizenExperienceHandler().addExperience(XP_PER_HARVEST); harvestCrop(position.above()); - worker.getCitizenColonyHandler().getColony().getStatisticsManager().increment(CROPS_HARVESTED, worker.getCitizenColonyHandler().getColony().getDay()); + worker.getCitizenColonyHandler().getColonyOrRegister().getStatisticsManager().increment(CROPS_HARVESTED, worker.getCitizenColonyHandler().getColonyOrRegister().getDay()); return true; } if (mineBlock(position.above())) { - worker.getCitizenColonyHandler().getColony().getStatisticsManager().increment(CROPS_HARVESTED, worker.getCitizenColonyHandler().getColony().getDay()); + worker.getCitizenColonyHandler().getColonyOrRegister().getStatisticsManager().increment(CROPS_HARVESTED, worker.getCitizenColonyHandler().getColonyOrRegister().getDay()); worker.getCitizenExperienceHandler().addExperience(XP_PER_HARVEST); } else @@ -850,7 +850,7 @@ else if (block instanceof MinecoloniesCropBlock minecoloniesCrop) @Override protected List increaseBlockDrops(final List drops) { - final double increaseCrops = worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(FARMING); + final double increaseCrops = worker.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(FARMING); if (increaseCrops == 0) { return drops; @@ -888,7 +888,7 @@ private void harvestCrop(@NotNull final BlockPos pos) final int fortune = ItemStackUtils.getFortuneOf(tool, world); final BlockState state = world.getBlockState(pos); - final double chance = worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(FARMING); + final double chance = worker.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(FARMING); final NonNullList drops = NonNullList.create(); state.getDrops(new LootParams.Builder((ServerLevel) world).withLuck(fortune) diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFisherman.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFisherman.java index 56c22b61fc6..108e429c63d 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFisherman.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFisherman.java @@ -459,7 +459,7 @@ private IAIState doFishing() { playCaughtFishSound(); this.incrementActionsDoneAndDecSaturation(); - worker.getCitizenColonyHandler().getColony().getStatisticsManager().increment(FISH_CAUGHT, worker.getCitizenColonyHandler().getColony().getDay()); + worker.getCitizenColonyHandler().getColonyOrRegister().getStatisticsManager().increment(FISH_CAUGHT, worker.getCitizenColonyHandler().getColonyOrRegister().getDay()); building.getModule(STATS_MODULE).increment(FISH_CAUGHT); if (worker.getRandom().nextDouble() < CHANCE_NEW_POND) diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkCook.java b/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkCook.java index 64c41c83332..ec1fbbcba74 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkCook.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkCook.java @@ -144,7 +144,7 @@ protected boolean reachedMaxToKeep() } final int buildingLimit = Math.max(1, building.getBuildingLevel() * building.getBuildingLevel()) * SLOT_PER_LINE; return InventoryUtils.getCountFromBuildingWithLimit(building, - ItemStackUtils.CAN_EAT.and(stack -> FoodUtils.canEat(stack, building.getBuildingLevel() - 1)), + CAN_EAT.and(stack -> FoodUtils.canEat(stack, building.getBuildingLevel() - 1)), stack -> stack.getMaxStackSize() * 6) > buildingLimit; } @@ -199,7 +199,7 @@ private IAIState serveFoodToCitizen() if (!citizenToServe.isEmpty()) { final int foodSlot = InventoryUtils.findFirstSlotInItemHandlerWith(worker.getInventoryCitizen(), - stack -> ItemStackUtils.CAN_EAT.test(stack) && canEat(stack, citizenToServe.isEmpty() ? null : citizenToServe.get(0))); + stack -> CAN_EAT.test(stack) && canEat(stack, citizenToServe.isEmpty() ? null : citizenToServe.get(0))); if (foodSlot != -1) { final ItemStack stack = worker.getInventoryCitizen().extractItem(foodSlot, 1, false); @@ -310,7 +310,7 @@ protected IAIState checkForImportantJobs() continue; } - final Predicate foodPredicate = stack -> ItemStackUtils.CAN_EAT.test(stack) && canEat(stack, citizen); + final Predicate foodPredicate = stack -> CAN_EAT.test(stack) && canEat(stack, citizen); if (InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), foodPredicate)) { citizenToServe.add(citizen); @@ -327,7 +327,7 @@ protected IAIState checkForImportantJobs() if (!playerToServe.isEmpty()) { - final Predicate foodPredicate = stack -> ItemStackUtils.CAN_EAT.test(stack); + final Predicate foodPredicate = stack -> CAN_EAT.test(stack); if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), foodPredicate)) { if (InventoryUtils.hasItemInProvider(building, foodPredicate)) @@ -376,7 +376,7 @@ protected IRequestable getSmeltAbleClass() final List blockedItems = new ArrayList<>(building.getModule(ITEMLIST_FOODEXCLUSION).getList()); for (final Map.Entry content : building.getTileEntity().getAllContent().entrySet()) { - if (content.getValue() > content.getKey().getItemStack().getMaxStackSize() * 6 && ItemStackUtils.CAN_EAT.test(content.getKey().getItemStack())) + if (content.getValue() > content.getKey().getItemStack().getMaxStackSize() * 6 && CAN_EAT.test(content.getKey().getItemStack())) { blockedItems.add(content.getKey()); } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkDeliveryman.java b/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkDeliveryman.java index 6a01be17db8..71f92cbcae5 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkDeliveryman.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkDeliveryman.java @@ -340,7 +340,7 @@ private IAIState deliver() final ILocation targetBuildingLocation = ((Delivery) currentTask.getRequest()).getTarget(); if (!targetBuildingLocation.isReachableFromLocation(worker.getLocation())) { - Log.getLogger().info(worker.getCitizenColonyHandler().getColony().getName() + ": " + worker.getName() + ": Can't inter dimension yet: "); + Log.getLogger().info(worker.getCitizenColonyHandler().getColonyOrRegister().getName() + ": " + worker.getName() + ": Can't inter dimension yet: "); return START_WORKING; } @@ -439,9 +439,9 @@ private IAIState deliver() workerInventory.insertItem(i, insertionResultStack, false); } worker.getCitizenColonyHandler() - .getColony() + .getColonyOrRegister() .getStatisticsManager() - .incrementBy(ITEMS_DELIVERED, count - insertionResultStack.getCount(), worker.getCitizenColonyHandler().getColony().getDay()); + .incrementBy(ITEMS_DELIVERED, count - insertionResultStack.getCount(), worker.getCitizenColonyHandler().getColonyOrRegister().getDay()); } if (!extracted) diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkUndertaker.java b/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkUndertaker.java index 4bffde006d5..68a3c710132 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkUndertaker.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkUndertaker.java @@ -168,7 +168,7 @@ private IAIState emptyGrave() } worker.getCitizenData().setVisibleStatus(EMPTYING_ICON); - worker.setSprinting(worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(UNDERTAKER_RUN) > 0); + worker.setSprinting(worker.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(UNDERTAKER_RUN) > 0); unequip(); @Nullable final BlockPos gravePos = buildingGraveyard.getGraveToWorkOn(); @@ -225,7 +225,7 @@ private IAIState digGrave() } worker.getCitizenData().setVisibleStatus(DIGGING_ICON); - worker.setSprinting(worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(UNDERTAKER_RUN) > 0); + worker.setSprinting(worker.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(UNDERTAKER_RUN) > 0); @Nullable final BlockPos gravePos = buildingGraveyard.getGraveToWorkOn(); @@ -368,11 +368,11 @@ private double getResurrectChance(@NotNull final BuildingGraveyard buildingGrave double totemChance = getTotemResurrectChance(); double chance = buildingGraveyard.getBuildingLevel() * RESURRECT_BUILDING_LVL_WEIGHT + worker.getCitizenData().getCitizenSkillHandler().getLevel(Skill.Mana) * RESURRECT_WORKER_MANA_LVL_WEIGHT + - worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(RESURRECT_CHANCE) + + worker.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(RESURRECT_CHANCE) + totemChance; final double cap = - MAX_RESURRECTION_CHANCE + worker.getCitizenColonyHandler().getColony().getBuildingManager().getMysticalSiteMaxBuildingLevel() * MAX_RESURRECTION_CHANCE_MYSTICAL_LVL_BONUS + MAX_RESURRECTION_CHANCE + worker.getCitizenColonyHandler().getColonyOrRegister().getBuildingManager().getMysticalSiteMaxBuildingLevel() * MAX_RESURRECTION_CHANCE_MYSTICAL_LVL_BONUS + totemChance; if (chance > cap) { @@ -388,7 +388,7 @@ private double getResurrectChance(@NotNull final BuildingGraveyard buildingGrave */ private double getTotemResurrectChance() { - if (worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(USE_TOTEM) > 0) + if (worker.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(USE_TOTEM) > 0) { final int totems = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), Items.TOTEM_OF_UNDYING); @@ -436,7 +436,7 @@ private IAIState buryCitizen() { // couldn't find a place to dig a grave MessageUtils.forCitizen(worker, Component.translatable(MESSAGE_INFO_CITIZEN_UNDERTAKER_GRAVEYARD_NO_SPACE, module.getLastGraveData().getCitizenName())) - .sendTo(worker.getCitizenColonyHandler().getColony().getMessagePlayerEntities()); + .sendTo(worker.getCitizenColonyHandler().getColonyOrRegister().getMessagePlayerEntities()); return IDLE; } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/util/BuildingStructureHandler.java b/src/main/java/com/minecolonies/core/entity/ai/workers/util/BuildingStructureHandler.java index c9c0e690155..c9eb2d0dbf5 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/util/BuildingStructureHandler.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/util/BuildingStructureHandler.java @@ -214,9 +214,9 @@ public void triggerSuccess(final BlockPos pos, final List list, final structureAI.reduceNeededResources(stack); structureAI.getWorker() .getCitizenColonyHandler() - .getColony() + .getColonyOrRegister() .getStatisticsManager() - .increment(BLOCKS_PLACED, structureAI.getWorker().getCitizenColonyHandler().getColony().getDay()); + .increment(BLOCKS_PLACED, structureAI.getWorker().getCitizenColonyHandler().getColonyOrRegister().getDay()); } structureAI.getWorker().queueSound(state.getSoundType().getPlaceSound(), worldPos, 10, 0); @@ -224,7 +224,7 @@ public void triggerSuccess(final BlockPos pos, final List list, final if (state.getBlock() == ModBlocks.blockWayPoint) { - structureAI.getWorker().getCitizenColonyHandler().getColony().addWayPoint(worldPos, state); + structureAI.getWorker().getCitizenColonyHandler().getColonyOrRegister().addWayPoint(worldPos, state); } } diff --git a/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java b/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java index f98efea8650..35df8cd212a 100755 --- a/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java +++ b/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java @@ -2,7 +2,6 @@ import com.minecolonies.api.blocks.AbstractBlockHut; import com.minecolonies.api.colony.*; -import com.minecolonies.api.colony.buildings.IBuilding; import com.minecolonies.api.colony.buildings.IGuardBuilding; import com.minecolonies.api.colony.buildings.registry.BuildingEntry; import com.minecolonies.api.colony.citizens.event.CitizenRemovedEvent; @@ -339,7 +338,7 @@ private EntityState initialize() else { citizenColonyHandler.registerWithColony(citizenColonyHandler.getColonyId(), citizenId); - if (citizenData != null && isAlive() && citizenColonyHandler.getColony() != null) + if (citizenData != null && isAlive() && citizenColonyHandler.getColonyOrRegister() != null) { initTasks(); return EntityState.ACTIVE_SERVER; @@ -783,9 +782,9 @@ else if (!hat.isEmpty() && hat.getItem() == ModItems.santaHat) } this.setCustomNameVisible(MineColonies.getConfig().getServer().alwaysRenderNameTag.get()); - if (!citizenColonyHandler.getColony().getTextureStyleId().equals(getEntityData().get(DATA_STYLE))) + if (!citizenColonyHandler.getColonyOrRegister().getTextureStyleId().equals(getEntityData().get(DATA_STYLE))) { - getEntityData().set(DATA_STYLE, citizenColonyHandler.getColony().getTextureStyleId()); + getEntityData().set(DATA_STYLE, citizenColonyHandler.getColonyOrRegister().getTextureStyleId()); } if (!citizenData.getTextureSuffix().equals(getEntityData().get(DATA_TEXTURE_SUFFIX))) { @@ -839,7 +838,7 @@ public boolean canPathOnRails() } return false; } - return getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(RAILS) > 0; + return getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(RAILS) > 0; } /** @@ -858,7 +857,7 @@ public boolean canClimbVines() } return false; } - return getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(VINES) > 0; + return getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(VINES) > 0; } /** @@ -885,7 +884,7 @@ private void checkHeal() final double healAmount; if (citizenSaturation >= FULL_SATURATION + limitDecrease) { - healAmount = 2 * (1.0 + getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(REGENERATION)); + healAmount = 2 * (1.0 + getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(REGENERATION)); } else if (citizenSaturation < LOW_SATURATION) { @@ -893,7 +892,7 @@ else if (citizenSaturation < LOW_SATURATION) } else { - healAmount = 1 * (1.0 + getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(REGENERATION)); + healAmount = 1 * (1.0 + getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(REGENERATION)); } heal((float) healAmount); @@ -1329,7 +1328,7 @@ public boolean hurt(@NotNull final DamageSource damageSource, final float damage return false; } - if (getCitizenColonyHandler().getColony() == null) + if (getCitizenColonyHandler().getColonyOrRegister() == null) { return super.hurt(damageSource, damage); } @@ -1369,11 +1368,11 @@ private boolean checkIfValidDamageSource(final DamageSource source, final float return false; } - final IColony attackerColony = ((EntityCitizen) sourceEntity).citizenColonyHandler.getColony(); - if (attackerColony != null && citizenColonyHandler.getColony() != null) + final IColony attackerColony = ((EntityCitizen) sourceEntity).citizenColonyHandler.getColonyOrRegister(); + if (attackerColony != null && citizenColonyHandler.getColonyOrRegister() != null) { final IPermissions permission = attackerColony.getPermissions(); - citizenColonyHandler.getColony().getPermissions().addPlayer(permission.getOwner(), permission.getOwnerName(), permission.getRank(permission.HOSTILE_RANK_ID)); + citizenColonyHandler.getColonyOrRegister().getPermissions().addPlayer(permission.getOwner(), permission.getOwnerName(), permission.getRank(permission.HOSTILE_RANK_ID)); } } @@ -1381,12 +1380,12 @@ private boolean checkIfValidDamageSource(final DamageSource source, final float { if (sourceEntity instanceof ServerPlayer) { - if (citizenColonyHandler.getColony().getRaiderManager().isRaided()) + if (citizenColonyHandler.getColonyOrRegister().getRaiderManager().isRaided()) { return false; } - if (damage > 1 && !getCitizenColonyHandler().getColony().getPermissions().hasPermission((Player) sourceEntity, Action.HURT_CITIZEN)) + if (damage > 1 && !getCitizenColonyHandler().getColonyOrRegister().getPermissions().hasPermission((Player) sourceEntity, Action.HURT_CITIZEN)) { return false; } @@ -1433,9 +1432,9 @@ private boolean handleDamagePerformed(@NotNull final DamageSource damageSource, { if (citizenJobHandler.getColonyJob() instanceof JobKnight) { - if (citizenColonyHandler.getColony().getResearchManager().getResearchEffects().getEffectStrength(BLOCK_ATTACKS) > 0) + if (citizenColonyHandler.getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(BLOCK_ATTACKS) > 0) { - if (getRandom().nextDouble() < citizenColonyHandler.getColony().getResearchManager().getResearchEffects().getEffectStrength(BLOCK_ATTACKS)) + if (getRandom().nextDouble() < citizenColonyHandler.getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(BLOCK_ATTACKS)) { return false; } @@ -1445,7 +1444,7 @@ private boolean handleDamagePerformed(@NotNull final DamageSource damageSource, if (citizenData.getWorkBuilding() instanceof AbstractBuildingGuards && ((AbstractBuildingGuards) citizenData.getWorkBuilding()).shallRetrieveOnLowHealth() && getHealth() < ((int) getMaxHealth() * 0.2D)) { - damageInc *= 1 - citizenColonyHandler.getColony().getResearchManager().getResearchEffects().getEffectStrength(FLEEING_DAMAGE); + damageInc *= 1 - citizenColonyHandler.getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(FLEEING_DAMAGE); } } } @@ -1476,14 +1475,19 @@ && getHealth() < ((int) getMaxHealth() * 0.2D)) } } - if (result && damageSource.getEntity() instanceof LivingEntity) + if (!result) + { + return false; + } + + if (damageSource.getEntity() instanceof LivingEntity) { threatTable.addThreat((LivingEntity) damageSource.getEntity(), (int) damageInc); } if (damageSource.is(DamageTypeTags.IS_FIRE) || damageSource.is(DamageTypeTags.IS_LIGHTNING)) { - return result; + return true; } if (!level().isClientSide) @@ -1495,7 +1499,7 @@ && getHealth() < ((int) getMaxHealth() * 0.2D)) } } - return result; + return true; } /** @@ -1549,7 +1553,7 @@ public void callForHelp(final Entity attacker, final int guardHelpRange) List possibleGuards = new ArrayList<>(); - for (final ICitizenData entry : getCitizenColonyHandler().getColony().getCitizenManager().getCitizens()) + for (final ICitizenData entry : getCitizenColonyHandler().getColonyOrRegister().getCitizenManager().getCitizens()) { if (entry.getEntity().isPresent()) { @@ -1608,15 +1612,15 @@ public void onPlayerCollide(final Player player) @Override public void die(@NotNull final DamageSource damageSource) { - if (citizenColonyHandler.getColony() != null && getCitizenData() != null) + if (citizenColonyHandler.getColonyOrRegister() != null && getCitizenData() != null) { - citizenColonyHandler.getColony().getRaiderManager().onLostCitizen(getCitizenData()); + citizenColonyHandler.getColonyOrRegister().getRaiderManager().onLostCitizen(getCitizenData()); citizenExperienceHandler.dropExperience(); this.remove(RemovalReason.KILLED); if (!(citizenJobHandler.getColonyJob() instanceof AbstractJobGuard)) { - citizenColonyHandler.getColony() + citizenColonyHandler.getColonyOrRegister() .getCitizenManager() .injectModifier(new ExpirationBasedHappinessModifier(HappinessConstants.DEATH, 3.0, new StaticHappinessSupplier(0.0), 3)); } @@ -1624,17 +1628,17 @@ public void die(@NotNull final DamageSource damageSource) if (!(citizenJobHandler.getColonyJob() instanceof AbstractJobGuard)) { - citizenColonyHandler.getColony().getCitizenManager().updateCitizenMourn(citizenData, true); + citizenColonyHandler.getColonyOrRegister().getCitizenManager().updateCitizenMourn(citizenData, true); } - getCitizenColonyHandler().getColony().getStatisticsManager().increment(DEATH, getCitizenColonyHandler().getColony().getDay()); + getCitizenColonyHandler().getColonyOrRegister().getStatisticsManager().increment(DEATH, getCitizenColonyHandler().getColonyOrRegister().getDay()); boolean graveSpawned = false; if (!isInvisible()) { - if (citizenColonyHandler.getColony().isCoordInColony(level(), blockPosition())) + if (citizenColonyHandler.getColonyOrRegister().isCoordInColony(level(), blockPosition())) { - graveSpawned = getCitizenColonyHandler().getColony().getGraveManager().createCitizenGrave(level(), blockPosition(), citizenData); + graveSpawned = getCitizenColonyHandler().getColonyOrRegister().getGraveManager().createCitizenGrave(level(), blockPosition(), citizenData); } else { @@ -1642,7 +1646,7 @@ public void die(@NotNull final DamageSource damageSource) } } - if (getCitizenColonyHandler().getColony() != null && getCitizenData() != null) + if (getCitizenColonyHandler().getColonyOrRegister() != null && getCitizenData() != null) { MessageUtils.format(getCombatTracker().getDeathMessage()) .append(Component.literal("! ")) @@ -1652,18 +1656,18 @@ public void die(@NotNull final DamageSource damageSource) : Component.empty()) .append(graveSpawned ? Component.translatable(WARNING_GRAVE_SPAWNED) : Component.empty()) .withPriority(MessagePriority.DANGER) - .sendTo(getCitizenColonyHandler().getColony()).forManagers(); + .sendTo(getCitizenColonyHandler().getColonyOrRegister()).forManagers(); } if (citizenData.getJob() != null) { citizenData.getJob().onRemoval(); } - citizenColonyHandler.getColony().getCitizenManager().removeCivilian(getCitizenData()); + citizenColonyHandler.getColonyOrRegister().getCitizenManager().removeCivilian(getCitizenData()); final String deathCause = Component.literal(damageSource.getLocalizedDeathMessage(this).getString()).getString().replaceFirst(this.getDisplayName().getString(), "Citizen"); - citizenColonyHandler.getColony().getEventDescriptionManager().addEventDescription(new CitizenDiedEvent(blockPosition(), citizenData.getName(), deathCause)); + citizenColonyHandler.getColonyOrRegister().getEventDescriptionManager().addEventDescription(new CitizenDiedEvent(blockPosition(), citizenData.getName(), deathCause)); try { @@ -1749,11 +1753,11 @@ public int getArmorValue() { if (citizenJobHandler.getColonyJob() instanceof JobKnight) { - return (int) (super.getArmorValue() * (1 + citizenColonyHandler.getColony().getResearchManager().getResearchEffects().getEffectStrength(MELEE_ARMOR))); + return (int) (super.getArmorValue() * (1 + citizenColonyHandler.getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(MELEE_ARMOR))); } else if (citizenJobHandler.getColonyJob() instanceof JobRanger) { - return (int) (super.getArmorValue() * (1 + citizenColonyHandler.getColony().getResearchManager().getResearchEffects().getEffectStrength(ARCHER_ARMOR))); + return (int) (super.getArmorValue() * (1 + citizenColonyHandler.getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(ARCHER_ARMOR))); } return super.getArmorValue(); } @@ -1789,7 +1793,7 @@ public void setRemoved(final RemovalReason reason) @Override public void setCustomName(@Nullable final Component name) { - if (citizenData != null && citizenColonyHandler.getColony() != null && name != null) + if (citizenData != null && citizenColonyHandler.getColonyOrRegister() != null && name != null) { citizenData.setName(name.getString()); super.setCustomName(name); @@ -1932,4 +1936,10 @@ public void setMaxAir(final int maxAir) { this.maxAir = maxAir; } + + @Override + public int getTeamId() + { + return citizenColonyHandler.getColonyId(); + } } 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 0b11c7d0afe..7adabc8c35a 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 @@ -10,12 +10,10 @@ 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. @@ -142,6 +140,7 @@ public void updateColonyClient() citizen.discard(); return; } + colony = IColonyManager.getInstance().getColonyView(colonyId, citizen.level().dimension()); if (citizen.getCivilianID() == 0) { @@ -195,7 +194,7 @@ public double getPerBuildingFoodCost() */ @Override @Nullable - public IColony getColony() + public IColony getColonyOrRegister() { if (colony == null && !citizen.level().isClientSide) { @@ -205,6 +204,12 @@ public IColony getColony() return colony; } + @Override + public @Nullable IColony getColony() + { + return colony; + } + /** * Getter for the colony id. * @@ -236,10 +241,4 @@ public void onCitizenRemoved() citizen.getCitizenData().setLastPosition(citizen.blockPosition()); } } - - @Override - public PlayerTeam getTeam(final Level level) - { - return checkOrCreateTeam(level, IColony.getTeamName(level, colonyId), false); - } } diff --git a/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenDiseaseHandler.java b/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenDiseaseHandler.java index 40c9c95006c..edd811d634a 100755 --- a/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenDiseaseHandler.java +++ b/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenDiseaseHandler.java @@ -113,11 +113,11 @@ public void tick() private boolean canBecomeSick() { return !isSick() - && citizen.getCitizenColonyHandler().getColony() != null - && citizen.getCitizenColonyHandler().getColony().isActive() + && citizen.getCitizenColonyHandler().getColonyOrRegister() != null + && citizen.getCitizenColonyHandler().getColonyOrRegister().isActive() && !(citizen.getCitizenJobHandler().getColonyJob() instanceof JobHealer) && immunityTicks <= 0 - && citizen.getCitizenColonyHandler().getColony().getCitizenManager().getCurrentCitizenCount() > initialCitizenCount; + && citizen.getCitizenColonyHandler().getColonyOrRegister().getCitizenManager().getCurrentCitizenCount() > initialCitizenCount; } @Override @@ -127,8 +127,8 @@ public void onCollission(@NotNull final AbstractEntityCitizen citizen) && canBecomeSick() && citizen.getRandom().nextInt(ONE_HUNDRED_PERCENT) < 1) { - if (citizen.getCitizenColonyHandler().getColony() != null - && (citizen.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(MASKS) <= 0 || citizen.getRandom().nextBoolean())) + if (citizen.getCitizenColonyHandler().getColonyOrRegister() != null + && (citizen.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(MASKS) <= 0 || citizen.getRandom().nextBoolean())) { this.disease = citizen.getCitizenDiseaseHandler().getDisease(); } @@ -179,15 +179,15 @@ public void cure() if (citizen.getCitizenSleepHandler().isAsleep()) { citizen.stopSleeping(); - final BlockPos hospitalPos = citizen.getCitizenColonyHandler().getColony().getBuildingManager().getBestBuilding(citizen, BuildingCook.class); - final IColony colony = citizen.getCitizenColonyHandler().getColony(); + final BlockPos hospitalPos = citizen.getCitizenColonyHandler().getColonyOrRegister().getBuildingManager().getBestBuilding(citizen, BuildingCook.class); + final IColony colony = citizen.getCitizenColonyHandler().getColonyOrRegister(); final IBuilding hospital = colony.getBuildingManager().getBuilding(hospitalPos); if (hospital != null) { hospital.onWakeUp(); } - if (citizen.getCitizenColonyHandler().getColony() != null && citizen.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(VACCINES) > 0) + if (citizen.getCitizenColonyHandler().getColonyOrRegister() != null && citizen.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(VACCINES) > 0) { immunityTicks = IMMUNITY_TIME * VACCINE_MODIFIER; } @@ -196,7 +196,7 @@ public void cure() immunityTicks = IMMUNITY_TIME; } - citizen.getCitizenColonyHandler().getColony().getStatisticsManager().increment(CITIZENS_HEALED, citizen.getCitizenColonyHandler().getColony().getDay()); + citizen.getCitizenColonyHandler().getColonyOrRegister().getStatisticsManager().increment(CITIZENS_HEALED, citizen.getCitizenColonyHandler().getColonyOrRegister().getDay()); } citizen.markDirty(0); diff --git a/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenExperienceHandler.java b/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenExperienceHandler.java index fe06f36f850..78c789b45d5 100755 --- a/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenExperienceHandler.java +++ b/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenExperienceHandler.java @@ -93,7 +93,7 @@ public void addExperience(final double xp) return; } - localXp *= (1 + citizen.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(LEVELING)); + localXp *= (1 + citizen.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(LEVELING)); final WorkerBuildingModule module = workBuilding.getModuleMatching(WorkerBuildingModule.class, m -> m.getAssignedCitizen().contains(data)); final Skill primary = module.getPrimarySkill(); diff --git a/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenItemHandler.java b/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenItemHandler.java index 1aaf0b9c757..b0c8a2938a8 100755 --- a/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenItemHandler.java +++ b/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenItemHandler.java @@ -236,10 +236,10 @@ public void damageItemInHand(final InteractionHand hand, final int damage) } //Check if the effect exists first, to avoid unnecessary calls to random number generator. - if (citizen.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(TOOL_DURABILITY) > 0) + if (citizen.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(TOOL_DURABILITY) > 0) { if (citizen.getRandom().nextDouble() > (1 / (1 + citizen.getCitizenColonyHandler() - .getColony() + .getColonyOrRegister() .getResearchManager() .getResearchEffects() .getEffectStrength(TOOL_DURABILITY)))) @@ -319,10 +319,10 @@ public ItemEntity entityDropItem(@NotNull final ItemStack itemstack) @Override public void updateArmorDamage(final double damage) { - if (citizen.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(ARMOR_DURABILITY) > 0) + if (citizen.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(ARMOR_DURABILITY) > 0) { if (citizen.getRandom().nextDouble() > (1 / (1 + citizen.getCitizenColonyHandler() - .getColony() + .getColonyOrRegister() .getResearchManager() .getResearchEffects() .getEffectStrength(ARMOR_DURABILITY)))) diff --git a/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenJobHandler.java b/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenJobHandler.java index f8494bac050..8d3b9586e8b 100755 --- a/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenJobHandler.java +++ b/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenJobHandler.java @@ -107,7 +107,7 @@ public void onJobChanged(@Nullable final IJob job) // Calculate the number of guards for some advancements if (job instanceof AbstractJobGuard) { - IColony colony = citizen.getCitizenColonyHandler().getColony(); + IColony colony = citizen.getCitizenColonyHandler().getColonyOrRegister(); int guards = ((int) colony.getCitizenManager().getCitizens() .stream() .filter(citizen -> citizen.getJob() instanceof AbstractJobGuard) diff --git a/src/main/java/com/minecolonies/core/entity/mobs/EntityMercenary.java b/src/main/java/com/minecolonies/core/entity/mobs/EntityMercenary.java index 90488e925bd..767813b9c8e 100755 --- a/src/main/java/com/minecolonies/core/entity/mobs/EntityMercenary.java +++ b/src/main/java/com/minecolonies/core/entity/mobs/EntityMercenary.java @@ -47,7 +47,6 @@ import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.Heightmap; -import net.minecraft.world.scores.PlayerTeam; import net.neoforged.neoforge.items.IItemHandler; import org.jetbrains.annotations.NotNull; @@ -132,6 +131,11 @@ public class EntityMercenary extends AbstractFastMinecoloniesEntity implements N */ private static final String ENTITY_NAME = "Mercenary"; + /** + * Colony id of the assigned colony. + */ + private int colonyId; + /** * Constructor method for Mercenaries. * @@ -336,7 +340,7 @@ public void readAdditionalSaveData(final CompoundTag compound) worldTimeAtSpawn = compound.getLong(TAG_TIME); if (compound.contains(TAG_COLONY_ID)) { - final int colonyId = compound.getInt(TAG_COLONY_ID); + colonyId = compound.getInt(TAG_COLONY_ID); if (colonyId != 0) { setColony(IColonyManager.getInstance().getColonyByWorld(colonyId, level())); @@ -563,9 +567,8 @@ private static boolean isValidSpawnForMercenaries(final LevelAccessor world, fin } @Override - @Nullable - protected PlayerTeam getAssignedTeam() + public int getTeamId() { - return colony == null ? null : colony.getTeam(); + return colonyId; } } diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobEscapeWater.java b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobEscapeWater.java index 5c882dd1160..a9710805aa3 100644 --- a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobEscapeWater.java +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobEscapeWater.java @@ -54,7 +54,7 @@ public PathJobEscapeWater( preferredDirection = entity.blockPosition().offset(entity.blockPosition().subtract(avoid).multiply(range)); if (entity instanceof AbstractEntityCitizen) { - final IColony colony = ((AbstractEntityCitizen) entity).getCitizenColonyHandler().getColony(); + final IColony colony = ((AbstractEntityCitizen) entity).getCitizenColonyHandler().getColonyOrRegister(); if (colony != null) { preferredDirection = colony.getCenter(); diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobMoveAwayFromLocation.java b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobMoveAwayFromLocation.java index 84080483300..582ff0d55c8 100644 --- a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobMoveAwayFromLocation.java +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobMoveAwayFromLocation.java @@ -59,7 +59,7 @@ public PathJobMoveAwayFromLocation( preferredDirection = entity.blockPosition().offset(entity.blockPosition().subtract(avoid).multiply(range)); if (entity instanceof AbstractEntityCitizen) { - final IColony colony = ((AbstractEntityCitizen) entity).getCitizenColonyHandler().getColony(); + final IColony colony = ((AbstractEntityCitizen) entity).getCitizenColonyHandler().getColonyOrRegister(); if (colony != null) { preferredDirection = colony.getCenter(); diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/proxy/EntityCitizenWalkToProxy.java b/src/main/java/com/minecolonies/core/entity/pathfinding/proxy/EntityCitizenWalkToProxy.java index 6abe86d9c95..b02676f410f 100644 --- a/src/main/java/com/minecolonies/core/entity/pathfinding/proxy/EntityCitizenWalkToProxy.java +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/proxy/EntityCitizenWalkToProxy.java @@ -47,12 +47,12 @@ public EntityCitizenWalkToProxy(final AbstractEntityCitizen entity) @Override public Set getWayPoints() { - if (citizen.getCitizenColonyHandler().getColony() == null) + if (citizen.getCitizenColonyHandler().getColonyOrRegister() == null) { return Collections.emptySet(); } - return citizen.getCitizenColonyHandler().getColony().getWayPoints().keySet(); + return citizen.getCitizenColonyHandler().getColonyOrRegister().getWayPoints().keySet(); } @Override @@ -76,7 +76,7 @@ else if (citizen.getCitizenJobHandler().getColonyJob() != null && citizen.getCit AbstractBuildingGuards guardbuilding = (AbstractBuildingGuards) building; if (guardbuilding.getTask().equals(GuardTaskSetting.PATROL_MINE) && guardbuilding.getMinePos() != null) { - final IBuilding miner = citizen.getCitizenColonyHandler().getColony().getBuildingManager().getBuilding(guardbuilding.getMinePos()); + final IBuilding miner = citizen.getCitizenColonyHandler().getColonyOrRegister().getBuildingManager().getBuilding(guardbuilding.getMinePos()); if (miner instanceof BuildingMiner) { return getMinerProxy(target, distanceToPath, (BuildingMiner) miner); diff --git a/src/main/java/com/minecolonies/core/entity/visitor/VisitorCitizen.java b/src/main/java/com/minecolonies/core/entity/visitor/VisitorCitizen.java index cb989d2535d..d2f9b38676c 100644 --- a/src/main/java/com/minecolonies/core/entity/visitor/VisitorCitizen.java +++ b/src/main/java/com/minecolonies/core/entity/visitor/VisitorCitizen.java @@ -42,7 +42,6 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.PathfinderMob; import net.minecraft.world.entity.ai.goal.FloatGoal; -import net.minecraft.world.entity.ai.goal.InteractGoal; import net.minecraft.world.entity.ai.goal.OpenDoorGoal; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; @@ -66,8 +65,7 @@ /** * Visitor citizen entity */ -public class -VisitorCitizen extends AbstractEntityCitizen +public class VisitorCitizen extends AbstractEntityCitizen { /** * The citizen experience handler @@ -180,7 +178,7 @@ public boolean hurt(@NotNull final DamageSource damageSource, final float damage final TavernBuildingModule module = home.getModule(BuildingModules.TAVERN_VISITOR); for (final Integer id : module.getExternalCitizens()) { - ICitizenData data = citizenColonyHandler.getColony().getVisitorManager().getCivilian(id); + ICitizenData data = citizenColonyHandler.getColonyOrRegister().getVisitorManager().getCivilian(id); if (data != null && data.getEntity().isPresent() && data.getEntity().get().getLastHurtByMob() == null) { data.getEntity().get().setLastHurtByMob((LivingEntity) damageSource.getEntity()); @@ -193,7 +191,7 @@ public boolean hurt(@NotNull final DamageSource damageSource, final float damage { if (sourceEntity instanceof ServerPlayer) { - return damage <= 1 || getCitizenColonyHandler().getColony().getPermissions().hasPermission((Player) sourceEntity, Action.HURT_VISITOR); + return damage <= 1 || getCitizenColonyHandler().getColonyOrRegister().getPermissions().hasPermission((Player) sourceEntity, Action.HURT_VISITOR); } else { @@ -626,7 +624,7 @@ public void die(DamageSource cause) super.die(cause); if (!level().isClientSide()) { - IColony colony = getCitizenColonyHandler().getColony(); + IColony colony = getCitizenColonyHandler().getColonyOrRegister(); if (colony != null && getCitizenData() != null) { colony.getVisitorManager().removeCivilian(getCitizenData()); @@ -688,4 +686,10 @@ public void setRemoved(final RemovalReason reason) citizenColonyHandler.onCitizenRemoved(); super.setRemoved(reason); } + + @Override + public int getTeamId() + { + return citizenColonyHandler.getColonyId(); + } } diff --git a/src/main/java/com/minecolonies/core/event/EventHandler.java b/src/main/java/com/minecolonies/core/event/EventHandler.java index f7563e5dbe4..26419d4fb86 100755 --- a/src/main/java/com/minecolonies/core/event/EventHandler.java +++ b/src/main/java/com/minecolonies/core/event/EventHandler.java @@ -687,7 +687,7 @@ public static void onCropTrample(BlockEvent.FarmlandTrampleEvent event) if (!event.getLevel().isClientSide() && event.getEntity() instanceof AbstractEntityCitizen && ((AbstractEntityCitizen) event.getEntity()).getCitizenJobHandler().getColonyJob() instanceof JobFarmer - && ((AbstractEntityCitizen) event.getEntity()).getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(SOFT_SHOES) > 0 + && ((AbstractEntityCitizen) event.getEntity()).getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(SOFT_SHOES) > 0 ) { event.setCanceled(true); diff --git a/src/main/java/com/minecolonies/core/util/TeamUtils.java b/src/main/java/com/minecolonies/core/util/TeamUtils.java deleted file mode 100644 index 88c7a9b3509..00000000000 --- a/src/main/java/com/minecolonies/core/util/TeamUtils.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.minecolonies.core.util; - -import net.minecraft.world.level.Level; -import net.minecraft.world.scores.PlayerTeam; -import org.jetbrains.annotations.Nullable; - -/** - * Utility class for working with {@link net.minecraft.world.scores.Team instances}. - */ -public class TeamUtils -{ - - /** - * Check or create a team. - * - * @param level the level to create the team in. - * @param name the team name. - */ - @Nullable - public static PlayerTeam checkOrCreateTeam(@Nullable final Level level, final String name) - { - return checkOrCreateTeam(level, name, true); - } - - /** - * Check or create a team. - * - * @param level the level to create the team in. - * @param name the team name. - * @param allowFriendlyFire whether this team allows friendly fire or not. - */ - @Nullable - public static PlayerTeam checkOrCreateTeam(@Nullable final Level level, final String name, boolean allowFriendlyFire) - { - if (level == null) - { - return null; - } - - PlayerTeam team = level.getScoreboard().getPlayerTeam(name); - if (team == null) - { - team = level.getScoreboard().addPlayerTeam(name); - } - team.setAllowFriendlyFire(allowFriendlyFire); - return team; - } -}