فهرست منبع

Merge remote-tracking branch 'architectury/feature/optional_tags' into 1.16

shedaniel 4 سال پیش
والد
کامیت
f99ac935ed
20فایلهای تغییر یافته به همراه440 افزوده شده و 46 حذف شده
  1. 2 2
      build.gradle
  2. 0 11
      common/build.gradle
  3. 19 0
      common/src/main/java/me/shedaniel/architectury/event/events/BlockEvent.java
  4. 19 0
      common/src/main/java/me/shedaniel/architectury/event/events/LightningEvent.java
  5. 56 0
      common/src/main/java/me/shedaniel/architectury/hooks/TagHooks.java
  6. 19 0
      common/src/main/java/me/shedaniel/architectury/mixin/BlockLandingInvoker.java
  7. 34 0
      common/src/main/java/me/shedaniel/architectury/mixin/FluidTagsAccessor.java
  8. 19 0
      common/src/main/java/me/shedaniel/architectury/mixin/MixinLightningBolt.java
  9. 11 14
      common/src/main/resources/architectury-common.mixins.json
  10. 0 6
      fabric/build.gradle
  11. 33 0
      fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/TagHooksImpl.java
  12. 19 0
      fabric/src/main/java/me/shedaniel/architectury/plugin/fabric/ArchitecturyMixinPlugin.java
  13. 79 0
      forge/src/main/java/me/shedaniel/architectury/hooks/forge/TagHooksImpl.java
  14. 65 0
      forge/src/main/java/me/shedaniel/architectury/mixin/forge/GameRulesAccessor.java
  15. 9 8
      forge/src/main/java/me/shedaniel/architectury/registry/forge/GameRuleFactoryImpl.java
  16. 0 4
      forge/src/main/resources/META-INF/accesstransformer.cfg
  17. 1 1
      forge/src/main/resources/architectury.mixins.json
  18. 2 0
      testmod-common/src/main/java/me/shedaniel/architectury/test/TestMod.java
  19. 47 0
      testmod-common/src/main/java/me/shedaniel/architectury/test/tags/TestTags.java
  20. 6 0
      testmod-common/src/main/resources/data/architectury-test/tags/blocks/heart_particles2.json

+ 2 - 2
build.gradle

