Skip to content

Commit 6fabf3e

Browse files
committed
Generate block resources.
1 parent b21f4e4 commit 6fabf3e

File tree

9 files changed

+139
-57
lines changed

9 files changed

+139
-57
lines changed

build.gradle

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ subprojects {
9797
projectId = uploadSettings["curse-id"]
9898
projectSlug = uploadSettings["curse-slug"]
9999
announcementTitle = "Lootr ${rootProject.minecraft_version}-${rootProject.mod_version} ${uploadSettings["title"]} on CurseForge"
100-
minecraftVersions.addAll(rootProject.minecraft_versions.split(","))
100+
// TODO: Hard-coded
101+
minecraftVersions.add(rootProject.minecraft_version)
102+
minecraftVersions.add("1.21.1")
101103

102104
if (uploadDependencies.size() > 0) {
103105
uploadDependencies.each { dep, required ->
@@ -117,7 +119,9 @@ subprojects {
117119
accessToken = project.findProperty("modrinth_auth")
118120
projectId = uploadSettings["modrinth-id"]
119121
announcementTitle = "Lootr ${rootProject.minecraft_version}-${rootProject.mod_version} ${uploadSettings["title"]} on Modrinth"
120-
minecraftVersions.addAll(rootProject.minecraft_versions.split(","))
122+
// TODO: Hard-coded
123+
minecraftVersions.add(rootProject.minecraft_version)
124+
minecraftVersions.add("1.21.1")
121125

122126
dependencies {
123127
uploadDependencies.each { dep, required ->
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
// 1.21 2024-08-18T14:50:21.7769156 Loot Tables
1+
// 1.21 2024-09-08T12:21:48.2313791 Loot Tables
2+
8eea450cccf954b00efcdda2a3d48df6ea079d09 data/lootr/loot_table/blocks/lootr_barrel.json
3+
05d03b8f6075123c44e0b3ffc269fd47e9a59f68 data/lootr/loot_table/blocks/lootr_chest.json
4+
260c0547345a0ae965137f565c61a8d3786d02fd data/lootr/loot_table/blocks/lootr_inventory.json
5+
25f1b2dfda93600fb2f1872a58e575debe732695 data/lootr/loot_table/blocks/lootr_shulker.json
6+
3447a563cf17c2ca6469d4847c40697d3a7a936c data/lootr/loot_table/blocks/lootr_trapped_chest.json
7+
12c3e3df4e2b4efcb00682913ce6234d95ec8db4 data/lootr/loot_table/blocks/trophy.json
28
345594272603fec7ed1bce397953f4284f6667b8 data/lootr/loot_table/chests/elytra.json

common/src/main/resources/data/lootr/loot_tables/blocks/lootr_barrel.json

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,29 @@
22
"type": "minecraft:block",
33
"pools": [
44
{
5-
"rolls": 1,
5+
"bonus_rolls": 0.0,
6+
"conditions": [
7+
{
8+
"condition": "minecraft:survives_explosion"
9+
}
10+
],
611
"entries": [
712
{
813
"type": "minecraft:item",
914
"functions": [
1015
{
11-
"function": "minecraft:copy_name",
16+
"function": "minecraft:copy_components",
17+
"include": [
18+
"minecraft:custom_name"
19+
],
1220
"source": "block_entity"
1321
}
1422
],
1523
"name": "minecraft:barrel"
1624
}
1725
],
18-
"conditions": [
19-
{
20-
"condition": "minecraft:survives_explosion"
21-
}
22-
]
26+
"rolls": 1.0
2327
}
24-
]
28+
],
29+
"random_sequence": "lootr:blocks/lootr_barrel"
2530
}

common/src/main/resources/data/lootr/loot_tables/blocks/lootr_chest.json

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,29 @@
22
"type": "minecraft:block",
33
"pools": [
44
{
5-
"rolls": 1,
5+
"bonus_rolls": 0.0,
6+
"conditions": [
7+
{
8+
"condition": "minecraft:survives_explosion"
9+
}
10+
],
611
"entries": [
712
{
813
"type": "minecraft:item",
914
"functions": [
1015
{
11-
"function": "minecraft:copy_name",
16+
"function": "minecraft:copy_components",
17+
"include": [
18+
"minecraft:custom_name"
19+
],
1220
"source": "block_entity"
1321
}
1422
],
1523
"name": "minecraft:chest"
1624
}
1725
],
18-
"conditions": [
19-
{
20-
"condition": "minecraft:survives_explosion"
21-
}
22-
]
26+
"rolls": 1.0
2327
}
24-
]
28+
],
29+
"random_sequence": "lootr:blocks/lootr_chest"
2530
}

common/src/main/resources/data/lootr/loot_tables/blocks/lootr_inventory.json

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,29 @@
22
"type": "minecraft:block",
33
"pools": [
44
{
5-
"rolls": 1,
5+
"bonus_rolls": 0.0,
6+
"conditions": [
7+
{
8+
"condition": "minecraft:survives_explosion"
9+
}
10+
],
611
"entries": [
712
{
813
"type": "minecraft:item",
914
"functions": [
1015
{
11-
"function": "minecraft:copy_name",
16+
"function": "minecraft:copy_components",
17+
"include": [
18+
"minecraft:custom_name"
19+
],
1220
"source": "block_entity"
1321
}
1422
],
1523
"name": "minecraft:chest"
1624
}
1725
],
18-
"conditions": [
19-
{
20-
"condition": "minecraft:survives_explosion"
21-
}
22-
]
26+
"rolls": 1.0
2327
}
24-
]
28+
],
29+
"random_sequence": "lootr:blocks/lootr_inventory"
2530
}

