|
| 1 | +/* |
| 2 | + * This file is part of Loofah, licensed under the MIT License (MIT). |
| 3 | + * |
| 4 | + * Copyright (c) Nelind <https://www.nelind.dk> |
| 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 dk.nelind.loofah.mixin.core.tags; |
| 26 | + |
| 27 | +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; |
| 28 | +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; |
| 29 | +import com.llamalad7.mixinextras.sugar.Local; |
| 30 | +import net.minecraft.resources.ResourceLocation; |
| 31 | +import net.minecraft.tags.TagEntry; |
| 32 | +import net.minecraft.tags.TagLoader; |
| 33 | +import org.spongepowered.asm.mixin.Mixin; |
| 34 | +import org.spongepowered.asm.mixin.injection.At; |
| 35 | +import org.spongepowered.asm.mixin.injection.Coerce; |
| 36 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 37 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 38 | +import org.spongepowered.common.bridge.tags.TagLoaderBridge; |
| 39 | + |
| 40 | +import java.util.Collection; |
| 41 | +import java.util.List; |
| 42 | +import java.util.Map; |
| 43 | +import java.util.function.Consumer; |
| 44 | + |
| 45 | +/** Copied from {@link org.spongepowered.vanilla.mixin.core.tags.TagLoaderMixin_Vanilla} */ |
| 46 | +@Mixin(TagLoader.class) |
| 47 | +public abstract class TagLoaderMixin_Fabric<T> implements TagLoaderBridge<T> { |
| 48 | + |
| 49 | + @WrapOperation( |
| 50 | + method = "build(Lnet/minecraft/tags/TagEntry$Lookup;Ljava/util/List;)Lcom/mojang/datafixers/util/Either;", |
| 51 | + at = @At( |
| 52 | + value = "INVOKE", |
| 53 | + target = "Lnet/minecraft/tags/TagEntry;build(Lnet/minecraft/tags/TagEntry$Lookup;Ljava/util/function/Consumer;)Z" |
| 54 | + ) |
| 55 | + ) |
| 56 | + protected boolean fabric$onBuildTag( |
| 57 | + final TagEntry instance, |
| 58 | + final TagEntry.Lookup<T> lookup, |
| 59 | + final Consumer<T> consumer, |
| 60 | + final Operation<Boolean> original, |
| 61 | + final TagEntry.Lookup<T> $$0, |
| 62 | + final List<TagLoader.EntryWithSource> $$1, |
| 63 | + final @Local TagLoader.EntryWithSource entry |
| 64 | + ) { |
| 65 | + return this.bridge$acceptTag(instance, lookup, consumer, original::call, $$1, entry); |
| 66 | + } |
| 67 | + |
| 68 | + @Inject(method = "lambda$build$5", at = @At("HEAD")) |
| 69 | + private void fabric$onStartBuildingTag( |
| 70 | + final TagEntry.Lookup<T> $$0x, |
| 71 | + final Map<ResourceLocation, Collection<T>> $$1x, |
| 72 | + final ResourceLocation $$2x, |
| 73 | + final @Coerce Object $$3x, |
| 74 | + final CallbackInfo ci |
| 75 | + ) { |
| 76 | + this.bridge$buildingTagKey($$2x); |
| 77 | + } |
| 78 | + |
| 79 | + @Inject(method = "lambda$build$5", at = @At("RETURN")) |
| 80 | + private void fabric$onDoneBuildingTag(final CallbackInfo ci) { |
| 81 | + this.bridge$buildingTagKey(null); |
| 82 | + } |
| 83 | +} |
0 commit comments