3939import java .util .function .Predicate ;
4040import java .util .function .ToIntFunction ;
4141
42- import net .minecraft .commands .arguments .ResourceKeyArgument ;
43- import net .minecraft .core .Holder ;
44- import net .minecraft .resources .ResourceKey ;
45- import net .minecraft .util .profiling .Profiler ;
4642import org .bukkit .Bukkit ;
4743import org .bukkit .Color ;
4844import org .bukkit .Location ;
136132import net .minecraft .commands .arguments .ParticleArgument ;
137133import net .minecraft .commands .arguments .RangeArgument ;
138134import net .minecraft .commands .arguments .ResourceArgument ;
135+ import net .minecraft .commands .arguments .ResourceKeyArgument ;
139136import net .minecraft .commands .arguments .ResourceLocationArgument ;
140137import net .minecraft .commands .arguments .ScoreHolderArgument ;
141138import net .minecraft .commands .arguments .ScoreboardSlotArgument ;
155152import net .minecraft .commands .functions .InstantiatedFunction ;
156153import net .minecraft .commands .synchronization .ArgumentUtils ;
157154import net .minecraft .core .BlockPos ;
155+ import net .minecraft .core .Holder ;
158156import net .minecraft .core .particles .BlockParticleOption ;
159157import net .minecraft .core .particles .ColorParticleOption ;
160158import net .minecraft .core .particles .DustColorTransitionOptions ;
185183import net .minecraft .server .packs .resources .SimpleReloadInstance ;
186184import net .minecraft .sounds .SoundEvent ;
187185import net .minecraft .util .Unit ;
186+ import net .minecraft .util .profiling .Profiler ;
188187import net .minecraft .util .profiling .ProfilerFiller ;
189188import net .minecraft .world .entity .Entity ;
189+ import net .minecraft .world .flag .FeatureFlagSet ;
190190import net .minecraft .world .item .ItemStack ;
191191import net .minecraft .world .item .crafting .RecipeHolder ;
192192import net .minecraft .world .level .DataPackConfig ;
193193import net .minecraft .world .level .Level ;
194194import net .minecraft .world .level .WorldDataConfiguration ;
195+ import net .minecraft .world .level .block .entity .FuelValues ;
195196import net .minecraft .world .level .block .state .pattern .BlockInWorld ;
196197import net .minecraft .world .level .gameevent .BlockPositionSource ;
197198import net .minecraft .world .phys .Vec2 ;
207208@ RequireField (in = EntitySelector .class , name = "usesSelector" , ofType = boolean .class )
208209// @RequireField(in = ItemInput.class, name = "tag", ofType = CompoundTag.class)
209210@ RequireField (in = ServerFunctionLibrary .class , name = "dispatcher" , ofType = CommandDispatcher .class )
211+ @ RequireField (in = MinecraftServer .class , name = "fuelValues" , ofType = FuelValues .class )
210212public class NMS_1_21_R2 extends NMS_Common {
211213
212214 private static final SafeVarHandle <SimpleHelpMap , Map <String , HelpTopic >> helpMapTopics ;
213215 private static final Field entitySelectorUsesSelector ;
214216 // private static final SafeVarHandle<ItemInput, CompoundTag> itemInput;
215217 private static final Field serverFunctionLibraryDispatcher ;
216218 private static final boolean vanillaCommandDispatcherFieldExists ;
219+ private static final SafeVarHandle <MinecraftServer , FuelValues > minecraftServerFuelValues ;
217220
218221 // Derived from net.minecraft.commands.Commands;
219222 private static final CommandBuildContext COMMAND_BUILD_CONTEXT ;
@@ -244,6 +247,8 @@ public class NMS_1_21_R2 extends NMS_Common {
244247 fieldExists = false ;
245248 }
246249 vanillaCommandDispatcherFieldExists = fieldExists ;
250+
251+ minecraftServerFuelValues = SafeVarHandle .ofOrNull (MinecraftServer .class , "fuelValues" , "fuelValues" , FuelValues .class );
247252 }
248253
249254 private static NamespacedKey fromResourceLocation (ResourceLocation key ) {
@@ -974,6 +979,10 @@ public final void reloadDataPacks() {
974979 MultiPackResourceManager resourceManager = new MultiPackResourceManager (PackType .SERVER_DATA ,
975980 packResources );
976981
982+ // TODO: I'm not sure if this is sufficient anymore - Do we not want to load tags for existing
983+ // registries here as well?
984+ // List<PendingTags<?>> TagList = TagLoader.loadTagsForExistingRegistries(resourceManager, this.<MinecraftServer>getMinecraftServer().registries().compositeAccess());
985+
977986 // Not using packResources, because we really really want this to work
978987 CompletableFuture <?> simpleReloadInstance = SimpleReloadInstance .create (resourceManager ,
979988 serverResources .managers ().listeners (), this .<MinecraftServer >getMinecraftServer ().executor ,
@@ -990,6 +999,8 @@ public final void reloadDataPacks() {
990999 this .<MinecraftServer >getMinecraftServer ().resources = serverResources ;
9911000 this .<MinecraftServer >getMinecraftServer ().server .syncCommands ();
9921001 this .<MinecraftServer >getMinecraftServer ().getPackRepository ().setSelected (collection );
1002+
1003+ final FeatureFlagSet enabledFeatures = this .<MinecraftServer >getMinecraftServer ().getWorldData ().getDataConfiguration ().enabledFeatures ();
9931004
9941005 // this.<MinecraftServer>getMinecraftServer().getSelectedPacks
9951006 Collection <String > selectedIDs = this .<MinecraftServer >getMinecraftServer ().getPackRepository ()
@@ -1001,11 +1012,11 @@ public final void reloadDataPacks() {
10011012 disabledIDs .removeIf (enabledIDs ::contains );
10021013
10031014 this .<MinecraftServer >getMinecraftServer ().getWorldData ()
1004- .setDataConfiguration (new WorldDataConfiguration (new DataPackConfig (enabledIDs , disabledIDs ),
1005- this .<MinecraftServer >getMinecraftServer ().getWorldData ().getDataConfiguration ()
1006- .enabledFeatures ()));
1015+ .setDataConfiguration (new WorldDataConfiguration (new DataPackConfig (enabledIDs , disabledIDs ), enabledFeatures ));
10071016 // this.<MinecraftServer>getMinecraftServer().resources.managers().updateRegistryTags(registryAccess);
1008- this .<MinecraftServer >getMinecraftServer ().resources .managers ().updateStaticRegistryTags (); // TODO
1017+ this .<MinecraftServer >getMinecraftServer ().resources .managers ().updateStaticRegistryTags (); // TODO: Review this
1018+ this .<MinecraftServer >getMinecraftServer ().resources .managers ().getRecipeManager ().finalizeRecipeLoading (enabledFeatures );
1019+
10091020 // May need to be commented out, may not. Comment it out just in case.
10101021 // For some reason, calling getPlayerList().saveAll() may just hang
10111022 // the server indefinitely. Not sure why!
@@ -1014,6 +1025,13 @@ public final void reloadDataPacks() {
10141025 // this.<MinecraftServer>getMinecraftServer().getFunctions().replaceLibrary(this.<MinecraftServer>getMinecraftServer().resources.managers().getFunctionLibrary());
10151026 this .<MinecraftServer >getMinecraftServer ().getStructureManager ()
10161027 .onResourceManagerReload (this .<MinecraftServer >getMinecraftServer ().resources .resourceManager ());
1028+
1029+ // Set fuel values with the new loaded fuel values from the list of enabled features
1030+ minecraftServerFuelValues .set (this .<MinecraftServer >getMinecraftServer (),
1031+ FuelValues .vanillaBurnTimes (this .<MinecraftServer >getMinecraftServer ().registries ().compositeAccess (),
1032+ enabledFeatures
1033+ )
1034+ );
10171035 });
10181036
10191037 // Step 4: Block the thread until everything's done
0 commit comments