Skip to content

Commit

Permalink
Merge branch 'HexatomicRing-Navigation-Fix' of https://github.com/Hex…
Browse files Browse the repository at this point in the history
…atomicRing/minecolonies into HexatomicRing-Navigation-Fix
  • Loading branch information
HexatomicRing committed Nov 5, 2024
2 parents acb9857 + f738cb2 commit ab82b60
Show file tree
Hide file tree
Showing 82 changed files with 1,057 additions and 712 deletions.
6 changes: 4 additions & 2 deletions documentation/formatter/intellij/Minecolonies.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<option name="WRAP_COMMENTS" value="true" />
<JavaCodeStyleSettings>
<option name="BLANK_LINES_AROUND_INITIALIZER" value="0" />
<option name="RECORD_COMPONENTS_WRAP" value="2"/>
<option name="NEW_LINE_AFTER_LPAREN_IN_RECORD_HEADER" value="true"/>
</JavaCodeStyleSettings>
<MarkdownNavigatorCodeStyleSettings>
<option name="RIGHT_MARGIN" value="72" />
Expand Down Expand Up @@ -66,8 +68,8 @@
<option name="FOR_BRACE_FORCE" value="3" />
<option name="ENUM_CONSTANTS_WRAP" value="2" />
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="2" />
<option name="USE_RELATIVE_INDENTS" value="true" />
<option name="CONTINUATION_INDENT_SIZE" value="4"/>
<option name="USE_RELATIVE_INDENTS" value="false"/>
</indentOptions>
<arrangement>
<groups>
Expand Down
3 changes: 1 addition & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ usesSonarQube=true

usesCrowdInTranslationManagement=true
crowdInDownloadDirectory=src/main/resources/assets/minecolonies/lang
usesCrowdInBuildingWithFilteredBranches=true
usesCrowdInUploadWithFilteredBranches=true
usesCrowdInUploadWithFilteredBranchesSpec=(version|release)\/.+

additionalModsInDataGen=structurize;domum_ornamentum
7 changes: 7 additions & 0 deletions src/main/java/com/minecolonies/api/colony/ICitizenData.java
Original file line number Diff line number Diff line change
Expand Up @@ -432,4 +432,11 @@ default boolean hasCustomTexture()
* @return true if so.
*/
boolean hasQuestAssignment();

/**
* Get the home position of the citizen.
* @return the pos to go home to.
*/
@Nullable
BlockPos getHomePosition();
}
6 changes: 3 additions & 3 deletions src/main/java/com/minecolonies/api/colony/IColony.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ public interface IColony
*
* @return The team name
*/
default String getTeamName()
static String getTeamName(final Level level, final int id)
{
final String dim = getDimension().location().getPath();
return TEAM_COLONY_NAME + "_" + (dim.length() > 10 ? dim.hashCode() : dim) + "_" + getID();
final String dim = level.dimension().location().getPath();
return TEAM_COLONY_NAME + "_" + (dim.length() > 10 ? dim.hashCode() : dim) + "_" + id;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,4 +513,10 @@ default void writeToItemStack(final ItemStack stack)
getColony().writeToItemStack(stack);
new BuildingId(getID()).writeToItemStack(stack);
}

/**
* Get the standing position for a building.
* @return the standing pos.
*/
BlockPos getStandingPosition();
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ public interface IRegisteredStructureManager
* Get the first building matching the conditions.
*
* @param predicate the predicate matching the building.
* @return the position or null.
* @return the building or null.
*/
@Nullable
BlockPos getFirstBuildingMatching(final Predicate<IBuilding> predicate);
IBuilding getFirstBuildingMatching(final Predicate<IBuilding> predicate);

/**
* Register a new leisure site.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.minecolonies.api.util.constant.NbtTagConstants;
import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
Expand All @@ -37,7 +36,6 @@
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.crafting.RecipeManager;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.AirBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.FurnaceBlockEntity;
Expand Down Expand Up @@ -148,16 +146,6 @@ public class CompatibilityManager implements ICompatibilityManager
*/
private static ImmutableList<ItemStack> allItems = ImmutableList.of();

