-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add kill resurrected vampire advancement
- Loading branch information
1 parent
7aeb15e
commit fdc276e
Showing
8 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
src/generated/resources/data/vampirism/advancements/hunter/kill_resurrected_vampire.json
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,67 @@ | ||
{ | ||
"parent": "vampirism:hunter/become_hunter", | ||
"criteria": { | ||
"killed": { | ||
"conditions": { | ||
"entity": [ | ||
{ | ||
"condition": "minecraft:entity_properties", | ||
"entity": "this", | ||
"predicate": { | ||
"effects": { | ||
"vampirism:neonatal": {} | ||
}, | ||
"type_specific": { | ||
"faction": { | ||
"id": "vampirism:vampire" | ||
}, | ||
"level": 1 | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"trigger": "minecraft:player_killed_entity" | ||
}, | ||
"main": { | ||
"conditions": { | ||
"type": "LEVEL", | ||
"faction": "vampirism:hunter", | ||
"level": 1 | ||
}, | ||
"trigger": "vampirism:faction" | ||
} | ||
}, | ||
"display": { | ||
"announce_to_chat": true, | ||
"description": { | ||
"extra": [ | ||
{ | ||
"text": "\n" | ||
}, | ||
{ | ||
"translate": "advancement.vampirism.kill_resurrected_vampire.desc" | ||
} | ||
], | ||
"translate": "advancement.vampirism.kill_resurrected_vampire" | ||
}, | ||
"frame": "task", | ||
"hidden": true, | ||
"icon": { | ||
"item": "vampirism:soul_orb_vampire" | ||
}, | ||
"show_toast": true, | ||
"title": { | ||
"translate": "advancement.vampirism.kill_resurrected_vampire" | ||
} | ||
}, | ||
"requirements": [ | ||
[ | ||
"killed" | ||
], | ||
[ | ||
"main" | ||
] | ||
], | ||
"sends_telemetry_event": true | ||
} |
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
88 changes: 88 additions & 0 deletions
88
src/main/java/de/teamlapen/vampirism/advancements/critereon/FactionSubPredicate.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,88 @@ | ||
package de.teamlapen.vampirism.advancements.critereon; | ||
|
||
import com.google.common.base.Preconditions; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.mojang.datafixers.util.Pair; | ||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.DataResult; | ||
import com.mojang.serialization.JsonOps; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import de.teamlapen.vampirism.api.entity.factions.IFaction; | ||
import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; | ||
import de.teamlapen.vampirism.entity.factions.FactionPlayerHandler; | ||
import net.minecraft.advancements.critereon.EntitySubPredicate; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.phys.Vec3; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.jetbrains.annotations.Range; | ||
|
||
import java.util.Optional; | ||
|
||
public class FactionSubPredicate implements EntitySubPredicate { | ||
|
||
private static final Codec<FactionSubPredicate> CODEC = RecordCodecBuilder.create(instance -> instance.group( | ||
IPlayableFaction.CODEC.optionalFieldOf("faction").forGetter(p -> Optional.ofNullable(p.faction)), | ||
Codec.INT.fieldOf("level").forGetter(p -> p.level) | ||
).apply(instance, (Optional<IFaction<?>> faction1, Integer level1) -> new FactionSubPredicate(((IPlayableFaction<?>) faction1.orElse(null)), level1))); | ||
|
||
@Nullable | ||
private final IPlayableFaction<?> faction; | ||
@Range(from = 1, to = Integer.MAX_VALUE) | ||
private final int level; | ||
|
||
private FactionSubPredicate(@Nullable IPlayableFaction<?> faction, int level) { | ||
Preconditions.checkArgument(level > 0, "Level must be greater than 0"); | ||
this.faction = faction; | ||
this.level = level; | ||
} | ||
|
||
public static FactionSubPredicate of(@NotNull IPlayableFaction<?> faction) { | ||
return new FactionSubPredicate(faction, 1); | ||
} | ||
|
||
public static FactionSubPredicate of(@NotNull IPlayableFaction<?> faction, @Range(from = 1, to = Integer.MAX_VALUE) int level) { | ||
return new FactionSubPredicate(faction, level); | ||
} | ||
|
||
public static FactionSubPredicate of(@Range(from = 1, to = Integer.MAX_VALUE) int level) { | ||
return new FactionSubPredicate(null, level); | ||
} | ||
|
||
@Override | ||
public boolean matches(@NotNull Entity pEntity, @NotNull ServerLevel pLevel, @Nullable Vec3 p_218830_) { | ||
if (pEntity instanceof Player player) { | ||
return FactionPlayerHandler.getOpt(player).map(handler -> { | ||
IPlayableFaction<?> currentFaction = handler.getCurrentFaction(); | ||
if (currentFaction != null) { | ||
if (this.faction == null) { | ||
return handler.getCurrentLevel() >= this.level; | ||
} else if (currentFaction == this.faction) { | ||
return handler.getCurrentLevel() >= this.level; | ||
} | ||
} | ||
return false; | ||
}).orElse(false); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public @NotNull JsonObject serializeCustomData() { | ||
DataResult<JsonElement> jsonElementDataResult = CODEC.encodeStart(JsonOps.INSTANCE, this); | ||
return jsonElementDataResult.result().orElseThrow().getAsJsonObject(); | ||
} | ||
|
||
@Override | ||
public @NotNull Type type() { | ||
return FactionSubPredicate::fromJson; | ||
} | ||
|
||
public static FactionSubPredicate fromJson(JsonObject json) { | ||
DataResult<Pair<FactionSubPredicate, JsonElement>> decode = CODEC.decode(JsonOps.INSTANCE, json); | ||
return decode.result().orElseThrow().getFirst(); | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
src/main/java/de/teamlapen/vampirism/mixin/EntitySubPredicateTypesAccessor.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,19 @@ | ||
package de.teamlapen.vampirism.mixin; | ||
|
||
import com.google.common.collect.BiMap; | ||
import net.minecraft.advancements.critereon.EntitySubPredicate; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Mutable; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
@Mixin(EntitySubPredicate.Types.class) | ||
public interface EntitySubPredicateTypesAccessor { | ||
|
||
@Final | ||
@Mutable | ||
@Accessor("TYPES") | ||
static void setTypes(BiMap<String, EntitySubPredicate.Type> types) { | ||
throw new IllegalStateException("Mixin failed to apply"); | ||
} | ||
} |
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