|
| 1 | +/* |
| 2 | + * This file is part of Sponge, licensed under the MIT License (MIT). |
| 3 | + * |
| 4 | + * Copyright (c) SpongePowered <https://www.spongepowered.org> |
| 5 | + * Copyright (c) contributors |
| 6 | + * |
| 7 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | + * of this software and associated documentation files (the "Software"), to deal |
| 9 | + * in the Software without restriction, including without limitation the rights |
| 10 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | + * copies of the Software, and to permit persons to whom the Software is |
| 12 | + * furnished to do so, subject to the following conditions: |
| 13 | + * |
| 14 | + * The above copyright notice and this permission notice shall be included in |
| 15 | + * all copies or substantial portions of the Software. |
| 16 | + * |
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 23 | + * THE SOFTWARE. |
| 24 | + */ |
| 25 | +package org.spongepowered.neoforge.mixin.core.world.item.crafting; |
| 26 | + |
| 27 | +import com.google.gson.JsonElement; |
| 28 | +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; |
| 29 | +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; |
| 30 | +import com.mojang.serialization.Codec; |
| 31 | +import com.mojang.serialization.DynamicOps; |
| 32 | +import net.minecraft.resources.FileToIdConverter; |
| 33 | +import net.minecraft.resources.Identifier; |
| 34 | +import net.minecraft.server.packs.resources.ResourceManager; |
| 35 | +import net.minecraft.world.item.crafting.Recipe; |
| 36 | +import net.minecraft.world.item.crafting.RecipeManager; |
| 37 | +import org.spongepowered.api.registry.Registry; |
| 38 | +import org.spongepowered.api.registry.RegistryHolder; |
| 39 | +import org.spongepowered.api.registry.RegistryTypes; |
| 40 | +import org.spongepowered.asm.mixin.Mixin; |
| 41 | +import org.spongepowered.asm.mixin.injection.At; |
| 42 | +import org.spongepowered.common.launch.Launch; |
| 43 | +import org.spongepowered.common.registry.RegistryHolderLogic; |
| 44 | +import org.spongepowered.common.registry.SpongeRegistryHolder; |
| 45 | + |
| 46 | +import java.util.Map; |
| 47 | +import java.util.SortedMap; |
| 48 | +import java.util.TreeMap; |
| 49 | +import java.util.function.Consumer; |
| 50 | +import java.util.stream.Stream; |
| 51 | + |
| 52 | +@Mixin(RecipeManager.class) |
| 53 | +public abstract class RecipeManagerMixin_Neo { |
| 54 | + |
| 55 | + @SuppressWarnings("unchecked") |
| 56 | + @WrapOperation(method = "prepare(Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/util/profiling/ProfilerFiller;)Lnet/minecraft/world/item/crafting/RecipeMap;", |
| 57 | + at = @At(value = "INVOKE", target = "Lnet/minecraft/server/packs/resources/SimpleJsonResourceReloadListener;scanDirectoryWithModifier(Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/resources/FileToIdConverter;Lcom/mojang/serialization/DynamicOps;Lcom/mojang/serialization/Codec;Ljava/util/Map;Ljava/util/function/Consumer;)V")) |
| 58 | + private void impl$onPrepare(final ResourceManager $$0, final FileToIdConverter $$1, final DynamicOps<JsonElement> $$2, final Codec<Recipe<?>> $$3, |
| 59 | + final Map<Identifier, Recipe<?>> $$4, final Consumer<Map<Identifier, JsonElement>> $$5, final Operation<Void> original) { |
| 60 | + SortedMap<Identifier, Recipe<?>> result = new TreeMap<>(); |
| 61 | + original.call($$0, $$1, $$2, $$3, result, $$5); |
| 62 | + final RegistryHolderLogic registryHolder = ((SpongeRegistryHolder) $$0).registryHolder(); |
| 63 | + final Registry<Recipe<?>> registry = (Registry<Recipe<?>>) (Object) registryHolder.registry(RegistryTypes.RECIPE); |
| 64 | + result.forEach((k, v) -> registry.register((org.spongepowered.api.ResourceKey) (Object) k, v)); |
| 65 | + Launch.instance().lifecycle().processServerRegistries((RegistryHolder) $$0, Stream.of(registry)); |
| 66 | + registry.streamEntries().forEach(e -> $$4.put((Identifier) (Object) e.key(), e.value())); |
| 67 | + } |
| 68 | +} |
0 commit comments