Skip to content

Commit

Permalink
Merge branch 'version/main' into fix/build_pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
Thodor12 authored Aug 20, 2024
2 parents 532726d + e185b01 commit d8fd3f1
Show file tree
Hide file tree
Showing 23 changed files with 193 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,10 @@ default int getSuitabilityMetric(@NotNull final IRequestManager manager, @NotNul
* @return The priority of this resolver.
*/
int getPriority();

/**
* If this resolver has valid data in it.
* @return true if so.
*/
boolean isValid();
}
27 changes: 24 additions & 3 deletions src/main/java/com/minecolonies/core/colony/ColonyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,14 @@ public void onWorldLoad(@NotNull final Level world)
c.onWorldLoad(world);
}

MinecraftForge.EVENT_BUS.post(new ColonyManagerLoadedEvent(this));
try
{
MinecraftForge.EVENT_BUS.post(new ColonyManagerLoadedEvent(this));
}
catch (final Exception e)
{
Log.getLogger().error("Error during ColonyManagerLoadedEvent", e);
}
}
}

Expand All @@ -660,7 +667,14 @@ public void onWorldUnload(@NotNull final Level world)
BackUpHelper.backupColonyData();
}

MinecraftForge.EVENT_BUS.post(new ColonyManagerUnloadedEvent(this));
try
{
MinecraftForge.EVENT_BUS.post(new ColonyManagerUnloadedEvent(this));
}
catch (final Exception e)
{
Log.getLogger().error("Error during ColonyManagerUnloadedEvent", e);
}
}
}

Expand Down Expand Up @@ -689,7 +703,14 @@ public void handleColonyViewMessage(
}
view.handleColonyViewMessage(colonyData, world, isNewSubscription);