common/src/main/resources/data/lootr/loot_tables/blocks/lootr_shulker.json

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,29 @@
22
"type": "minecraft:block",
33
"pools": [
44
{
5-
"rolls": 1,
5+
"bonus_rolls": 0.0,
6+
"conditions": [
7+
{
8+
"condition": "minecraft:survives_explosion"
9+
}
10+
],
611
"entries": [
712
{
813
"type": "minecraft:item",
914
"functions": [
1015
{
11-
"function": "minecraft:copy_name",
16+
"function": "minecraft:copy_components",
17+
"include": [
18+
"minecraft:custom_name"
19+
],
1220
"source": "block_entity"
1321
}
1422
],
1523
"name": "minecraft:shulker_box"
1624
}
1725
],
18-
"conditions": [
19-
{
20-
"condition": "minecraft:survives_explosion"
21-
}
22-
]
26+
"rolls": 1.0
2327
}
24-
]
28+
],
29+
"random_sequence": "lootr:blocks/lootr_shulker"
2530
}

common/src/main/resources/data/lootr/loot_tables/blocks/lootr_trapped_chest.json

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,29 @@
22
"type": "minecraft:block",
33
"pools": [
44
{
5-
"rolls": 1,
5+
"bonus_rolls": 0.0,
6+
"conditions": [
7+
{
8+
"condition": "minecraft:survives_explosion"
9+
}
10+
],
611
"entries": [
712
{
813
"type": "minecraft:item",
914
"functions": [
1015
{
11-
"function": "minecraft:copy_name",
16+
"function": "minecraft:copy_components",
17+
"include": [
18+
"minecraft:custom_name"
19+
],
1220
"source": "block_entity"
1321
}
1422
],
1523
"name": "minecraft:trapped_chest"
1624
}
1725
],
18-
"conditions": [
19-
{
20-
"condition": "minecraft:survives_explosion"
21-
}
22-
]
26+
"rolls": 1.0
2327
}
24-
]
28+
],
29+
"random_sequence": "lootr:blocks/lootr_trapped_chest"
2530
}

common/src/main/resources/data/lootr/loot_tables/blocks/trophy.json

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,20 @@
22
"type": "minecraft:block",
33
"pools": [
44
{
5-
"rolls": 1,
5+
"bonus_rolls": 0.0,
6+
"conditions": [
7+
{
8+
"condition": "minecraft:survives_explosion"
9+
}
10+
],
611
"entries": [
712
{
813
"type": "minecraft:item",
9-
"functions": [
10-
{
11-
"function": "minecraft:copy_name",
12-
"source": "block_entity"
13-
}
14-
],
1514
"name": "lootr:trophy"
1615
}
1716
],
18-
"conditions": [
19-
{
20-
"condition": "minecraft:survives_explosion"
21-
}
22-
]
17+
"rolls": 1.0
2318
}
24-
]
19+
],
20+
"random_sequence": "lootr:blocks/trophy"
2521
}

neoforge/src/main/java/noobanidus/mods/lootr/neoforge/gen/LootrLootTableProvider.java

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,78 @@
11
package noobanidus.mods.lootr.neoforge.gen;
22

