Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@ public class CompatibilityManager implements ICompatibilityManager
*/
private final Map<Integer, List<ItemStorage>> luckyOres = new HashMap<>();

/**
* The items and weights of the recruitment.
*/
private final List<Tuple<Item, Integer>> recruitmentCostsWeights = new ArrayList<>();

/**
* Random obj.
*/
Expand Down Expand Up @@ -166,7 +161,6 @@ private void clear()
fuel.clear();
compostRecipes.clear();

recruitmentCostsWeights.clear();
monsters = ImmutableSet.of();
creativeModeTabMap.clear();
}
Expand All @@ -182,7 +176,6 @@ public void discover(@NotNull final RecipeManager recipeManager, final Level lev
clear();
discoverAllItems(level);

discoverRecruitCosts();
discoverModCompat();

discoverCompostRecipes(recipeManager);
Expand Down Expand Up @@ -247,7 +240,6 @@ public void deserialize(@NotNull final FriendlyByteBuf buf, final ClientLevel le
discoverCompostRecipes(deserializeCompostRecipes(buf));

// the below are loaded from config files, which have been synched already by this point
discoverRecruitCosts();
discoverModCompat();

for (int i = 0, amount = buf.readInt(); i < amount; i++)
Expand Down Expand Up @@ -476,12 +468,6 @@ public Set<ItemStorage> getImmutableFlowers()
return beekeeperflowers;
}

@Override
public List<Tuple<Item, Integer>> getRecruitmentCostsWeights()
{
return Collections.unmodifiableList(recruitmentCostsWeights);
}

@Override
public boolean isOre(final BlockState block)
{
Expand Down Expand Up @@ -763,43 +749,6 @@ private void discoverFood(final ItemStack stack)
}
}

/**
* Parses recruitment costs from config
*/
private void discoverRecruitCosts()
{
if (recruitmentCostsWeights.isEmpty())
{
for (final String itemString : MinecoloniesAPIProxy.getInstance().getConfig().getServer().configListRecruitmentItems.get())
{
final String[] split = itemString.split(";");
if (split.length < 2)
{
Log.getLogger().warn("Wrong configured recruitment cost: " + itemString);
continue;
}

final Item item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(split[0]));
if (item == null || item == Items.AIR)
{
Log.getLogger().warn("Invalid recruitment item: " + item);
continue;
}

try
{
final int rarity = Integer.parseInt(split[split.length - 1]);
recruitmentCostsWeights.add(new Tuple<>(item, rarity));
}
catch (final NumberFormatException ex)
{
Log.getLogger().warn("Invalid recruitment weight for: " + item);
}
}
}
Log.getLogger().info("Finished discovering recruitment costs");
}

