-
Notifications
You must be signed in to change notification settings - Fork 756
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement 3 new advancements to take advantage of tool stat predicates
Netherite Tier is a simple stat in set check, usng the harvest tiers stat One shot is a stat minimum check Perfect aim checks for an exact stat value, the maximum value Also update the abilities advancement for new abilities
- Loading branch information
1 parent
3350452
commit 4d809a3
Showing
10 changed files
with
480 additions
and
60 deletions.
There are no files selected for viewing
264 changes: 216 additions & 48 deletions
264
src/generated/resources/data/tconstruct/advancements/smeltery/abilities.json
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
src/generated/resources/data/tconstruct/advancements/tools/material_master.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
42 changes: 42 additions & 0 deletions
42
src/generated/resources/data/tconstruct/advancements/tools/netherite_tier.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,42 @@ | ||
{ | ||
"parent": "tconstruct:tools/tinker_tool", | ||
"display": { | ||
"icon": { | ||
"item": "minecraft:netherite_ingot" | ||
}, | ||
"title": { | ||
"translate": "advancements.tconstruct.tools.netherite_tier.title" | ||
}, | ||
"description": { | ||
"translate": "advancements.tconstruct.tools.netherite_tier.description" | ||
}, | ||
"frame": "goal", | ||
"show_toast": true, | ||
"announce_to_chat": true, | ||
"hidden": false | ||
}, | ||
"criteria": { | ||
"harvest_level": { | ||
"trigger": "minecraft:inventory_changed", | ||
"conditions": { | ||
"items": [ | ||
{ | ||
"type": "tconstruct:tool_stack", | ||
"predicate": { | ||
"type": "tconstruct:stat_in_set", | ||
"stat": "tconstruct:harvest_tier", | ||
"values": [ | ||
"minecraft:netherite" | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"requirements": [ | ||
[ | ||
"harvest_level" | ||
] | ||
] | ||
} |
40 changes: 40 additions & 0 deletions
40
src/generated/resources/data/tconstruct/advancements/tools/one_shot.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,40 @@ | ||
{ | ||
"parent": "tconstruct:tools/tinker_tool", | ||
"display": { | ||
"icon": { | ||
"item": "minecraft:zombie_head" | ||
}, | ||
"title": { | ||
"translate": "advancements.tconstruct.tools.one_shot.title" | ||
}, | ||
"description": { | ||
"translate": "advancements.tconstruct.tools.one_shot.description" | ||
}, | ||
"frame": "goal", | ||
"show_toast": true, | ||
"announce_to_chat": true, | ||
"hidden": false | ||
}, | ||
"criteria": { | ||
"damage": { | ||
"trigger": "minecraft:inventory_changed", | ||
"conditions": { | ||
"items": [ | ||
{ | ||
"type": "tconstruct:tool_stack", | ||
"predicate": { | ||
"type": "tconstruct:stat_in_range", | ||
"stat": "tconstruct:attack_damage", | ||
"min": 20.0 | ||
} | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"requirements": [ | ||
[ | ||
"damage" | ||
] | ||
] | ||
} |
41 changes: 41 additions & 0 deletions
41
src/generated/resources/data/tconstruct/advancements/tools/perfect_aim.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,41 @@ | ||
{ | ||
"parent": "tconstruct:tools/tinker_tool", | ||
"display": { | ||
"icon": { | ||
"item": "minecraft:target" | ||
}, | ||
"title": { | ||
"translate": "advancements.tconstruct.tools.perfect_aim.title" | ||
}, | ||
"description": { | ||
"translate": "advancements.tconstruct.tools.perfect_aim.description" | ||
}, | ||
"frame": "goal", | ||
"show_toast": true, | ||
"announce_to_chat": true, | ||
"hidden": false | ||
}, | ||
"criteria": { | ||
"accuracy": { | ||
"trigger": "minecraft:inventory_changed", | ||
"conditions": { | ||
"items": [ | ||
{ | ||
"type": "tconstruct:tool_stack", | ||
"predicate": { | ||
"type": "tconstruct:stat_in_range", | ||
"stat": "tconstruct:accuracy", | ||
"min": 1.0, | ||
"max": 1.0 | ||
} | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"requirements": [ | ||
[ | ||
"accuracy" | ||
] | ||
] | ||
} |
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
95 changes: 95 additions & 0 deletions
95
src/main/java/slimeknights/tconstruct/library/json/predicate/tool/StatInSetPredicate.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,95 @@ | ||
package slimeknights.tconstruct.library.json.predicate.tool; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonObject; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.util.GsonHelper; | ||
import slimeknights.mantle.data.GenericLoaderRegistry.IGenericLoader; | ||
import slimeknights.mantle.data.predicate.IJsonPredicate; | ||
import slimeknights.mantle.util.JsonHelper; | ||
import slimeknights.tconstruct.library.tools.nbt.IToolContext; | ||
import slimeknights.tconstruct.library.tools.stat.IToolStat; | ||
import slimeknights.tconstruct.library.tools.stat.ToolStats; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* Predicate which checks if a stat is in the given set of values | ||
* @param <T> Stat type | ||
* @param stat Stat to check | ||
* @param values Set of values to match | ||
* @see slimeknights.tconstruct.library.tools.stat.StatPredicate | ||
*/ | ||
public record StatInSetPredicate<T>(IToolStat<T> stat, Set<T> values) implements ToolContextPredicate { | ||
public StatInSetPredicate(IToolStat<T> stat, T value) { | ||
this(stat, Set.of(value)); | ||
} | ||
|
||
@Override | ||
public boolean matches(IToolContext tool) { | ||
return values.contains(tool.getStats().get(stat)); | ||
} | ||
|
||
@Override | ||
public IGenericLoader<? extends IJsonPredicate<IToolContext>> getLoader() { | ||
return LOADER; | ||
} | ||
|
||
public static final IGenericLoader<StatInSetPredicate<?>> LOADER = new IGenericLoader<>() { | ||
@Override | ||
public StatInSetPredicate<?> deserialize(JsonObject json) { | ||
return deserialize(json, ToolStats.fromJson(GsonHelper.getAsString(json, "stat"))); | ||
} | ||
|
||
/** Handles generics for the set parsing */ | ||
private static <T> StatInSetPredicate<T> deserialize(JsonObject json, IToolStat<T> stat) { | ||
Set<T> values = ImmutableSet.copyOf(JsonHelper.parseList(json, "values", (element, key) -> stat.deserialize(element))); | ||
return new StatInSetPredicate<>(stat, values); | ||
} | ||
|
||
@Override | ||
public void serialize(StatInSetPredicate<?> object, JsonObject json) { | ||
json.addProperty("stat", object.stat.getName().toString()); | ||
serializeSet(object, json); | ||
} | ||
|
||
/** Handles generics for the set serializing */ | ||
private static <T> void serializeSet(StatInSetPredicate<T> object, JsonObject json) { | ||
JsonArray array = new JsonArray(); | ||
for (T value : object.values) { | ||
array.add(object.stat.serialize(value)); | ||
} | ||
json.add("values", array); | ||
} | ||
|
||
@Override | ||
public StatInSetPredicate<?> fromNetwork(FriendlyByteBuf buffer) { | ||
return fromNetwork(buffer, ToolStats.fromNetwork(buffer)); | ||
} | ||
|
||
/** Handles generics for the set reading */ | ||
private static <T> StatInSetPredicate<T> fromNetwork(FriendlyByteBuf buffer, IToolStat<T> stat) { | ||
ImmutableSet.Builder<T> builder = ImmutableSet.builder(); | ||
int max = buffer.readVarInt(); | ||
for (int i = 0; i < max; i++) { | ||
builder.add(stat.fromNetwork(buffer)); | ||
} | ||
return new StatInSetPredicate<>(stat, builder.build()); | ||
} | ||
|
||
@Override | ||
public void toNetwork(StatInSetPredicate<?> object, FriendlyByteBuf buffer) { | ||
buffer.writeUtf(object.stat.toString()); | ||
setToNetwork(object, buffer); | ||
} | ||
|
||
/** Handles generics for the set writing */ | ||
private static <T> void setToNetwork(StatInSetPredicate<T> object, FriendlyByteBuf buffer) { | ||
buffer.writeVarInt(object.values.size()); | ||
for (T value : object.values) { | ||
object.stat.toNetwork(buffer, value); | ||
} | ||
} | ||
}; | ||
} |
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