Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent some crashes
Browse files Browse the repository at this point in the history
someaddons committed Aug 28, 2024
1 parent 4f972e8 commit ad47daf
Showing 3 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -84,8 +84,6 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static com.minecolonies.api.colony.requestsystem.requestable.deliveryman.AbstractDeliverymanRequestable.MAX_BUILDING_PRIORITY;
import static com.minecolonies.api.colony.requestsystem.requestable.deliveryman.AbstractDeliverymanRequestable.getPlayerActionPriority;
import static com.minecolonies.api.util.constant.BuildingConstants.CONST_DEFAULT_MAX_BUILDING_LEVEL;
import static com.minecolonies.api.util.constant.BuildingConstants.NO_WORK_ORDER;
import static com.minecolonies.api.util.constant.Constants.MOD_ID;
@@ -1897,10 +1895,21 @@ public final ImmutableCollection<IRequestResolver<?>> getResolvers()
final IStandardRequestManager requestManager = (IStandardRequestManager) colony.getRequestManager();
if (!requestManager.getProviderHandler().getRegisteredResolvers(this).isEmpty())
{
return ImmutableList.copyOf(requestManager.getProviderHandler().getRegisteredResolvers(this)
.stream()
.map(token -> requestManager.getResolverHandler().getResolver(token))
.collect(Collectors.toList()));
List<IRequestResolver<? extends IRequestable>> list = new ArrayList<>();
for (Iterator<IToken<?>> iterator = requestManager.getProviderHandler().getRegisteredResolvers(this).iterator(); iterator.hasNext(); )
{
final IToken<?> token = iterator.next();
try
{
IRequestResolver<? extends IRequestable> resolver = requestManager.getResolverHandler().getResolver(token);
list.add(resolver);
}
catch (Exception e)
{
iterator.remove();
}
}
return ImmutableList.copyOf(list);
}

return createResolvers();
6 changes: 3 additions & 3 deletions src/main/java/com/minecolonies/core/event/EventHandler.java
Original file line number Diff line number Diff line change
@@ -601,14 +601,14 @@ public static void onBlockBreak(@NotNull final BlockEvent.BreakEvent event)
if (event.getState().getBlock() instanceof SpawnerBlock)
{
final BlockEntity spawner = event.getLevel().getBlockEntity(event.getPos());
if (spawner instanceof SpawnerBlockEntity)
if (spawner instanceof SpawnerBlockEntity spawnerBE && spawnerBE.getSpawner().nextSpawnData != null)
{
final IColony colony = IColonyManager.getInstance()
.getColonyByDimension(((SpawnerBlockEntity) spawner).getSpawner().nextSpawnData.getEntityToSpawn().getInt(TAG_COLONY_ID),
.getColonyByDimension(spawnerBE.getSpawner().nextSpawnData.getEntityToSpawn().getInt(TAG_COLONY_ID),
world.dimension());
if (colony != null)
{
colony.getEventManager().onTileEntityBreak(((SpawnerBlockEntity) spawner).getSpawner().nextSpawnData.getEntityToSpawn().getInt(TAG_EVENT_ID), spawner);
colony.getEventManager().onTileEntityBreak(spawnerBE.getSpawner().nextSpawnData.getEntityToSpawn().getInt(TAG_EVENT_ID), spawner);
}
}
}
Original file line number Diff line number Diff line change
@@ -150,7 +150,7 @@ public PlaySoundForCitizenMessage(final int entityID, final SoundEvent event, fi
@Override
public void toBytes(final FriendlyByteBuf buf)
{
buf.writeResourceLocation(ForgeRegistries.SOUND_EVENTS.getKey(this.soundEvent));
buf.writeResourceLocation(this.soundEvent.getLocation());
buf.writeInt(soundSource.ordinal());
buf.writeBlockPos(pos);
buf.writeUtf(dimensionID.location().toString());

0 comments on commit ad47daf

Please sign in to comment.