2020-07-22 06:23:34 +01:00
|
|
|
package net.minecraft.advancements.critereon;
|
|
|
|
|
|
|
|
import com.google.gson.JsonElement;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import net.minecraft.advancements.CriterionTriggerInstance;
|
|
|
|
import net.minecraft.world.entity.Entity;
|
|
|
|
import java.util.Collection;
|
|
|
|
import net.minecraft.server.level.ServerPlayer;
|
|
|
|
import com.google.gson.JsonDeserializationContext;
|
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
import net.minecraft.resources.ResourceLocation;
|
|
|
|
|
2020-07-22 06:25:47 +01:00
|
|
|
public class ChanneledLightningTrigger extends SimpleCriterionTrigger<TriggerInstance> {
|
2020-07-22 06:23:34 +01:00
|
|
|
private static final ResourceLocation ID;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ResourceLocation getId() {
|
|
|
|
return ChanneledLightningTrigger.ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TriggerInstance createInstance(final JsonObject jsonObject, final JsonDeserializationContext jsonDeserializationContext) {
|
|
|
|
final EntityPredicate[] arr4 = EntityPredicate.fromJsonArray(jsonObject.get("victims"));
|
|
|
|
return new TriggerInstance(arr4);
|
|
|
|
}
|
|
|
|
|
2020-07-22 06:25:47 +01:00
|
|
|
public void trigger(final ServerPlayer xe, final Collection<? extends Entity> collection) {
|
|
|
|
this.trigger(xe.getAdvancements(), a -> a.matches(xe, collection));
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static {
|
|
|
|
ID = new ResourceLocation("channeled_lightning");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
|
|
|
private final EntityPredicate[] victims;
|
|
|
|
|
|
|
|
public TriggerInstance(final EntityPredicate[] arr) {
|
|
|
|
super(ChanneledLightningTrigger.ID);
|
|
|
|
this.victims = arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static TriggerInstance channeledLightning(final EntityPredicate... arr) {
|
|
|
|
return new TriggerInstance(arr);
|
|
|
|
}
|
|
|
|
|
2020-07-22 06:25:47 +01:00
|
|
|
public boolean matches(final ServerPlayer xe, final Collection<? extends Entity> collection) {
|
|
|
|
for (final EntityPredicate bb7 : this.victims) {
|
2020-07-22 06:23:34 +01:00
|
|
|
boolean boolean8 = false;
|
2020-07-22 06:25:47 +01:00
|
|
|
for (final Entity akn10 : collection) {
|
|
|
|
if (bb7.matches(xe, akn10)) {
|
2020-07-22 06:23:34 +01:00
|
|
|
boolean8 = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!boolean8) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public JsonElement serializeToJson() {
|
|
|
|
final JsonObject jsonObject2 = new JsonObject();
|
|
|
|
jsonObject2.add("victims", EntityPredicate.serializeArrayToJson(this.victims));
|
|
|
|
return jsonObject2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|