-
Notifications
You must be signed in to change notification settings - Fork 754
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement mapping from enchantments to modifiers
TODO: add tags for common ones from other mods
- Loading branch information
1 parent
c72210a
commit bcafa06
Showing
6 changed files
with
283 additions
and
4 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/generated/resources/data/tconstruct/tinkering/enchantments_to_modifiers.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,31 @@ | ||
{ | ||
"minecraft:unbreaking": "tconstruct:reinforced", | ||
"minecraft:protection": "tconstruct:protection", | ||
"minecraft:fire_protection": "tconstruct:fire_protection", | ||
"minecraft:blast_protection": "tconstruct:blast_protection", | ||
"minecraft:projectile_protection": "tconstruct:projectile_protection", | ||
"minecraft:feather_falling": "tconstruct:feather_falling", | ||
"minecraft:respiration": "tconstruct:respiration", | ||
"minecraft:aqua_affinity": "tconstruct:aqua_affinity", | ||
"minecraft:thorns": "tconstruct:thorns", | ||
"minecraft:frost_walker": "tconstruct:frost_walker", | ||
"minecraft:soul_speed": "tconstruct:soulspeed", | ||
"minecraft:sharpness": "tconstruct:sharpness", | ||
"minecraft:smite": "tconstruct:smite", | ||
"minecraft:bane_of_arthropods": "tconstruct:bane_of_sssss", | ||
"minecraft:knockback": "tconstruct:knockback", | ||
"minecraft:fire_aspect": "tconstruct:fiery", | ||
"minecraft:looting": "tconstruct:looting", | ||
"minecraft:sweeping": "tconstruct:sweeping_edge", | ||
"minecraft:impaling": "tconstruct:antiaquatic", | ||
"minecraft:efficiency": "tconstruct:haste", | ||
"minecraft:silk_touch": "tconstruct:silky", | ||
"minecraft:fortune": "tconstruct:fortune", | ||
"minecraft:power": "tconstruct:power", | ||
"minecraft:punch": "tconstruct:punch", | ||
"minecraft:flame": "tconstruct:fiery", | ||
"minecraft:infinity": "tconstruct:crystalshot", | ||
"minecraft:multishot": "tconstruct:multishot", | ||
"minecraft:quick_charge": "tconstruct:quick_charge", | ||
"minecraft:piercing": "tconstruct:impaling" | ||
} |
54 changes: 54 additions & 0 deletions
54
...slimeknights/tconstruct/library/data/tinkering/AbstractEnchantmentToModifierProvider.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,54 @@ | ||
package slimeknights.tconstruct.library.data.tinkering; | ||
|
||
import com.google.gson.JsonObject; | ||
import net.minecraft.data.DataGenerator; | ||
import net.minecraft.data.HashCache; | ||
import net.minecraft.server.packs.PackType; | ||
import net.minecraft.tags.TagKey; | ||
import net.minecraft.world.item.enchantment.Enchantment; | ||
import slimeknights.mantle.data.GenericDataProvider; | ||
import slimeknights.tconstruct.TConstruct; | ||
import slimeknights.tconstruct.library.modifiers.ModifierId; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
/** Data generator for mappings from enchantments to modifiers */ | ||
public abstract class AbstractEnchantmentToModifierProvider extends GenericDataProvider { | ||
/** Compiled JSON to save, no need to do anything fancier, it already does merging for us */ | ||
private final JsonObject enchantmentMap = new JsonObject(); | ||
|
||
public AbstractEnchantmentToModifierProvider(DataGenerator generator) { | ||
super(generator, PackType.SERVER_DATA, "tinkering"); | ||
} | ||
|
||
/** Add any mappings */ | ||
protected abstract void addEnchantmentMappings(); | ||
|
||
@Override | ||
public void run(HashCache pCache) throws IOException { | ||
enchantmentMap.entrySet().clear(); | ||
addEnchantmentMappings(); | ||
saveThing(pCache, TConstruct.getResource("enchantments_to_modifiers"), enchantmentMap); | ||
} | ||
|
||
/* Helpers */ | ||
|
||
/** Adds the given enchantment */ | ||
protected void add(Enchantment enchantment, ModifierId modifierId) { | ||
String key = Objects.requireNonNull(enchantment.getRegistryName()).toString(); | ||
if (enchantmentMap.has(key)) { | ||
throw new IllegalArgumentException("Duplicate enchantment " + key); | ||
} | ||
enchantmentMap.addProperty(key, modifierId.toString()); | ||
} | ||
|
||
/** Adds the given enchantment tag */ | ||
protected void add(TagKey<Enchantment> tag, ModifierId modifierId) { | ||
String key = "#" + tag.location(); | ||
if (enchantmentMap.has(key)) { | ||
throw new IllegalArgumentException("Duplicate enchantment tag " + tag.location()); | ||
} | ||
enchantmentMap.addProperty(key, modifierId.toString()); | ||
} | ||
} |
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
Oops, something went wrong.