Skip to content

Commit 3e2bcb4

Browse files
committed
Port fabric-tag-api-v1
1 parent 5adff2d commit 3e2bcb4

8 files changed

Lines changed: 48 additions & 152 deletions

File tree

fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/api/datagen/v1/provider/FabricProvidedTagBuilder.java

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,32 @@
1616

1717
package net.fabricmc.fabric.api.datagen.v1.provider;
1818

19+
import java.util.Arrays;
1920
import java.util.Collection;
2021
import java.util.stream.Stream;
22+
23+
import net.fabricmc.fabric.impl.datagen.ForcedTagEntry;
2124
import net.minecraft.data.tags.TagsProvider;
25+
import net.minecraft.data.tags.TagsProvider.TagAppender;
2226
import net.minecraft.resources.ResourceKey;
27+
import net.minecraft.tags.TagEntry;
2328
import net.minecraft.tags.TagKey;
29+
import net.neoforged.neoforge.common.extensions.ITagAppenderExtension;
2430

2531
/**
2632
* Interface-injected to {@link TagsProvider.TagAppender}.
2733
*/
2834
@SuppressWarnings("unchecked")
29-
public interface FabricProvidedTagBuilder<T> {
35+
public interface FabricProvidedTagBuilder<T> extends ITagAppenderExtension<T> {
3036
/**
3137
* Sets the value of the {@code replace} flag. When set to {@code true}
3238
* this tag will replace contents of any other tag.
3339
* @param replace whether to replace the contents of the tag
3440
* @return this, for chaining
3541
*/
3642
default FabricProvidedTagBuilder<T> setReplace(boolean replace) {
37-
throw new AssertionError("Implemented via mixin");
43+
replace(replace);
44+
return this;
3845
}
3946

4047
/**
@@ -44,16 +51,18 @@ default FabricProvidedTagBuilder<T> setReplace(boolean replace) {
4451
* @return this, for chaining
4552
*/
4653
default FabricProvidedTagBuilder<T> forceAddTag(TagKey<T> tag) {
47-
throw new AssertionError("Implemented via mixin");
54+
self().add(new ForcedTagEntry(TagEntry.element(tag.location())));
55+
return this;
4856
}
4957

5058
/**
51-
* Removes an entry from the tag.
52-
* @param element The entry to remove from the contents of the tag
53-
* @return this, for chaining
54-
*/
55-
default FabricProvidedTagBuilder<T> remove(ResourceKey<T> element) {
56-
throw new AssertionError("Implemented via mixin");
59+
* Removes an entry from the tag.
60+
*
61+
* @param element The entry to remove from the contents of the tag
62+
* @return this, for chaining
63+
*/
64+
default TagAppender<T> remove(ResourceKey<T> element) {
65+
return ITagAppenderExtension.super.remove(element);
5766
}
5867

5968
/**
@@ -62,7 +71,8 @@ default FabricProvidedTagBuilder<T> remove(ResourceKey<T> element) {
6271
* @return this, for chaining
6372
*/
6473
default FabricProvidedTagBuilder<T> remove(final ResourceKey<T>... elements) {
65-
throw new AssertionError("Implemented via mixin");
74+
removeAll(Arrays.asList(elements));
75+
return this;
6676
}
6777

6878
/**
@@ -71,7 +81,10 @@ default FabricProvidedTagBuilder<T> remove(final ResourceKey<T>... elements) {
7181
* @return this, for chaining
7282
*/
7383
default FabricProvidedTagBuilder<T> removeAll(final Collection<ResourceKey<T>> elements) {
74-
throw new AssertionError("Implemented via mixin");
84+
for (ResourceKey<T> element : elements) {
85+
remove(element);
86+
}
87+
return this;
7588
}
7689

7790
/**
@@ -80,7 +93,8 @@ default FabricProvidedTagBuilder<T> removeAll(final Collection<ResourceKey<T>> e
8093
* @return this, for chaining
8194
*/
8295
default FabricProvidedTagBuilder<T> removeAll(final Stream<ResourceKey<T>> elements) {
83-
throw new AssertionError("Implemented via mixin");
96+
elements.forEach(this::remove);
97+
return this;
8498
}
8599

86100
/**
@@ -89,6 +103,11 @@ default FabricProvidedTagBuilder<T> removeAll(final Stream<ResourceKey<T>> eleme
89103
* @return this, for chaining
90104
*/
91105
default FabricProvidedTagBuilder<T> removeTag(TagKey<T> tag) {
92-
throw new AssertionError("Implemented via mixin");
106+
remove(tag);
107+
return this;
93108
}
109+
110+
private TagsProvider.TagAppender<T> self() {
111+
return (TagsProvider.TagAppender<T>) this;
112+
}
94113
}

fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/api/datagen/v1/provider/FabricTagProvider.java

Lines changed: 8 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,9 @@
1616

1717
package net.fabricmc.fabric.api.datagen.v1.provider;
1818

19-
import java.util.Collection;
20-
import java.util.Objects;
21-
import java.util.Optional;
22-
import java.util.concurrent.CompletableFuture;
23-
import java.util.function.Function;
24-
import java.util.stream.Stream;
25-
26-
import org.jetbrains.annotations.Nullable;
2719
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
2820
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
2921
import net.fabricmc.fabric.impl.datagen.ForcedTagEntry;
30-
import net.fabricmc.fabric.impl.datagen.TagBuilderHooks;
3122
import net.minecraft.core.Holder;
3223
import net.minecraft.core.HolderLookup;
3324
import net.minecraft.core.Registry;
@@ -37,20 +28,20 @@
3728
import net.minecraft.data.tags.TagsProvider;
3829
import net.minecraft.resources.ResourceKey;
3930
import net.minecraft.resources.ResourceLocation;
40-
import net.minecraft.tags.BlockTags;
41-
import net.minecraft.tags.EntityTypeTags;
42-
import net.minecraft.tags.FluidTags;
43-
import net.minecraft.tags.GameEventTags;
44-
import net.minecraft.tags.ItemTags;
45-
import net.minecraft.tags.TagBuilder;
46-
import net.minecraft.tags.TagEntry;
47-
import net.minecraft.tags.TagKey;
31+
import net.minecraft.tags.*;
4832
import net.minecraft.world.entity.EntityType;
4933
import net.minecraft.world.item.Item;
5034
import net.minecraft.world.item.enchantment.Enchantment;
5135
import net.minecraft.world.level.block.Block;
5236
import net.minecraft.world.level.block.entity.BlockEntityType;
5337
import net.minecraft.world.level.material.Fluid;
38+
import org.jetbrains.annotations.Nullable;
39+
40+
import java.util.Objects;
41+
import java.util.Optional;
42+
import java.util.concurrent.CompletableFuture;
43+
import java.util.function.Function;
44+
import java.util.stream.Stream;
5445

5546
/**
5647
* Implement this class (or one of the inner classes) to generate a tag list.
@@ -395,85 +386,5 @@ public final FabricTagBuilder add(ResourceKey<T>... registryKeys) {
395386

396387
return this;
397388
}
398-
399-
/**
400-
* Remove an element from the tag.
401-
*
402-
* @return the {@link FabricTagBuilder} instance
403-
*/
404-
public FabricTagBuilder remove(T element) {
405-
remove(reverseLookup(element));
406-
return this;
407-
}
408-
409-
/**
410-
* Remove multiple elements from the tag.
411-
*
412-
* @return the {@link FabricTagBuilder} instance
413-
*/
414-
@SafeVarargs
415-
public final FabricTagBuilder remove(T... elements) {
416-
Stream.of(elements).map(FabricTagProvider.this::reverseLookup).forEach(this::remove);
417-
return this;
418-
}
419-
420-
/**
421-
* Remove an element from the tag.
422-
*
423-
* @return the {@link FabricTagBuilder} instance
424-
*/
425-
@Override
426-
public FabricTagBuilder remove(ResourceKey<T> registryKey) {
427-
((TagBuilderHooks) this.builder).fabric_removeElement(registryKey.location());
428-
return this;
429-
}
430-
431-
/**
432-
* Remove multiple elements from the tag.
433-
*
434-
* @return the {@link FabricTagBuilder} instance
435-
*/
436-
@SafeVarargs
437-
@Override
438-
public final FabricTagBuilder remove(ResourceKey<T>... registryKeys) {
439-
for (ResourceKey<T> registryKey : registryKeys) {
440-
remove(registryKey);
441-
}
442-
443-
return this;
444-
}
445-
446-
/**
447-
* Remove multiple elements from the tag.
448-
*
449-
* @return the {@link FabricTagBuilder} instance
450-
*/
451-
@Override
452-
public FabricTagBuilder removeAll(final Collection<ResourceKey<T>> registryKeys) {
453-
registryKeys.forEach(this::remove);
454-
return this;
455-
}
456-
457-
/**
458-
* Remove multiple elements from the tag.
459-
*
460-
* @return the {@link FabricTagBuilder} instance
461-
*/
462-
@Override
463-
public FabricTagBuilder removeAll(final Stream<ResourceKey<T>> registryKeys) {
464-
registryKeys.forEach(this::remove);
465-
return this;
466-
}
467-
468-
/**
469-
* Remove another tag from this tag.
470-
*
471-
* @return the {@link FabricTagBuilder} instance
472-
*/
473-
@Override
474-
public FabricTagBuilder removeTag(TagKey<T> tag) {
475-
((TagBuilderHooks) this.builder).fabric_removeTag(tag.location());
476-
return this;
477-
}
478389
}
479390
}

fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/impl/datagen/TagBuilderHooks.java

Lines changed: 0 additions & 35 deletions
This file was deleted.

fabric-data-generation-api-v1/src/testmod/java/net/fabricmc/fabric/test/datagen/DataGeneratorTestEntrypoint.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
import net.minecraft.world.level.storage.loot.predicates.LootItemBlockStatePropertyCondition;
100100
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
101101
import net.minecraft.world.level.storage.loot.providers.number.ConstantValue;
102+
import net.neoforged.neoforge.common.extensions.ITagAppenderExtension;
102103

103104
public class DataGeneratorTestEntrypoint implements DataGeneratorEntrypoint {
104105
private static final ResourceCondition ALWAYS_LOADED = ResourceConditions.alwaysTrue();
@@ -325,7 +326,7 @@ protected void addTags(HolderLookup.Provider registries) {
325326
.remove(Blocks.RED_SAND.builtInRegistryHolder().key())
326327
.removeTag(BlockTags.DIRT);
327328

328-
tag(BlockTags.NEEDS_DIAMOND_TOOL)
329+
((ITagAppenderExtension<Block>) tag(BlockTags.NEEDS_DIAMOND_TOOL))
329330
.remove(
330331
Blocks.ANCIENT_DEBRIS.builtInRegistryHolder().key(),
331332
Blocks.NETHERITE_BLOCK.builtInRegistryHolder().key(),
@@ -402,7 +403,7 @@ public void generateAdvancement(HolderLookup.Provider registryLookup, Consumer<A
402403
.addCriterion("killed_something", KilledTrigger.TriggerInstance.playerKilledEntity())
403404
.save(withConditions(consumer, NEVER_LOADED), MOD_ID + ":test/root_not_loaded");
404405
AdvancementHolder adventureChild = Advancement.Builder.advancement()
405-
.display(SIMPLE_BLOCK,
406+
.display(SIMPLE_BLOCK.value(),
406407
Component.translatable("advancements.test.adventure_child.title"),
407408
Component.translatable("advancements.test.adventure_child.description"),
408409
ResourceLocation.withDefaultNamespace("textures/gui/advancements/backgrounds/end.png"),

fabric-tag-api-v1/src/main/java/net/fabricmc/fabric/mixin/tag/TagFileMixin.java renamed to fabric-tag-api-v1/src/main/java/net/fabricmc/fabric/mixin/tags/TagFileMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package net.fabricmc.fabric.mixin.tag;
17+
package net.fabricmc.fabric.mixin.tags;
1818

1919
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
2020
import com.mojang.serialization.MapCodec;

fabric-tag-api-v1/src/main/resources/fabric-tag-api-v1.mixins.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"required": true,
3-
"package": "net.fabricmc.fabric.mixin.tag",
3+
"package": "net.fabricmc.fabric.mixin.tags",
44
"compatibilityLevel": "JAVA_21",
55
"mixins": [
66
"TagFileMixin"

fabric-tag-api-v1/src/testmod/java/net/fabricmc/fabric/test/tag/TagTestUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static <T> void assertInTag(GameTestHelper context, Logger logger, String succes
8484
HolderSet.Named<T> registryEntryList = lookup.getOrThrow(tag);
8585
Set<ResourceKey<T>> actual = registryEntryList.contents
8686
.stream()
87-
.map(entry -> entry.getKey().orElseThrow())
87+
.map(entry -> entry.unwrapKey().orElseThrow())
8888
.collect(Collectors.toSet());
8989

9090
for (ResourceKey<T> key : expected) {
@@ -123,7 +123,7 @@ static <T> void assertTagContent(GameTestHelper context, Logger logger, String s
123123
HolderSet.Named<T> registryEntryList = lookup.getOrThrow(tag);
124124
Set<ResourceKey<T>> actual = registryEntryList.contents
125125
.stream()
126-
.map(entry -> entry.getKey().orElseThrow())
126+
.map(entry -> entry.unwrapKey().orElseThrow())
127127
.collect(Collectors.toSet());
128128

129129
if (!actual.equals(expected)) {

ffapi.gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
loom.platform=neoforge
22
fabric.loom.dontRemap=true
33

4-
implementationVersion=2.2.5
4+
implementationVersion=2.3.0
55

66
versionMc=1.21.1
77
versionForge=21.1.219

0 commit comments

Comments
 (0)