From a78dd4ea1b73002bdcb5893738e48f9833e95dc6 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 1 Jul 2022 13:54:16 +0200 Subject: [PATCH 1/7] Fix Entity.getEncodeId not being transitive accessible on 1.18 --- common/src/main/resources/architectury.accessWidener | 1 + 1 file changed, 1 insertion(+) diff --git a/common/src/main/resources/architectury.accessWidener b/common/src/main/resources/architectury.accessWidener index d2f7bd8b..a7e960f7 100644 --- a/common/src/main/resources/architectury.accessWidener +++ b/common/src/main/resources/architectury.accessWidener @@ -55,6 +55,7 @@ transitive-accessible method net/minecraft/advancements/CriteriaTriggers registe transitive-accessible method net/minecraft/world/inventory/MenuType (Lnet/minecraft/world/inventory/MenuType$MenuSupplier;)V transitive-accessible class net/minecraft/world/inventory/MenuType$MenuSupplier accessible method net/minecraft/world/entity/Entity getEncodeId ()Ljava/lang/String; +transitive-accessible method net/minecraft/world/entity/Entity getEncodeId ()Ljava/lang/String; accessible field net/minecraft/server/packs/repository/PackRepository sources Ljava/util/Set; mutable field net/minecraft/server/packs/repository/PackRepository sources Ljava/util/Set; accessible field net/minecraft/world/level/biome/Biome climateSettings Lnet/minecraft/world/level/biome/Biome$ClimateSettings; From 128141a99d5f9efe44b82575947aab970d15e4a0 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 20 Jul 2022 17:22:38 +0200 Subject: [PATCH 2/7] [ci skip] Fix Item pickup not being cancellable on Forge (#301) --- .../architectury/event/forge/EventHandlerImplCommon.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/forge/src/main/java/dev/architectury/event/forge/EventHandlerImplCommon.java b/forge/src/main/java/dev/architectury/event/forge/EventHandlerImplCommon.java index 511b03a6..891a3514 100644 --- a/forge/src/main/java/dev/architectury/event/forge/EventHandlerImplCommon.java +++ b/forge/src/main/java/dev/architectury/event/forge/EventHandlerImplCommon.java @@ -296,7 +296,14 @@ public class EventHandlerImplCommon { @SubscribeEvent(priority = EventPriority.HIGH) public static void event(EntityItemPickupEvent event) { - PlayerEvent.PICKUP_ITEM_PRE.invoker().canPickup(event.getPlayer(), event.getItem(), event.getItem().getItem()); + // note: this event is weird, cancel is equivalent to denying the pickup, + // and setting the result to ALLOW will pick it up without adding it to the player's inventory + var result = PlayerEvent.PICKUP_ITEM_PRE.invoker().canPickup(event.getPlayer(), event.getItem(), event.getItem().getItem()); + if (result.isFalse()) { + event.setCanceled(true); + } else if (result.isTrue()) { + event.setResult(Event.Result.ALLOW); + } } @SubscribeEvent(priority = EventPriority.HIGH) From 6b83a15e815aac831b65b7e916c37eb9687333ff Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+juuxel@users.noreply.github.com> Date: Wed, 20 Jul 2022 23:22:47 +0800 Subject: [PATCH 3/7] [ci skip] Add loot table modification event (#287) * Add loot table modification event Closes #42. It's a simple wrapper around the platform events. * Add param for builtin loot tables Co-authored-by: shedaniel (cherry picked from commit f0555ce0eb2fae2ac87059770616e402514dd1fa) --- .../event/events/common/LootEvent.java | 98 +++++++++++++++++++ .../event/fabric/EventHandlerImpl.java | 4 + .../LootTableModificationContextImpl.java | 42 ++++++++ .../event/forge/EventHandlerImplCommon.java | 6 ++ .../LootTableModificationContextImpl.java | 37 +++++++ .../java/dev/architectury/test/TestMod.java | 3 + .../dev/architectury/test/loot/TestLoot.java | 39 ++++++++ 7 files changed, 229 insertions(+) create mode 100644 common/src/main/java/dev/architectury/event/events/common/LootEvent.java create mode 100644 fabric/src/main/java/dev/architectury/event/fabric/LootTableModificationContextImpl.java create mode 100644 forge/src/main/java/dev/architectury/event/forge/LootTableModificationContextImpl.java create mode 100644 testmod-common/src/main/java/dev/architectury/test/loot/TestLoot.java diff --git a/common/src/main/java/dev/architectury/event/events/common/LootEvent.java b/common/src/main/java/dev/architectury/event/events/common/LootEvent.java new file mode 100644 index 00000000..dedf9277 --- /dev/null +++ b/common/src/main/java/dev/architectury/event/events/common/LootEvent.java @@ -0,0 +1,98 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021, 2022 architectury + * + * 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 dev.architectury.event.events.common; + +import dev.architectury.event.Event; +import dev.architectury.event.EventFactory; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.storage.loot.LootPool; +import net.minecraft.world.level.storage.loot.LootTables; +import org.jetbrains.annotations.ApiStatus; + +/** + * Events related to loot tables and loot generation. + */ +public interface LootEvent { + /** + * An event to modify loot tables when they are loaded. + * This can be used to add new drops via new loot pools to existing loot tables + * without replacing the entire table. + * + *

Built-in loot tables

+ *

{@linkplain ModifyLootTable The event interface} includes a {@code builtin} parameter. + * If it's {@code true}, the loot table is built-in to vanilla or a mod. + * Otherwise, it's from a user data pack. The parameter can be used to only modify built-in loot tables + * and let user-provided loot tables act as full "overwrites". + * + *

This event only runs for built-in loot tables on Forge due to the limitations of + * {@code LootTableLoadEvent}. + * + *

Example: adding diamonds as a drop for dirt

+ *
{@code
+     * LootEvent.MODIFY_LOOT_TABLE.register((lootTables, id, context, builtin) -> {
+     *     // Check that the loot table is dirt and built-in
+     *     if (builtin && Blocks.DIRT.getLootTable().equals(id)) {
+     *         // Create a loot pool with a single item entry of Items.DIAMOND
+     *         LootPool.Builder pool = LootPool.lootPool().add(LootItem.lootTableItem(Items.DIAMOND));
+     *         context.addPool(pool);
+     *     }
+     * });
+     * }
+ * + * @see ModifyLootTable#modifyLootTable(LootTables, ResourceLocation, LootTableModificationContext, boolean) + */ + Event MODIFY_LOOT_TABLE = EventFactory.createLoop(); + + @FunctionalInterface + interface ModifyLootTable { + /** + * Modifies a loot table. + * + * @param lootTables the {@link LootTables} instance containing all loot tables + * @param id the loot table ID + * @param context the context used to modify the loot table + * @param builtin if {@code true}, the loot table is built-in; + * if {@code false}, it is from a user data pack + */ + void modifyLootTable(LootTables lootTables, ResourceLocation id, LootTableModificationContext context, boolean builtin); + } + + /** + * A platform-specific bridge for modifying a specific loot table. + */ + @ApiStatus.NonExtendable + interface LootTableModificationContext { + /** + * Adds a pool to the loot table. + * + * @param pool the pool to add + */ + void addPool(LootPool pool); + + /** + * Adds a pool to the loot table. + * + * @param pool the pool to add + */ + default void addPool(LootPool.Builder pool) { + addPool(pool.build()); + } + } +} diff --git a/fabric/src/main/java/dev/architectury/event/fabric/EventHandlerImpl.java b/fabric/src/main/java/dev/architectury/event/fabric/EventHandlerImpl.java index 1169449a..83fef1d5 100644 --- a/fabric/src/main/java/dev/architectury/event/fabric/EventHandlerImpl.java +++ b/fabric/src/main/java/dev/architectury/event/fabric/EventHandlerImpl.java @@ -26,6 +26,7 @@ import dev.architectury.event.events.client.ClientTooltipEvent; import dev.architectury.event.events.common.CommandRegistrationEvent; import dev.architectury.event.events.common.InteractionEvent; import dev.architectury.event.events.common.LifecycleEvent; +import dev.architectury.event.events.common.LootEvent; import dev.architectury.event.events.common.TickEvent; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -41,6 +42,7 @@ import net.fabricmc.fabric.api.event.player.AttackBlockCallback; import net.fabricmc.fabric.api.event.player.UseBlockCallback; import net.fabricmc.fabric.api.event.player.UseItemCallback; import net.minecraft.commands.Commands; +import net.fabricmc.fabric.api.loot.v2.LootTableEvents; public class EventHandlerImpl { @Environment(EnvType.CLIENT) @@ -76,6 +78,8 @@ public class EventHandlerImpl { UseItemCallback.EVENT.register((player, world, hand) -> InteractionEvent.RIGHT_CLICK_ITEM.invoker().click(player, hand).asMinecraft()); UseBlockCallback.EVENT.register((player, world, hand, hitResult) -> InteractionEvent.RIGHT_CLICK_BLOCK.invoker().click(player, hand, hitResult.getBlockPos(), hitResult.getDirection()).asMinecraft()); AttackBlockCallback.EVENT.register((player, world, hand, pos, face) -> InteractionEvent.LEFT_CLICK_BLOCK.invoker().click(player, hand, pos, face).asMinecraft()); + + LootTableEvents.MODIFY.register((resourceManager, lootManager, id, tableBuilder, source) -> LootEvent.MODIFY_LOOT_TABLE.invoker().modifyLootTable(lootManager, id, new LootTableModificationContextImpl(tableBuilder), source.isBuiltin())); } @Environment(EnvType.SERVER) diff --git a/fabric/src/main/java/dev/architectury/event/fabric/LootTableModificationContextImpl.java b/fabric/src/main/java/dev/architectury/event/fabric/LootTableModificationContextImpl.java new file mode 100644 index 00000000..3d00da9a --- /dev/null +++ b/fabric/src/main/java/dev/architectury/event/fabric/LootTableModificationContextImpl.java @@ -0,0 +1,42 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021, 2022 architectury + * + * 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 dev.architectury.event.fabric; + +import dev.architectury.event.events.common.LootEvent; +import net.minecraft.world.level.storage.loot.LootPool; +import net.minecraft.world.level.storage.loot.LootTable; + +final class LootTableModificationContextImpl implements LootEvent.LootTableModificationContext { + private final LootTable.Builder tableBuilder; + + LootTableModificationContextImpl(LootTable.Builder tableBuilder) { + this.tableBuilder = tableBuilder; + } + + @Override + public void addPool(LootPool pool) { + tableBuilder.pool(pool); + } + + @Override + public void addPool(LootPool.Builder pool) { + tableBuilder.withPool(pool); + } +} diff --git a/forge/src/main/java/dev/architectury/event/forge/EventHandlerImplCommon.java b/forge/src/main/java/dev/architectury/event/forge/EventHandlerImplCommon.java index 891a3514..f0ded37f 100644 --- a/forge/src/main/java/dev/architectury/event/forge/EventHandlerImplCommon.java +++ b/forge/src/main/java/dev/architectury/event/forge/EventHandlerImplCommon.java @@ -33,6 +33,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; import net.minecraftforge.event.CommandEvent; +import net.minecraftforge.event.LootTableLoadEvent; import net.minecraftforge.event.RegisterCommandsEvent; import net.minecraftforge.event.ServerChatEvent; import net.minecraftforge.event.TickEvent.Phase; @@ -424,6 +425,11 @@ public class EventHandlerImplCommon { ChunkEvent.LOAD_DATA.invoker().load(event.getChunk(), level instanceof ServerLevel ? (ServerLevel) level : null, event.getData()); } + @SubscribeEvent(priority = EventPriority.HIGH) + public static void event(LootTableLoadEvent event) { + LootEvent.MODIFY_LOOT_TABLE.invoker().modifyLootTable(event.getLootTableManager(), event.getName(), new LootTableModificationContextImpl(event.getTable()), true); + } + public interface WorldEventAttachment { LevelAccessor architectury$getAttachedLevel(); diff --git a/forge/src/main/java/dev/architectury/event/forge/LootTableModificationContextImpl.java b/forge/src/main/java/dev/architectury/event/forge/LootTableModificationContextImpl.java new file mode 100644 index 00000000..b8eff2ea --- /dev/null +++ b/forge/src/main/java/dev/architectury/event/forge/LootTableModificationContextImpl.java @@ -0,0 +1,37 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021, 2022 architectury + * + * 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 dev.architectury.event.forge; + +import dev.architectury.event.events.common.LootEvent; +import net.minecraft.world.level.storage.loot.LootPool; +import net.minecraft.world.level.storage.loot.LootTable; + +final class LootTableModificationContextImpl implements LootEvent.LootTableModificationContext { + private final LootTable table; + + LootTableModificationContextImpl(LootTable table) { + this.table = table; + } + + @Override + public void addPool(LootPool pool) { + table.addPool(pool); + } +} diff --git a/testmod-common/src/main/java/dev/architectury/test/TestMod.java b/testmod-common/src/main/java/dev/architectury/test/TestMod.java index 77f82e80..c1768bd6 100644 --- a/testmod-common/src/main/java/dev/architectury/test/TestMod.java +++ b/testmod-common/src/main/java/dev/architectury/test/TestMod.java @@ -28,6 +28,7 @@ import dev.architectury.test.entity.TestEntity; import dev.architectury.test.events.DebugEvents; import dev.architectury.test.gamerule.TestGameRules; import dev.architectury.test.item.TestBlockInteractions; +import dev.architectury.test.loot.TestLoot; import dev.architectury.test.networking.TestModNet; import dev.architectury.test.particle.TestParticles; import dev.architectury.test.registry.TestRegistries; @@ -55,6 +56,8 @@ public class TestMod { TestParticles.initialize(); TestModNet.initialize(); TestBlockInteractions.init(); + TestLoot.init(); + TestWorldGeneration.initialize(); EnvExecutor.runInEnv(Env.CLIENT, () -> TestMod.Client::initializeClient); } diff --git a/testmod-common/src/main/java/dev/architectury/test/loot/TestLoot.java b/testmod-common/src/main/java/dev/architectury/test/loot/TestLoot.java new file mode 100644 index 00000000..9ae36a74 --- /dev/null +++ b/testmod-common/src/main/java/dev/architectury/test/loot/TestLoot.java @@ -0,0 +1,39 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021, 2022 architectury + * + * 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 dev.architectury.test.loot; + +import dev.architectury.event.events.common.LootEvent; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.storage.loot.LootPool; +import net.minecraft.world.level.storage.loot.entries.LootItem; + +public class TestLoot { + public static void init() { + LootEvent.MODIFY_LOOT_TABLE.register((lootTables, id, context, builtin) -> { + // Check that the loot table is dirt and built-in + if (builtin && Blocks.DIRT.getLootTable().equals(id)) { + // Create a loot pool with a single item entry of Items.DIAMOND + LootPool.Builder pool = LootPool.lootPool().add(LootItem.lootTableItem(Items.DIAMOND)); + context.addPool(pool); + } + }); + } +} From dfce9f247d6b9c3f788dd259b6dc5fd6e9407d60 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Wed, 20 Jul 2022 23:21:42 +0800 Subject: [PATCH 4/7] [ci skip] Add WorldGen testmod (#298) (cherry picked from commit c259d62ba3ae9edde5e750eae044f28a4b6664c6) --- .../java/dev/architectury/test/TestMod.java | 1 + .../test/worldgen/TestWorldGeneration.java | 56 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 testmod-common/src/main/java/dev/architectury/test/worldgen/TestWorldGeneration.java diff --git a/testmod-common/src/main/java/dev/architectury/test/TestMod.java b/testmod-common/src/main/java/dev/architectury/test/TestMod.java index c1768bd6..009bcf22 100644 --- a/testmod-common/src/main/java/dev/architectury/test/TestMod.java +++ b/testmod-common/src/main/java/dev/architectury/test/TestMod.java @@ -35,6 +35,7 @@ import dev.architectury.test.registry.TestRegistries; import dev.architectury.test.registry.client.TestKeybinds; import dev.architectury.test.tags.TestTags; import dev.architectury.test.trade.TestTrades; +import dev.architectury.test.worldgen.TestWorldGeneration; import dev.architectury.utils.Env; import dev.architectury.utils.EnvExecutor; import net.fabricmc.api.EnvType; diff --git a/testmod-common/src/main/java/dev/architectury/test/worldgen/TestWorldGeneration.java b/testmod-common/src/main/java/dev/architectury/test/worldgen/TestWorldGeneration.java new file mode 100644 index 00000000..e9aca40f --- /dev/null +++ b/testmod-common/src/main/java/dev/architectury/test/worldgen/TestWorldGeneration.java @@ -0,0 +1,56 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021, 2022 architectury + * + * 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 dev.architectury.test.worldgen; + +import dev.architectury.event.events.common.LifecycleEvent; +import dev.architectury.registry.level.biome.BiomeModifications; +import dev.architectury.test.TestMod; +import net.minecraft.core.Holder; +import net.minecraft.data.worldgen.features.FeatureUtils; +import net.minecraft.data.worldgen.features.OreFeatures; +import net.minecraft.data.worldgen.placement.PlacementUtils; +import net.minecraft.tags.BiomeTags; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.levelgen.GenerationStep; +import net.minecraft.world.level.levelgen.VerticalAnchor; +import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; +import net.minecraft.world.level.levelgen.feature.Feature; +import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration; +import net.minecraft.world.level.levelgen.placement.*; + +import java.util.List; + +public class TestWorldGeneration { + public static void initialize() { + LifecycleEvent.SETUP.register(() -> { + Holder> configuredFeature = FeatureUtils.register(TestMod.MOD_ID + ":diamond_blocks", Feature.ORE, + new OreConfiguration(OreFeatures.NATURAL_STONE, Blocks.DIAMOND_BLOCK.defaultBlockState(), 33)); + Holder placedFeature = PlacementUtils.register(TestMod.MOD_ID + ":diamond_blocks", configuredFeature, + List.of(CountPlacement.of(4), InSquarePlacement.spread(), + HeightRangePlacement.uniform(VerticalAnchor.bottom(), VerticalAnchor.absolute(15)), + BiomeFilter.biome())); + BiomeModifications.addProperties((ctx, mutable) -> { + if (ctx.hasTag(BiomeTags.IS_FOREST)) { + mutable.getGenerationProperties().addFeature(GenerationStep.Decoration.TOP_LAYER_MODIFICATION, placedFeature); + } + }); + }); + } +} From 81f4de28ba0f27f0e34e3d61d3f806dc732af6fb Mon Sep 17 00:00:00 2001 From: itsmeow Date: Fri, 10 Jun 2022 01:47:34 +0800 Subject: [PATCH 5/7] Implement hasTag onto BiomeContext (#272) * Implement hasTag onto BiomeContext * Improve optional handling [norelease] to allow for version bumping and reformatting before release (cherry picked from commit 16a7d23602670dc8f5cc2d3d5cb23a88d6d41706) --- .../level/biome/BiomeModifications.java | 5 +++++ .../event/fabric/EventHandlerImpl.java | 8 ++----- .../biome/fabric/BiomeModificationsImpl.java | 6 +++++ fabric/src/main/resources/fabric.mod.json | 2 +- .../biome/forge/BiomeModificationsImpl.java | 22 +++++++++++++++++++ gradle.properties | 2 +- 6 files changed, 37 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/dev/architectury/registry/level/biome/BiomeModifications.java b/common/src/main/java/dev/architectury/registry/level/biome/BiomeModifications.java index 4f0c2fcf..e2aed79e 100644 --- a/common/src/main/java/dev/architectury/registry/level/biome/BiomeModifications.java +++ b/common/src/main/java/dev/architectury/registry/level/biome/BiomeModifications.java @@ -22,7 +22,10 @@ package dev.architectury.registry.level.biome; import com.google.common.base.Predicates; import dev.architectury.hooks.level.biome.BiomeProperties; import dev.architectury.injectables.annotations.ExpectPlatform; +import net.minecraft.core.Holder; import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagKey; +import net.minecraft.world.level.biome.Biome; import java.util.function.BiConsumer; import java.util.function.Predicate; @@ -89,5 +92,7 @@ public final class BiomeModifications { ResourceLocation getKey(); BiomeProperties getProperties(); + + boolean hasTag(TagKey tag); } } diff --git a/fabric/src/main/java/dev/architectury/event/fabric/EventHandlerImpl.java b/fabric/src/main/java/dev/architectury/event/fabric/EventHandlerImpl.java index 83fef1d5..e5ad152d 100644 --- a/fabric/src/main/java/dev/architectury/event/fabric/EventHandlerImpl.java +++ b/fabric/src/main/java/dev/architectury/event/fabric/EventHandlerImpl.java @@ -23,11 +23,7 @@ import dev.architectury.event.events.client.ClientGuiEvent; import dev.architectury.event.events.client.ClientLifecycleEvent; import dev.architectury.event.events.client.ClientTickEvent; import dev.architectury.event.events.client.ClientTooltipEvent; -import dev.architectury.event.events.common.CommandRegistrationEvent; -import dev.architectury.event.events.common.InteractionEvent; -import dev.architectury.event.events.common.LifecycleEvent; -import dev.architectury.event.events.common.LootEvent; -import dev.architectury.event.events.common.TickEvent; +import dev.architectury.event.events.common.*; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents; @@ -41,8 +37,8 @@ import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents; import net.fabricmc.fabric.api.event.player.AttackBlockCallback; import net.fabricmc.fabric.api.event.player.UseBlockCallback; import net.fabricmc.fabric.api.event.player.UseItemCallback; -import net.minecraft.commands.Commands; import net.fabricmc.fabric.api.loot.v2.LootTableEvents; +import net.minecraft.commands.Commands; public class EventHandlerImpl { @Environment(EnvType.CLIENT) diff --git a/fabric/src/main/java/dev/architectury/registry/level/biome/fabric/BiomeModificationsImpl.java b/fabric/src/main/java/dev/architectury/registry/level/biome/fabric/BiomeModificationsImpl.java index a95b0989..5ce8e7c7 100644 --- a/fabric/src/main/java/dev/architectury/registry/level/biome/fabric/BiomeModificationsImpl.java +++ b/fabric/src/main/java/dev/architectury/registry/level/biome/fabric/BiomeModificationsImpl.java @@ -33,6 +33,7 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.Music; import net.minecraft.sounds.SoundEvent; +import net.minecraft.tags.TagKey; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.MobCategory; import net.minecraft.world.level.biome.*; @@ -110,6 +111,11 @@ public class BiomeModificationsImpl { public BiomeProperties getProperties() { return properties; } + + @Override + public boolean hasTag(TagKey tag) { + return context.hasTag(tag); + } }; } diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 824d52b1..9915e78d 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -36,7 +36,7 @@ "depends": { "minecraft": "~1.18.2-", "fabricloader": ">=0.13.0", - "fabric": ">=0.50.0" + "fabric": ">=0.54.0" }, "breaks": { "optifabric": "<1.13.0" diff --git a/forge/src/main/java/dev/architectury/registry/level/biome/forge/BiomeModificationsImpl.java b/forge/src/main/java/dev/architectury/registry/level/biome/forge/BiomeModificationsImpl.java index 498931a9..2c9806c0 100644 --- a/forge/src/main/java/dev/architectury/registry/level/biome/forge/BiomeModificationsImpl.java +++ b/forge/src/main/java/dev/architectury/registry/level/biome/forge/BiomeModificationsImpl.java @@ -23,9 +23,15 @@ import com.google.common.collect.Lists; import dev.architectury.forge.ArchitecturyForge; import dev.architectury.hooks.level.biome.*; import dev.architectury.registry.level.biome.BiomeModifications.BiomeContext; +import dev.architectury.utils.GameInstance; import net.minecraft.core.Holder; +import net.minecraft.core.Registry; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; +import net.minecraft.sounds.Music; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.tags.TagKey; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.MobCategory; import net.minecraft.world.level.biome.Biome; @@ -43,6 +49,7 @@ import org.apache.commons.lang3.tuple.Pair; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.function.BiConsumer; import java.util.function.BiPredicate; import java.util.function.Predicate; @@ -83,6 +90,21 @@ public class BiomeModificationsImpl { public BiomeProperties getProperties() { return properties; } + + @Override + public boolean hasTag(TagKey tag) { + MinecraftServer server = GameInstance.getServer(); + if (server != null) { + Optional> registry = server.registryAccess().registry(Registry.BIOME_REGISTRY); + if (registry.isPresent()) { + Optional> holder = registry.get().getHolder(ResourceKey.create(Registry.BIOME_REGISTRY, event.getName())); + if (holder.isPresent()) { + return holder.get().is(tag); + } + } + } + return false; + } }; } diff --git a/gradle.properties b/gradle.properties index b57ee11d..b351a5b7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,7 +14,7 @@ base_version=4.5 maven_group=dev.architectury fabric_loader_version=0.13.3 -fabric_api_version=0.50.0+1.18.2 +fabric_api_version=0.58.0+1.18.2 mod_menu_version=3.0.0 forge_version=40.1.14 From 7b4b91ea477c54987b06332107ba7b79ab98deb4 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 23 Jul 2022 03:09:02 +0800 Subject: [PATCH 6/7] Bump to 4.6 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index b351a5b7..ae2a4f0f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ artifact_type=release archives_base_name=architectury archives_base_name_snapshot=architectury-snapshot -base_version=4.5 +base_version=4.6 maven_group=dev.architectury fabric_loader_version=0.13.3 From a7d31393a0efe8b6e5ea70f1fbfecf477ac51753 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 31 Jul 2022 18:48:38 +0200 Subject: [PATCH 7/7] Fix ParticleProviderRegistry not working properly on Forge, add Javadocs (#305) * Fix ParticleProviderRegistry not working properly on Forge, add Javadocs Based on https://github.com/architectury/architectury-api/pull/196#issuecomment-1200268981, supersedes #196 * Update testmod, fix bounds on deferred register * Warn when registering particles too late on Forge --- .../particle/ParticleProviderRegistry.java | 21 +++++++++++++++++++ .../forge/ParticleProviderRegistryImpl.java | 21 ++++++++++++------- gradle.properties | 2 +- .../test/particle/TestParticles.java | 4 +--- .../particles/test_particle.json | 0 .../particles/test_particle.json | 2 -- 6 files changed, 37 insertions(+), 13 deletions(-) rename {testmod-fabric => testmod-common}/src/main/resources/assets/architectury_test/particles/test_particle.json (100%) delete mode 100644 testmod-forge/src/main/resources/assets/architectury_test/particles/test_particle.json diff --git a/common/src/main/java/dev/architectury/registry/client/particle/ParticleProviderRegistry.java b/common/src/main/java/dev/architectury/registry/client/particle/ParticleProviderRegistry.java index 9f1bb711..63c4104d 100644 --- a/common/src/main/java/dev/architectury/registry/client/particle/ParticleProviderRegistry.java +++ b/common/src/main/java/dev/architectury/registry/client/particle/ParticleProviderRegistry.java @@ -19,7 +19,9 @@ package dev.architectury.registry.client.particle; +import dev.architectury.event.events.client.ClientLifecycleEvent; import dev.architectury.injectables.annotations.ExpectPlatform; +import dev.architectury.registry.registries.RegistrySupplier; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.particle.ParticleProvider; @@ -31,6 +33,17 @@ import net.minecraft.core.particles.ParticleType; import java.util.List; +/** + * A utility class for registering custom {@link ParticleProvider}s for particle types. + *

+ * This class's methods should be invoked before {@link ClientLifecycleEvent#CLIENT_SETUP}, + * as doing so afterwards will result in the providers not being registered properly on Forge, causing crashes on startup. + *

+ * Generally speaking, you should either listen to the registration of your particle type yourself and use either + * {@link #register(ParticleType, ParticleProvider)} or {@link #register(ParticleType, DeferredParticleProvider)} to register the provider, + * or use the helper methods {@link #register(RegistrySupplier, ParticleProvider)} and {@link #register(RegistrySupplier, DeferredParticleProvider)}, + * which will automatically handle the listening for you. + */ @Environment(EnvType.CLIENT) public final class ParticleProviderRegistry { public interface ExtendedSpriteSet extends SpriteSet { @@ -39,6 +52,14 @@ public final class ParticleProviderRegistry { List getSprites(); } + public static void register(RegistrySupplier> supplier, ParticleProvider provider) { + supplier.listen(it -> register(it, provider)); + } + + public static void register(RegistrySupplier> supplier, DeferredParticleProvider provider) { + supplier.listen(it -> register(it, provider)); + } + @ExpectPlatform public static void register(ParticleType type, ParticleProvider provider) { throw new AssertionError(); diff --git a/forge/src/main/java/dev/architectury/registry/client/particle/forge/ParticleProviderRegistryImpl.java b/forge/src/main/java/dev/architectury/registry/client/particle/forge/ParticleProviderRegistryImpl.java index 952646f1..91253305 100644 --- a/forge/src/main/java/dev/architectury/registry/client/particle/forge/ParticleProviderRegistryImpl.java +++ b/forge/src/main/java/dev/architectury/registry/client/particle/forge/ParticleProviderRegistryImpl.java @@ -19,6 +19,7 @@ package dev.architectury.registry.client.particle.forge; +import com.mojang.logging.LogUtils; import dev.architectury.forge.ArchitecturyForge; import dev.architectury.registry.client.particle.ParticleProviderRegistry; import net.minecraft.client.Minecraft; @@ -33,13 +34,17 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.ParticleFactoryRegisterEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; +import org.slf4j.Logger; import java.util.ArrayList; import java.util.List; import java.util.Random; -@Mod.EventBusSubscriber(modid = ArchitecturyForge.MOD_ID, value = Dist.CLIENT) +@Mod.EventBusSubscriber(modid = ArchitecturyForge.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD) public class ParticleProviderRegistryImpl { + + public static final Logger LOGGER = LogUtils.getLogger(); + private static final class ExtendedSpriteSetImpl implements ParticleProviderRegistry.ExtendedSpriteSet { private final ParticleEngine engine; private final SpriteSet delegate; @@ -72,28 +77,30 @@ public class ParticleProviderRegistryImpl { private static ArrayList deferred = new ArrayList<>(); - private static void _register(ParticleType type, ParticleProvider provider) { + private static void doRegister(ParticleType type, ParticleProvider provider) { Minecraft.getInstance().particleEngine.register(type, provider); } - private static void _register(ParticleType type, ParticleProviderRegistry.DeferredParticleProvider provider) { + private static void doRegister(ParticleType type, ParticleProviderRegistry.DeferredParticleProvider provider) { Minecraft.getInstance().particleEngine.register(type, sprites -> provider.create(new ExtendedSpriteSetImpl(Minecraft.getInstance().particleEngine, sprites))); } public static void register(ParticleType type, ParticleProvider provider) { if (deferred == null) { - _register(type, provider); + LOGGER.warn("Something is attempting to register particle providers at a later point than intended! This might cause issues!", new Throwable()); + doRegister(type, provider); } else { - deferred.add(() -> _register(type, provider)); + deferred.add(() -> doRegister(type, provider)); } } public static void register(ParticleType type, ParticleProviderRegistry.DeferredParticleProvider provider) { if (deferred == null) { - _register(type, provider); + LOGGER.warn("Something is attempting to register particle providers at a later point than intended! This might cause issues!", new Throwable()); + doRegister(type, provider); } else { - deferred.add(() -> _register(type, provider)); + deferred.add(() -> doRegister(type, provider)); } } diff --git a/gradle.properties b/gradle.properties index ae2a4f0f..17f53994 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ artifact_type=release archives_base_name=architectury archives_base_name_snapshot=architectury-snapshot -base_version=4.6 +base_version=4.7 maven_group=dev.architectury fabric_loader_version=0.13.3 diff --git a/testmod-common/src/main/java/dev/architectury/test/particle/TestParticles.java b/testmod-common/src/main/java/dev/architectury/test/particle/TestParticles.java index 246afabd..dfa89af6 100644 --- a/testmod-common/src/main/java/dev/architectury/test/particle/TestParticles.java +++ b/testmod-common/src/main/java/dev/architectury/test/particle/TestParticles.java @@ -40,9 +40,7 @@ public class TestParticles { public static void initialize() { PARTICLE_TYPES.register(); if (Platform.getEnvironment() == Env.CLIENT) { - ClientLifecycleEvent.CLIENT_SETUP.register(instance -> { - ParticleProviderRegistry.register(TEST_PARTICLE.get(), HeartParticle.Provider::new); - }); + ParticleProviderRegistry.register(TEST_PARTICLE, HeartParticle.Provider::new); } } } diff --git a/testmod-fabric/src/main/resources/assets/architectury_test/particles/test_particle.json b/testmod-common/src/main/resources/assets/architectury_test/particles/test_particle.json similarity index 100% rename from testmod-fabric/src/main/resources/assets/architectury_test/particles/test_particle.json rename to testmod-common/src/main/resources/assets/architectury_test/particles/test_particle.json diff --git a/testmod-forge/src/main/resources/assets/architectury_test/particles/test_particle.json b/testmod-forge/src/main/resources/assets/architectury_test/particles/test_particle.json deleted file mode 100644 index 7a73a41b..00000000 --- a/testmod-forge/src/main/resources/assets/architectury_test/particles/test_particle.json +++ /dev/null @@ -1,2 +0,0 @@ -{ -} \ No newline at end of file