Skip to content

Commit

Permalink
Rework lucky ores to become datapacks (#10343)
Browse files Browse the repository at this point in the history
Rework lucky ores to become datapacks
  • Loading branch information
Thodor12 authored Nov 24, 2024
1 parent a38fbcb commit c95b48b
Show file tree
Hide file tree
Showing 13 changed files with 312 additions and 128 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"pools": [
{
"bonus_rolls": 0.0,
"entries": [
{
"type": "minecraft:item",
"name": "minecraft:coal_ore",
"weight": 64
},
{
"type": "minecraft:item",
"name": "minecraft:copper_ore",
"weight": 48
}
],
"rolls": 1.0
}
],
"random_sequence": "minecolonies:loot_tables/miner/lucky_ore1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"pools": [
{
"bonus_rolls": 0.0,
"entries": [
{
"type": "minecraft:item",
"name": "minecraft:coal_ore",
"weight": 64
},
{
"type": "minecraft:item",
"name": "minecraft:copper_ore",
"weight": 48
},
{
"type": "minecraft:item",
"name": "minecraft:iron_ore",
"weight": 32
},
{
"type": "minecraft:item",
"name": "minecraft:gold_ore",
"weight": 16
}
],
"rolls": 1.0
}
],
"random_sequence": "minecolonies:loot_tables/miner/lucky_ore2"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"pools": [
{
"bonus_rolls": 0.0,
"entries": [
{
"type": "minecraft:item",
"name": "minecraft:coal_ore",
"weight": 64
},
{
"type": "minecraft:item",
"name": "minecraft:copper_ore",
"weight": 48
},
{
"type": "minecraft:item",
"name": "minecraft:iron_ore",
"weight": 32
},
{
"type": "minecraft:item",
"name": "minecraft:gold_ore",
"weight": 16
},
{
"type": "minecraft:item",
"name": "minecraft:redstone_ore",
"weight": 8
},
{
"type": "minecraft:item",
"name": "minecraft:lapis_ore",
"weight": 4
}
],
"rolls": 1.0
}
],
"random_sequence": "minecolonies:loot_tables/miner/lucky_ore3"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"pools": [
{
"bonus_rolls": 0.0,
"entries": [
{
"type": "minecraft:item",
"name": "minecraft:coal_ore",
"weight": 64
},
{
"type": "minecraft:item",
"name": "minecraft:copper_ore",
"weight": 48
},
{
"type": "minecraft:item",
"name": "minecraft:iron_ore",
"weight": 32
},
{
"type": "minecraft:item",
"name": "minecraft:gold_ore",
"weight": 16
},
{
"type": "minecraft:item",
"name": "minecraft:redstone_ore",
"weight": 8
},
{
"type": "minecraft:item",
"name": "minecraft:lapis_ore",
"weight": 4
},
{
"type": "minecraft:item",
"name": "minecraft:diamond_ore",
"weight": 2
},
{
"type": "minecraft:item",
"name": "minecraft:emerald_ore"
}
],
"rolls": 1.0
}
],
"random_sequence": "minecolonies:loot_tables/miner/lucky_ore4"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"pools": [
{
"bonus_rolls": 0.0,
"entries": [
{
"type": "minecraft:item",
"name": "minecraft:coal_ore",
"weight": 64
},
{
"type": "minecraft:item",
"name": "minecraft:copper_ore",
"weight": 48
},
{
"type": "minecraft:item",
"name": "minecraft:iron_ore",
"weight": 32
},
{
"type": "minecraft:item",
"name": "minecraft:gold_ore",
"weight": 16
},
{
"type": "minecraft:item",
"name": "minecraft:redstone_ore",
"weight": 8
},
{
"type": "minecraft:item",
"name": "minecraft:lapis_ore",
"weight": 4
},
{
"type": "minecraft:item",
"name": "minecraft:diamond_ore",
"weight": 2
},
{
"type": "minecraft:item",
"name": "minecraft:emerald_ore"
}
],
"rolls": 1.0
}
],
"random_sequence": "minecolonies:loot_tables/miner/lucky_ore5"
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@

import static com.minecolonies.api.util.ItemStackUtils.*;
import static com.minecolonies.api.util.constant.Constants.DEFAULT_TAB_KEY;
import static com.minecolonies.api.util.constant.Constants.ONE_HUNDRED_PERCENT;
import static com.minecolonies.api.util.constant.NbtTagConstants.TAG_SAP_LEAF;

/**
Expand Down Expand Up @@ -122,11 +121,6 @@ public class CompatibilityManager implements ICompatibilityManager
*/
private final List<String> diseaseList = new ArrayList<>();

/**
* List of lucky oreBlocks which get dropped by the miner.
*/
private final Map<Integer, List<ItemStorage>> luckyOres = new HashMap<>();

/**
* The items and weights of the recruitment.
*/
Expand Down Expand Up @@ -175,7 +169,6 @@ private void clear()
fuel.clear();
compostRecipes.clear();

