From f662b794a7b66a1d3c304475db5169640e377f17 Mon Sep 17 00:00:00 2001 From: EightSidedSquare Date: Fri, 17 Oct 2025 23:19:04 -0400 Subject: [PATCH 1/2] Add firework star explosion type registry --- .../FireworkStarExplosionTypeRegistry.java | 52 +++++++++++++++++++ ...FireworkStarExplosionTypeRegistryImpl.java | 34 ++++++++++++ .../registry/FireworkStarRecipeAccessor.java | 41 +++++++++++++++ .../fabric-content-registries-v0.mixins.json | 1 + 4 files changed, 128 insertions(+) create mode 100644 fabric-content-registries-v0/src/main/java/net/fabricmc/fabric/api/registry/FireworkStarExplosionTypeRegistry.java create mode 100644 fabric-content-registries-v0/src/main/java/net/fabricmc/fabric/impl/content/registry/FireworkStarExplosionTypeRegistryImpl.java create mode 100644 fabric-content-registries-v0/src/main/java/net/fabricmc/fabric/mixin/content/registry/FireworkStarRecipeAccessor.java diff --git a/fabric-content-registries-v0/src/main/java/net/fabricmc/fabric/api/registry/FireworkStarExplosionTypeRegistry.java b/fabric-content-registries-v0/src/main/java/net/fabricmc/fabric/api/registry/FireworkStarExplosionTypeRegistry.java new file mode 100644 index 0000000000..96899ed963 --- /dev/null +++ b/fabric-content-registries-v0/src/main/java/net/fabricmc/fabric/api/registry/FireworkStarExplosionTypeRegistry.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.api.registry; + +import java.util.Objects; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.minecraft.component.type.FireworkExplosionComponent; +import net.minecraft.item.ItemConvertible; +import net.minecraft.recipe.FireworkStarRecipe; + +import net.fabricmc.fabric.impl.content.registry.FireworkStarExplosionTypeRegistryImpl; + +/** + * A registry for the {@link FireworkExplosionComponent.Type} of an item for the {@link FireworkStarRecipe}. + */ +public final class FireworkStarExplosionTypeRegistry { + private static final Logger LOGGER = LoggerFactory.getLogger(FireworkStarExplosionTypeRegistry.class); + + private FireworkStarExplosionTypeRegistry() { + } + + /** + * Registers an explosion type for the item. + * @param item the item to register + * @param explosionType the firework explosion type + */ + public static void register(ItemConvertible item, FireworkExplosionComponent.Type explosionType) { + Objects.requireNonNull(item, "Item cannot be null!"); + FireworkExplosionComponent.Type oldValue = FireworkStarExplosionTypeRegistryImpl.getFireworkStarExplosionTypeRegistry().put(item.asItem(), explosionType); + + if (oldValue != null) { + LOGGER.info("Overriding previous firework star explosion type of {}, was: {}, now: {}", item.asItem().toString(), oldValue, explosionType); + } + } +} diff --git a/fabric-content-registries-v0/src/main/java/net/fabricmc/fabric/impl/content/registry/FireworkStarExplosionTypeRegistryImpl.java b/fabric-content-registries-v0/src/main/java/net/fabricmc/fabric/impl/content/registry/FireworkStarExplosionTypeRegistryImpl.java new file mode 100644 index 0000000000..59e29cfc6a --- /dev/null +++ b/fabric-content-registries-v0/src/main/java/net/fabricmc/fabric/impl/content/registry/FireworkStarExplosionTypeRegistryImpl.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.impl.content.registry; + +import java.util.Map; + +import net.minecraft.component.type.FireworkExplosionComponent; +import net.minecraft.item.Item; + +import net.fabricmc.fabric.impl.content.registry.util.ImmutableCollectionUtils; +import net.fabricmc.fabric.mixin.content.registry.FireworkStarRecipeAccessor; + +public final class FireworkStarExplosionTypeRegistryImpl { + private FireworkStarExplosionTypeRegistryImpl() { + } + + public static Map getFireworkStarExplosionTypeRegistry() { + return ImmutableCollectionUtils.getAsMutableMap(FireworkStarRecipeAccessor::fabric_getTypeModifierMap, FireworkStarRecipeAccessor::fabric_setTypeModifierMap); + } +} diff --git a/fabric-content-registries-v0/src/main/java/net/fabricmc/fabric/mixin/content/registry/FireworkStarRecipeAccessor.java b/fabric-content-registries-v0/src/main/java/net/fabricmc/fabric/mixin/content/registry/FireworkStarRecipeAccessor.java new file mode 100644 index 0000000000..8044987cae --- /dev/null +++ b/fabric-content-registries-v0/src/main/java/net/fabricmc/fabric/mixin/content/registry/FireworkStarRecipeAccessor.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.mixin.content.registry; + +import java.util.Map; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.gen.Accessor; + +import net.minecraft.component.type.FireworkExplosionComponent; +import net.minecraft.item.Item; +import net.minecraft.recipe.FireworkStarRecipe; + +@Mixin(FireworkStarRecipe.class) +public interface FireworkStarRecipeAccessor { + @Mutable + @Accessor("TYPE_MODIFIER_MAP") + static void fabric_setTypeModifierMap(Map typeModifierMap) { + throw new AssertionError("Untransformed @Accessor"); + } + + @Accessor("TYPE_MODIFIER_MAP") + static Map fabric_getTypeModifierMap() { + throw new AssertionError("Untransformed @Accessor"); + } +} diff --git a/fabric-content-registries-v0/src/main/resources/fabric-content-registries-v0.mixins.json b/fabric-content-registries-v0/src/main/resources/fabric-content-registries-v0.mixins.json index 67387fbfde..9b92ac64c4 100644 --- a/fabric-content-registries-v0/src/main/resources/fabric-content-registries-v0.mixins.json +++ b/fabric-content-registries-v0/src/main/resources/fabric-content-registries-v0.mixins.json @@ -10,6 +10,7 @@ "BrewingRecipeRegistryBuilderMixin", "FarmerWorkTaskAccessor", "FireBlockMixin", + "FireworkStarRecipeAccessor", "FuelRegistryMixin", "GiveGiftsToHeroTaskAccessor", "GiveGiftsToHeroTaskMixin", From bd755563b9e1529135212594e09ba2f7ecec0774 Mon Sep 17 00:00:00 2001 From: EightSidedSquare Date: Fri, 17 Oct 2025 23:19:10 -0400 Subject: [PATCH 2/2] Add tests --- .../registry/ContentRegistryGameTest.java | 29 +++++++++++++++++++ .../content/registry/ContentRegistryTest.java | 5 ++++ 2 files changed, 34 insertions(+) diff --git a/fabric-content-registries-v0/src/testmod/java/net/fabricmc/fabric/test/content/registry/ContentRegistryGameTest.java b/fabric-content-registries-v0/src/testmod/java/net/fabricmc/fabric/test/content/registry/ContentRegistryGameTest.java index 30d91bcc4b..b346407bc2 100644 --- a/fabric-content-registries-v0/src/testmod/java/net/fabricmc/fabric/test/content/registry/ContentRegistryGameTest.java +++ b/fabric-content-registries-v0/src/testmod/java/net/fabricmc/fabric/test/content/registry/ContentRegistryGameTest.java @@ -16,9 +16,12 @@ package net.fabricmc.fabric.test.content.registry; +import java.util.List; import java.util.function.BiConsumer; import java.util.function.Consumer; +import it.unimi.dsi.fastutil.ints.IntList; + import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.ComposterBlock; @@ -29,13 +32,18 @@ import net.minecraft.block.entity.HopperBlockEntity; import net.minecraft.block.enums.BlockHalf; import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.FireworkExplosionComponent; import net.minecraft.component.type.PotionContentsComponent; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.potion.Potions; +import net.minecraft.recipe.RecipeType; +import net.minecraft.recipe.input.CraftingRecipeInput; +import net.minecraft.server.world.ServerWorld; import net.minecraft.test.TestContext; import net.minecraft.text.Text; +import net.minecraft.util.DyeColor; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; @@ -243,4 +251,25 @@ public void testBrewingDirt(TestContext context) { context.complete(); }); } + + @GameTest + public void testFireworkStarExplosionTypeRegistry(TestContext context) { + CraftingRecipeInput inventory = CraftingRecipeInput.create(1, 3, List.of( + Items.GUNPOWDER.getDefaultStack(), + Items.RED_DYE.getDefaultStack(), + Items.NETHER_STAR.getDefaultStack())); + ServerWorld world = context.getWorld(); + ItemStack result = world.getRecipeManager().getFirstMatch(RecipeType.CRAFTING, inventory, world) + .map(recipe -> recipe.value().craft(inventory, world.getRegistryManager())) + .orElse(ItemStack.EMPTY); + ItemStack expected = Items.FIREWORK_STAR.getDefaultStack(); + expected.set(DataComponentTypes.FIREWORK_EXPLOSION, new FireworkExplosionComponent( + FireworkExplosionComponent.Type.STAR, + IntList.of(DyeColor.RED.getFireworkColor()), + IntList.of(), + false, + false)); + context.assertTrue(ItemStack.areEqual(result, expected), Text.literal("crafting result should be red firework star with star explosion type")); + context.complete(); + } } diff --git a/fabric-content-registries-v0/src/testmod/java/net/fabricmc/fabric/test/content/registry/ContentRegistryTest.java b/fabric-content-registries-v0/src/testmod/java/net/fabricmc/fabric/test/content/registry/ContentRegistryTest.java index d2d7bad869..0b50835fff 100644 --- a/fabric-content-registries-v0/src/testmod/java/net/fabricmc/fabric/test/content/registry/ContentRegistryTest.java +++ b/fabric-content-registries-v0/src/testmod/java/net/fabricmc/fabric/test/content/registry/ContentRegistryTest.java @@ -25,6 +25,7 @@ import net.minecraft.block.Blocks; import net.minecraft.block.Oxidizable; import net.minecraft.block.OxidizableBlock; +import net.minecraft.component.type.FireworkExplosionComponent; import net.minecraft.entity.ai.pathing.PathNodeType; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.HoeItem; @@ -55,6 +56,7 @@ import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.registry.CompostingChanceRegistry; import net.fabricmc.fabric.api.registry.FabricBrewingRecipeRegistryBuilder; +import net.fabricmc.fabric.api.registry.FireworkStarExplosionTypeRegistry; import net.fabricmc.fabric.api.registry.FlammableBlockRegistry; import net.fabricmc.fabric.api.registry.FlattenableBlockRegistry; import net.fabricmc.fabric.api.registry.FuelRegistryEvents; @@ -107,6 +109,7 @@ public void onInitialize() { // - instant health potions can be brewed from awkward potions with any item in the 'minecraft:small_flowers' tag // - if Redstone Experiments experiment is enabled, luck potions can be brewed from awkward potions with a bundle // - dirty potions can be brewed by adding any item in the 'minecraft:dirt' tag to any standard potion + // - nether stars can be used to create a firework star with the star explosion type CompostingChanceRegistry.INSTANCE.add(Items.OBSIDIAN, 0.5F); FlammableBlockRegistry.getDefaultInstance().add(Blocks.DIAMOND_BLOCK, 4, 4); @@ -195,6 +198,8 @@ public void onInitialize() { builder.registerPotionRecipe(Potions.AWKWARD, Ingredient.ofItems(Items.BUNDLE), Potions.LUCK); } }); + + FireworkStarExplosionTypeRegistry.register(Items.NETHER_STAR, FireworkExplosionComponent.Type.STAR); } public static class TestEventBlock extends Block {