/**
* Free block positions everyone can interact with.
*/
private final Set<Block> freeBlocks = new HashSet<>();

/**
* Free positions everyone can interact with.
*/
private final Set<BlockPos> freePositions = new HashSet<>();

/**
* Hashmap of mobs we may or may not attack.
*/
Expand Down Expand Up @@ -195,8 +183,6 @@ private void clear()
recruitmentCostsWeights.clear();
diseases.clear();
diseaseList.clear();
freeBlocks.clear();
freePositions.clear();
monsters = ImmutableSet.of();
creativeModeTabMap.clear();
}
Expand All @@ -215,7 +201,6 @@ public void discover(@NotNull final RecipeManager recipeManager, final Level lev
discoverLuckyOres();
discoverRecruitCosts();
discoverDiseases();
discoverFreeBlocksAndPos();
discoverModCompat();

discoverCompostRecipes(recipeManager);
Expand Down Expand Up @@ -272,7 +257,6 @@ public void deserialize(@NotNull final RegistryFriendlyByteBuf buf, final Client
discoverLuckyOres();
discoverRecruitCosts();
discoverDiseases();
discoverFreeBlocksAndPos();
discoverModCompat();
}

Expand Down Expand Up @@ -591,18 +575,6 @@ public ItemStack getRandomLuckyOre(final double chanceBonus, final int buildingL
return ItemStack.EMPTY;
}

@Override
public boolean isFreeBlock(final Block block)
{
return freeBlocks.contains(block);
}

@Override
public boolean isFreePos(final BlockPos block)
{
return freePositions.contains(block);
}

@Override
public CreativeModeTab getCreativeTab(final ItemStorage checkItem)
{
Expand Down Expand Up @@ -992,32 +964,6 @@ private static Tuple<BlockState, ItemStorage> readLeafSaplingEntryFromNBT(@NotNu
return new Tuple<>(NbtUtils.readBlockState(BuiltInRegistries.BLOCK.asLookup(), compound), new ItemStorage(ItemStack.parseOptional(provider, compound.getCompound(NbtTagConstants.STACK)), false, true));
}

/**
* Load free blocks and pos from the config and add to colony.
*/
private void discoverFreeBlocksAndPos()
{
for (final String s : MinecoloniesAPIProxy.getInstance().getConfig().getServer().freeToInteractBlocks.get())
{
try
{
final Block block = BuiltInRegistries.BLOCK.get(ResourceLocation.parse(s));
if (block != null && !(block instanceof AirBlock))
{
freeBlocks.add(block);
}
}
catch (final Exception ex)
{
final BlockPos pos = BlockPosUtil.getBlockPosOfString(s);
if (pos != null)
{
freePositions.add(pos);
}
}
}
}

/**
* Inits compats
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.minecolonies.api.util.Disease;
import com.minecolonies.api.util.Tuple;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.RegistryFriendlyByteBuf;
Expand Down Expand Up @@ -249,20 +248,6 @@ public interface ICompatibilityManager
*/
ItemStack getRandomLuckyOre(final double chanceBonus, final int buildingLevel);

/**
* Check if the block is configured to bypass the colony restrictions.
* @param block the block to check.
* @return true if so.
*/
boolean isFreeBlock(Block block);

/**
* Check if the position is configured to bypass the colony restrictions.
* @param block the position to check.
* @return true if so.
*/
boolean isFreePos(BlockPos block);

/**
* Get the creative tab for a stack.
* @param checkItem the storage wrapper.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public class ServerConfiguration extends AbstractConfiguration

public final BooleanValue enableColonyProtection;
public final EnumValue<Explosions> turnOffExplosionsInColonies;
public final ConfigValue<List<? extends String>> freeToInteractBlocks;

/* -------------------------------------------------------------------------------- *
* ------------------- ######## Compatibility Settings ######## ------------------- *
Expand Down Expand Up @@ -201,7 +200,6 @@ public ServerConfiguration(final Builder builder)

enableColonyProtection = defineBoolean("enablecolonyprotection", true);
turnOffExplosionsInColonies = defineEnum("turnoffexplosionsincolonies", Explosions.DAMAGE_ENTITIES);
freeToInteractBlocks = defineList("freetointeractblocks", () -> "block ID or position (x y z)", stringValidator, "dirt", "0 0 0");

swapToCategory("compatibility");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.items.IItemHandler;
import net.minecraft.world.scores.PlayerTeam;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -239,6 +240,18 @@ public boolean isNoAi()
return false;
}

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

/**
* Sets the textures of all citizens and distinguishes between male and female.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.minecolonies.api.colony.IColony;
import com.minecolonies.api.colony.buildings.IBuilding;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.world.level.Level;
import net.minecraft.world.scores.PlayerTeam;
import org.jetbrains.annotations.Nullable;

public interface ICitizenColonyHandler
Expand Down Expand Up @@ -73,4 +75,10 @@ public interface ICitizenColonyHandler
void onSyncDataUpdate(EntityDataAccessor<?> dataAccessor);

boolean registered();

/**
* Get the citizen team.
* @return the team.
*/
PlayerTeam getTeam(final Level level);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ public interface ICitizenSleepHandler
*/
void onWakeUp();

/**
* Determines the home position
*
* @return home pos or null
*/
BlockPos findHomePos();

/**
* Get the bed location of the citizen.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,13 @@
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.
*/
public abstract class AbstractEntityRaiderMob extends AbstractFastMinecoloniesEntity implements IThreatTableEntity, Enemy
{
/**
* Difficulty at which raiders team up
*/
private static final double TEAM_DIFFICULTY = 2.0d;

/**
* The percent of life taken per damage modifier
*/
Expand Down Expand Up @@ -523,14 +519,14 @@ public SpawnGroupData finalizeSpawn(
final ServerLevelAccessor worldIn,
final DifficultyInstance difficultyIn,
final MobSpawnType reason,
@Nullable final SpawnGroupData p_21437_)
@Nullable final SpawnGroupData spawnDataIn)
{
RaiderMobUtils.setEquipment(this);
return super.finalizeSpawn(worldIn, difficultyIn, reason, p_21437_);
return super.finalizeSpawn(worldIn, difficultyIn, reason, spawnDataIn);
}

@Override
public void remove(RemovalReason reason)
public void remove(@NotNull final RemovalReason reason)
{
if (!level().isClientSide && colony != null && eventID > 0)
{
Expand Down Expand Up @@ -725,38 +721,15 @@ public void initStatsFor(final double baseHealth, final double difficulty, final
this.setEnvDamageImmunity(true);
}

if (difficulty >= TEAM_DIFFICULTY)
{
level().getScoreboard().addPlayerToTeam(getScoreboardName(), checkOrCreateTeam());
}

this.getAttribute(Attributes.MAX_HEALTH).setBaseValue(baseHealth);
this.setHealth(this.getMaxHealth());
}

/**
* Creates or gets the scoreboard team
*
* @return Scoreboard team
*/
private PlayerTeam checkOrCreateTeam()
{
if (this.level().getScoreboard().getPlayerTeam(getTeamName()) == null)
{
this.level().getScoreboard().addPlayerTeam(getTeamName());
this.level().getScoreboard().getPlayerTeam(getTeamName()).setAllowFriendlyFire(false);
}
return this.level().getScoreboard().getPlayerTeam(getTeamName());
}

/**
* Gets the scoreboard team name
*
* @return
*/
protected String getTeamName()
@Override
@Nullable
protected PlayerTeam getAssignedTeam()
{
return RAID_TEAM;
return checkOrCreateTeam(level(), RAID_TEAM);
}

/**
Expand Down
Loading

0 comments on commit ab82b60

Please sign in to comment.