Tags Helper improvements
This commit is contained in:
parent
4b78008e1d
commit
75d3347a45
2 changed files with 44 additions and 16 deletions
|
@ -1,24 +1,35 @@
|
|||
package ru.betterend.mixin.common;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
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.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
import net.minecraft.tag.Tag;
|
||||
import net.minecraft.tag.TagGroup;
|
||||
import net.minecraft.tag.TagGroupLoader;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import ru.betterend.util.TagHelper;
|
||||
|
||||
@Mixin(TagGroupLoader.class)
|
||||
public class TagGroupLoaderMixin {
|
||||
@Inject(method = "applyReload", at = @At(value = "HEAD"))
|
||||
private void onReload(Map<Identifier, Tag.Builder> tags, CallbackInfoReturnable<TagGroup<?>> info) {
|
||||
tags.forEach((id, builder) -> {
|
||||
TagHelper.apply(id, builder);
|
||||
});
|
||||
|
||||
@Shadow
|
||||
private String entryType;
|
||||
|
||||
@Inject(method = "prepareReload", at = @At("RETURN"), cancellable = true)
|
||||
public void prepareReload(ResourceManager manager, Executor prepareExecutor, CallbackInfoReturnable<CompletableFuture<Map<Identifier, Tag.Builder>>> info) {
|
||||
CompletableFuture<Map<Identifier, Tag.Builder>> future = info.getReturnValue();
|
||||
info.setReturnValue(CompletableFuture.supplyAsync(() -> {
|
||||
Map<Identifier, Tag.Builder> map = future.join();
|
||||
TagHelper.apply(entryType, map);
|
||||
return map;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue