Skip to content

Commit

Permalink
Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Thodor12 committed Nov 17, 2024
1 parent db074ea commit 372f8ee
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -41,11 +41,6 @@ public class BuildingLibrary extends AbstractBuilding
*/
private final List<BlockPos> bookCases = new ArrayList<>();

/**
* Random obj for random calc.
*/
private final Random random = new Random();

/**
* Instantiates the building.
*
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,11 +51,6 @@ public class BuildingUniversity extends AbstractBuilding
*/
private final List<BlockPos> bookCases = new ArrayList<>();

/**
* Random obj for random calc.
*/
private final Random random = new Random();

/**
* Instantiates the building.
*
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -117,12 +113,12 @@ private IAIState study()
return getState();
}

final Map<ResourceLocation, StudyItem> studyItems = StudyItemListener.getAllStudyItems();
final Collection<StudyItem> studyItems = StudyItemListener.getAllStudyItems().values();

// Search for Items to use to study
final List<StudyItem> availableItemKeys = new ArrayList<>();
final Map<StudyItem, Integer> 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)
Expand All @@ -136,7 +132,7 @@ private IAIState study()
if (availableItems.isEmpty())
{
final List<ItemStack> 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)
Expand Down

0 comments on commit 372f8ee

Please sign in to comment.