Skip to content

Commit

Permalink
物品标签
Browse files Browse the repository at this point in the history
  • Loading branch information
Gu-ZT committed Mar 3, 2024
1 parent 23c7106 commit 177a26f
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ gradle-app.setting
.gradletasknamecache

**/build/
**/generated/

# Common working directory
run/
Expand Down
32 changes: 31 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ plugins {
id 'maven-publish'
}

version = build_number == 'undefined' ? project.mod_version : "${project.mod_version}.build+${project.build_number}"
mod_id = project.mod_id
version = project.build_number == 'undefined' ? project.mod_version : "${project.mod_version}.build+${project.build_number}"
group = project.maven_group

base {
Expand All @@ -18,6 +19,21 @@ repositories {
// for more information about repositories.
}

loom {
runs {
// 这会添加一个运行数据生成 API 的新 gradle 任务:"gradlew runDatagen"
datagen {
inherit server
name "Data Generation"
vmArg "-Dfabric-api.datagen"
vmArg "-Dfabric-api.datagen.output-dir=${file("src/main/generated")}"
vmArg "-Dfabric-api.datagen.modid=${mod_id}"

runDir "build/datagen"
}
}
}

dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
Expand Down Expand Up @@ -64,12 +80,26 @@ java {
withSourcesJar()
}

jar.dependsOn(runDatagen)
jar {
from("src/main/generated"){
duplicatesStrategy DuplicatesStrategy.INCLUDE
}
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}" }
}
}

sourceSets {
main {
resources {
srcDirs += [
'src/main/generated'
]
}
}
}

// configure the maven publication
publishing {
publications {
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.15.7

# Mod Properties
mod_id = anvilcraft
mod_version = 0.0.1
maven_group = dev.dubhe
archives_base_name = AnvilCraft
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// 1.20.1 2024-03-04T03:25:06.9109196 AnvilCraft/Tags for minecraft:item
c2e0578add0db934d06b4790b09b1dea8bfe54d7 data\c\tags\items\flour.json
57f11b39a3960a24a6460feffe1a5c8c9e8f3368 data\c\tags\items\dough.json
57f11b39a3960a24a6460feffe1a5c8c9e8f3368 data\c\tags\items\dough\wheat.json
c2e0578add0db934d06b4790b09b1dea8bfe54d7 data\c\tags\items\flour\wheat.json
6 changes: 6 additions & 0 deletions src/main/generated/data/c/tags/items/dough.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"anvilcraft:dough"
]
}
6 changes: 6 additions & 0 deletions src/main/generated/data/c/tags/items/dough/wheat.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"anvilcraft:dough"
]
}
6 changes: 6 additions & 0 deletions src/main/generated/data/c/tags/items/flour.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"anvilcraft:flour"
]
}
6 changes: 6 additions & 0 deletions src/main/generated/data/c/tags/items/flour/wheat.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"anvilcraft:flour"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package dev.dubhe.anvilcraft.data;

import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;

public class AnvilCraftDataGenerator implements DataGeneratorEntrypoint {
@Override
public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {
FabricDataGenerator.Pack pack = fabricDataGenerator.createPack();
pack.addProvider(MyItemTagGenerator::new);
}
}
62 changes: 62 additions & 0 deletions src/main/java/dev/dubhe/anvilcraft/data/MyItemTagGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package dev.dubhe.anvilcraft.data;

import dev.dubhe.anvilcraft.items.ModItemTags;
import dev.dubhe.anvilcraft.items.ModItems;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.item.Item;

import java.util.concurrent.CompletableFuture;

