Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul study items #10338

Merged
merged 3 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ public class ServerConfiguration extends AbstractConfiguration
* ------------------- ######## Claim settings ######## ------------------- *
* --------------------------------------------------------------------------- */

public final ForgeConfigSpec.IntValue maxColonySize;
public final ForgeConfigSpec.IntValue minColonyDistance;
public final ForgeConfigSpec.IntValue initialColonySize;
public final ForgeConfigSpec.IntValue maxDistanceFromWorldSpawn;
public final ForgeConfigSpec.IntValue minDistanceFromWorldSpawn;
public final ForgeConfigSpec.IntValue maxColonySize;
public final ForgeConfigSpec.IntValue minColonyDistance;
public final ForgeConfigSpec.IntValue initialColonySize;
public final ForgeConfigSpec.IntValue maxDistanceFromWorldSpawn;
public final ForgeConfigSpec.IntValue minDistanceFromWorldSpawn;

/* ------------------------------------------------------------------------- *
* ------------------- ######## Combat Settings ######## ------------------- *
Expand Down Expand Up @@ -96,7 +96,6 @@ public class ServerConfiguration extends AbstractConfiguration
* ------------------- ######## Compatibility Settings ######## ------------------- *
* -------------------------------------------------------------------------------- */

public final ForgeConfigSpec.ConfigValue<List<? extends String>> configListStudyItems;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> configListRecruitmentItems;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> luckyOres;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> diseases;
Expand All @@ -118,7 +117,6 @@ public class ServerConfiguration extends AbstractConfiguration

public final ForgeConfigSpec.BooleanValue creativeResolve;


/**
* Builds server configuration.
*
Expand Down Expand Up @@ -194,11 +192,6 @@ protected ServerConfiguration(final ForgeConfigSpec.Builder builder)

swapToCategory(builder, "compatibility");

configListStudyItems = defineList(builder, "configliststudyitems",
Arrays.asList
("minecraft:paper;400;100", "minecraft:book;600;10"),
s -> s instanceof String);

configListRecruitmentItems = defineList(builder, "configlistrecruitmentitems",
Arrays.asList
("minecraft:hay_block;3",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
package com.minecolonies.core.colony.buildings.workerbuildings;

import com.minecolonies.api.colony.IColony;
import com.minecolonies.api.entity.ai.workers.util.StudyItem;
import com.minecolonies.api.util.Log;
import com.minecolonies.core.MineColonies;
import com.minecolonies.api.util.MathUtils;
import com.minecolonies.core.colony.buildings.AbstractBuilding;
import com.minecolonies.core.datalistener.StudyItemListener;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.nbt.Tag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Tuple;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.common.Tags;
import net.minecraftforge.registries.ForgeRegistries;
import org.jetbrains.annotations.NotNull;

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 @@ -36,25 +31,15 @@ public class BuildingLibrary extends AbstractBuilding
*/
private static final String LIBRARY_HUT_NAME = "library";

/**
* List of registered barrels.
*/
private final List<BlockPos> bookCases = new ArrayList<>();

/**
* Max building level of the hut.
*/
private static final int MAX_BUILDING_LEVEL = 5;

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

/**
* Study Item list, loaded from config, Typle<int,int> First is the study chance increase,second is the breakchance
* List of registered barrels.
*/
private final List<StudyItem> studyItems;
private final List<BlockPos> bookCases = new ArrayList<>();

/**
* Instantiates the building.
Expand All @@ -65,50 +50,7 @@ public class BuildingLibrary extends AbstractBuilding
public BuildingLibrary(final IColony c, final BlockPos l)
{
super(c, l);

studyItems = parseFromConfig();
}

/**
* Parses Study Items from the Config and adds them on the keepX list
*
* @return the list of study items
*/
private List<StudyItem> parseFromConfig()
{
final List<StudyItem> studyItemList = new ArrayList<>();

for (final String entry : MineColonies.getConfig().getServer().configListStudyItems.get())
{

try
{
final String[] entries = entry.split(";");
if (entries.length < 3)
{
Log.getLogger().info("Minecolonies: Parsing config for study items for Library failed for entry:" + entry);
continue;
}
final Item item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(entries[0]));
final int skillChance = Integer.parseInt(entries[1]);
final int breakChance = Integer.parseInt(entries[2]);

if (item == null || skillChance < 100 || skillChance > 1000 || breakChance > 100 || breakChance < 0)
{
Log.getLogger().info("Minecolonies: Parsing config for study items for Library failed for entry:" + entry);
continue;
}

studyItemList.add(new StudyItem(item, skillChance, breakChance));
// Keep a certain part of the items in the Chest
keepX.put(itemStack -> itemStack.getItem() == item, new Tuple<>(breakChance < 5 ? 5 : breakChance, true));
}
catch (NumberFormatException | ClassCastException e)
{
Log.getLogger().info("Minecolonies: Parsing config for study items for Library failed for entry:" + entry + " Exception:" + e.getMessage());
}
}
return studyItemList;
keepX.put(StudyItemListener::isStudyItem, new Tuple<>(64, true));
}

@NotNull
Expand All @@ -118,12 +60,6 @@ public String getSchematicName()
return LIBRARY_HUT_NAME;
}

@Override
public int getMaxBuildingLevel()
{
return MAX_BUILDING_LEVEL;
}

@Override
public void deserializeNBT(final CompoundTag compound)
{
Expand Down Expand Up @@ -151,6 +87,12 @@ public CompoundTag serializeNBT()
return compound;
}

@Override
public int getMaxBuildingLevel()
{
return MAX_BUILDING_LEVEL;
}

@Override
public void registerBlockPosition(@NotNull final Block block, @NotNull final BlockPos pos, @NotNull final Level world)
{
Expand All @@ -172,17 +114,12 @@ 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;
}
bookCases.remove(returnPos);
return getPosition();
}

public List<StudyItem> getStudyItems()
{
return studyItems;
}
}
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
Loading