private static CompoundTag writeLeafSaplingEntryToNBT(final BlockState state, final ItemStorage storage)
{
final CompoundTag compound = NbtUtils.writeBlockState(state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,6 @@ public interface ICompatibilityManager
*/
ImmutableSet<ResourceLocation> getAllMonsters();

/**
* Gets the list of recruitment costs with weights
*
* @return list of costs
*/
List<Tuple<Item, Integer>> getRecruitmentCostsWeights();

/**
* Checks if a certain Block is an ore.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ public class ServerConfiguration extends AbstractConfiguration
* ------------------- ######## Compatibility Settings ######## ------------------- *
* -------------------------------------------------------------------------------- */

public final ForgeConfigSpec.ConfigValue<List<? extends String>> configListRecruitmentItems;
public final ForgeConfigSpec.BooleanValue auditCraftingTags;
public final ForgeConfigSpec.BooleanValue debugInventories;
public final ForgeConfigSpec.BooleanValue blueprintBuildMode;
Expand Down Expand Up @@ -188,23 +187,6 @@ protected ServerConfiguration(final ForgeConfigSpec.Builder builder)

swapToCategory(builder, "compatibility");

configListRecruitmentItems = defineList(builder, "configlistrecruitmentitems",
Arrays.asList
("minecraft:hay_block;3",
"minecraft:book;2",
"minecraft:enchanted_book;9",
"minecraft:diamond;9",
"minecraft:emerald;8",
"minecraft:baked_potato;1",
"minecraft:gold_ingot;2",
"minecraft:redstone;2",
"minecraft:lapis_lazuli;2",
"minecraft:cake;11",
"minecraft:sunflower;5",
"minecraft:honeycomb;6",
"minecraft:quartz;3"),
s -> s instanceof String);

auditCraftingTags = defineBoolean(builder, "auditcraftingtags", false);
debugInventories = defineBoolean(builder, "debuginventories", false);
blueprintBuildMode = defineBoolean(builder, "blueprintbuildmode", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
import com.minecolonies.api.colony.interactionhandling.ChatPriority;
import com.minecolonies.api.sounds.TavernSounds;
import com.minecolonies.api.util.BlockPosUtil;
import com.minecolonies.api.util.Tuple;
import com.minecolonies.core.Network;
import com.minecolonies.core.client.gui.huts.WindowHutLiving;
import com.minecolonies.core.colony.buildings.views.LivingBuildingView;
import com.minecolonies.core.colony.eventhooks.citizenEvents.VisitorSpawnedEvent;
import com.minecolonies.core.colony.interactionhandling.RecruitmentInteraction;
import com.minecolonies.core.datalistener.CustomVisitorListener;
import com.minecolonies.core.datalistener.RecruitmentItemsListener;
import com.minecolonies.core.datalistener.RecruitmentItemsListener.RecruitCost;
import com.minecolonies.core.network.messages.client.colony.PlayMusicAtPosMessage;
import net.minecraft.world.entity.player.Player;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -53,10 +53,10 @@ public class TavernBuildingModule extends AbstractBuildingModule implements IDef
/**
* Skill levels
*/
private static final int LEATHER_SKILL_LEVEL = 20;
private static final int GOLD_SKILL_LEVEL = 25;
private static final int IRON_SKILL_LEVEL = 30;
private static final int DIAMOND_SKILL_LEVEL = 35;
public static final int LEATHER_SKILL_LEVEL = 20;
public static final int GOLD_SKILL_LEVEL = 25;
public static final int IRON_SKILL_LEVEL = 30;
public static final int DIAMOND_SKILL_LEVEL = 35;

/**
* Music interval
Expand Down Expand Up @@ -154,7 +154,7 @@ public void onColonyTick(@NotNull final IColony colony)

if (building.getBuildingLevel() > 0 && externalCitizens.size() < 3 * building.getBuildingLevel() && noVisitorTime <= 0)
{
spawnVisitor();
spawnVisitorInternal();
noVisitorTime =
colony.getWorld().getRandom().nextInt(3000) + (6000 / building.getBuildingLevel()) * colony.getCitizenManager().getCurrentCitizenCount() / colony.getCitizenManager()
.getMaxCitizens();
Expand All @@ -168,34 +168,59 @@ public void onUpgradeComplete(final int newlevel)
}

/**
* Spawns a recruitable visitor citizen.
* Spawns a visitor specifically for the tavern logic.
*/
private void spawnVisitor()
private void spawnVisitorInternal()
{
IVisitorData newCitizen = (IVisitorData) building.getColony().getVisitorManager().createAndRegisterCivilianData();
externalCitizens.add(newCitizen.getId());

newCitizen.setBedPos(building.getPosition());
newCitizen.setHomeBuilding(building);

int recruitLevel = building.getColony().getWorld().random.nextInt(10 * building.getBuildingLevel()) + 15;
List<com.minecolonies.api.util.Tuple<Item, Integer>> recruitCosts = IColonyManager.getInstance().getCompatibilityManager().getRecruitmentCostsWeights();
final IVisitorData visitorData = spawnVisitor();

if (newCitizen.getName().contains("Ray"))
if (!CustomVisitorListener.chanceCustomVisitors(visitorData))
{
newCitizen.setRecruitCosts(new ItemStack(Items.BAKED_POTATO, 64));
visitorData.triggerInteraction(new RecruitmentInteraction(Component.translatable(
"com.minecolonies.coremod.gui.chat.recruitstory" + (building.getColony().getWorld().random.nextInt(MAX_STORY) + 1), visitorData.getName().split(" ")[0]),
ChatPriority.IMPORTANT));
}
}

/**
* Spawns a visitor citizen that can be recruited.
*/
public IVisitorData spawnVisitor()
{
final int recruitLevel = building.getColony().getWorld().random.nextInt(10 * building.getBuildingLevel()) + 15;
final RecruitCost cost = RecruitmentItemsListener.getRandomRecruitCost(building.getColony().getWorld().getRandom(), recruitLevel);

final IVisitorData newCitizen = (IVisitorData) building.getColony().getVisitorManager().createAndRegisterCivilianData();
newCitizen.setBedPos(building.getPosition());
newCitizen.setHomeBuilding(building);
newCitizen.getCitizenSkillHandler().init(recruitLevel);
newCitizen.setRecruitCosts(cost.toItemStack(recruitLevel));

BlockPos spawnPos = BlockPosUtil.findSpawnPosAround(building.getColony().getWorld(), building.getPosition());
if (spawnPos == null)
{
spawnPos = building.getPosition();
}

Tuple<Item, Integer> cost = recruitCosts.get(building.getColony().getWorld().random.nextInt(recruitCosts.size()));
building.getColony().getVisitorManager().spawnOrCreateCivilian(newCitizen, building.getColony().getWorld(), spawnPos, true);
if (newCitizen.getEntity().isPresent())
{
newCitizen.getEntity().get().setItemSlot(EquipmentSlot.FEET, getBoots(recruitLevel));
}
building.getColony().getEventDescriptionManager().addEventDescription(new VisitorSpawnedEvent(spawnPos, newCitizen.getName()));

externalCitizens.add(newCitizen.getId());
return newCitizen;
}

/**
* Get the boots for the given recruit level.
*
* @param recruitLevel the input recruit level.
* @return the itemstack for the boots.
*/
private ItemStack getBoots(final int recruitLevel)
{
ItemStack boots = ItemStack.EMPTY;
if (recruitLevel > LEATHER_SKILL_LEVEL)
{
Expand All @@ -209,38 +234,15 @@ private void spawnVisitor()
}
if (recruitLevel > IRON_SKILL_LEVEL)
{
if (cost.getB() <= 2)
{
cost = recruitCosts.get(building.getColony().getWorld().random.nextInt(recruitCosts.size()));
}
// Iron
boots = new ItemStack(Items.IRON_BOOTS);
}
if (recruitLevel > DIAMOND_SKILL_LEVEL)
{
if (cost.getB() <= 3)
{
cost = recruitCosts.get(building.getColony().getWorld().random.nextInt(recruitCosts.size()));
}
// Diamond
boots = new ItemStack(Items.DIAMOND_BOOTS);
}

newCitizen.setRecruitCosts(new ItemStack(cost.getA(), (int) (recruitLevel * 3.0 / cost.getB())));

if (!CustomVisitorListener.chanceCustomVisitors(newCitizen))
{
newCitizen.triggerInteraction(new RecruitmentInteraction(Component.translatable(
"com.minecolonies.coremod.gui.chat.recruitstory" + (building.getColony().getWorld().random.nextInt(MAX_STORY) + 1), newCitizen.getName().split(" ")[0]),
ChatPriority.IMPORTANT));
}

building.getColony().getVisitorManager().spawnOrCreateCivilian(newCitizen, building.getColony().getWorld(), spawnPos, true);
if (newCitizen.getEntity().isPresent())
{
newCitizen.getEntity().get().setItemSlot(EquipmentSlot.FEET, boots);
}
building.getColony().getEventDescriptionManager().addEventDescription(new VisitorSpawnedEvent(spawnPos, newCitizen.getName()));
return boots;
}

@Override
Expand Down
Loading