public class MyItemTagGenerator extends FabricTagProvider<Item> {
public MyItemTagGenerator(FabricDataOutput output, CompletableFuture<HolderLookup.Provider> registriesFuture) {
super(output, Registries.ITEM, registriesFuture);
}

@Override
protected void addTags(HolderLookup.Provider arg) {
this.getOrCreateTagBuilder(ModItemTags.FLOUR).setReplace(false)
.add(ModItems.FLOUR);
this.getOrCreateTagBuilder(ModItemTags.WHEAT_FLOUR).setReplace(false)
.add(ModItems.FLOUR);
this.getOrCreateTagBuilder(ModItemTags.DOUGH).setReplace(false)
.add(ModItems.DOUGH);
this.getOrCreateTagBuilder(ModItemTags.WHEAT_DOUGH).setReplace(false)
.add(ModItems.DOUGH);
this.getOrCreateTagBuilder(ModItemTags.PICKAXES).setReplace(false)
.add(ModItems.AMETHYST_PICKAXE)
.add(ModItems.CHANGEABLE_PICKAXE_SILK_TOUCH)
.add(ModItems.CHANGEABLE_PICKAXE_FORTUNE);
this.getOrCreateTagBuilder(ModItemTags.AXES).setReplace(false)
.add(ModItems.AMETHYST_AXE);
this.getOrCreateTagBuilder(ModItemTags.HOES).setReplace(false)
.add(ModItems.AMETHYST_HOE);
this.getOrCreateTagBuilder(ModItemTags.SHOVELS).setReplace(false)
.add(ModItems.AMETHYST_SHOVEL);
this.getOrCreateTagBuilder(ModItemTags.SWORDS).setReplace(false)
.add(ModItems.AMETHYST_SWORD);
this.getOrCreateTagBuilder(ModItemTags.FOODS).setReplace(false)
.add(ModItems.CHOCOLATE)
.add(ModItems.CHOCOLATE_BLACK)
.add(ModItems.CHOCOLATE_WHITE)
.add(ModItems.CREAMY_BREAD_ROLL)
.add(ModItems.MEATBALLS)
.add(ModItems.DUMPLING)
.add(ModItems.SHENGJIAN)
.add(ModItems.SWEET_DUMPLING)
.add(ModItems.BEEF_MUSHROOM_STEW);
this.getOrCreateTagBuilder(ModItemTags.PROTOCOL).setReplace(false)
.add(ModItems.PROTOCOL_ABSORB)
.add(ModItems.PROTOCOL_PROTECT)
.add(ModItems.PROTOCOL_RESTOCK)
.add(ModItems.PROTOCOL_REPAIR);
this.getOrCreateTagBuilder(ModItemTags.RAW_FOODS).setReplace(false)
.add(ModItems.BEEF_MUSHROOM_STEW_RAW)
.add(ModItems.DUMPLING_RAW)
.add(ModItems.MEATBALLS_RAW)
.add(ModItems.SWEET_DUMPLING_RAW)
.add(ModItems.SHENGJIAN_RAW);
}
}
31 changes: 31 additions & 0 deletions src/main/java/dev/dubhe/anvilcraft/items/ModItemTags.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package dev.dubhe.anvilcraft.items;

import dev.dubhe.anvilcraft.AnvilCraft;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import org.jetbrains.annotations.NotNull;

public class ModItemTags {
public static final TagKey<Item> FLOUR = bindC("flour");
public static final TagKey<Item> WHEAT_FLOUR = bindC("flour/wheat");
public static final TagKey<Item> DOUGH = bindC("dough");
public static final TagKey<Item> WHEAT_DOUGH = bindC("dough/wheat");
public static final TagKey<Item> PICKAXES = bindC("pickaxes");
public static final TagKey<Item> AXES = bindC("axes");
public static final TagKey<Item> HOES = bindC("hoes");
public static final TagKey<Item> SHOVELS = bindC("shovels");
public static final TagKey<Item> SWORDS = bindC("swords");
public static final TagKey<Item> FOODS = bindC("foods");
public static final TagKey<Item> PROTOCOL = bind("protocol");
public static final TagKey<Item> RAW_FOODS = bind("raw_foods");

private static @NotNull TagKey<Item> bindC(String id) {
return TagKey.create(Registries.ITEM, new ResourceLocation("c", id));
}

private static @NotNull TagKey<Item> bind(String id) {
return TagKey.create(Registries.ITEM, AnvilCraft.of(id));
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
"repo": "https://github.com/Gu-ZT/AnvilCraft"
},
"license": "LGPL-3.0",
"icon": "assets/anvilcraft/icon.png",
"icon": "assets/anvilcraft/textures/icon.png",
"environment": "*",
"entrypoints": {
"client": [
"dev.dubhe.anvilcraft.client.AnvilCraftClient"
],
"main": [
"dev.dubhe.anvilcraft.AnvilCraft"
],
"fabric-datagen": [
"dev.dubhe.anvilcraft.data.AnvilCraftDataGenerator"
]
},
"mixins": [
Expand Down

0 comments on commit 177a26f

Please sign in to comment.