Changed TagLoader injection point
This commit is contained in:
parent
6487ac81c6
commit
bc07b34f1c
2 changed files with 12 additions and 12 deletions
|
@ -3,11 +3,14 @@ package ru.betterend.mixin.common;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.At.Shift;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
@ -16,20 +19,19 @@ import net.minecraft.resources.ResourceLocation;
|
|||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.tags.TagLoader;
|
||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
import ru.betterend.util.TagHelper;
|
||||
|
||||
@Mixin(TagLoader.class)
|
||||
public class TagLoaderMixin {
|
||||
@Shadow
|
||||
private String name;
|
||||
|
||||
@Inject(method = "prepare", at = @At("RETURN"), cancellable = true)
|
||||
public void be_prepareReload(ResourceManager manager, Executor executor, CallbackInfoReturnable<CompletableFuture<Map<ResourceLocation, Tag.Builder>>> info) {
|
||||
CompletableFuture<Map<ResourceLocation, Tag.Builder>> future = info.getReturnValue();
|
||||
info.setReturnValue(CompletableFuture.supplyAsync(() -> {
|
||||
Map<ResourceLocation, Tag.Builder> map = Maps.newHashMap(future.join());
|
||||
TagHelper.apply(name, map);
|
||||
return map;
|
||||
}, executor));
|
||||
|
||||
@ModifyArg(method = "prepare", at = @At(value = "INVOKE",
|
||||
target = "Ljava/util/concurrent/CompletableFuture;supplyAsync(Ljava/util/function/Supplier;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;"))
|
||||
public Supplier<Map<ResourceLocation, Tag.Builder>> be_modifyTags(Supplier<Map<ResourceLocation, Tag.Builder>> supplier, Executor executor) {
|
||||
Map<ResourceLocation, Tag.Builder> map = supplier.get();
|
||||
TagHelper.apply(name, map);
|
||||
return () -> map;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,9 +66,7 @@ public class TagHelper {
|
|||
endTags = TAGS_ITEM;
|
||||
}
|
||||
if (endTags != null) {
|
||||
endTags.forEach((id, ids) -> {
|
||||
apply(tagsMap.computeIfAbsent(id, key -> Tag.Builder.tag()), ids);
|
||||
});
|
||||
endTags.forEach((id, ids) -> apply(tagsMap.computeIfAbsent(id, key -> Tag.Builder.tag()), ids));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue