-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…ocs and stuff
- Loading branch information
Showing
15 changed files
with
414 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
common-1.16.5/src/main/java/agency/highlysuspect/apathy/rule/PartialSpecEffect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package agency.highlysuspect.apathy.rule; | ||
|
||
import agency.highlysuspect.apathy.VerConv; | ||
import agency.highlysuspect.apathy.core.Apathy; | ||
import agency.highlysuspect.apathy.core.rule.CoolGsonHelper; | ||
import agency.highlysuspect.apathy.core.rule.JsonSerializer; | ||
import agency.highlysuspect.apathy.core.rule.Partial; | ||
import agency.highlysuspect.apathy.core.rule.PartialSpecAlways; | ||
import agency.highlysuspect.apathy.core.rule.Spec; | ||
import agency.highlysuspect.apathy.core.rule.Who; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonPrimitive; | ||
import net.minecraft.core.Registry; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.effect.MobEffect; | ||
import net.minecraft.world.entity.LivingEntity; | ||
|
||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public class PartialSpecEffect implements Spec<Partial, PartialSpecEffect> { | ||
public PartialSpecEffect(Set<MobEffect> mobEffects, Who who) { | ||
this.mobEffects = mobEffects; | ||
this.who = who; | ||
} | ||
|
||
private final Set<MobEffect> mobEffects; | ||
private final Who who; | ||
|
||
@Override | ||
public Spec<Partial, ?> optimize() { | ||
if(mobEffects.isEmpty()) return PartialSpecAlways.FALSE; | ||
else return this; | ||
} | ||
|
||
@Override | ||
public Partial build() { | ||
//i love useless microoptimizations | ||
if(mobEffects.size() == 1) { | ||
MobEffect theEffect = mobEffects.iterator().next(); | ||
return (attacker, defender) -> { | ||
LivingEntity which = who.choose(VerConv.mob(attacker), VerConv.player(defender)); | ||
return which.hasEffect(theEffect); | ||
}; | ||
} else return (attacker, defender) -> { | ||
LivingEntity which = who.choose(VerConv.mob(attacker), VerConv.player(defender)); | ||
for(MobEffect effect : mobEffects) { | ||
if(which.hasEffect(effect)) return true; | ||
} | ||
return false; | ||
}; | ||
} | ||
|
||
@Override | ||
public JsonSerializer<PartialSpecEffect> getSerializer() { | ||
return Serializer.INSTANCE; | ||
} | ||
|
||
public static class Serializer implements JsonSerializer<PartialSpecEffect> { | ||
public static final Serializer INSTANCE = new Serializer(); | ||
|
||
@Override | ||
public void write(PartialSpecEffect thing, JsonObject json) { | ||
json.add("effects", thing.mobEffects.stream() | ||
.map(Registry.MOB_EFFECT::getKey) | ||
.filter(Objects::nonNull) | ||
.map(ResourceLocation::toString) | ||
.map(JsonPrimitive::new) | ||
.collect(CoolGsonHelper.toJsonArray())); | ||
json.addProperty("who", thing.who.toString()); | ||
} | ||
|
||
@Override | ||
public PartialSpecEffect read(JsonObject json) { | ||
Set<MobEffect> mobEffects = CoolGsonHelper.streamArray(json.getAsJsonArray("effects")) | ||
.map(JsonElement::getAsString) | ||
.map(ResourceLocation::new) | ||
.flatMap(rl -> { | ||
MobEffect effect = Registry.MOB_EFFECT.get(rl); | ||
if(effect == null) { | ||
Apathy.instance.log.error("unknown mob effect: " + rl); | ||
return Stream.of(); | ||
} else return Stream.of(effect); | ||
}) | ||
.collect(Collectors.toSet()); | ||
Who who = Who.fromString(json.get("who").getAsString()); | ||
return new PartialSpecEffect(mobEffects, who); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
common-1.18.2/src/main/java/agency/highlysuspect/apathy/rule/PartialSpecEffect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package agency.highlysuspect.apathy.rule; | ||
|
||
import agency.highlysuspect.apathy.VerConv; | ||
import agency.highlysuspect.apathy.core.Apathy; | ||
import agency.highlysuspect.apathy.core.rule.CoolGsonHelper; | ||
import agency.highlysuspect.apathy.core.rule.JsonSerializer; | ||
import agency.highlysuspect.apathy.core.rule.Partial; | ||
import agency.highlysuspect.apathy.core.rule.PartialSpecAlways; | ||
import agency.highlysuspect.apathy.core.rule.Spec; | ||
import agency.highlysuspect.apathy.core.rule.Who; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonPrimitive; | ||
import net.minecraft.core.Registry; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.effect.MobEffect; | ||
import net.minecraft.world.entity.LivingEntity; | ||
|
||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public class PartialSpecEffect implements Spec<Partial, PartialSpecEffect> { | ||
public PartialSpecEffect(Set<MobEffect> mobEffects, Who who) { | ||
this.mobEffects = mobEffects; | ||
this.who = who; | ||
} | ||
|
||
private final Set<MobEffect> mobEffects; | ||
private final Who who; | ||
|
||
@Override | ||
public Spec<Partial, ?> optimize() { | ||
if(mobEffects.isEmpty()) return PartialSpecAlways.FALSE; | ||
else return this; | ||
} | ||
|
||
@Override | ||
public Partial build() { | ||
//i love useless microoptimizations | ||
if(mobEffects.size() == 1) { | ||
MobEffect theEffect = mobEffects.iterator().next(); | ||
return (attacker, defender) -> { | ||
LivingEntity which = who.choose(VerConv.mob(attacker), VerConv.player(defender)); | ||
return which.hasEffect(theEffect); | ||
}; | ||
} else return (attacker, defender) -> { | ||
LivingEntity which = who.choose(VerConv.mob(attacker), VerConv.player(defender)); | ||
for(MobEffect effect : mobEffects) { | ||
if(which.hasEffect(effect)) return true; | ||
} | ||
return false; | ||
}; | ||
} | ||
|
||
@Override | ||
public JsonSerializer<PartialSpecEffect> getSerializer() { | ||
return Serializer.INSTANCE; | ||
} | ||
|
||
public static class Serializer implements JsonSerializer<PartialSpecEffect> { | ||
public static final Serializer INSTANCE = new Serializer(); | ||
|
||
@Override | ||
public void write(PartialSpecEffect thing, JsonObject json) { | ||
json.add("effects", thing.mobEffects.stream() | ||
.map(Registry.MOB_EFFECT::getKey) | ||
.filter(Objects::nonNull) | ||
.map(ResourceLocation::toString) | ||
.map(JsonPrimitive::new) | ||
.collect(CoolGsonHelper.toJsonArray())); | ||
json.addProperty("who", thing.who.toString()); | ||
} | ||
|
||
@Override | ||
public PartialSpecEffect read(JsonObject json) { | ||
Set<MobEffect> mobEffects = CoolGsonHelper.streamArray(json.getAsJsonArray("effects")) | ||
.map(JsonElement::getAsString) | ||
.map(ResourceLocation::new) | ||
.flatMap(rl -> { | ||
MobEffect effect = Registry.MOB_EFFECT.get(rl); | ||
if(effect == null) { | ||
Apathy.instance.log.error("unknown mob effect: " + rl); | ||
return Stream.of(); | ||
} else return Stream.of(effect); | ||
}) | ||
.collect(Collectors.toSet()); | ||
Who who = Who.fromString(json.get("who").getAsString()); | ||
return new PartialSpecEffect(mobEffects, who); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...1.19.2-begrudgingly/src/main/java/agency/highlysuspect/apathy/rule/PartialSpecEffect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package agency.highlysuspect.apathy.rule; | ||
|
||
import agency.highlysuspect.apathy.VerConv; | ||
import agency.highlysuspect.apathy.core.Apathy; | ||
import agency.highlysuspect.apathy.core.rule.CoolGsonHelper; | ||
import agency.highlysuspect.apathy.core.rule.JsonSerializer; | ||
import agency.highlysuspect.apathy.core.rule.Partial; | ||
import agency.highlysuspect.apathy.core.rule.PartialSpecAlways; | ||
import agency.highlysuspect.apathy.core.rule.Spec; | ||
import agency.highlysuspect.apathy.core.rule.Who; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonPrimitive; | ||
import net.minecraft.core.Registry; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.effect.MobEffect; | ||
import net.minecraft.world.entity.LivingEntity; | ||
|
||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public class PartialSpecEffect implements Spec<Partial, PartialSpecEffect> { | ||
public PartialSpecEffect(Set<MobEffect> mobEffects, Who who) { | ||
this.mobEffects = mobEffects; | ||
this.who = who; | ||
} | ||
|
||
private final Set<MobEffect> mobEffects; | ||
private final Who who; | ||
|
||
@Override | ||
public Spec<Partial, ?> optimize() { | ||
if(mobEffects.isEmpty()) return PartialSpecAlways.FALSE; | ||
else return this; | ||
} | ||
|
||
@Override | ||
public Partial build() { | ||
//i love useless microoptimizations | ||
if(mobEffects.size() == 1) { | ||
MobEffect theEffect = mobEffects.iterator().next(); | ||
return (attacker, defender) -> { | ||
LivingEntity which = who.choose(VerConv.mob(attacker), VerConv.player(defender)); | ||
return which.hasEffect(theEffect); | ||
}; | ||
} else return (attacker, defender) -> { | ||
LivingEntity which = who.choose(VerConv.mob(attacker), VerConv.player(defender)); | ||
for(MobEffect effect : mobEffects) { | ||
if(which.hasEffect(effect)) return true; | ||
} | ||
return false; | ||
}; | ||
} | ||
|
||
@Override | ||
public JsonSerializer<PartialSpecEffect> getSerializer() { | ||
return Serializer.INSTANCE; | ||
} | ||
|
||
public static class Serializer implements JsonSerializer<PartialSpecEffect> { | ||
public static final Serializer INSTANCE = new Serializer(); | ||
|
||
@Override | ||
public void write(PartialSpecEffect thing, JsonObject json) { | ||
json.add("effects", thing.mobEffects.stream() | ||
.map(Registry.MOB_EFFECT::getKey) | ||
.filter(Objects::nonNull) | ||
.map(ResourceLocation::toString) | ||
.map(JsonPrimitive::new) | ||
.collect(CoolGsonHelper.toJsonArray())); | ||
json.addProperty("who", thing.who.toString()); | ||
} | ||
|
||
@Override | ||
public PartialSpecEffect read(JsonObject json) { | ||
Set<MobEffect> mobEffects = CoolGsonHelper.streamArray(json.getAsJsonArray("effects")) | ||
.map(JsonElement::getAsString) | ||
.map(ResourceLocation::new) | ||
.flatMap(rl -> { | ||
MobEffect effect = Registry.MOB_EFFECT.get(rl); | ||
if(effect == null) { | ||
Apathy.instance.log.error("unknown mob effect: " + rl); | ||
return Stream.of(); | ||
} else return Stream.of(effect); | ||
}) | ||
.collect(Collectors.toSet()); | ||
Who who = Who.fromString(json.get("who").getAsString()); | ||
return new PartialSpecEffect(mobEffects, who); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.