From 372f8eeca6e6b7aa87b60a819d9b5e3fbfc54d90 Mon Sep 17 00:00:00 2001 From: Thom van den Akker Date: Sun, 17 Nov 2024 16:10:32 +0100 Subject: [PATCH] Changes --- .../buildings/workerbuildings/BuildingLibrary.java | 9 ++------- .../workerbuildings/BuildingUniversity.java | 8 ++------ .../entity/ai/workers/education/EntityAIStudy.java | 12 ++++-------- 3 files changed, 8 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/minecolonies/core/colony/buildings/workerbuildings/BuildingLibrary.java b/src/main/java/com/minecolonies/core/colony/buildings/workerbuildings/BuildingLibrary.java index 4b41e8bdbc5..a1d608d3cdb 100755 --- a/src/main/java/com/minecolonies/core/colony/buildings/workerbuildings/BuildingLibrary.java +++ b/src/main/java/com/minecolonies/core/colony/buildings/workerbuildings/BuildingLibrary.java @@ -1,6 +1,7 @@ package com.minecolonies.core.colony.buildings.workerbuildings; import com.minecolonies.api.colony.IColony; +import com.minecolonies.api.util.MathUtils; import com.minecolonies.core.colony.buildings.AbstractBuilding; import com.minecolonies.core.datalistener.StudyItemListener; import net.minecraft.core.BlockPos; @@ -16,7 +17,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.Random; import static com.minecolonies.api.util.constant.NbtTagConstants.TAG_BOOKCASES; import static com.minecolonies.api.util.constant.NbtTagConstants.TAG_POS; @@ -41,11 +41,6 @@ public class BuildingLibrary extends AbstractBuilding */ private final List bookCases = new ArrayList<>(); - /** - * Random obj for random calc. - */ - private final Random random = new Random(); - /** * Instantiates the building. * @@ -119,7 +114,7 @@ public BlockPos getRandomBookShelf() { return getPosition(); } - final BlockPos returnPos = bookCases.get(random.nextInt(bookCases.size())); + final BlockPos returnPos = bookCases.get(MathUtils.RANDOM.nextInt(bookCases.size())); if (colony.getWorld().getBlockState(returnPos).is(Tags.Blocks.BOOKSHELVES)) { return returnPos; diff --git a/src/main/java/com/minecolonies/core/colony/buildings/workerbuildings/BuildingUniversity.java b/src/main/java/com/minecolonies/core/colony/buildings/workerbuildings/BuildingUniversity.java index 65f45c250e3..50ce10cbcf0 100755 --- a/src/main/java/com/minecolonies/core/colony/buildings/workerbuildings/BuildingUniversity.java +++ b/src/main/java/com/minecolonies/core/colony/buildings/workerbuildings/BuildingUniversity.java @@ -5,6 +5,7 @@ import com.minecolonies.api.colony.jobs.ModJobs; import com.minecolonies.api.research.IGlobalResearchTree; import com.minecolonies.api.research.ILocalResearch; +import com.minecolonies.api.util.MathUtils; import com.minecolonies.api.util.MessageUtils; import com.minecolonies.core.colony.buildings.AbstractBuilding; import com.minecolonies.core.colony.buildings.modules.WorkerBuildingModule; @@ -50,11 +51,6 @@ public class BuildingUniversity extends AbstractBuilding */ private final List bookCases = new ArrayList<>(); - /** - * Random obj for random calc. - */ - private final Random random = new Random(); - /** * Instantiates the building. * @@ -121,7 +117,7 @@ public BlockPos getRandomBookShelf() { return getPosition(); } - final BlockPos returnPos = bookCases.get(random.nextInt(bookCases.size())); + final BlockPos returnPos = bookCases.get(MathUtils.RANDOM.nextInt(bookCases.size())); if (colony.getWorld().getBlockState(returnPos).is(Tags.Blocks.BOOKSHELVES)) { return returnPos; diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIStudy.java b/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIStudy.java index 439998d5068..dee2f982caa 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIStudy.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIStudy.java @@ -14,17 +14,13 @@ import com.minecolonies.core.entity.ai.workers.AbstractEntityAISkill; import com.minecolonies.core.entity.pathfinding.navigation.PathfindingAIHelper; import net.minecraft.core.BlockPos; -import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvents; import net.minecraft.world.InteractionHand; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import static com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState.*; import static com.minecolonies.api.util.constant.Constants.TICKS_SECOND; @@ -117,12 +113,12 @@ private IAIState study() return getState(); } - final Map studyItems = StudyItemListener.getAllStudyItems(); + final Collection studyItems = StudyItemListener.getAllStudyItems().values(); // Search for Items to use to study final List availableItemKeys = new ArrayList<>(); final Map availableItems = new HashMap<>(); - for (final StudyItem curItem : studyItems.values()) + for (final StudyItem curItem : studyItems) { final int slot = InventoryUtils.findFirstSlotInProviderNotEmptyWith(worker, (item) -> item.is(curItem.item())); if (slot != -1) @@ -136,7 +132,7 @@ private IAIState study() if (availableItems.isEmpty()) { final List itemsToRequest = new ArrayList<>(); - for (final StudyItem studyItem : studyItems.values()) + for (final StudyItem studyItem : studyItems) { final int bSlot = InventoryUtils.findFirstSlotInProviderWith(building, studyItem.item()); if (bSlot > -1)