package net.minecraft.server;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class LootItemConditionReference implements LootItemCondition {
private static final Logger LOGGER = LogManager.getLogger();
private final MinecraftKey b;
public LootItemConditionReference(MinecraftKey minecraftkey) {
this.b = minecraftkey;
}
@Override
public void a(LootCollector lootcollector) {
if (lootcollector.b(this.b)) {
lootcollector.a("Condition " + this.b + " is recursively called");
} else {
LootItemCondition.super.a(lootcollector);
LootItemCondition lootitemcondition = lootcollector.d(this.b);
if (lootitemcondition == null) {
lootcollector.a("Unknown condition table called " + this.b);
} else {
lootitemcondition.a(lootcollector.a(".{" + this.b + "}", this.b));
}
}
}
public boolean test(LootTableInfo loottableinfo) {
LootItemCondition lootitemcondition = loottableinfo.b(this.b);
if (loottableinfo.a(lootitemcondition)) {
boolean flag;
try {
flag = lootitemcondition.test(loottableinfo);
} finally {
loottableinfo.b(lootitemcondition);
}
return flag;
} else {
LootItemConditionReference.LOGGER.warn("Detected infinite loop in loot tables");
return false;
}
}
public static class a extends LootItemCondition.b<LootItemConditionReference> {
protected a() {
super(new MinecraftKey("reference"), LootItemConditionReference.class);
}
public void a(JsonObject jsonobject, LootItemConditionReference lootitemconditionreference, JsonSerializationContext jsonserializationcontext) {
jsonobject.addProperty("name", lootitemconditionreference.b.toString());
}
@Override
public LootItemConditionReference b(JsonObject jsonobject, JsonDeserializationContext jsondeserializationcontext) {
MinecraftKey minecraftkey = new MinecraftKey(ChatDeserializer.h(jsonobject, "name"));
return new LootItemConditionReference(minecraftkey);
}
}
}