From 503e80885628def0495775002080a2555e863913 Mon Sep 17 00:00:00 2001 From: Gugle Date: Fri, 6 Sep 2024 21:17:00 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=F0=9F=8C=9F=20=E6=9B=B4=E6=96=B0=E6=B3=A8?= =?UTF-8?q?=E5=86=8C=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/registrator/builder/BlockBuilder.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/dev/anvilcraft/lib/registrator/builder/BlockBuilder.java b/common/src/main/java/dev/anvilcraft/lib/registrator/builder/BlockBuilder.java index a418577..e494a55 100644 --- a/common/src/main/java/dev/anvilcraft/lib/registrator/builder/BlockBuilder.java +++ b/common/src/main/java/dev/anvilcraft/lib/registrator/builder/BlockBuilder.java @@ -22,6 +22,7 @@ import java.util.function.Function; import java.util.function.Supplier; +@SuppressWarnings("unused") public class BlockBuilder extends EntryBuilder { private final BlockEntry entry; private final Function factory; @@ -30,7 +31,7 @@ public class BlockBuilder extends EntryBuilder { }; private ItemBuilder itemBuilder = new BlockItemBuilder<>(this.registrator, this, this.id, BlockItem::new); private Supplier> dropOther = null; - private ItemEntry itemEntry = null; + private ItemEntry itemEntry = null; public BlockBuilder(AbstractRegistrator registrator, String id, Function factory) { super(registrator, id); @@ -49,9 +50,7 @@ public BlockBuilder initialProperties(BlockEntry entry) { } public BlockBuilder defaultBlockState(){ - return state((tBlockEntry, provider) -> { - provider.simpleBlock(tBlockEntry.get()); - }); + return state((tBlockEntry, provider) -> provider.simpleBlock(tBlockEntry.get())); } public BlockBuilder initialProperties(Supplier supplier) { @@ -84,6 +83,7 @@ public final BlockBuilder tag(TagKey... tags) { return this; } + @SuppressWarnings("UnusedReturnValue") public BlockBuilder defaultLoot() { return loot(BlockLootTableProvider::dropSelf); } @@ -138,7 +138,7 @@ public T build() { @Override public BlockEntry register() { this.itemEntry = itemBuilder.register(); - this.entry.setBlockItem((ItemEntry) itemEntry); + this.entry.setBlockItem(itemEntry); this.registrator.addBuilder(BuiltInRegistries.BLOCK, this); if (dropOther != null) { this.loot((blockLootTableProvider, t) -> blockLootTableProvider.dropOther(this.entry.get(), dropOther.get())); From 003e01616265331ed1ac33a748baa688cbefb61f Mon Sep 17 00:00:00 2001 From: ZhuRuoLing Date: Fri, 6 Sep 2024 21:41:28 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8Dforge?= =?UTF-8?q?=E4=B8=8D=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../anvilcraft/lib/registrator/forge/RegistratorImpl.java | 4 ++-- .../anvilcraft/lib/registrator/forge/RegistratorImpl.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/forge/src/main/java/dev/anvilcraft/lib/registrator/forge/RegistratorImpl.java b/forge/src/main/java/dev/anvilcraft/lib/registrator/forge/RegistratorImpl.java index e16e9e5..8c888ab 100644 --- a/forge/src/main/java/dev/anvilcraft/lib/registrator/forge/RegistratorImpl.java +++ b/forge/src/main/java/dev/anvilcraft/lib/registrator/forge/RegistratorImpl.java @@ -4,8 +4,8 @@ import dev.anvilcraft.lib.registrator.Registrator; import dev.anvilcraft.lib.registrator.builder.EntryBuilder; import net.minecraft.core.Registry; -import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.registries.RegisterEvent; import org.jetbrains.annotations.NotNull; @@ -16,7 +16,7 @@ private RegistratorImpl(String modid) { @Override public void init() { - MinecraftForge.EVENT_BUS.addListener(this::register); + FMLJavaModLoadingContext.get().getModEventBus().addListener(this::register); } @SubscribeEvent diff --git a/neoforge/src/main/java/dev/anvilcraft/lib/registrator/forge/RegistratorImpl.java b/neoforge/src/main/java/dev/anvilcraft/lib/registrator/forge/RegistratorImpl.java index e16e9e5..05467de 100644 --- a/neoforge/src/main/java/dev/anvilcraft/lib/registrator/forge/RegistratorImpl.java +++ b/neoforge/src/main/java/dev/anvilcraft/lib/registrator/forge/RegistratorImpl.java @@ -6,6 +6,7 @@ import net.minecraft.core.Registry; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.registries.RegisterEvent; import org.jetbrains.annotations.NotNull; @@ -16,10 +17,9 @@ private RegistratorImpl(String modid) { @Override public void init() { - MinecraftForge.EVENT_BUS.addListener(this::register); + FMLJavaModLoadingContext.get().getModEventBus().addListener(this::register); } - - @SubscribeEvent + public void register(RegisterEvent event) { for (Registry registry : this.manager) { this.init(event, registry); From d89e7e531d7c1e19b4e247dd45dc440201b5a1f9 Mon Sep 17 00:00:00 2001 From: ZhuRuoLing Date: Fri, 6 Sep 2024 21:54:05 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8Dforge?= =?UTF-8?q?=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/registrator/builder/forge/BlockEntityBuilderImpl.java | 3 ++- .../lib/registrator/builder/forge/EntityBuilderImpl.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/forge/src/main/java/dev/anvilcraft/lib/registrator/builder/forge/BlockEntityBuilderImpl.java b/forge/src/main/java/dev/anvilcraft/lib/registrator/builder/forge/BlockEntityBuilderImpl.java index 691234b..2e94c8f 100644 --- a/forge/src/main/java/dev/anvilcraft/lib/registrator/builder/forge/BlockEntityBuilderImpl.java +++ b/forge/src/main/java/dev/anvilcraft/lib/registrator/builder/forge/BlockEntityBuilderImpl.java @@ -11,6 +11,7 @@ import net.minecraftforge.client.event.EntityRenderersEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import org.jetbrains.annotations.NotNull; public class BlockEntityBuilderImpl extends BlockEntityBuilder { @@ -24,7 +25,7 @@ protected BlockEntityBuilderImpl(AbstractRegistrator registrator, String id, Tri @Override protected void registerRenderer() { - MinecraftForge.EVENT_BUS.addListener(this::registerRenderers); + FMLJavaModLoadingContext.get().getModEventBus().addListener(this::registerRenderers); } private void registerRenderers(FMLClientSetupEvent event) { diff --git a/forge/src/main/java/dev/anvilcraft/lib/registrator/builder/forge/EntityBuilderImpl.java b/forge/src/main/java/dev/anvilcraft/lib/registrator/builder/forge/EntityBuilderImpl.java index 1a23c9f..ed990fd 100644 --- a/forge/src/main/java/dev/anvilcraft/lib/registrator/builder/forge/EntityBuilderImpl.java +++ b/forge/src/main/java/dev/anvilcraft/lib/registrator/builder/forge/EntityBuilderImpl.java @@ -8,6 +8,7 @@ import net.minecraft.world.level.Level; import net.minecraftforge.client.event.EntityRenderersEvent; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import org.jetbrains.annotations.NotNull; import java.util.function.BiFunction; @@ -24,7 +25,7 @@ public static EntityBuilder create(AbstractRegistrator reg @Override protected void registerRenderer() { - MinecraftForge.EVENT_BUS.addListener(this::registerRenderers); + FMLJavaModLoadingContext.get().getModEventBus().addListener(this::registerRenderers); } private void registerRenderers(EntityRenderersEvent.RegisterRenderers event) { From 6efbeebb96d0373aa753fbe1bcb498963605a26a Mon Sep 17 00:00:00 2001 From: ZhuRuoLing Date: Fri, 6 Sep 2024 22:08:02 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8Ddatagen=20?= =?UTF-8?q?mixin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/src/main/resources/anvillib-common.mixins.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/src/main/resources/anvillib-common.mixins.json b/common/src/main/resources/anvillib-common.mixins.json index b0d9d42..4b46e9c 100644 --- a/common/src/main/resources/anvillib-common.mixins.json +++ b/common/src/main/resources/anvillib-common.mixins.json @@ -4,7 +4,9 @@ "package": "dev.anvilcraft.lib.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ - "ItemPropertiesAccessor" + "ItemPropertiesAccessor", + "LootContextParamSetsAccessor", + "LootTableProviderAccessor" ], "client": [ "BlockEntityRenderersAccessor" From aa2092ff0280272be2e829e43ae8288b1956cdd3 Mon Sep 17 00:00:00 2001 From: ZhuRuoLing Date: Fri, 6 Sep 2024 22:19:28 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8Ddatagen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/anvilcraft/lib/registrator/builder/BlockBuilder.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/common/src/main/java/dev/anvilcraft/lib/registrator/builder/BlockBuilder.java b/common/src/main/java/dev/anvilcraft/lib/registrator/builder/BlockBuilder.java index e494a55..4103f08 100644 --- a/common/src/main/java/dev/anvilcraft/lib/registrator/builder/BlockBuilder.java +++ b/common/src/main/java/dev/anvilcraft/lib/registrator/builder/BlockBuilder.java @@ -32,6 +32,7 @@ public class BlockBuilder extends EntryBuilder { private ItemBuilder itemBuilder = new BlockItemBuilder<>(this.registrator, this, this.id, BlockItem::new); private Supplier> dropOther = null; private ItemEntry itemEntry = null; + private BiConsumer, RegistratorRecipeProvider> recipeFunction = null; public BlockBuilder(AbstractRegistrator registrator, String id, Function factory) { super(registrator, id); @@ -118,6 +119,9 @@ public BlockItemBuilder blockItem() { public BlockItemBuilder item(BiFunction factory) { BlockItemBuilder itemBuilder = new BlockItemBuilder<>(this.registrator, this, this.id, factory); + if (recipeFunction != null){ + itemBuilder.recipe(recipeFunction::accept); + } this.itemBuilder = itemBuilder; dropOther = () -> itemEntry; return itemBuilder; @@ -148,6 +152,7 @@ public BlockEntry register() { public BlockBuilder recipe(BiConsumer, RegistratorRecipeProvider> fn) { itemBuilder.recipe(fn::accept); + this.recipeFunction = fn; return this; } From 842bde6424f193e1646a1d6ab58b6b65fc429a95 Mon Sep 17 00:00:00 2001 From: ZhuRuoLing Date: Fri, 6 Sep 2024 22:21:11 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8Ddatagen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/anvilcraft/lib/registrator/builder/BlockBuilder.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/common/src/main/java/dev/anvilcraft/lib/registrator/builder/BlockBuilder.java b/common/src/main/java/dev/anvilcraft/lib/registrator/builder/BlockBuilder.java index 4103f08..5b2f8a0 100644 --- a/common/src/main/java/dev/anvilcraft/lib/registrator/builder/BlockBuilder.java +++ b/common/src/main/java/dev/anvilcraft/lib/registrator/builder/BlockBuilder.java @@ -105,9 +105,7 @@ public BlockBuilder lang(String name) { return this; } public BlockBuilder defaultItem() { - this.itemBuilder = new BlockItemBuilder<>(this.registrator, this, this.id, BlockItem::new); - this.defaultLoot(); - return this; + return this.blockItem().builder().defaultLoot(); } public BlockItemBuilder blockItem() { From c5e96a9ab34618156d2a285a1095770ea67b7292 Mon Sep 17 00:00:00 2001 From: ZhuRuoLing Date: Fri, 6 Sep 2024 22:33:02 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8Ddatagen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../anvilcraft/lib/registrator/builder/BlockBuilder.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/dev/anvilcraft/lib/registrator/builder/BlockBuilder.java b/common/src/main/java/dev/anvilcraft/lib/registrator/builder/BlockBuilder.java index 5b2f8a0..08fe388 100644 --- a/common/src/main/java/dev/anvilcraft/lib/registrator/builder/BlockBuilder.java +++ b/common/src/main/java/dev/anvilcraft/lib/registrator/builder/BlockBuilder.java @@ -117,9 +117,6 @@ public BlockItemBuilder blockItem() { public BlockItemBuilder item(BiFunction factory) { BlockItemBuilder itemBuilder = new BlockItemBuilder<>(this.registrator, this, this.id, factory); - if (recipeFunction != null){ - itemBuilder.recipe(recipeFunction::accept); - } this.itemBuilder = itemBuilder; dropOther = () -> itemEntry; return itemBuilder; @@ -139,8 +136,14 @@ public T build() { @Override public BlockEntry register() { + if (this.recipeFunction != null){ + this.itemBuilder.recipe( + (itemEntry1, registratorRecipeProvider) -> recipeFunction.accept(itemEntry1, registratorRecipeProvider) + ); + } this.itemEntry = itemBuilder.register(); this.entry.setBlockItem(itemEntry); + this.registrator.addBuilder(BuiltInRegistries.BLOCK, this); if (dropOther != null) { this.loot((blockLootTableProvider, t) -> blockLootTableProvider.dropOther(this.entry.get(), dropOther.get())); From fb3d29f38bb70cda3f0dc7c64779053739b89c82 Mon Sep 17 00:00:00 2001 From: ZhuRuoLing Date: Fri, 6 Sep 2024 22:56:10 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8Ddatagen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/registrator/builder/BlockBuilder.java | 3 ++- .../anvilcraft/lib/registrator/entry/BlockEntry.java | 2 ++ .../java/dev/anvilcraft/lib/test/TestRegisters.java | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/dev/anvilcraft/lib/registrator/builder/BlockBuilder.java b/common/src/main/java/dev/anvilcraft/lib/registrator/builder/BlockBuilder.java index 08fe388..79b185e 100644 --- a/common/src/main/java/dev/anvilcraft/lib/registrator/builder/BlockBuilder.java +++ b/common/src/main/java/dev/anvilcraft/lib/registrator/builder/BlockBuilder.java @@ -137,6 +137,7 @@ public T build() { @Override public BlockEntry register() { if (this.recipeFunction != null){ + System.out.println("register itemBuilder = " + itemBuilder); this.itemBuilder.recipe( (itemEntry1, registratorRecipeProvider) -> recipeFunction.accept(itemEntry1, registratorRecipeProvider) ); @@ -152,7 +153,7 @@ public BlockEntry register() { } public BlockBuilder recipe(BiConsumer, RegistratorRecipeProvider> fn) { - itemBuilder.recipe(fn::accept); + System.out.println("itemBuilder = " + itemBuilder); this.recipeFunction = fn; return this; } diff --git a/common/src/main/java/dev/anvilcraft/lib/registrator/entry/BlockEntry.java b/common/src/main/java/dev/anvilcraft/lib/registrator/entry/BlockEntry.java index 8ee84a3..48e9cab 100644 --- a/common/src/main/java/dev/anvilcraft/lib/registrator/entry/BlockEntry.java +++ b/common/src/main/java/dev/anvilcraft/lib/registrator/entry/BlockEntry.java @@ -2,6 +2,7 @@ import dev.anvilcraft.lib.registrator.builder.BlockBuilder; import dev.anvilcraft.lib.registrator.builder.ItemBuilder; +import lombok.Getter; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.Item; @@ -14,6 +15,7 @@ public class BlockEntry extends RegistryEntry implements ItemLike { private final BlockBuilder blockBuilder; + @Getter private ItemEntry blockItem = null; public BlockEntry(BlockBuilder blockBuilder) { diff --git a/fabric/src/test/java/dev/anvilcraft/lib/test/TestRegisters.java b/fabric/src/test/java/dev/anvilcraft/lib/test/TestRegisters.java index 31cf783..44215ae 100644 --- a/fabric/src/test/java/dev/anvilcraft/lib/test/TestRegisters.java +++ b/fabric/src/test/java/dev/anvilcraft/lib/test/TestRegisters.java @@ -38,6 +38,15 @@ public class TestRegisters { public static final BlockEntry TEST_BLOCK = REGISTRATOR .block("test_block", Block::new) .tag(TEST_BLOCK_TAG) + .recipe((e, p) -> { + ShapedRecipeBuilder.shaped(RecipeCategory.MISC, e) + .pattern("xxx") + .pattern("xxx") + .pattern("xxx") + .define('x', TEST_ITEM.asItem()) + .unlockedBy("has_apple", RecipeProvider.has(Items.APPLE)) + .save(p); + }) .defaultItem() .register(); @@ -51,5 +60,6 @@ public class TestRegisters { .register(); public static void register() { + System.out.println("TEST_BLOCK.getBlockItem().builder() = " + TEST_BLOCK.getBlockItem().getItemBuilder()); } } From 61bdbf8546fe106cb79cfede7ed432b4e3a9184e Mon Sep 17 00:00:00 2001 From: ZhuRuoLing Date: Fri, 6 Sep 2024 23:01:43 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=F0=9F=90=9B=20=E5=88=A0=E9=99=A4println?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/anvilcraft/lib/registrator/builder/BlockBuilder.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/common/src/main/java/dev/anvilcraft/lib/registrator/builder/BlockBuilder.java b/common/src/main/java/dev/anvilcraft/lib/registrator/builder/BlockBuilder.java index 79b185e..8b055f5 100644 --- a/common/src/main/java/dev/anvilcraft/lib/registrator/builder/BlockBuilder.java +++ b/common/src/main/java/dev/anvilcraft/lib/registrator/builder/BlockBuilder.java @@ -137,7 +137,6 @@ public T build() { @Override public BlockEntry register() { if (this.recipeFunction != null){ - System.out.println("register itemBuilder = " + itemBuilder); this.itemBuilder.recipe( (itemEntry1, registratorRecipeProvider) -> recipeFunction.accept(itemEntry1, registratorRecipeProvider) ); @@ -153,7 +152,6 @@ public BlockEntry register() { } public BlockBuilder recipe(BiConsumer, RegistratorRecipeProvider> fn) { - System.out.println("itemBuilder = " + itemBuilder); this.recipeFunction = fn; return this; }