diff --git a/src/main/java/com/minecolonies/api/colony/IColony.java b/src/main/java/com/minecolonies/api/colony/IColony.java index 8b49e882c6b..1ac43da9e65 100755 --- a/src/main/java/com/minecolonies/api/colony/IColony.java +++ b/src/main/java/com/minecolonies/api/colony/IColony.java @@ -18,7 +18,6 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.LevelChunk; -import net.minecraft.world.scores.PlayerTeam; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.CapabilityManager; import net.minecraftforge.common.capabilities.CapabilityToken; @@ -119,17 +118,6 @@ public interface IColony */ boolean hasBuilding(final String building, final int level, final boolean singleBuilding); - /** - * Defines the team name for all colonies (both Colony and ColonyView) - * - * @return The team name - */ - static String getTeamName(final Level level, final int id) - { - final String dim = level.dimension().location().getPath(); - return TEAM_COLONY_NAME + "_" + (dim.length() > 10 ? dim.hashCode() : dim) + "_" + id; - } - /** * Getter for the team colony color. * @@ -151,13 +139,6 @@ static String getTeamName(final Level level, final int id) */ boolean isDay(); - /** - * Retrieves the team of the colony - * - * @return Team of the colony - */ - PlayerTeam getTeam(); - /** * Get the last contact of a player to the colony in hours. * diff --git a/src/main/java/com/minecolonies/api/colony/IColonyView.java b/src/main/java/com/minecolonies/api/colony/IColonyView.java index 361a8c4e62b..a5347b2beac 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; @@ -343,9 +342,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 8b6ffe83a0a..f1a8fd4338a 100755 --- a/src/main/java/com/minecolonies/api/entity/citizen/AbstractEntityCitizen.java +++ b/src/main/java/com/minecolonies/api/entity/citizen/AbstractEntityCitizen.java @@ -25,7 +25,10 @@ import com.minecolonies.core.entity.pathfinding.navigation.AbstractAdvancedPathNavigate; import com.minecolonies.core.entity.pathfinding.navigation.PathingStuckHandler; import com.mojang.datafixers.util.Pair; +import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; @@ -46,7 +49,6 @@ import net.minecraft.world.item.ShieldItem; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; -import net.minecraft.world.scores.PlayerTeam; import net.minecraftforge.items.IItemHandler; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -235,18 +237,6 @@ public boolean isNoAi() return false; } - @Override - @Nullable - protected PlayerTeam getAssignedTeam() - { - final ICitizenColonyHandler citizenColonyHandler = getCitizenColonyHandler(); - if (citizenColonyHandler == null) - { - return null; - } - return citizenColonyHandler.getTeam(level); - } - /** * Sets the textures of all citizens and distinguishes between male and female. */ @@ -782,4 +772,29 @@ public boolean isSleeping() { return getCitizenSleepHandler().isAsleep(); } + + @Override + public int getTeamColor() + { + if (getCitizenColonyHandler().getColony() == null) + { + return super.getTeamColor(); + } + return getCitizenColonyHandler().getColony().getTeamColonyColor().getColor(); + } + + @Override + @NotNull + public Component getDisplayName() + { + if (getCitizenColonyHandler().getColony() == null) + { + return super.getDisplayName(); + } + if (getName() instanceof MutableComponent mutableComponent) + { + return mutableComponent.withStyle(getCitizenColonyHandler().getColony().getTeamColonyColor()).withStyle((style) -> style.withHoverEvent(this.createHoverEvent()).withInsertion(this.getStringUUID())); + } + return super.getDisplayName(); + } } 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 6cce739ffdc..6e8df051538 100644 --- a/src/main/java/com/minecolonies/api/entity/mobs/AbstractEntityRaiderMob.java +++ b/src/main/java/com/minecolonies/api/entity/mobs/AbstractEntityRaiderMob.java @@ -41,7 +41,6 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.ServerLevelAccessor; import net.minecraft.world.level.chunk.LevelChunk; -import net.minecraft.world.scores.PlayerTeam; import net.minecraftforge.common.util.ITeleporter; import org.jetbrains.annotations.NotNull; @@ -52,7 +51,6 @@ import static com.minecolonies.api.util.constant.ColonyManagerConstants.NO_COLONY_ID; import static com.minecolonies.api.util.constant.NbtTagConstants.*; import static com.minecolonies.api.util.constant.RaiderConstants.*; -import static com.minecolonies.core.util.TeamUtils.checkOrCreateTeam; /** * Abstract for all raider entities. @@ -732,13 +730,6 @@ public void initStatsFor(final double baseHealth, final double difficulty, final this.setHealth(this.getMaxHealth()); } - @Override - @Nullable - protected PlayerTeam getAssignedTeam() - { - return checkOrCreateTeam(level, RAID_TEAM); - } - /** * Get the mobs difficulty * @@ -774,4 +765,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 83cc31828c3..f0d1c5d2331 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; @@ -15,15 +16,12 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.entity.EntityTypeTest; import net.minecraft.world.phys.Vec3; -import net.minecraft.world.scores.PlayerTeam; -import net.minecraft.world.scores.Team; import net.minecraftforge.common.util.ITeleporter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; -import java.util.Objects; /** * Special abstract minecolonies mob that overrides laggy vanilla behaviour. @@ -320,78 +318,6 @@ public void updateSwimAmount() } - /** - * Get the team this entity is assigned to. - * - * @return the team instance. - */ - @Nullable - protected abstract PlayerTeam getAssignedTeam(); - - @Override - @Nullable - public final Team getTeam() - { - final PlayerTeam assignedTeam = getAssignedTeam(); - registerToTeamInternal(assignedTeam); - return assignedTeam; - } - - /** - * Register this entity to its own assigned team. - */ - public void registerToTeam() - { - registerToTeamInternal(getAssignedTeam()); - } - - /** - * Internal method for team registration. - * - * @param team the team to register to. - */ - private void registerToTeamInternal(@Nullable final PlayerTeam team) - { - if (team != null && !isInTeam(team)) - { - level.getScoreboard().addPlayerToTeam(getScoreboardName(), team); - } - } - - /** - * Remove the entity from its own assigned team. - */ - public void removeFromTeam() - { - final PlayerTeam team = getAssignedTeam(); - if (team != null && isInTeam(team)) - { - level.getScoreboard().removePlayerFromTeam(getScoreboardName(), team); - } - } - - /** - * Check if the current entity is assigned to the provided team. - * - * @param team the input team. - * @return true if so. - */ - private boolean isInTeam(@NotNull final PlayerTeam team) - { - return Objects.equals(level.getScoreboard().getPlayersTeam(getScoreboardName()), team); - } - - @Override - public void remove(@NotNull final RemovalReason reason) - { - super.remove(reason); - final PlayerTeam playersTeam = level.getScoreboard().getPlayersTeam(getScoreboardName()); - if (playersTeam != null) - { - level.getScoreboard().removePlayerFromTeam(getScoreboardName(), playersTeam); - } - } - /** * Static Byte values to avoid frequent autoboxing */ @@ -426,4 +352,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 756d08837ba..9f375c7a027 100644 --- a/src/main/java/com/minecolonies/api/loot/ResearchUnlocked.java +++ b/src/main/java/com/minecolonies/api/loot/ResearchUnlocked.java @@ -89,7 +89,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 760c1ab3651..fc31a5628db 100644 --- a/src/main/java/com/minecolonies/api/util/FoodUtils.java +++ b/src/main/java/com/minecolonies/api/util/FoodUtils.java @@ -82,7 +82,7 @@ public static double getFoodValue(final ItemStack foodStack, final AbstractEntit { final FoodProperties itemFood = foodStack.getItem().getFoodProperties(foodStack, citizen); final int housingLevel = citizen.getCitizenData().getHomeBuilding() == null ? 0 : citizen.getCitizenData().getHomeBuilding().getBuildingLevel(); - final double researchBonus = citizen.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(SATURATION); + final double researchBonus = citizen.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(SATURATION); return getFoodValue(foodStack, itemFood, housingLevel, researchBonus); } diff --git a/src/main/java/com/minecolonies/api/util/ItemStackUtils.java b/src/main/java/com/minecolonies/api/util/ItemStackUtils.java index 78ee90a9a51..6062dcc8035 100755 --- a/src/main/java/com/minecolonies/api/util/ItemStackUtils.java +++ b/src/main/java/com/minecolonies/api/util/ItemStackUtils.java @@ -981,7 +981,7 @@ else if (foodStack.getItem() instanceof ItemBowlFood) citizen.getCitizenData().getCitizenHappinessHandler().addModifier(new ExpirationBasedHappinessModifier(HADGREATFOOD, 2.0, new StaticHappinessSupplier(2.0), 5)); } - IColony citizenColony = citizen.getCitizenColonyHandler().getColony(); + IColony citizenColony = citizen.getCitizenColonyHandler().getColonyOrRegister(); if (citizenColony != null) { AdvancementUtils.TriggerAdvancementPlayersForColony(citizenColony, playerMP -> AdvancementTriggers.CITIZEN_EAT_FOOD.trigger(playerMP, foodStack)); diff --git a/src/main/java/com/minecolonies/api/util/MessageUtils.java b/src/main/java/com/minecolonies/api/util/MessageUtils.java index e8185273fd4..1e8ef2e1caf 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/client/render/worldevent/ColonyBorderRenderer.java b/src/main/java/com/minecolonies/core/client/render/worldevent/ColonyBorderRenderer.java index 813fbe5a1ff..7ab104509df 100644 --- a/src/main/java/com/minecolonies/core/client/render/worldevent/ColonyBorderRenderer.java +++ b/src/main/java/com/minecolonies/core/client/render/worldevent/ColonyBorderRenderer.java @@ -152,8 +152,7 @@ private static VertexBuffer draw(final BufferBuilder bufferbuilder, final Color colour = colonyColours.computeIfAbsent(colonyId, id -> { final IColonyView colony = IMinecoloniesAPI.getInstance().getColonyManager().getColonyView(id, Minecraft.getInstance().level.dimension()); - final ChatFormatting team = colony != null ? colony.getTeamColonyColor() - : id == playerColonyId ? ChatFormatting.WHITE : ChatFormatting.RED; + final ChatFormatting team = colony != null ? colony.getTeamColonyColor() : id == playerColonyId ? ChatFormatting.WHITE : ChatFormatting.RED; return new Color(team.getColor()); }); diff --git a/src/main/java/com/minecolonies/core/colony/Colony.java b/src/main/java/com/minecolonies/core/colony/Colony.java index 12bf606ccbb..b73baca9a75 100644 --- a/src/main/java/com/minecolonies/core/colony/Colony.java +++ b/src/main/java/com/minecolonies/core/colony/Colony.java @@ -60,7 +60,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.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.TickEvent; import net.minecraftforge.registries.ForgeRegistries; @@ -80,7 +79,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. @@ -363,7 +361,6 @@ protected Colony(final int id, @Nullable final Level world) { this.dimensionId = world.dimension(); onWorldLoad(world); - checkOrCreateTeam(world, IColony.getTeamName(world, id), false); } this.permissions = new Permissions(this); researchManager = new ResearchManager(this); @@ -627,14 +624,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. * @@ -645,12 +634,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 d5ed603c49b..ac5c75219c2 100644 --- a/src/main/java/com/minecolonies/core/colony/ColonyView.java +++ b/src/main/java/com/minecolonies/core/colony/ColonyView.java @@ -56,7 +56,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.minecraftforge.event.TickEvent; import net.minecraftforge.registries.ForgeRegistries; import org.jetbrains.annotations.NotNull; @@ -1250,12 +1249,6 @@ public boolean isDay() return false; } - @Override - public PlayerTeam getTeam() - { - return world.getScoreboard().getPlayerTeam(IColony.getTeamName(world, id)); - } - @Override public int getLastContactInHours() { diff --git a/src/main/java/com/minecolonies/core/colony/jobs/JobKnight.java b/src/main/java/com/minecolonies/core/colony/jobs/JobKnight.java index a2402c7fb92..d92e3fb7b12 100755 --- a/src/main/java/com/minecolonies/core/colony/jobs/JobKnight.java +++ b/src/main/java/com/minecolonies/core/colony/jobs/JobKnight.java @@ -90,7 +90,7 @@ public boolean ignoresDamage(@NotNull final DamageSource damageSource) // Apply the colony Flag to the shield ItemStack shieldStack = worker.getInventoryCitizen().getHeldItem(InteractionHand.OFF_HAND); CompoundTag nbt = shieldStack.getOrCreateTagElement("BlockEntityTag"); - nbt.put(TAG_BANNER_PATTERNS, worker.getCitizenColonyHandler().getColony().getColonyFlag()); + nbt.put(TAG_BANNER_PATTERNS, worker.getCitizenColonyHandler().getColonyOrRegister().getColonyFlag()); worker.decreaseSaturationForContinuousAction(); return true; 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 d3696441380..034851a156c 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 a027f58587e..467026724e2 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 @@ -100,7 +100,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 62ff67c0a77..061fe362d9e 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 86db768247e..92ef2a4db55 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 @@ -261,7 +261,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) { @@ -429,7 +429,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 787c7654710..e6170b11543 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 991d2301080..5331c365dc6 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 @@ -178,8 +178,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) @@ -290,8 +290,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 e5f26d3efcd..af02042cba1 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 @@ -165,7 +165,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 2f9ecc6dac4..16195643d4a 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 a4a3fd9b51e..9f7157c1a88 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 @@ -957,7 +957,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 { @@ -983,7 +983,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 73c384b4a6e..87c8165e40d 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 @@ -332,7 +332,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 83d74074cb3..aba1aed1ea4 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(); @@ -705,7 +705,7 @@ public void loadStructure(@NotNull final IWorkOrder workOrder, final int rotateT } 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 dd1881be270..35133163f24 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; } @@ -389,7 +389,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())); } @@ -403,19 +403,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; } @@ -440,7 +440,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())); } @@ -459,7 +459,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 54ce1b22346..78bdacc45fd 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 @@ -1,6 +1,5 @@ package com.minecolonies.core.entity.ai.workers; -import com.minecolonies.api.colony.buildings.ModBuildings; import com.minecolonies.api.colony.interactionhandling.ChatPriority; import com.minecolonies.api.colony.jobs.ModJobs; import com.minecolonies.api.entity.ai.IStateAI; @@ -155,7 +154,7 @@ private IState calculateNextState() } // Raiding - if (citizen.getCitizenColonyHandler().getColony().getRaiderManager().isRaided()) + if (citizen.getCitizenColonyHandler().getColonyOrRegister().getRaiderManager().isRaided()) { citizen.getCitizenData().triggerInteraction(new StandardInteraction(Component.translatable(COM_MINECOLONIES_COREMOD_ENTITY_CITIZEN_RAID), ChatPriority.IMPORTANT)); citizen.setVisibleStatusIfNone(RAIDED); @@ -303,7 +302,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 360fa56d6ce..7df9cdf604c 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.translatable(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 1766b4fb4f1..85d6e3d617a 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 @@ -538,9 +538,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 c650c45cb68..e07ca0abfab 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 @@ -189,7 +189,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 a76affc6a2e..9297ca57114 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 93c38b31aa7..a6864ea4838 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 aeff87b16fa..449e3cd1adc 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 @@ -273,7 +273,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 @@ -355,7 +355,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; @@ -394,7 +394,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))); @@ -816,7 +816,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 d155eaf432c..1dd075118c9 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 @@ -132,7 +132,7 @@ protected void doAttack(final LivingEntity target) final ItemStack stack = new ItemStack(Items.SPLASH_POTION); 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 d3da694774b..240ace960d4 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 @@ -109,7 +109,7 @@ protected IAIState attackProtect() { final int shieldSlot = InventoryUtils.findFirstSlotInItemHandlerWith(user.getInventoryCitizen(), Items.SHIELD); if (shieldSlot != -1 && target != null && target.isAlive() && nextAttackTime - user.level.getGameTime() >= MIN_TIME_TO_ATTACK && - user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(SHIELD_USAGE) > 0) + user.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(SHIELD_USAGE) > 0) { user.getCitizenItemHandler().setHeldItem(InteractionHand.OFF_HAND, shieldSlot); user.startUsingItem(InteractionHand.OFF_HAND); @@ -117,7 +117,7 @@ protected IAIState attackProtect() // Apply the colony Flag to the shield ItemStack shieldStack = user.getInventoryCitizen().getHeldItem(InteractionHand.OFF_HAND); CompoundTag nbt = shieldStack.getOrCreateTagElement("BlockEntityTag"); - nbt.put(TAG_BANNER_PATTERNS, user.getCitizenColonyHandler().getColony().getColonyFlag()); + nbt.put(TAG_BANNER_PATTERNS, user.getCitizenColonyHandler().getColonyOrRegister().getColonyFlag()); user.lookAt(target, (float) TURN_AROUND, (float) TURN_AROUND); user.decreaseSaturationForContinuousAction(); @@ -176,7 +176,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) @@ -199,7 +199,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)); @@ -267,7 +267,7 @@ private double getAttackDamage() addDmg += EnchantmentHelper.getDamageBonus(heldItem, target.getMobType()) / 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) @@ -275,7 +275,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)); @@ -365,7 +365,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 22e95a04c30..12f043df468 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 @@ -155,9 +155,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++; } @@ -167,7 +167,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); } @@ -252,9 +252,9 @@ private double calculateDamage(final AbstractArrow arrow) final ItemStack heldItem = user.getItemInHand(InteractionHand.MAIN_HAND); damage += EnchantmentHelper.getDamageBonus(heldItem, target.getMobType()) / 2.5; damage += EnchantmentHelper.getItemEnchantmentLevel(Enchantments.POWER_ARROWS, heldItem); - damage += user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(ARCHER_DAMAGE); + damage += user.getCitizenColonyHandler().getColonyOrRegister().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) @@ -284,7 +284,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; } @@ -386,7 +386,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 afc5e3d0315..fe68dcb17fb 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 @@ -7,8 +7,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; @@ -31,8 +29,6 @@ import net.minecraft.world.item.Items; import net.minecraft.world.level.block.*; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.FluidState; -import net.minecraft.world.level.material.Fluids; import net.minecraftforge.common.ToolActions; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -955,7 +951,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 b16cb91b6a5..6125db4afc5 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 fe56af58b26..29be030759e 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 @@ -60,7 +60,6 @@ import static com.minecolonies.api.util.constant.NbtTagConstants.*; import static com.minecolonies.api.util.constant.EquipmentLevelConstants.*; import static com.minecolonies.core.colony.buildings.modules.BuildingModules.NETHERMINER_MENU; -import static com.minecolonies.core.colony.buildings.modules.BuildingModules.NETHERMINER_MENU; import static com.minecolonies.core.entity.ai.workers.production.EntityAIStructureMiner.*; public class EntityAIWorkNether extends AbstractEntityAICrafting @@ -1007,11 +1006,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) { @@ -1019,7 +1018,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 7ac9e5f6f13..abd9db32586 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 @@ -591,7 +591,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; } @@ -650,14 +650,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 @@ -851,7 +851,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; @@ -889,7 +889,7 @@ private void harvestCrop(@NotNull final BlockPos pos) final int fortune = ItemStackUtils.getFortuneOf(tool); 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 bb699cd24a5..b505adb3f04 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 @@ -460,7 +460,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 90f423461b0..9d84f77eead 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 @@ -12,7 +12,6 @@ import com.minecolonies.api.entity.ai.statemachine.states.IAIState; import com.minecolonies.api.entity.citizen.AbstractEntityCitizen; import com.minecolonies.api.entity.citizen.VisibleCitizenStatus; -import com.minecolonies.api.items.IMinecoloniesFoodItem; import com.minecolonies.api.util.*; import com.minecolonies.api.util.constant.CitizenConstants; import com.minecolonies.api.util.constant.Constants; @@ -22,16 +21,10 @@ import com.minecolonies.core.colony.jobs.JobCook; import com.minecolonies.core.entity.ai.workers.AbstractEntityAIUsesFurnace; import com.minecolonies.core.entity.citizen.EntityCitizen; -import com.minecolonies.core.entity.pathfinding.navigation.MovementHandler; -import com.minecolonies.core.tileentities.TileEntityRack; -import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.FurnaceBlockEntity; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.wrapper.InvWrapper; @@ -41,7 +34,6 @@ import java.util.function.Predicate; import static com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState.*; -import static com.minecolonies.api.util.ItemStackUtils.CAN_EAT; import static com.minecolonies.api.util.constant.CitizenConstants.AVERAGE_SATURATION; import static com.minecolonies.api.util.constant.CitizenConstants.FULL_SATURATION; import static com.minecolonies.api.util.constant.Constants.*; @@ -198,7 +190,7 @@ private IAIState serveFoodToCitizen() { final ItemStack stack = worker.getInventoryCitizen().extractItem(foodSlot, 1, false); citizenData.increaseSaturation(FoodUtils.getFoodValue(stack, worker)); - worker.getCitizenColonyHandler().getColony().getStatisticsManager().increment(FOOD_SERVED, worker.getCitizenColonyHandler().getColony().getDay()); + worker.getCitizenColonyHandler().getColonyOrRegister().getStatisticsManager().increment(FOOD_SERVED, worker.getCitizenColonyHandler().getColonyOrRegister().getDay()); } else { @@ -236,7 +228,7 @@ else if (InventoryUtils.hasItemInItemHandler(handler, canEatPredicate)) final int transferCount = Math.min(countInSlot, building.getBuildingLevel()); if (InventoryUtils.transferXOfItemStackIntoNextFreeSlotInItemHandler(worker.getInventoryCitizen(), foodSlot, qty, citizenData.getInventory())) { - worker.getCitizenColonyHandler().getColony().getStatisticsManager().incrementBy(FOOD_SERVED, qty, worker.getCitizenColonyHandler().getColony().getDay()); + worker.getCitizenColonyHandler().getColonyOrRegister().getStatisticsManager().incrementBy(FOOD_SERVED, qty, worker.getCitizenColonyHandler().getColonyOrRegister().getDay()); worker.getCitizenExperienceHandler().addExperience(BASE_XP_GAIN); this.incrementActionsDoneAndDecSaturation(); } @@ -287,7 +279,7 @@ else if (InventoryUtils.hasItemInItemHandler(handler, canEatPredicate)) playerToServe.clear(); return START_WORKING; } - worker.getCitizenColonyHandler().getColony().getStatisticsManager().incrementBy(FOOD_SERVED, count, worker.getCitizenColonyHandler().getColony().getDay()); + worker.getCitizenColonyHandler().getColonyOrRegister().getStatisticsManager().incrementBy(FOOD_SERVED, count, worker.getCitizenColonyHandler().getColonyOrRegister().getDay()); MessageUtils.format(MESSAGE_INFO_CITIZEN_COOK_SERVE_PLAYER, worker.getName().getString()).sendTo(player); worker.getCitizenExperienceHandler().addExperience(BASE_XP_GAIN); 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 c93ec2ad0ea..09fbf366b2a 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 @@ -341,7 +341,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; } @@ -440,9 +440,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 bddd751da18..3869a78df89 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 @@ -169,7 +169,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(); @@ -226,7 +226,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(); @@ -348,8 +348,8 @@ private IAIState tryResurrect() .getCitizenManager() .resurrectCivilianData(graveData.getCitizenDataNBT(), true, world, gravePos); MessageUtils.format(MESSAGE_INFO_CITIZEN_UNDERTAKER_RESURRECTED_SUCCESS, citizenData.getName()).sendTo(buildingGraveyard.getColony()).forManagers(); - worker.getCitizenColonyHandler().getColony().getCitizenManager().updateCitizenMourn(citizenData, false); - AdvancementUtils.TriggerAdvancementPlayersForColony(worker.getCitizenColonyHandler().getColony(), + worker.getCitizenColonyHandler().getColonyOrRegister().getCitizenManager().updateCitizenMourn(citizenData, false); + AdvancementUtils.TriggerAdvancementPlayersForColony(worker.getCitizenColonyHandler().getColonyOrRegister(), playerMP -> AdvancementTriggers.CITIZEN_RESURRECT.trigger(playerMP)); buildingGraveyard.getFirstModuleOccurance(GraveyardManagementModule.class).setLastGraveData(null); world.setBlockAndUpdate(gravePos, Blocks.AIR.defaultBlockState()); @@ -371,11 +371,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) { @@ -391,13 +391,13 @@ 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); if (totems > 0) { - AdvancementUtils.TriggerAdvancementPlayersForColony(worker.getCitizenColonyHandler().getColony(), AdvancementTriggers.UNDERTAKER_TOTEM::trigger); + AdvancementUtils.TriggerAdvancementPlayersForColony(worker.getCitizenColonyHandler().getColonyOrRegister(), AdvancementTriggers.UNDERTAKER_TOTEM::trigger); } if (totems == 1) @@ -439,7 +439,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; } @@ -460,7 +460,7 @@ private IAIState buryCitizen() module.buryCitizenHere(burialPos, worker); //Disabled until Mourning AI update: worker.getCitizenColonyHandler().getColony().setNeedToMourn(false, buildingGraveyard.getLastGraveData().getCitizenName()); - AdvancementUtils.TriggerAdvancementPlayersForColony(worker.getCitizenColonyHandler().getColony(), playerMP -> AdvancementTriggers.CITIZEN_BURY.trigger(playerMP)); + AdvancementUtils.TriggerAdvancementPlayersForColony(worker.getCitizenColonyHandler().getColonyOrRegister(), playerMP -> AdvancementTriggers.CITIZEN_BURY.trigger(playerMP)); module.setLastGraveData(null); burialPos = null; 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 66daa38cf39..553c73d76f2 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()); } BlockState blockStateForSound; @@ -236,7 +236,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 30903db982c..973a1fa6ac0 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; @@ -338,7 +337,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; @@ -786,9 +785,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))) { @@ -842,7 +841,7 @@ public boolean canPathOnRails() } return false; } - return getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(RAILS) > 0; + return getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(RAILS) > 0; } /** @@ -861,7 +860,7 @@ public boolean canClimbVines() } return false; } - return getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(VINES) > 0; + return getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(VINES) > 0; } /** @@ -883,12 +882,12 @@ private void checkHeal() { if (getHealth() < (citizenDiseaseHandler.isSick() ? getMaxHealth() / 3 : getMaxHealth()) && getLastHurtByMob() == null) { - final double limitDecrease = getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(SATLIMIT); + final double limitDecrease = getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(SATLIMIT); final double healAmount; if (citizenData.getSaturation() >= 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 (citizenData.getSaturation() < LOW_SATURATION) { @@ -896,7 +895,7 @@ else if (citizenData.getSaturation() < 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); @@ -1314,7 +1313,7 @@ public boolean hurt(@NotNull final DamageSource damageSource, final float damage Log.getLogger() .warn("Entity:" + getName() + " uuid:" + getUUID() + " id:" + getId() + " removed:" + isRemoved() + " colonyid:" + citizenColonyHandler.getColonyId() - + " entitydata colony id:" + getEntityData().get(DATA_COLONY_ID) + " hascolony:" + (citizenColonyHandler.getColony() != null) + + + " entitydata colony id:" + getEntityData().get(DATA_COLONY_ID) + " hascolony:" + (citizenColonyHandler.getColonyOrRegister() != null) + " registered:" + citizenColonyHandler.registered() + " world:" + level + " saved data:" + tag + " removalReason: " + removalReason); } @@ -1334,7 +1333,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); } @@ -1374,11 +1373,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)); } } @@ -1386,12 +1385,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; } @@ -1438,9 +1437,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; } @@ -1450,21 +1449,24 @@ 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); } } } - final boolean result = super.hurt(damageSource, damageInc); + if (!super.hurt(damageSource, damageInc)) + { + return false; + } - if (result && damageSource.getEntity() instanceof LivingEntity) + 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) @@ -1476,7 +1478,7 @@ && getHealth() < ((int) getMaxHealth() * 0.2D)) } } - return result; + return true; } /** @@ -1530,7 +1532,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()) { @@ -1589,15 +1591,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)); } @@ -1605,17 +1607,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 { @@ -1623,7 +1625,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("! ")) @@ -1633,18 +1635,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 { @@ -1730,11 +1732,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(); } @@ -1806,7 +1808,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); @@ -1980,4 +1982,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 436c432f848..37932a1f590 100755 --- a/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenColonyHandler.java +++ b/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenColonyHandler.java @@ -9,14 +9,10 @@ import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Entity; -import net.minecraft.world.item.Item; -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. @@ -143,6 +139,7 @@ public void updateColonyClient() citizen.discard(); return; } + colony = IColonyManager.getInstance().getColonyView(colonyId, citizen.level.dimension()); if (citizen.getCivilianID() == 0) { @@ -196,7 +193,7 @@ public double getPerBuildingFoodCost() */ @Override @Nullable - public IColony getColony() + public IColony getColonyOrRegister() { if (colony == null && !citizen.level.isClientSide) { @@ -206,6 +203,12 @@ public IColony getColony() return colony; } + @Override + public @Nullable IColony getColony() + { + return colony; + } + /** * Getter for the colony id. * @@ -237,10 +240,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 8d5f9ec68c8..41668e3dd14 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 @@ -116,11 +116,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 @@ -130,8 +130,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(); } @@ -182,15 +182,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; } @@ -199,7 +199,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 53fe86aeba0..54913b566de 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 218747e1bb5..0e33726b673 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 @@ -240,10 +240,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)))) @@ -323,10 +323,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 66ee7d54c62..815ef5f3c85 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,12 +107,12 @@ 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) .count()); - AdvancementUtils.TriggerAdvancementPlayersForColony(citizen.getCitizenColonyHandler().getColony(), + AdvancementUtils.TriggerAdvancementPlayersForColony(citizen.getCitizenColonyHandler().getColonyOrRegister(), player -> AdvancementTriggers.ARMY_POPULATION.trigger(player, guards)); } diff --git a/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenSleepHandler.java b/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenSleepHandler.java index e10a5ae2003..0fe0fa4b38f 100755 --- a/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenSleepHandler.java +++ b/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenSleepHandler.java @@ -260,8 +260,8 @@ public boolean shouldGoSleep() final double timeNeeded = (Math.sqrt(xDiff * xDiff + zDiff * zDiff + yDiff * yDiff) + additionalDist) * TIME_PER_BLOCK; // Estimated arrival is 1hour past night - final double timeLeft = (citizen.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(WORK_LONGER) == 0 - ? NIGHT : NIGHT + citizen.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(WORK_LONGER) * 1000) - (citizen.level.getDayTime() % 24000); + final double timeLeft = (citizen.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(WORK_LONGER) == 0 + ? NIGHT : NIGHT + citizen.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(WORK_LONGER) * 1000) - (citizen.level.getDayTime() % 24000); if (timeLeft <= 0 || (timeLeft - timeNeeded <= 0)) { if (citizen.getCitizenData().getWorkBuilding() != null) 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 1b826568d9d..686e5a1cefe 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.minecraftforge.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. * @@ -338,7 +342,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)); @@ -565,9 +569,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 398ed008d54..e23dbdcd65f 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 46570112c42..eb59eca7778 100644 --- a/src/main/java/com/minecolonies/core/entity/visitor/VisitorCitizen.java +++ b/src/main/java/com/minecolonies/core/entity/visitor/VisitorCitizen.java @@ -43,7 +43,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; @@ -67,8 +66,7 @@ /** * Visitor citizen entity */ -public class -VisitorCitizen extends AbstractEntityCitizen +public class VisitorCitizen extends AbstractEntityCitizen { /** * The citizen experience handler @@ -183,7 +181,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()); @@ -196,7 +194,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 { @@ -629,7 +627,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()); @@ -691,4 +689,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 43ef544affb..b8812e661be 100755 --- a/src/main/java/com/minecolonies/core/event/EventHandler.java +++ b/src/main/java/com/minecolonies/core/event/EventHandler.java @@ -785,7 +785,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; - } -}