Skip to content

Commit

Permalink
Implement modifier and material tags
Browse files Browse the repository at this point in the history
Modifier tags can be used in modifier entries as part of the compound logic. They also are needed for a future feature
Material tags work in random materials and as a filter for the book
  • Loading branch information
KnightMiner committed Oct 9, 2022
1 parent 945f79e commit 288eb4d
Show file tree
Hide file tree
Showing 22 changed files with 804 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,8 @@
"upgrades": 1
},
"requirements": {
"options": [
{
"name": "tconstruct:diamond",
"level": 1
},
{
"name": "tconstruct:emerald",
"level": 1
}
],
"matches_needed": 1,
"tag": "tconstruct:gems",
"level": 1,
"error": "recipe.tconstruct.modifier.netherite_requirements"
},
"result": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"replace": false,
"values": [
"tconstruct:wood",
"tconstruct:flint",
"tconstruct:rock",
"tconstruct:bone",
"tconstruct:leather",
"tconstruct:vine",
"tconstruct:string",
"tconstruct:iron",
"tconstruct:scorched_stone",
"tconstruct:slimewood",
"tconstruct:necrotic_bone",
"tconstruct:bloodbone",
"tconstruct:chain",
"tconstruct:nahuatl",
"tconstruct:cobalt",
"tconstruct:darkthread",
"tconstruct:manyullyn",
"tconstruct:queens_slime",
"tconstruct:blazing_bone",
"tconstruct:ancient_hide"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"replace": false,
"values": [
{
"id": "tconstruct:diamond",
"required": false
},
{
"id": "tconstruct:emerald",
"required": false
}
]
}
26 changes: 26 additions & 0 deletions src/main/java/slimeknights/tconstruct/common/TinkerTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.material.Fluid;
import slimeknights.tconstruct.TConstruct;
import slimeknights.tconstruct.library.materials.definition.IMaterial;
import slimeknights.tconstruct.library.materials.definition.MaterialManager;
import slimeknights.tconstruct.library.modifiers.Modifier;
import slimeknights.tconstruct.library.modifiers.ModifierManager;
import slimeknights.tconstruct.library.tools.stat.ToolStats;

