Skip to content

Commit

Permalink
Merge branch 'version/main' into aipathing
Browse files Browse the repository at this point in the history
  • Loading branch information
someaddons authored Dec 22, 2024
2 parents 33f3ac3 + 5f82e61 commit 0f7fa10
Show file tree
Hide file tree
Showing 63 changed files with 803 additions and 493 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ usesSonarQube=true

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

additionalModsInDataGen=structurize;domum_ornamentum
3 changes: 3 additions & 0 deletions src/main/java/com/minecolonies/api/IMinecoloniesAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.minecolonies.api.entity.citizen.happiness.HappinessRegistry;
import com.minecolonies.api.entity.pathfinding.registry.IPathNavigateRegistry;
import com.minecolonies.api.equipment.registry.EquipmentTypeEntry;
import com.minecolonies.api.eventbus.EventBus;
import com.minecolonies.api.quests.registries.QuestRegistries;
import com.minecolonies.api.research.IGlobalResearchTree;
import com.minecolonies.api.research.ModResearchCostTypes.ResearchCostType;
Expand Down Expand Up @@ -101,4 +102,6 @@ static IMinecoloniesAPI getInstance()
void onRegistryNewRegistry(NewRegistryEvent event);

IForgeRegistry<EquipmentTypeEntry> getEquipmentTypeRegistry();

EventBus getEventBus();
}
9 changes: 8 additions & 1 deletion src/main/java/com/minecolonies/api/MinecoloniesAPIProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.minecolonies.api.entity.citizen.happiness.HappinessRegistry;
import com.minecolonies.api.entity.pathfinding.registry.IPathNavigateRegistry;
import com.minecolonies.api.equipment.registry.EquipmentTypeEntry;
import com.minecolonies.api.eventbus.EventBus;
import com.minecolonies.api.quests.registries.QuestRegistries;
import com.minecolonies.api.research.IGlobalResearchTree;
import com.minecolonies.api.research.ModResearchCostTypes.ResearchCostType;
Expand All @@ -32,7 +33,7 @@

