From 7e743dcb640418a32410b5892cc88b31d498ef55 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 23 Feb 2021 00:16:26 +0800 Subject: [PATCH] Add licenses and implement optional tags, requires some testing. --- build.gradle | 4 +- common/build.gradle | 11 ---- .../architectury/event/events/BlockEvent.java | 19 ++++++ .../event/events/LightningEvent.java | 19 ++++++ .../architectury/hooks/TagHooks.java | 56 +++++++++++++++++ .../mixin/BlockLandingInvoker.java | 19 ++++++ .../architectury/mixin/FluidTagsAccessor.java | 34 ++++++++++ .../mixin/MixinLightningBolt.java | 19 ++++++ .../resources/architectury-common.mixins.json | 25 ++++---- fabric/build.gradle | 6 -- .../hooks/fabric/TagHooksImpl.java | 33 ++++++++++ .../fabric/ArchitecturyMixinPlugin.java | 19 ++++++ .../mixin/forge/TagHooksImpl.java | 63 +++++++++++++++++++ 13 files changed, 294 insertions(+), 33 deletions(-) create mode 100644 common/src/main/java/me/shedaniel/architectury/hooks/TagHooks.java create mode 100644 common/src/main/java/me/shedaniel/architectury/mixin/FluidTagsAccessor.java create mode 100644 fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/TagHooksImpl.java create mode 100644 forge/src/main/java/me/shedaniel/architectury/mixin/forge/TagHooksImpl.java diff --git a/build.gradle b/build.gradle index 13e5f950..6814500c 100644 --- a/build.gradle +++ b/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" diff --git a/common/build.gradle b/common/build.gradle index 6afb50d7..85ea3d18 100644 --- a/common/build.gradle +++ b/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 } } diff --git a/common/src/main/java/me/shedaniel/architectury/event/events/BlockEvent.java b/common/src/main/java/me/shedaniel/architectury/event/events/BlockEvent.java index 484b9ea9..4c783f1b 100644 --- a/common/src/main/java/me/shedaniel/architectury/event/events/BlockEvent.java +++ b/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; diff --git a/common/src/main/java/me/shedaniel/architectury/event/events/LightningEvent.java b/common/src/main/java/me/shedaniel/architectury/event/events/LightningEvent.java index 034db226..f1fac890 100644 --- a/common/src/main/java/me/shedaniel/architectury/event/events/LightningEvent.java +++ b/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; diff --git a/common/src/main/java/me/shedaniel/architectury/hooks/TagHooks.java b/common/src/main/java/me/shedaniel/architectury/hooks/TagHooks.java new file mode 100644 index 00000000..c596fcf0 --- /dev/null +++ b/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 Tag.Named getOptional(ResourceLocation id, Supplier> collection) { + throw new AssertionError(); + } + + public static Tag.Named getItemOptional(ResourceLocation id) { + return getOptional(id, ItemTags::getAllTags); + } + + public static Tag.Named getBlockOptional(ResourceLocation id) { + return getOptional(id, BlockTags::getAllTags); + } + + public static Tag.Named getFluidOptional(ResourceLocation id) { + return getOptional(id, FluidTagsAccessor.getHelper()::getAllTags); + } + + public static Tag.Named> getEntityTypeOptional(ResourceLocation id) { + return getOptional(id, EntityTypeTags::getAllTags); + } +} diff --git a/common/src/main/java/me/shedaniel/architectury/mixin/BlockLandingInvoker.java b/common/src/main/java/me/shedaniel/architectury/mixin/BlockLandingInvoker.java index aead19c7..36996dce 100644 --- a/common/src/main/java/me/shedaniel/architectury/mixin/BlockLandingInvoker.java +++ b/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; diff --git a/common/src/main/java/me/shedaniel/architectury/mixin/FluidTagsAccessor.java b/common/src/main/java/me/shedaniel/architectury/mixin/FluidTagsAccessor.java new file mode 100644 index 00000000..f095c06e --- /dev/null +++ b/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 getHelper() { + throw new AssertionError(); + } +} diff --git a/common/src/main/java/me/shedaniel/architectury/mixin/MixinLightningBolt.java b/common/src/main/java/me/shedaniel/architectury/mixin/MixinLightningBolt.java index b2743063..eb9ed20d 100644 --- a/common/src/main/java/me/shedaniel/architectury/mixin/MixinLightningBolt.java +++ b/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; diff --git a/common/src/main/resources/architectury-common.mixins.json b/common/src/main/resources/architectury-common.mixins.json index f7f31de0..e8e55db3 100644 --- a/common/src/main/resources/architectury-common.mixins.json +++ b/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 + } } diff --git a/fabric/build.gradle b/fabric/build.gradle index 71b9f0df..523ca587 100644 --- a/fabric/build.gradle +++ b/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" diff --git a/fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/TagHooksImpl.java b/fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/TagHooksImpl.java new file mode 100644 index 00000000..378405c8 --- /dev/null +++ b/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 Tag.Named getOptional(ResourceLocation id, Supplier> collection) { + return TagRegistry.create(id, collection); + } +} diff --git a/fabric/src/main/java/me/shedaniel/architectury/plugin/fabric/ArchitecturyMixinPlugin.java b/fabric/src/main/java/me/shedaniel/architectury/plugin/fabric/ArchitecturyMixinPlugin.java index a97f2c28..bde86bc3 100644 --- a/fabric/src/main/java/me/shedaniel/architectury/plugin/fabric/ArchitecturyMixinPlugin.java +++ b/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; diff --git a/forge/src/main/java/me/shedaniel/architectury/mixin/forge/TagHooksImpl.java b/forge/src/main/java/me/shedaniel/architectury/mixin/forge/TagHooksImpl.java new file mode 100644 index 00000000..78da2d03 --- /dev/null +++ b/forge/src/main/java/me/shedaniel/architectury/mixin/forge/TagHooksImpl.java @@ -0,0 +1,63 @@ +/* + * 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.resources.ResourceLocation; +import net.minecraft.tags.Tag; +import net.minecraft.tags.TagCollection; + +import java.lang.ref.WeakReference; +import java.util.List; +import java.util.function.Supplier; + +public class TagHooksImpl { + public static Tag.Named getOptional(ResourceLocation id, Supplier> collection) { + return new Tag.Named() { + private volatile Tag backend; + private volatile WeakReference> backendCollection; + + @Override + public ResourceLocation getName() { + return id; + } + + @Override + public boolean contains(T object) { + return getBackend().contains(object); + } + + @Override + public List getValues() { + return getBackend().getValues(); + } + + private Tag getBackend() { + TagCollection 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; + } + } + }; + } +}