33
import net.minecraft.core.HolderLookup;
4+
import net.minecraft.core.component.DataComponents;
5+
import net.minecraft.core.registries.BuiltInRegistries;
46
import net.minecraft.data.PackOutput;
7+
import net.minecraft.data.loot.BlockLootSubProvider;
58
import net.minecraft.data.loot.LootTableProvider;
69
import net.minecraft.data.loot.LootTableSubProvider;
710
import net.minecraft.resources.ResourceKey;
11+
import net.minecraft.world.flag.FeatureFlags;
812
import net.minecraft.world.item.Items;
13+
import net.minecraft.world.level.block.Block;
14+
import net.minecraft.world.level.block.Blocks;
15+
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
916
import net.minecraft.world.level.storage.loot.LootPool;
1017
import net.minecraft.world.level.storage.loot.LootTable;
1118
import net.minecraft.world.level.storage.loot.entries.LootItem;
19+
import net.minecraft.world.level.storage.loot.functions.CopyComponentsFunction;
1220
import net.minecraft.world.level.storage.loot.functions.SetItemCountFunction;
1321
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
1422
import net.minecraft.world.level.storage.loot.providers.number.ConstantValue;
1523
import noobanidus.mods.lootr.common.api.LootrAPI;
24+
import noobanidus.mods.lootr.neoforge.init.ModBlocks;
1625

26+
import java.util.HashSet;
1727
import java.util.List;
28+
import java.util.Locale;
1829
import java.util.Set;
1930
import java.util.concurrent.CompletableFuture;
2031
import java.util.function.BiConsumer;
2132

2233
public class LootrLootTableProvider {
2334
public static LootTableProvider create(PackOutput output, CompletableFuture<HolderLookup.Provider> provider) {
24-
return new LootTableProvider(output, Set.of(LootrAPI.ELYTRA_CHEST), List.of(new LootTableProvider.SubProviderEntry(ChestLootTables::new, LootContextParamSets.CHEST)), provider);
35+
return new LootTableProvider(output, Set.of(LootrAPI.ELYTRA_CHEST), List.of(new LootTableProvider.SubProviderEntry(ChestLootTables::new, LootContextParamSets.CHEST), new LootTableProvider.SubProviderEntry(LootrBlockLootTables::new, LootContextParamSets.BLOCK)), provider);
36+
}
37+
38+
public static class LootrBlockLootTables extends BlockLootSubProvider {
39+
protected LootrBlockLootTables(HolderLookup.Provider arg2) {
40+
super(Set.of(), FeatureFlags.REGISTRY.allFlags(), arg2);
41+
}
42+
43+
protected LootTable.Builder lootrBlockDrop (Block block) {
44+
return LootTable.lootTable().withPool(this.applyExplosionCondition(block, LootPool.lootPool().setRolls(ConstantValue.exactly(1.0f)).add(LootItem.lootTableItem(block).apply(CopyComponentsFunction.copyComponents(CopyComponentsFunction.Source.BLOCK_ENTITY).include(DataComponents.CUSTOM_NAME)))));
45+
}
46+
47+
@Override
48+
protected void generate() {
49+
this.add(ModBlocks.CHEST.get(), lootrBlockDrop(Blocks.CHEST));
50+
this.add(ModBlocks.BARREL.get(), lootrBlockDrop(Blocks.BARREL));
51+
this.add(ModBlocks.INVENTORY.get(), lootrBlockDrop(Blocks.CHEST));
52+
this.add(ModBlocks.TRAPPED_CHEST.get(), lootrBlockDrop(Blocks.TRAPPED_CHEST));
53+
this.add(ModBlocks.SHULKER.get(), lootrBlockDrop(Blocks.SHULKER_BOX));
54+
this.dropSelf(ModBlocks.TROPHY.get());
55+
}
56+
57+
@Override
58+
public void generate(BiConsumer<ResourceKey<LootTable>, LootTable.Builder> biConsumer) {
59+
this.generate();
60+
HashSet<ResourceKey> set = new HashSet<ResourceKey>();
61+
for (Block block : List.of(ModBlocks.CHEST.get(), ModBlocks.BARREL.get(), ModBlocks.INVENTORY.get(), ModBlocks.TRAPPED_CHEST.get(), ModBlocks.SHULKER.get(), ModBlocks.TROPHY.get())) {
62+
ResourceKey resourceKey = block.getLootTable();
63+
if (resourceKey == BuiltInLootTables.EMPTY || !set.add(resourceKey)) {
64+
continue;
65+
}
66+
LootTable.Builder builder = this.map.remove(resourceKey);
67+
if (builder == null) {
68+
throw new IllegalStateException(String.format(Locale.ROOT, "Missing loottable '%s' for '%s'", resourceKey.location(), BuiltInRegistries.BLOCK.getKey(block)));
69+
}
70+
biConsumer.accept((ResourceKey<LootTable>)resourceKey, builder);
71+
}
72+
if (!this.map.isEmpty()) {
73+
throw new IllegalStateException("Created block loot tables for non-blocks: " + this.map.keySet());
74+
}
75+
}
2576
}
2677

2778
public static class ChestLootTables implements LootTableSubProvider {

0 commit comments

Comments
 (0)