mirror of
https://github.com/FabricMC/fabric.git
synced 2024-11-27 01:55:41 -05:00
Add basic test for tags, useful to ensure that datapack loading is working as expected
This commit is contained in:
parent
277876c741
commit
dff23fa481
2 changed files with 20 additions and 1 deletions
|
@ -1,8 +1,9 @@
|
||||||
archivesBaseName = "fabric-tool-attribute-api-v1"
|
archivesBaseName = "fabric-tool-attribute-api-v1"
|
||||||
version = getSubprojectVersion(project, "1.1.1")
|
version = getSubprojectVersion(project, "1.1.2")
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile project(path: ':fabric-api-base', configuration: 'dev')
|
compile project(path: ':fabric-api-base', configuration: 'dev')
|
||||||
compile project(path: ':fabric-tag-extensions-v0', configuration: 'dev')
|
compile project(path: ':fabric-tag-extensions-v0', configuration: 'dev')
|
||||||
testmodCompile project(path: ':fabric-object-builder-api-v1', configuration: 'dev')
|
testmodCompile project(path: ':fabric-object-builder-api-v1', configuration: 'dev')
|
||||||
|
testmodCompile project(path: ':fabric-events-lifecycle-v0', configuration: 'dev')
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package net.fabricmc.fabric.test.tool.attribute;
|
package net.fabricmc.fabric.test.tool.attribute;
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.api.event.server.ServerTickCallback;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.MaterialColor;
|
import net.minecraft.block.MaterialColor;
|
||||||
|
@ -23,6 +24,7 @@ import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.item.BlockItem;
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.sound.BlockSoundGroup;
|
import net.minecraft.sound.BlockSoundGroup;
|
||||||
import net.minecraft.tag.Tag;
|
import net.minecraft.tag.Tag;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
@ -35,6 +37,9 @@ import net.fabricmc.fabric.api.tool.attribute.v1.DynamicAttributeTool;
|
||||||
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
|
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
|
||||||
|
|
||||||
public class ToolAttributeTest implements ModInitializer {
|
public class ToolAttributeTest implements ModInitializer {
|
||||||
|
|
||||||
|
private boolean hasValidatedTags = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
// Register a custom shovel that has a mining level of 2 (iron) dynamically.
|
// Register a custom shovel that has a mining level of 2 (iron) dynamically.
|
||||||
|
@ -47,6 +52,19 @@ public class ToolAttributeTest implements ModInitializer {
|
||||||
.strength(0.6F)
|
.strength(0.6F)
|
||||||
.sounds(BlockSoundGroup.GRAVEL)));
|
.sounds(BlockSoundGroup.GRAVEL)));
|
||||||
Registry.register(Registry.ITEM, new Identifier("fabric-tool-attribute-api-v1-testmod", "hardened_block"), new BlockItem(block, new Item.Settings()));
|
Registry.register(Registry.ITEM, new Identifier("fabric-tool-attribute-api-v1-testmod", "hardened_block"), new BlockItem(block, new Item.Settings()));
|
||||||
|
|
||||||
|
ServerTickCallback.EVENT.register(this::validateTags);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateTags(MinecraftServer server) {
|
||||||
|
if (hasValidatedTags) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
hasValidatedTags = true;
|
||||||
|
|
||||||
|
if (FabricToolTags.PICKAXES.values().isEmpty()) {
|
||||||
|
throw new AssertionError("Failed to load tool tags");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TestShovel extends Item implements DynamicAttributeTool {
|
private static class TestShovel extends Item implements DynamicAttributeTool {
|
||||||
|
|
Loading…
Reference in a new issue