MinecraftForge.EVENT_BUS.post(new ColonyViewUpdatedEvent(view));
try
{
MinecraftForge.EVENT_BUS.post(new ColonyViewUpdatedEvent(view));
}
catch (final Exception e)
{
Log.getLogger().error("Error during ColonyViewUpdatedEvent", e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,13 @@ public void handleCustomRecipeManagerMessage(final FriendlyByteBuf buff)
lootTables.put(id, drops);
}

MinecraftForge.EVENT_BUS.post(new CustomRecipesReloadedEvent());
try
{
MinecraftForge.EVENT_BUS.post(new CustomRecipesReloadedEvent());
}
catch (final Exception e)
{
Log.getLogger().error("Error during CustomRecipesReloadedEvent", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.minecolonies.api.colony.interactionhandling.IInteractionResponseHandler;
import com.minecolonies.api.colony.interactionhandling.ModInteractionResponseHandlers;
import com.minecolonies.api.util.InventoryUtils;
import com.minecolonies.api.util.Log;
import com.minecolonies.api.util.MessageUtils;
import com.minecolonies.api.util.Tuple;
import com.minecolonies.api.util.constant.Constants;
Expand Down Expand Up @@ -189,7 +190,14 @@ public void onServerResponseTriggered(final int responseId, final Player player,
MessageUtils.format(MESSAGE_RECRUITMENT_SUCCESS, data.getName()).sendTo(colony).forAllPlayers();
}

MinecraftForge.EVENT_BUS.post(new CitizenAddedEvent(newCitizen, CitizenAddedEvent.Source.HIRED));
try
{
MinecraftForge.EVENT_BUS.post(new CitizenAddedEvent(newCitizen, CitizenAddedEvent.Source.HIRED));
}
catch (final Exception e)
{
Log.getLogger().error("Error during CitizenAddedEvent", e);
}
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,14 @@ public ICitizenData resurrectCivilianData(@NotNull final CompoundTag compoundNBT
citizens.put(citizenData.getId(), citizenData);
spawnOrCreateCitizen(citizenData, world, spawnPos);

MinecraftForge.EVENT_BUS.post(new CitizenAddedEvent(citizenData, CitizenAddedEvent.Source.RESURRECTED));

try
{
MinecraftForge.EVENT_BUS.post(new CitizenAddedEvent(citizenData, CitizenAddedEvent.Source.RESURRECTED));
}
catch (final Exception e)
{
Log.getLogger().error("Error during CitizenAddedEvent", e);
}
return citizenData;
}

Expand Down Expand Up @@ -618,8 +624,14 @@ else if (femaleCount < (getCitizens().size() - 1) / 2.0)

spawnOrCreateCivilian(newCitizen, colony.getWorld(), null, true);

MinecraftForge.EVENT_BUS.post(new CitizenAddedEvent(newCitizen, CitizenAddedEvent.Source.INITIAL));

try
{
MinecraftForge.EVENT_BUS.post(new CitizenAddedEvent(newCitizen, CitizenAddedEvent.Source.INITIAL));
}
catch (final Exception e)
{
Log.getLogger().error("Error during CitizenAddedEvent", e);
}
colony.getEventDescriptionManager().addEventDescription(new CitizenSpawnedEvent(colony.getBuildingManager().getTownHall().getPosition(),
newCitizen.getName()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.util.Tuple;

import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

import static com.minecolonies.api.util.constant.NbtTagConstants.*;

Expand Down Expand Up @@ -118,15 +116,18 @@ public StandardRequestResolversIdentitiesDataStore deserialize(@NotNull final IF
{
final IToken<?> token = controller.deserialize(nbt.getCompound(TAG_TOKEN));
final ListTag list = nbt.getList(TAG_LIST, Tag.TAG_COMPOUND);
final BiMap<IToken<?>, IRequestResolver<?>> biMap = HashBiMap.create();

final Map<IToken<?>, IRequestResolver<?>> map = NBTUtils.streamCompound(list).map(CompoundTag -> {
final IToken<?> id = controller.deserialize(CompoundTag.getCompound(TAG_TOKEN));
final IRequestResolver<?> resolver = controller.deserialize(CompoundTag.getCompound(TAG_RESOLVER));

return new Tuple<IToken<?>, IRequestResolver<?>>(id, resolver);
}).collect(Collectors.toMap((Tuple<IToken<?>, IRequestResolver<?>> t) -> t.getA(), (Tuple<IToken<?>, IRequestResolver<?>> t) -> t.getB()));

final BiMap<IToken<?>, IRequestResolver<?>> biMap = HashBiMap.create(map);
for (int i = 0; i < list.size(); i++)
{
final CompoundTag mapCompound = list.getCompound(i);
final IToken<?> id = controller.deserialize(mapCompound.getCompound(TAG_TOKEN));
final IRequestResolver<?> resolver = controller.deserialize(mapCompound.getCompound(TAG_RESOLVER));
if (resolver.isValid())
{
biMap.put(id, resolver);
}
}

return new StandardRequestResolversIdentitiesDataStore(token, biMap);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,11 @@ public MutableComponent getRequesterDisplayName(
{
return Component.translatable(TranslationConstants.COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN);
}

@Override
public boolean isValid()
{
// Always valid
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,11 @@ public void setAllAssignedRequests(final Set<IToken<?>> assignedRequests)
this.assignedRequests.clear();
this.assignedRequests.addAll(assignedRequests);
}

@Override
public boolean isValid()
{
// Always valid
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,11 @@ public void onColonyUpdate(@NotNull final IRequestManager manager, @NotNull fina
}
});
}

@Override
public boolean isValid()
{
// Always valid
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,11 @@ protected boolean internalCanResolve(final List<TileEntityWareHouse> wareHouses,
}
return false;
}

@Override
public boolean isValid()
{
// Always valid
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,11 @@ public void resolveRequest(@NotNull final IRequestManager manager, @NotNull fina
}

public abstract void resolveForBuilding(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends R> request, @NotNull final AbstractBuilding building);

@Override
public boolean isValid()
{
// Always valid.
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,10 @@ public void resolveForBuilding(@NotNull final IRequestManager manager, @NotNull

manager.updateRequestState(request.getId(), RequestState.RESOLVED);
}

@Override
public boolean isValid()
{
return jobEntry != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -369,4 +369,10 @@ public void resolveForBuilding(@NotNull final IRequestManager manager, @NotNull
{
manager.updateRequestState(request.getId(), RequestState.RESOLVED);
}

@Override
public boolean isValid()
{
return jobEntry != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,11 @@ public int getPriority()
{
return CONST_WAREHOUSE_RESOLVER_PRIORITY;
}

@Override
public boolean isValid()
{
// Always valid
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.minecolonies.api.colony.IColony;
import com.minecolonies.api.colony.IColonyManager;
import com.minecolonies.api.colony.citizens.event.CitizenAddedEvent;
import com.minecolonies.api.util.Log;
import com.minecolonies.core.commands.commandTypes.IMCCommand;
import com.minecolonies.core.commands.commandTypes.IMCOPCommand;
import com.mojang.brigadier.arguments.IntegerArgumentType;
Expand Down Expand Up @@ -42,8 +43,14 @@ public int onExecute(final CommandContext<CommandSourceStack> context)
final ICitizenData newCitizen = colony.getCitizenManager().spawnOrCreateCivilian(null, colony.getWorld(), null, true);
context.getSource().sendSuccess(() -> Component.translatable(COMMAND_CITIZEN_SPAWN_SUCCESS, newCitizen.getName()), true);

MinecraftForge.EVENT_BUS.post(new CitizenAddedEvent(newCitizen, CitizenAddedEvent.Source.COMMANDS));

try
{
MinecraftForge.EVENT_BUS.post(new CitizenAddedEvent(newCitizen, CitizenAddedEvent.Source.COMMANDS));
}
catch (final Exception e)
{
Log.getLogger().error("Error during CitizenAddedEvent", e);
}
return 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,14 @@ public void executeSpecificCompleteActions()
if (wo instanceof WorkOrderBuilding)
{
final IBuilding building = colony.getBuildingManager().getBuilding(wo.getLocation());
MinecraftForge.EVENT_BUS.post(new BuildingConstructionEvent(building, BuildingConstructionEvent.EventType.fromWorkOrderType(wo.getWorkOrderType())));
try
{
MinecraftForge.EVENT_BUS.post(new BuildingConstructionEvent(building, BuildingConstructionEvent.EventType.fromWorkOrderType(wo.getWorkOrderType())));
}
catch (final Exception e)
{
Log.getLogger().error("Error during BuildingConstructionEvent", e);
}
switch (wo.getWorkOrderType())
{
case BUILD:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,14 @@ public void die(@NotNull final DamageSource damageSource)
Component.literal(damageSource.getLocalizedDeathMessage(this).getString()).getString().replaceFirst(this.getDisplayName().getString(), "Citizen");
citizenColonyHandler.getColony().getEventDescriptionManager().addEventDescription(new CitizenDiedEvent(blockPosition(), citizenData.getName(), deathCause));

MinecraftForge.EVENT_BUS.post(new CitizenRemovedEvent(citizenData, damageSource));
try
{
MinecraftForge.EVENT_BUS.post(new CitizenRemovedEvent(citizenData, damageSource));
}
catch (final Exception e)
{
Log.getLogger().error("Error during CitizenRemovedEvent", e);
}
}
super.die(damageSource);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.minecolonies.api.colony.buildings.IBuilding;
import com.minecolonies.api.colony.event.ColonyCreatedEvent;
import com.minecolonies.api.network.IMessage;
import com.minecolonies.api.util.Log;
import com.minecolonies.core.Network;
import com.minecolonies.core.network.messages.client.colony.OpenBuildingUIMessage;
import com.minecolonies.core.tileentities.TileEntityColonyBuilding;
Expand Down Expand Up @@ -189,10 +190,14 @@ else if (spawnDistance > MineColonies.getConfig().getServer().maxDistanceFromWor

Network.getNetwork().sendToPlayer(new OpenBuildingUIMessage(building), sender);

if (isLogicalServer)
try
{
MinecraftForge.EVENT_BUS.post(new ColonyCreatedEvent(createdColony));
}
catch (final Exception e)
{
Log.getLogger().error("Error during ColonyCreatedEvent", e);
}
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.minecolonies.api.colony.IColonyManager;
import com.minecolonies.api.colony.event.ColonyDeletedEvent;
import com.minecolonies.api.network.IMessage;
import com.minecolonies.api.util.Log;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.common.MinecraftForge;
import net.minecraft.network.FriendlyByteBuf;
Expand Down Expand Up @@ -55,7 +56,14 @@ public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalS

if (isLogicalServer)
{
MinecraftForge.EVENT_BUS.post(new ColonyDeletedEvent(colony));
try
{
MinecraftForge.EVENT_BUS.post(new ColonyDeletedEvent(colony));
}
catch (final Exception e)
{
Log.getLogger().error("Error during ColonyDeletedEvent", e);
}
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.minecolonies.api.colony.IColony;
import com.minecolonies.api.colony.event.ColonyInformationChangedEvent;
import com.minecolonies.api.util.Log;
import com.minecolonies.api.util.constant.Constants;
import com.minecolonies.core.network.messages.server.AbstractColonyServerMessage;
import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -39,11 +40,14 @@ public ColonyFlagChangeMessage (IColony colony, ListTag patternList)
protected void onExecute(NetworkEvent.Context ctxIn, boolean isLogicalServer, IColony colony)
{
colony.setColonyFlag(patterns);

if (isLogicalServer)
try
{
MinecraftForge.EVENT_BUS.post(new ColonyInformationChangedEvent(colony, ColonyInformationChangedEvent.Type.FLAG));
}
catch (final Exception e)
{
Log.getLogger().error("Error during ColonyInformationChangedEvent", e);
}
}

@Override
Expand Down
Loading

0 comments on commit d8fd3f1

Please sign in to comment.