public class TinkerTags {
Expand All @@ -21,6 +25,8 @@ public static void init() {
EntityTypes.init();
TileEntityTypes.init();
Biomes.init();
Modifiers.init();
Materials.init();
}

public static class Blocks {
Expand Down Expand Up @@ -442,4 +448,24 @@ private static TagKey<Biome> tag(String name) {
return TagKey.create(Registry.BIOME_REGISTRY, TConstruct.getResource(name));
}
}

public static class Modifiers {
private static void init() {}
/** Gem modifiers, one of which is needed for netherite */
public static final TagKey<Modifier> GEMS = tag("gems");

private static TagKey<Modifier> tag(String name) {
return ModifierManager.getTag(TConstruct.getResource(name));
}
}

public static class Materials {
private static void init() {}
/** Materials available in nether */
public static final TagKey<IMaterial> NETHER = tag("nether");

private static TagKey<IMaterial> tag(String name) {
return MaterialManager.getTag(TConstruct.getResource(name));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package slimeknights.tconstruct.common.data.tags;

import net.minecraft.data.DataGenerator;
import net.minecraftforge.common.data.ExistingFileHelper;
import slimeknights.tconstruct.TConstruct;
import slimeknights.tconstruct.common.TinkerTags;
import slimeknights.tconstruct.library.data.tinkering.AbstractMaterialTagProvider;
import slimeknights.tconstruct.tools.data.material.MaterialIds;

public class MaterialTagProvider extends AbstractMaterialTagProvider {
public MaterialTagProvider(DataGenerator generator, ExistingFileHelper existingFileHelper) {
super(generator, TConstruct.MOD_ID, existingFileHelper);
}

@Override
protected void addTags() {
tag(TinkerTags.Materials.NETHER).add(
// tier 1
MaterialIds.wood, MaterialIds.flint, MaterialIds.rock, MaterialIds.bone,
MaterialIds.leather, MaterialIds.vine, MaterialIds.string,
// tier 2
MaterialIds.iron, MaterialIds.scorchedStone, MaterialIds.slimewood, MaterialIds.necroticBone, MaterialIds.bloodbone,
MaterialIds.chain,
// tier 3
MaterialIds.nahuatl, MaterialIds.cobalt,
MaterialIds.darkthread,
// tier 4
MaterialIds.manyullyn, MaterialIds.queensSlime, MaterialIds.blazingBone,
MaterialIds.ancientHide
);
}

@Override
public String getName() {
return "Tinkers' Construct Material Tag Provider";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package slimeknights.tconstruct.common.data.tags;

import net.minecraft.data.DataGenerator;
import net.minecraftforge.common.data.ExistingFileHelper;
import slimeknights.tconstruct.TConstruct;
import slimeknights.tconstruct.common.TinkerTags;
import slimeknights.tconstruct.library.data.tinkering.AbstractModifierTagProvider;
import slimeknights.tconstruct.tools.data.ModifierIds;

public class ModifierTagProvider extends AbstractModifierTagProvider {
public ModifierTagProvider(DataGenerator generator, ExistingFileHelper existingFileHelper) {
super(generator, TConstruct.MOD_ID, existingFileHelper);
}

@Override
protected void addTags() {
tag(TinkerTags.Modifiers.GEMS).addOptional(ModifierIds.diamond, ModifierIds.emerald);
}

@Override
public String getName() {
return "Tinkers' Construct Modifier Tag Provider";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.util.GsonHelper;
import slimeknights.mantle.client.book.data.BookData;
import slimeknights.mantle.client.book.data.SectionData;
import slimeknights.mantle.client.book.transformer.BookTransformer;
import slimeknights.mantle.util.JsonHelper;
import slimeknights.tconstruct.TConstruct;
import slimeknights.tconstruct.library.client.book.content.ContentMaterial;
import slimeknights.tconstruct.library.materials.IMaterialRegistry;
import slimeknights.tconstruct.library.materials.MaterialRegistry;
import slimeknights.tconstruct.library.materials.definition.IMaterial;
import slimeknights.tconstruct.library.materials.definition.MaterialId;
import slimeknights.tconstruct.library.materials.definition.MaterialManager;
import slimeknights.tconstruct.library.materials.stats.IMaterialStats;
import slimeknights.tconstruct.library.materials.stats.MaterialStatsId;
import slimeknights.tconstruct.tools.stats.ExtraMaterialStats;
import slimeknights.tconstruct.tools.stats.HandleMaterialStats;
import slimeknights.tconstruct.tools.stats.HeadMaterialStats;

import javax.annotation.Nullable;
import java.util.Set;
import java.util.function.Predicate;

Expand All @@ -37,13 +43,22 @@ public void transform(BookData book) {
JsonElement json = section.extraData.get(KEY);
if (json != null) {
try {
int min, max;
int min = 0;
int max = Integer.MAX_VALUE;
boolean detailed;
TagKey<IMaterial> tag = null;

// if primitive, its either an int tier, or a tag
if (json.isJsonPrimitive()) {
min = json.getAsInt();
max = min;
if (json.getAsJsonPrimitive().isNumber()) {
min = json.getAsInt();
max = min;
} else {
tag = MaterialManager.getTag(JsonHelper.convertToResourceLocation(json, KEY.toString()));
}
detailed = false;
} else if (json.isJsonObject()) {
// object means we have a tier/min/max, or potentially a tag
JsonObject jsonObject = json.getAsJsonObject();
if (jsonObject.has("tier")) {
min = GsonHelper.getAsInt(jsonObject, "tier");
Expand All @@ -53,10 +68,13 @@ public void transform(BookData book) {
max = GsonHelper.getAsInt(jsonObject, "max", Integer.MAX_VALUE);
}
detailed = GsonHelper.getAsBoolean(jsonObject, "detailed", false);
if (jsonObject.has("tag")) {
tag = MaterialManager.getTag(JsonHelper.getResourceLocation(jsonObject, "tag"));
}
} else {
throw new JsonSyntaxException("Invalid tconstruct:material_tier, expected number or JSON object");
}
AbstractMaterialSectionTransformer.createPages(book, section, new ValidMaterial(VISIBLE_STATS, min, max), id -> new ContentMaterial(id, detailed));
AbstractMaterialSectionTransformer.createPages(book, section, new ValidMaterial(VISIBLE_STATS, min, max, tag), id -> new ContentMaterial(id, detailed));
} catch (JsonSyntaxException e) {
TConstruct.LOG.error("Failed to parse material tier section data", e);
}
Expand All @@ -65,16 +83,26 @@ public void transform(BookData book) {
}

/** Helper to create a material predicate */
public record ValidMaterial(Set<MaterialStatsId> visibleStats, int min, int max) implements Predicate<IMaterial> {
public record ValidMaterial(Set<MaterialStatsId> visibleStats, int min, int max, @Nullable TagKey<IMaterial> tag) implements Predicate<IMaterial> {
@Deprecated
public ValidMaterial(Set<MaterialStatsId> visibleStats, int min, int max) {
this(visibleStats, min, max, null);
}

@Override
public boolean test(IMaterial material) {
int tier = material.getTier();
if (tier < min || tier > max) {
return false;
}
IMaterialRegistry registry = MaterialRegistry.getInstance();
MaterialId id = material.getIdentifier();
if (tag != null && !registry.isInTag(id, tag)) {
return false;
}
// only show material stats for types with the proper stat types, as otherwise the page will be empty
// if you want to show another stat type, just override this method/implement the parent class
for (IMaterialStats stats : MaterialRegistry.getInstance().getAllStats(material.getIdentifier())) {
for (IMaterialStats stats : registry.getAllStats(id)) {
if (visibleStats.contains(stats.getIdentifier())) {
return true;
}
Expand Down

0 comments on commit 288eb4d

Please sign in to comment.