public final class MinecoloniesAPIProxy implements IMinecoloniesAPI
{
private static MinecoloniesAPIProxy ourInstance = new MinecoloniesAPIProxy();
private static final MinecoloniesAPIProxy ourInstance = new MinecoloniesAPIProxy();

private IMinecoloniesAPI apiInstance;

Expand Down Expand Up @@ -235,4 +236,10 @@ public IForgeRegistry<EquipmentTypeEntry> getEquipmentTypeRegistry()
{
return apiInstance.getEquipmentTypeRegistry();
}

@Override
public EventBus getEventBus()
{
return apiInstance.getEventBus();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ default ResourceLocation getTexture(@NotNull final AbstractEntityCitizen entityC
{
if (cachedHalloweenStyle == null)
{
if (MineColonies.getConfig().getServer().holidayFeatures.get() &&
if (MineColonies.getConfig().getClient().holidayFeatures.get() &&
((LocalDateTime.now().getDayOfMonth() >= 29 && LocalDateTime.now().getMonth() == Month.OCTOBER)
|| (LocalDateTime.now().getDayOfMonth() <= 2 && LocalDateTime.now().getMonth() == Month.NOVEMBER)))
{
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class ClientConfiguration extends AbstractConfiguration
public final ForgeConfigSpec.IntValue neighborbuildingrange;
public final ForgeConfigSpec.IntValue buildgogglerange;
public final ForgeConfigSpec.BooleanValue colonyteamborders;
public final ForgeConfigSpec.BooleanValue holidayFeatures;

/**
* Builds client configuration.
Expand All @@ -26,6 +27,7 @@ protected ClientConfiguration(final ForgeConfigSpec.Builder builder)
neighborbuildingrange = defineInteger(builder, "neighborbuildingrange", 4, -2, 16);
buildgogglerange = defineInteger(builder, "buildgogglerange", 50, 1, 250);
colonyteamborders = defineBoolean(builder, "colonyteamborders", true);
holidayFeatures = defineBoolean(builder, "holidayfeatures", true);

swapToCategory(builder, "pathfinding");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class ServerConfiguration extends AbstractConfiguration
public final ForgeConfigSpec.BooleanValue enableInDevelopmentFeatures;
public final ForgeConfigSpec.BooleanValue alwaysRenderNameTag;
public final ForgeConfigSpec.BooleanValue workersAlwaysWorkInRain;
public final ForgeConfigSpec.BooleanValue holidayFeatures;
public final ForgeConfigSpec.IntValue luckyBlockChance;
public final ForgeConfigSpec.IntValue minThLevelToTeleport;
public final ForgeConfigSpec.DoubleValue foodModifier;
Expand Down Expand Up @@ -132,7 +131,6 @@ protected ServerConfiguration(final ForgeConfigSpec.Builder builder)
enableInDevelopmentFeatures = defineBoolean(builder, "enableindevelopmentfeatures", false);
alwaysRenderNameTag = defineBoolean(builder, "alwaysrendernametag", true);
workersAlwaysWorkInRain = defineBoolean(builder, "workersalwaysworkinrain", false);
holidayFeatures = defineBoolean(builder, "holidayfeatures", true);
luckyBlockChance = defineInteger(builder, "luckyblockchance", 1, 0, 100);
minThLevelToTeleport = defineInteger(builder, "minthleveltoteleport", 3, 0, 5);
foodModifier = defineDouble(builder, "foodmodifier", 1.0, 0.1, 100);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.util.Tuple;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.*;
Expand Down Expand Up @@ -178,15 +177,12 @@ public AbstractAdvancedPathNavigate getNavigation()
this.navigation = newNavigator;
this.newNavigator.setCanFloat(true);
newNavigator.setSwimSpeedFactor(getSwimSpeedFactor());
this.newNavigator.getPathingOptions().setEnterDoors(true);
newNavigator.getPathingOptions().setEnterDoors(true);
newNavigator.getPathingOptions().setCanOpenDoors(true);
newNavigator.getPathingOptions().withDropCost(1D);
newNavigator.getPathingOptions().withJumpCost(1D);
newNavigator.getPathingOptions().setPassDanger(true);
PathingStuckHandler stuckHandler = PathingStuckHandler.createStuckHandler()
.withTakeDamageOnStuck(0.4f)
.withBuildLeafBridges()
.withChanceToByPassMovingAway(0.20)
.withPlaceLadders();
PathingStuckHandler stuckHandler = PathingStuckHandler.createStuckHandler();

if (MinecoloniesAPIProxy.getInstance().getConfig().getServer().raidersbreakblocks.get())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import com.minecolonies.api.enchants.ModEnchants;
import com.minecolonies.api.entity.CustomGoalSelector;
import com.minecolonies.api.entity.ai.combat.threat.IThreatTableEntity;
import com.minecolonies.api.entity.pathfinding.registry.IPathNavigateRegistry;
import com.minecolonies.api.items.IChiefSwordItem;
import com.minecolonies.api.util.ColonyUtils;
import com.minecolonies.api.util.DamageSourceKeys;
import com.minecolonies.core.entity.pathfinding.navigation.AbstractAdvancedPathNavigate;
import com.minecolonies.core.entity.pathfinding.navigation.PathingStuckHandler;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.DifficultyInstance;
Expand Down Expand Up @@ -171,6 +173,37 @@ public AbstractEntityMinecoloniesRaider(final EntityType<? extends AbstractEntit
RaiderMobUtils.setEquipment(this);
}

@NotNull
@Override
public AbstractAdvancedPathNavigate getNavigation()
{
if (this.newNavigator == null)
{
this.newNavigator = IPathNavigateRegistry.getInstance().getNavigateFor(this);
this.navigation = newNavigator;
this.newNavigator.setCanFloat(true);
newNavigator.setSwimSpeedFactor(getSwimSpeedFactor());
newNavigator.getPathingOptions().setEnterDoors(true);
newNavigator.getPathingOptions().withDropCost(1D);
newNavigator.getPathingOptions().withJumpCost(1D);
newNavigator.getPathingOptions().setPassDanger(true);
PathingStuckHandler stuckHandler = PathingStuckHandler.createStuckHandler()
.withTakeDamageOnStuck(0.4f)
.withBuildLeafBridges()
.withChanceToByPassMovingAway(0.20)
.withPlaceLadders();

if (MinecoloniesAPIProxy.getInstance().getConfig().getServer().raidersbreakblocks.get())
{
stuckHandler.withBlockBreaks();
stuckHandler.withCompleteStuckBlockBreak(6);
}

newNavigator.setStuckHandler(stuckHandler);
}
return newNavigator;
}

@Override
public boolean removeWhenFarAway(final double distanceToClosestPlayer)
{
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/com/minecolonies/api/eventbus/DefaultEventBus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.minecolonies.api.eventbus;

import com.minecolonies.api.util.Log;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Default implementation of the mod event bus.
*/
public class DefaultEventBus implements EventBus
{
/**
* The map of event handlers.
*/
private final Map<Class<? extends IModEvent>, List<EventHandler<? extends IModEvent>>> eventHandlersPerType = new HashMap<>();

@Override
public <T extends IModEvent> void subscribe(final @NotNull Class<T> eventType, final @NotNull EventHandler<T> handler)
{
Log.getLogger().debug("Registering event handler for id {}.", eventType.getSimpleName());

eventHandlersPerType.computeIfAbsent(eventType, (f) -> new ArrayList<>()).add(handler);
}

@Override
public void post(final @NotNull IModEvent event)
{
final List<EventHandler<? extends IModEvent>> eventHandlers = eventHandlersPerType.get(event.getClass());
if (eventHandlers == null)
{
return;
}

Log.getLogger().debug("Sending event '{}' for type '{}'. Sending to {} handlers.", event.getEventId(), event.getClass().getSimpleName(), eventHandlers.size());

for (final EventHandler<? extends IModEvent> handler : eventHandlers)
{
try
{
((EventHandler<IModEvent>) handler).apply(event);
}
catch (Exception ex)
{
Log.getLogger().warn("Sending event '{}' for type '{}'. Error occurred in handler:", event.getEventId(), event.getClass().getSimpleName(), ex);
}
}
}
}
36 changes: 36 additions & 0 deletions src/main/java/com/minecolonies/api/eventbus/EventBus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.minecolonies.api.eventbus;

import org.jetbrains.annotations.NotNull;

/**
* Interface for the mod event bus.
*/
public interface EventBus
{
/**
* Subscribe to the given event type, providing a handler function.
*
* @param eventType the event class type.
* @param handler the handler function handling the event logic.
* @param <T> the generic type of the event class.
*/
<T extends IModEvent> void subscribe(final @NotNull Class<T> eventType, final @NotNull EventHandler<T> handler);

/**
* Posts a new event on the event bus for the given type.
*
* @param event the event to send.
*/
void post(final @NotNull IModEvent event);

/**
* The event handler lambda definition.
*
* @param <T> the generic type of the event class.
*/
@FunctionalInterface
interface EventHandler<T extends IModEvent>
{
void apply(final @NotNull T event);
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/minecolonies/api/eventbus/IModEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.minecolonies.api.eventbus;

import java.util.UUID;

/**
* Default event interface.
*/
public interface IModEvent
{
/**
* The unique id for this event.
*
* @return the event id.
*/
UUID getEventId();
}
Loading

0 comments on commit 0f7fa10

Please sign in to comment.