@@ -1,6 +1,6 @@
 plugins {
-    id "architectury-plugin" version "3.0.79"
-    id "forgified-fabric-loom" version "0.6.67" apply false
+    id "architectury-plugin" version "3.0.85"
+    id "forgified-fabric-loom" version "0.6.70" apply false
     id "org.cadixdev.licenser" version "0.5.0"
     id "com.matthewprenger.cursegradle" version "1.4.0" apply false
     id "maven-publish"

+ 0 - 11
common/build.gradle

@@ -20,16 +20,6 @@ task sourcesJar(type: Jar, dependsOn: classes) {
     from sourceSets.main.allSource
 }
 
-task javadocs(type: Javadoc) {
-    source = sourceSets.main.allJava
-}
-
-task javadocsJar(type: Jar, dependsOn: javadocs) {
-    archiveClassifier.set("javadocs")
-    javadocs.failOnError false
-    from javadocs.destinationDir
-}
-
 publishing {
     publications {
         mavenCommon(MavenPublication) {
@@ -39,7 +29,6 @@ publishing {
             artifact(sourcesJar) {
                 builtBy remapSourcesJar
             }
-            artifact javadocsJar
         }
     }
 

+ 19 - 0
common/src/main/java/me/shedaniel/architectury/event/events/BlockEvent.java

@@ -1,3 +1,22 @@
+/*
+ * This file is part of architectury.
+ * Copyright (C) 2020, 2021 shedaniel
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
 package me.shedaniel.architectury.event.events;
 
 import me.shedaniel.architectury.event.Event;

+ 19 - 0
common/src/main/java/me/shedaniel/architectury/event/events/LightningEvent.java

@@ -1,3 +1,22 @@
+/*
+ * This file is part of architectury.
+ * Copyright (C) 2020, 2021 shedaniel
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
 package me.shedaniel.architectury.event.events;
 
 import me.shedaniel.architectury.event.Event;

+ 56 - 0
common/src/main/java/me/shedaniel/architectury/hooks/TagHooks.java

@@ -0,0 +1,56 @@
+/*
+ * This file is part of architectury.
+ * Copyright (C) 2020, 2021 shedaniel
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package me.shedaniel.architectury.hooks;
+
+import me.shedaniel.architectury.annotations.ExpectPlatform;
+import me.shedaniel.architectury.mixin.FluidTagsAccessor;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.tags.*;
+import net.minecraft.world.entity.EntityType;
+import net.minecraft.world.item.Item;
+import net.minecraft.world.level.block.Block;
+import net.minecraft.world.level.material.Fluid;
+
+import java.util.function.Supplier;
+
+public final class TagHooks {
+    private TagHooks() {}
+    
+    @ExpectPlatform
+    public static <T> Tag.Named<T> getOptional(ResourceLocation id, Supplier<TagCollection<T>> collection) {
+        throw new AssertionError();
+    }
+    
+    public static Tag.Named<Item> getItemOptional(ResourceLocation id) {
+        return getOptional(id, ItemTags::getAllTags);
+    }
+    
+    public static Tag.Named<Block> getBlockOptional(ResourceLocation id) {
+        return getOptional(id, BlockTags::getAllTags);
+    }
+    
+    public static Tag.Named<Fluid> getFluidOptional(ResourceLocation id) {
+        return getOptional(id, FluidTagsAccessor.getHelper()::getAllTags);
+    }
+    
+    public static Tag.Named<EntityType<?>> getEntityTypeOptional(ResourceLocation id) {
+        return getOptional(id, EntityTypeTags::getAllTags);
+    }
+}

+ 19 - 0
common/src/main/java/me/shedaniel/architectury/mixin/BlockLandingInvoker.java

@@ -1,3 +1,22 @@
+/*
+ * This file is part of architectury.
+ * Copyright (C) 2020, 2021 shedaniel
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
 package me.shedaniel.architectury.mixin;
 
 import me.shedaniel.architectury.event.events.BlockEvent;

+ 34 - 0
common/src/main/java/me/shedaniel/architectury/mixin/FluidTagsAccessor.java

@@ -0,0 +1,34 @@
+/*
+ * This file is part of architectury.
+ * Copyright (C) 2020, 2021 shedaniel
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package me.shedaniel.architectury.mixin;
+
+import net.minecraft.tags.FluidTags;
+import net.minecraft.tags.StaticTagHelper;
+import net.minecraft.world.level.material.Fluid;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.gen.Accessor;
+
+@Mixin(FluidTags.class)
+public interface FluidTagsAccessor {
+    @Accessor("HELPER")
+    static StaticTagHelper<Fluid> getHelper() {
+        throw new AssertionError();
+    }
+}

+ 19 - 0
common/src/main/java/me/shedaniel/architectury/mixin/MixinLightningBolt.java

@@ -1,3 +1,22 @@
+/*
+ * This file is part of architectury.
+ * Copyright (C) 2020, 2021 shedaniel
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
 package me.shedaniel.architectury.mixin;
 
 import me.shedaniel.architectury.event.events.LightningEvent;

+ 11 - 14
common/src/main/resources/architectury-common.mixins.json

@@ -1,16 +1,13 @@
 {
-    "required": true,
-    "package": "me.shedaniel.architectury.mixin",
-    "compatibilityLevel": "JAVA_8",
-    "minVersion": "0.7.11",
-    "client": [
-    ],
-    "mixins": [
-        "BlockLandingInvoker",
-        "MixinLightningBolt"
-    ],
-    "injectors": {
-        "maxShiftBy": 5,
-        "defaultRequire": 1
-    }
+  "required": true,
+  "package": "me.shedaniel.architectury.mixin",
+  "compatibilityLevel": "JAVA_8",
+  "minVersion": "0.7.11",
+  "client": [
+  ],
+  "mixins": ["BlockLandingInvoker", "FluidTagsAccessor", "MixinLightningBolt"],
+  "injectors": {
+    "maxShiftBy": 5,
+    "defaultRequire": 1
+  }
 }

+ 0 - 6
fabric/build.gradle

@@ -1,9 +1,3 @@
-import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer
-import com.github.jengelman.gradle.plugins.shadow.transformers.TransformerContext
-import shadow.org.apache.tools.zip.ZipEntry
-import shadow.org.apache.tools.zip.ZipOutputStream
-import shadow.org.codehaus.plexus.util.IOUtil
-
 plugins {
     id "com.github.johnrengelman.shadow" version "5.0.0"
     id "com.matthewprenger.cursegradle"

+ 33 - 0
fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/TagHooksImpl.java

@@ -0,0 +1,33 @@
+/*
+ * This file is part of architectury.
+ * Copyright (C) 2020, 2021 shedaniel
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package me.shedaniel.architectury.hooks.fabric;
+
+import net.fabricmc.fabric.api.tag.TagRegistry;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.tags.Tag;
+import net.minecraft.tags.TagCollection;
+
+import java.util.function.Supplier;
+
+public class TagHooksImpl {
+    public static <T> Tag.Named<T> getOptional(ResourceLocation id, Supplier<TagCollection<T>> collection) {
+        return TagRegistry.create(id, collection);
+    }
+}

+ 19 - 0
fabric/src/main/java/me/shedaniel/architectury/plugin/fabric/ArchitecturyMixinPlugin.java

@@ -1,3 +1,22 @@
+/*
+ * This file is part of architectury.
+ * Copyright (C) 2020, 2021 shedaniel
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
 package me.shedaniel.architectury.plugin.fabric;
 
 import net.fabricmc.loader.api.FabricLoader;

+ 79 - 0
forge/src/main/java/me/shedaniel/architectury/hooks/forge/TagHooksImpl.java

@@ -0,0 +1,79 @@
+/*
+ * This file is part of architectury.
+ * Copyright (C) 2020, 2021 shedaniel
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package me.shedaniel.architectury.hooks.forge;
+
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.tags.Tag;
+import net.minecraft.tags.TagCollection;
+
+import java.lang.ref.WeakReference;
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Supplier;
+
+public class TagHooksImpl {
+    public static <T> Tag.Named<T> getOptional(ResourceLocation id, Supplier<TagCollection<T>> collection) {
+        return new Tag.Named<T>() {
+            private volatile Tag<T> backend;
+            private volatile WeakReference<TagCollection<T>> backendCollection;
+            
+            @Override
+            public ResourceLocation getName() {
+                return id;
+            }
+            
+            @Override
+            public boolean contains(T object) {
+                return getBackend().contains(object);
+            }
+            
+            @Override
+            public List<T> getValues() {
+                return getBackend().getValues();
+            }
+            
+            private Tag<T> getBackend() {
+                TagCollection<T> currentCollection = collection.get();
+                
+                if (backend == null || backendCollection == null || backendCollection.get() != currentCollection) { // If not initialized or was tag changed.
+                    backendCollection = new WeakReference<>(currentCollection);
+                    return backend = currentCollection.getTagOrEmpty(id);
+                } else {
+                    return backend;
+                }
+            }
+            
+            @Override
+            public String toString() {
+                return "OptionalNamedTag[" + getName().toString() + ']';
+            }
+            
+            @Override
+            public boolean equals(Object o) {
+                return o == this || o instanceof Named && Objects.equals(getName(), ((Named) o).getName());
+            }
+            
+            @Override
+            public int hashCode() {
+                return getName().hashCode();
+            }
+        };
+    }
+}

+ 65 - 0
forge/src/main/java/me/shedaniel/architectury/mixin/forge/GameRulesAccessor.java

@@ -0,0 +1,65 @@
+/*
+ * This file is part of architectury.
+ * Copyright (C) 2020, 2021 shedaniel
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package me.shedaniel.architectury.mixin.forge;
+
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.world.level.GameRules;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.gen.Invoker;
+
+import java.util.function.BiConsumer;
+
+@Mixin(GameRules.class)
+public interface GameRulesAccessor {
+    /**
+     * Spliting simple classes because mixin can't handle refmap using the same name
+     */
+    @Mixin(GameRules.BooleanValue.class)
+    interface BooleanValue {
+        @Invoker("create")
+        static GameRules.Type<GameRules.BooleanValue> invokeCreateArchitectury(boolean value, BiConsumer<MinecraftServer, GameRules.BooleanValue> biConsumer) {
+            throw new AssertionError();
+        }
+    }
+    
+    @Mixin(GameRules.BooleanValue.class)
+    interface BooleanValueSimple {
+        @Invoker("create")
+        static GameRules.Type<GameRules.BooleanValue> invokeCreateArchitectury(boolean value) {
+            throw new AssertionError();
+        }
+    }
+    
+    @Mixin(GameRules.IntegerValue.class)
+    interface IntegerValue {
+        @Invoker("create")
+        static GameRules.Type<GameRules.IntegerValue> invokeCreateArchitectury(int value, BiConsumer<MinecraftServer, GameRules.IntegerValue> biConsumer) {
+            throw new AssertionError();
+        }
+    }
+    
+    @Mixin(GameRules.IntegerValue.class)
+    interface IntegerValueSimple {
+        @Invoker("create")
+        static GameRules.Type<GameRules.IntegerValue> invokeCreateArchitectury(int value) {
+            throw new AssertionError();
+        }
+    }
+}

+ 9 - 8
forge/src/main/java/me/shedaniel/architectury/registry/forge/GameRuleFactoryImpl.java

@@ -19,6 +19,7 @@
 
 package me.shedaniel.architectury.registry.forge;
 
+import me.shedaniel.architectury.mixin.forge.GameRulesAccessor;
 import net.minecraft.server.MinecraftServer;
 import net.minecraft.world.level.GameRules;
 
@@ -26,20 +27,20 @@ import java.util.function.BiConsumer;
 
 public class GameRuleFactoryImpl {
     private GameRuleFactoryImpl() {}
-
+    
     public static GameRules.Type<GameRules.BooleanValue> createBooleanRule(boolean defaultValue) {
-        return GameRules.BooleanValue.create(defaultValue);
+        return GameRulesAccessor.BooleanValueSimple.invokeCreateArchitectury(defaultValue);
     }
-
+    
     public static GameRules.Type<GameRules.BooleanValue> createBooleanRule(boolean defaultValue, BiConsumer<MinecraftServer, GameRules.BooleanValue> changedCallback) {
-        return GameRules.BooleanValue.create(defaultValue, changedCallback);
+        return GameRulesAccessor.BooleanValue.invokeCreateArchitectury(defaultValue, changedCallback);
     }
-
+    
     public static GameRules.Type<GameRules.IntegerValue> createIntRule(int defaultValue) {
-        return GameRules.IntegerValue.create(defaultValue);
+        return GameRulesAccessor.IntegerValueSimple.invokeCreateArchitectury(defaultValue);
     }
-
+    
     public static GameRules.Type<GameRules.IntegerValue> createIntRule(int defaultValue, BiConsumer<MinecraftServer, GameRules.IntegerValue> changedCallback) {
-        return GameRules.IntegerValue.create(defaultValue, changedCallback);
+        return GameRulesAccessor.IntegerValue.invokeCreateArchitectury(defaultValue, changedCallback);
     }
 }

+ 0 - 4
forge/src/main/resources/META-INF/accesstransformer.cfg

@@ -33,7 +33,3 @@ public-f net.minecraft.world.biome.BiomeAmbience field_242524_f # foliageColor
 public-f net.minecraft.world.biome.BiomeAmbience field_242525_g # grassColor
 public-f net.minecraft.world.biome.BiomeAmbience field_242526_h # grassColorModifier
 public net.minecraft.world.storage.FolderName <init>(Ljava/lang/String;)V
-public net.minecraft.world.GameRules$BooleanValue func_223567_b(ZLjava/util/function/BiConsumer;)Lnet/minecraft/world/GameRules$RuleType; # create
-public net.minecraft.world.GameRules$BooleanValue func_223568_b(Z)Lnet/minecraft/world/GameRules$RuleType; # create
-public net.minecraft.world.GameRules$IntegerValue func_223564_a(ILjava/util/function/BiConsumer;)Lnet/minecraft/world/GameRules$RuleType; # create
-public net.minecraft.world.GameRules$IntegerValue func_223559_b(I)Lnet/minecraft/world/GameRules$RuleType; # create

+ 1 - 1
forge/src/main/resources/architectury.mixins.json

@@ -8,7 +8,7 @@
   ],
   "mixins": [
     "BiomeGenerationSettingsBuilderAccessor", "MixinRegistryEntry", "MixinBlockEntity", "MixinBlockEntityExtension",
-    "MobSpawnSettingsBuilderAccessor"
+    "MobSpawnSettingsBuilderAccessor", "GameRulesAccessor", "GameRulesAccessor$BooleanValue", "GameRulesAccessor$BooleanValueSimple", "GameRulesAccessor$IntegerValue", "GameRulesAccessor$IntegerValueSimple"
   ],
   "injectors": {
     "defaultRequire": 1

+ 2 - 0
testmod-common/src/main/java/me/shedaniel/architectury/test/TestMod.java

@@ -27,6 +27,7 @@ import me.shedaniel.architectury.test.debug.client.ClientOverlayMessageSink;
 import me.shedaniel.architectury.test.gamerule.TestGameRules;
 import me.shedaniel.architectury.test.registry.TestRegistries;
 import me.shedaniel.architectury.test.registry.client.TestKeybinds;
+import me.shedaniel.architectury.test.tags.TestTags;
 import me.shedaniel.architectury.utils.Env;
 import me.shedaniel.architectury.utils.EnvExecutor;
 
@@ -38,6 +39,7 @@ public class TestMod {
         DebugEvents.initialize();
         TestRegistries.initialize();
         TestGameRules.init();
+        TestTags.initialize();
         if (Platform.getEnvironment() == Env.CLIENT)
             TestKeybinds.initialize();
     }

+ 47 - 0
testmod-common/src/main/java/me/shedaniel/architectury/test/tags/TestTags.java

@@ -0,0 +1,47 @@
+/*
+ * This file is part of architectury.
+ * Copyright (C) 2020, 2021 shedaniel
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package me.shedaniel.architectury.test.tags;
+
+import me.shedaniel.architectury.event.events.BlockEvent;
+import me.shedaniel.architectury.hooks.TagHooks;
+import me.shedaniel.architectury.test.TestMod;
+import net.minecraft.core.particles.ParticleTypes;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.server.level.ServerLevel;
+import net.minecraft.tags.Tag;
+import net.minecraft.world.InteractionResult;
+import net.minecraft.world.level.block.Block;
+
+public class TestTags {
+    public static void initialize() {
+        // This will not be present, but it should return an empty tag
+        Tag.Named<Block> heartParticles = TagHooks.getBlockOptional(new ResourceLocation(TestMod.MOD_ID, "heart_particles"));
+        // This will act like a normal tag, we have emerald block here
+        Tag.Named<Block> heartParticles2 = TagHooks.getBlockOptional(new ResourceLocation(TestMod.MOD_ID, "heart_particles2"));
+        
+        BlockEvent.BREAK.register((world, pos, state, player, xp) -> {
+            if (player != null && !world.isClientSide() && (state.is(heartParticles) || state.is(heartParticles2))) {
+                ((ServerLevel) world).sendParticles(player, ParticleTypes.HEART, false, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 10, 0.0, 0.0, 0.0, 0.0);
+            }
+            
+            return InteractionResult.PASS;
+        });
+    }
+}

+ 6 - 0
testmod-common/src/main/resources/data/architectury-test/tags/blocks/heart_particles2.json

@@ -0,0 +1,6 @@
+{
+    "replace": false,
+    "values": [
+        "minecraft:emerald_block"
+    ]
+}