Fix duplicate entry for loot tables (#389)

This commit is contained in:
IzzelAliz 2021-12-01 17:24:53 +08:00
parent e92876943d
commit c59c507524
No known key found for this signature in database
GPG Key ID: EE50E123A11D8338

View File

@ -2,18 +2,19 @@ package io.izzel.arclight.common.mixin.core.world.level.storage.loot;
import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonObject;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.level.storage.loot.LootTable;
import net.minecraft.world.level.storage.loot.LootTables;
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.CallbackInfo;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.level.storage.loot.LootTable;
import net.minecraft.world.level.storage.loot.LootTables;
@Mixin(LootTables.class)
public class LootTableManagerMixin {
@ -24,10 +25,10 @@ public class LootTableManagerMixin {
public Map<LootTable, ResourceLocation> lootTableToKey = ImmutableMap.of();
@Inject(method = "apply", at = @At("RETURN"))
@Inject(method = "apply(Ljava/util/Map;Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/util/profiling/ProfilerFiller;)V", at = @At("RETURN"))
private void arclight$buildRev(Map<ResourceLocation, JsonObject> objectIn, ResourceManager resourceManagerIn, ProfilerFiller profilerIn, CallbackInfo ci) {
ImmutableMap.Builder<LootTable, ResourceLocation> lootTableToKeyBuilder = ImmutableMap.builder();
Map<LootTable, ResourceLocation> lootTableToKeyBuilder = new HashMap<>();
this.tables.forEach((lootTable, key) -> lootTableToKeyBuilder.put(key, lootTable));
this.lootTableToKey = lootTableToKeyBuilder.build();
this.lootTableToKey = ImmutableMap.copyOf(lootTableToKeyBuilder);
}
}