luckyOres.clear();
recruitmentCostsWeights.clear();
diseases.clear();
diseaseList.clear();
Expand All @@ -194,7 +187,6 @@ public void discover(@NotNull final RecipeManager recipeManager, final Level lev
clear();
discoverAllItems(level);

discoverLuckyOres();
discoverRecruitCosts();
discoverDiseases();
discoverModCompat();
Expand Down Expand Up @@ -250,7 +242,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
discoverLuckyOres();
discoverRecruitCosts();
discoverDiseases();
discoverModCompat();
Expand Down Expand Up @@ -552,24 +543,6 @@ public void connectLeafToSapling(final Block leaf, final ItemStack stack)
}
}

@Override
public ItemStack getRandomLuckyOre(final double chanceBonus, final int buildingLevel)
{
if (random.nextDouble() * ONE_HUNDRED_PERCENT <= MinecoloniesAPIProxy.getInstance().getConfig().getServer().luckyBlockChance.get() * chanceBonus)
{
// fetch default config for all level
// override it if specific config for this level is available.
List<ItemStorage> luckyOresInLevel = luckyOres.get(0);
if (luckyOres.containsKey(buildingLevel))
{
luckyOresInLevel = luckyOres.get(buildingLevel);
}

return luckyOresInLevel.get(random.nextInt(luckyOresInLevel.size())).getItemStack().copy();
}
return ItemStack.EMPTY;
}

@Override
public CreativeModeTab getCreativeTab(final ItemStorage checkItem)
{
Expand Down Expand Up @@ -792,74 +765,6 @@ private void discoverFood(final ItemStack stack)
}
}

/**
* Run through all blocks and check if they match one of our lucky oreBlocks.
*/
private void discoverLuckyOres()
{
if (luckyOres.isEmpty())
{
for (final String ore : MinecoloniesAPIProxy.getInstance().getConfig().getServer().luckyOres.get())
{
final String[] split = ore.split("!");
if (split.length < 2)
{
Log.getLogger().warn("Wrong configured ore: " + ore);
continue;
}

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

final int defaultMineLevel = 0;
int buildingLevel = defaultMineLevel;
final ItemStack stack = new ItemStack(item, 1);
try
{
if (split.length == 3)
{
buildingLevel = Integer.parseInt(split[2]);
}

final int rarity = Integer.parseInt(split[1]);

luckyOres.putIfAbsent(buildingLevel, new ArrayList<>());

for (int i = 0; i < rarity; i++)
{
List<ItemStorage> luckyOreOnLevel = luckyOres.get(buildingLevel);
luckyOreOnLevel.add(new ItemStorage(stack));
}
}
catch (final NumberFormatException ex)
{
Log.getLogger().warn("Ore has invalid rarity or building level: " + ore);
}
}

List<ItemStorage> alternative = null;
int mineMaxLevel = 5;
for (int levelToTest = 0; levelToTest <= mineMaxLevel; levelToTest++)
{
if (luckyOres.containsKey(levelToTest) && !luckyOres.get(levelToTest).isEmpty())
{
alternative = luckyOres.get(levelToTest);
break;
}
}

for (int levelToReplace = 0; levelToReplace <= mineMaxLevel; levelToReplace++)
{
luckyOres.putIfAbsent(levelToReplace, alternative);
}
}
Log.getLogger().info("Finished discovering lucky oreBlocks " + luckyOres.size());
}

/**
* Parses recruitment costs from config
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,6 @@ public interface ICompatibilityManager
*/
boolean isLuckyBlock(final Block block);

/**
* Get a random lucky ore from a luckyblock.
* Loot may change depending on the mine level
*
* @param chanceBonus the chance bonus.
* @param buildingLevel level of the mine
* @return the lucky ore.
*/
ItemStack getRandomLuckyOre(final double chanceBonus, final int buildingLevel);

/**
* Get the creative tab for a stack.
* @param checkItem the storage wrapper.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public class ServerConfiguration extends AbstractConfiguration

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;
public final ForgeConfigSpec.BooleanValue auditCraftingTags;
public final ForgeConfigSpec.BooleanValue debugInventories;
Expand Down Expand Up @@ -215,17 +214,6 @@ protected ServerConfiguration(final ForgeConfigSpec.Builder builder)
"minecraft:honeycomb;6",
"minecraft:quartz;3"),
s -> s instanceof String);
luckyOres = defineList(builder, "luckyores",
Arrays.asList
("minecraft:coal_ore!64",
"minecraft:copper_ore!48",
"minecraft:iron_ore!32",
"minecraft:gold_ore!16",
"minecraft:redstone_ore!8",
"minecraft:lapis_ore!4",
"minecraft:diamond_ore!2",
"minecraft:emerald_ore!1"),
s -> s instanceof String);

diseases = defineList(builder, "diseases",
Arrays.asList("Influenza,100,minecraft:carrot,minecraft:potato",
Expand Down
Loading

0 comments on commit c95b48b

Please sign in to comment.