|
6 | 6 | package net.neoforged.neoforge.event;
|
7 | 7 |
|
8 | 8 | import java.util.Objects;
|
| 9 | +import net.minecraft.core.HolderLookup; |
| 10 | +import net.minecraft.core.registries.Registries; |
| 11 | +import net.minecraft.resources.ResourceKey; |
9 | 12 | import net.minecraft.resources.ResourceLocation;
|
10 | 13 | import net.minecraft.world.level.storage.loot.LootTable;
|
11 | 14 | import net.neoforged.bus.api.Event;
|
12 | 15 | import net.neoforged.bus.api.ICancellableEvent;
|
13 | 16 | import net.neoforged.fml.LogicalSide;
|
14 | 17 | import net.neoforged.neoforge.common.NeoForge;
|
| 18 | +import org.jetbrains.annotations.ApiStatus; |
| 19 | +import org.jetbrains.annotations.Nullable; |
15 | 20 |
|
16 | 21 | /**
|
17 | 22 | * Fired when a {@link LootTable} is loaded from JSON.
|
|
26 | 31 | * only on the {@linkplain LogicalSide#SERVER logical server}.</p>
|
27 | 32 | */
|
28 | 33 | public class LootTableLoadEvent extends Event implements ICancellableEvent {
|
| 34 | + private final HolderLookup.Provider registries; |
29 | 35 | private final ResourceLocation name;
|
30 | 36 | private LootTable table;
|
31 | 37 |
|
32 |
| - public LootTableLoadEvent(ResourceLocation name, LootTable table) { |
| 38 | + @Nullable |
| 39 | + private ResourceKey<LootTable> key; |
| 40 | + |
| 41 | + @ApiStatus.Internal |
| 42 | + public LootTableLoadEvent(HolderLookup.Provider registries, ResourceLocation name, LootTable table) { |
| 43 | + this.registries = registries; |
33 | 44 | this.name = name;
|
34 | 45 | this.table = table;
|
35 | 46 | }
|
36 | 47 |
|
| 48 | + /** |
| 49 | + * {@return a lookup provider that can be used to access registries} |
| 50 | + */ |
| 51 | + public HolderLookup.Provider getRegistries() { |
| 52 | + return this.registries; |
| 53 | + } |
| 54 | + |
37 | 55 | public ResourceLocation getName() {
|
38 | 56 | return this.name;
|
39 | 57 | }
|
40 | 58 |
|
| 59 | + public ResourceKey<LootTable> getKey() { |
| 60 | + if (this.key == null) { |
| 61 | + this.key = ResourceKey.create(Registries.LOOT_TABLE, name); |
| 62 | + } |
| 63 | + return this.key; |
| 64 | + } |
| 65 | + |
41 | 66 | public LootTable getTable() {
|
42 | 67 | return this.table;
|
43 | 68 | }
|
|
0 commit comments