diff --git a/testframework/src/main/java/net/neoforged/testframework/registration/DeferredBlockBuilder.java b/testframework/src/main/java/net/neoforged/testframework/registration/DeferredBlockBuilder.java index 8d76d213df..6dfa0fb94b 100644 --- a/testframework/src/main/java/net/neoforged/testframework/registration/DeferredBlockBuilder.java +++ b/testframework/src/main/java/net/neoforged/testframework/registration/DeferredBlockBuilder.java @@ -7,7 +7,6 @@ import com.mojang.serialization.MapCodec; import java.util.Objects; -import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.stream.Stream; import net.minecraft.client.color.item.ItemTintSource; @@ -18,7 +17,6 @@ import net.minecraft.client.data.models.model.ModelTemplates; import net.minecraft.client.data.models.model.TextureMapping; import net.minecraft.client.data.models.model.TextureSlot; -import net.minecraft.client.data.models.model.TexturedModel; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.core.Holder; import net.minecraft.core.registries.Registries; @@ -66,11 +64,34 @@ public DeferredBlockBuilder withLang(String name) { private boolean hasItem = false; private boolean hasColor = false; - public DeferredBlockBuilder withModel(BiConsumer consumer) { - helper.addClientProvider(client -> new ModelProvider(client.getGenerator().getPackOutput(), helper.modId()) { + public DeferredBlockBuilder withDefaultWhiteModel() { + if (!FMLLoader.getDist().isClient()) { + return this; + } + + helper.addClientProvider(event -> event.addProvider(new ModelProvider(event.getGenerator().getPackOutput(), helper.modId()) { @Override protected void registerModels(BlockModelGenerators blockModels, ItemModelGenerators itemModels) { - consumer.accept(value(), blockModels); + ModelTemplate template; + + if (hasColor) { + template = ExtendedModelTemplateBuilder.builder() + .element(element -> element + .from(0F, 0F, 0F) + .to(16F, 16F, 16F) + .allFaces((face, builder) -> builder + .uvs(0F, 0F, 16F, 16F) + .texture(TextureSlot.ALL) + .tintindex(0) + .cullface(face))) + .requiredTextureSlot(TextureSlot.ALL) + .build(); + } else { + template = ModelTemplates.CUBE_ALL; + } + + var modelPath = template.create(value(), TextureMapping.cube(ResourceLocation.fromNamespaceAndPath("testframework", "block/white")), blockModels.modelOutput); + blockModels.blockStateOutput.accept(BlockModelGenerators.createSimpleBlock(value(), modelPath)); } @Override @@ -85,46 +106,12 @@ protected Stream> getKnownBlocks() { @Override public String getName() { - return key.location().getPath() + "-model-generator"; + return key.location().toDebugFileName() + "-default-white-model-generator"; } - }); + })); return this; } - public DeferredBlockBuilder withModel(TexturedModel.Provider model) { - return withModel((block, blockModels) -> blockModels.createTrivialBlock(block, model)); - } - - public DeferredBlockBuilder withModel(TextureMapping textures, Consumer modelConsumer) { - return withModel((block, blockModels) -> { - var builder = ExtendedModelTemplateBuilder.builder(); - modelConsumer.accept(builder); - var modelPath = builder.build().create(block, textures, blockModels.modelOutput); - blockModels.blockStateOutput.accept(BlockModelGenerators.createSimpleBlock(block, modelPath)); - }); - } - - public DeferredBlockBuilder withDefaultWhiteModel() { - return withModel((block, blockModels) -> { - ModelTemplate template; - - if (hasColor) { - template = ExtendedModelTemplateBuilder.builder() - .element(element -> element - .from(0, 0, 0) - .to(16, 16, 16) - .allFaces((direction, faceBuilder) -> faceBuilder.uvs(0, 0, 16, 16).texture(TextureSlot.ALL).tintindex(0).cullface(direction))) - .requiredTextureSlot(TextureSlot.ALL) - .build(); - } else { - template = ModelTemplates.CUBE_ALL; - } - - var modelPath = template.create(block, TextureMapping.cube(ResourceLocation.fromNamespaceAndPath("testframework", "block/white")), blockModels.modelOutput); - blockModels.blockStateOutput.accept(BlockModelGenerators.createSimpleBlock(block, modelPath)); - }); - } - public DeferredBlockBuilder withColor(int color) { if (FMLLoader.getDist().isClient()) { colorInternal(color); diff --git a/testframework/src/main/java/net/neoforged/testframework/registration/DeferredItemBuilder.java b/testframework/src/main/java/net/neoforged/testframework/registration/DeferredItemBuilder.java index f5bc9e4a2a..420531dcb8 100644 --- a/testframework/src/main/java/net/neoforged/testframework/registration/DeferredItemBuilder.java +++ b/testframework/src/main/java/net/neoforged/testframework/registration/DeferredItemBuilder.java @@ -5,22 +5,9 @@ package net.neoforged.testframework.registration; -import java.util.function.BiConsumer; -import java.util.function.Consumer; -import java.util.stream.Stream; -import net.minecraft.client.data.models.BlockModelGenerators; -import net.minecraft.client.data.models.ItemModelGenerators; -import net.minecraft.client.data.models.ModelProvider; -import net.minecraft.client.data.models.model.ItemModelUtils; -import net.minecraft.client.data.models.model.ModelLocationUtils; -import net.minecraft.client.data.models.model.ModelTemplate; -import net.minecraft.client.data.models.model.TextureMapping; -import net.minecraft.core.Holder; import net.minecraft.resources.ResourceKey; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.Item; -import net.minecraft.world.level.block.Block; -import net.neoforged.neoforge.client.model.generators.template.ExtendedModelTemplateBuilder; import net.neoforged.neoforge.common.data.LanguageProvider; import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent; import net.neoforged.neoforge.registries.DeferredItem; @@ -46,43 +33,4 @@ public DeferredItemBuilder tab(ResourceKey tab) { }); return this; } - - public DeferredItemBuilder withModel(BiConsumer consumer) { - registrationHelper.addClientProvider(client -> new ModelProvider(client.getGenerator().getPackOutput(), registrationHelper.modId()) { - @Override - protected void registerModels(BlockModelGenerators blockModels, ItemModelGenerators itemModels) { - consumer.accept(value(), itemModels); - } - - @Override - protected Stream> getKnownItems() { - return Stream.of(DeferredItemBuilder.this); - } - - @Override - protected Stream> getKnownBlocks() { - return Stream.empty(); - } - - @Override - public String getName() { - return key.location().getPath() + "-model-generator"; - } - }); - return this; - } - - public DeferredItemBuilder withModel(ModelTemplate template) { - return withModel((item, itemModels) -> itemModels.generateFlatItem(item, template)); - } - - public DeferredItemBuilder withModel(TextureMapping textures, Consumer modelConsumer) { - return withModel((item, itemModels) -> { - var modelPath = ModelLocationUtils.getModelLocation(item); - var builder = ExtendedModelTemplateBuilder.builder(); - modelConsumer.accept(builder); - itemModels.itemModelOutput.accept(item, ItemModelUtils.plainModel(modelPath)); - builder.build().create(item, textures, itemModels.modelOutput); - }); - } } diff --git a/tests/src/main/java/net/neoforged/neoforge/debug/VanillaDataGenTest.java b/tests/src/main/java/net/neoforged/neoforge/debug/VanillaDataGenTest.java index 66523ef057..678e13599b 100644 --- a/tests/src/main/java/net/neoforged/neoforge/debug/VanillaDataGenTest.java +++ b/tests/src/main/java/net/neoforged/neoforge/debug/VanillaDataGenTest.java @@ -22,12 +22,13 @@ import net.minecraft.world.item.equipment.Equippable; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockBehaviour; +import net.neoforged.api.distmarker.Dist; import net.neoforged.testframework.DynamicTest; import net.neoforged.testframework.annotation.ForEachTest; import net.neoforged.testframework.annotation.TestHolder; import net.neoforged.testframework.registration.RegistrationHelper; -@ForEachTest(groups = "vanilla_data_gen") +@ForEachTest(groups = "vanilla_data_gen", side = Dist.CLIENT) public interface VanillaDataGenTest { @TestHolder(description = "Tests the the patched vanilla model generators work for modded usages") static void testModelGenerators(DynamicTest test, RegistrationHelper reg) { diff --git a/tests/src/main/java/net/neoforged/neoforge/debug/block/BlockTests.java b/tests/src/main/java/net/neoforged/neoforge/debug/block/BlockTests.java index 8e75108491..edfdad4af7 100644 --- a/tests/src/main/java/net/neoforged/neoforge/debug/block/BlockTests.java +++ b/tests/src/main/java/net/neoforged/neoforge/debug/block/BlockTests.java @@ -6,8 +6,13 @@ package net.neoforged.neoforge.debug.block; import java.util.Optional; +import java.util.stream.Stream; +import net.minecraft.client.data.models.BlockModelGenerators; +import net.minecraft.client.data.models.ItemModelGenerators; +import net.minecraft.client.data.models.ModelProvider; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.Holder; import net.minecraft.core.registries.Registries; import net.minecraft.gametest.framework.GameTest; import net.minecraft.network.protocol.game.ClientboundSoundPacket; @@ -22,6 +27,7 @@ import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.GameType; @@ -36,6 +42,7 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; import net.neoforged.neoforge.common.enums.BubbleColumnDirection; +import net.neoforged.neoforge.registries.DeferredItem; import net.neoforged.testframework.DynamicTest; import net.neoforged.testframework.annotation.ForEachTest; import net.neoforged.testframework.annotation.TestHolder; @@ -79,8 +86,29 @@ static void decoratedPotBreaking(final DynamicTest test) { static void woodlessFenceGate(final DynamicTest test, final RegistrationHelper reg) { final var gate = reg.blocks().registerBlock("gate", props -> new FenceGateBlock(props, SoundEvents.BARREL_OPEN, SoundEvents.CHEST_CLOSE), BlockBehaviour.Properties.ofFullCopy(Blocks.ACACIA_FENCE_GATE)) .withLang("Woodless Fence Gate") - .withBlockItem() - .withModel((block, blockModels) -> blockModels.createFenceGate(block, Blocks.IRON_BLOCK)); + .withBlockItem(); + + reg.addClientProvider(event -> event.addProvider(new ModelProvider(event.getGenerator().getPackOutput(), reg.modId()) { + @Override + protected void registerModels(BlockModelGenerators blockModels, ItemModelGenerators itemModels) { + blockModels.createFenceGate(gate.value(), Blocks.IRON_BLOCK); + } + + @Override + protected Stream> getKnownItems() { + return Stream.of(DeferredItem.createItem(gate.getId())); + } + + @Override + protected Stream> getKnownBlocks() { + return Stream.of(gate); + } + + @Override + public String getName() { + return "test_woodless_fence_gate_model_generator"; + } + })); test.onGameTest(helper -> helper.startSequence(() -> helper.makeTickingMockServerPlayerInCorner(GameType.SURVIVAL)) .thenExecute(() -> helper.setBlock(1, 1, 1, gate.get().defaultBlockState().setValue(FenceGateBlock.OPEN, true))) diff --git a/tests/src/main/java/net/neoforged/neoforge/debug/fluid/ClientFluidTests.java b/tests/src/main/java/net/neoforged/neoforge/debug/fluid/ClientFluidTests.java index 364d95dda5..d45d3f3457 100644 --- a/tests/src/main/java/net/neoforged/neoforge/debug/fluid/ClientFluidTests.java +++ b/tests/src/main/java/net/neoforged/neoforge/debug/fluid/ClientFluidTests.java @@ -5,13 +5,20 @@ package net.neoforged.neoforge.debug.fluid; +import java.util.stream.Stream; +import net.minecraft.client.data.models.BlockModelGenerators; +import net.minecraft.client.data.models.ItemModelGenerators; +import net.minecraft.client.data.models.ModelProvider; import net.minecraft.client.data.models.model.TextureMapping; import net.minecraft.client.data.models.model.TextureSlot; import net.minecraft.client.data.models.model.TexturedModel; import net.minecraft.client.renderer.block.LiquidBlockRenderer; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.Holder; import net.minecraft.gametest.framework.GameTest; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.TransparentBlock; import net.minecraft.world.level.block.state.BlockBehaviour; @@ -19,6 +26,7 @@ import net.minecraft.world.level.material.FluidState; import net.minecraft.world.level.material.Fluids; import net.neoforged.api.distmarker.Dist; +import net.neoforged.neoforge.registries.DeferredItem; import net.neoforged.testframework.DynamicTest; import net.neoforged.testframework.annotation.ForEachTest; import net.neoforged.testframework.annotation.TestHolder; @@ -52,13 +60,34 @@ public boolean shouldHideAdjacentFluidFace(BlockState state, Direction selfFace, static void testWaterGlassFaceRemoval(final DynamicTest test, final RegistrationHelper reg) { final var glass = reg.blocks().registerBlock("water_glass", WaterGlassBlock::new, BlockBehaviour.Properties.ofFullCopy(Blocks.GLASS)) .withLang("Water Glass") - .withBlockItem() - .withModel((block, blockModels) -> blockModels - .createTrivialBlock(block, TexturedModel.CUBE - .updateTemplate(modelTemplate -> modelTemplate.extend() - .renderType("cutout") - .build()) - .updateTexture(textures -> textures.put(TextureSlot.ALL, TextureMapping.getBlockTexture(Blocks.GLASS))))); + .withBlockItem(); + + reg.addClientProvider(event -> event.addProvider(new ModelProvider(event.getGenerator().getPackOutput(), reg.modId()) { + @Override + protected void registerModels(BlockModelGenerators blockModels, ItemModelGenerators itemModels) { + blockModels.createTrivialBlock(glass.value(), TexturedModel.CUBE + .updateTemplate(modelTemplate -> modelTemplate + .extend() + .renderType("cutout") + .build()) + .updateTexture(textures -> textures.put(TextureSlot.ALL, TextureMapping.getBlockTexture(Blocks.GLASS)))); + } + + @Override + protected Stream> getKnownItems() { + return Stream.of(DeferredItem.createItem(glass.getId())); + } + + @Override + protected Stream> getKnownBlocks() { + return Stream.of(glass); + } + + @Override + public String getName() { + return "test_water_glass_face_removal_model_generator"; + } + })); final var waterPosition = new BlockPos(1, 1, 2); final var glassDirection = WaterGlassBlock.HIDE_DIRECTION.getOpposite(); diff --git a/tests/src/main/java/net/neoforged/neoforge/debug/item/ItemTests.java b/tests/src/main/java/net/neoforged/neoforge/debug/item/ItemTests.java index 11a6d96aa8..94028ab5eb 100644 --- a/tests/src/main/java/net/neoforged/neoforge/debug/item/ItemTests.java +++ b/tests/src/main/java/net/neoforged/neoforge/debug/item/ItemTests.java @@ -8,11 +8,16 @@ import java.util.EnumMap; import java.util.function.Supplier; import java.util.function.UnaryOperator; +import java.util.stream.Stream; import net.minecraft.ChatFormatting; import net.minecraft.Util; +import net.minecraft.client.data.models.BlockModelGenerators; +import net.minecraft.client.data.models.ItemModelGenerators; +import net.minecraft.client.data.models.ModelProvider; import net.minecraft.client.renderer.entity.PigRenderer; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.Holder; import net.minecraft.core.dispenser.BlockSource; import net.minecraft.core.dispenser.DefaultDispenseItemBehavior; import net.minecraft.gametest.framework.GameTest; @@ -46,6 +51,7 @@ import net.minecraft.world.item.equipment.ArmorType; import net.minecraft.world.item.equipment.EquipmentAssets; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.DispenserBlock; import net.minecraft.world.level.block.entity.DispenserBlockEntity; @@ -139,8 +145,29 @@ public InteractionResult use(Level level, Player player, InteractionHand hand) { return sup; } }) - .tab(CreativeModeTabs.SPAWN_EGGS) - .withModel((item, itemModels) -> itemModels.generateSpawnEgg(item, 0xFFFFFF, 0xFFFFFF)); + .tab(CreativeModeTabs.SPAWN_EGGS); + + reg.addClientProvider(event -> event.addProvider(new ModelProvider(event.getGenerator().getPackOutput(), reg.modId()) { + @Override + protected void registerModels(BlockModelGenerators blockModels, ItemModelGenerators itemModels) { + itemModels.generateSpawnEgg(egg.value(), 0xFFFFFF, 0xFFFFFF); + } + + @Override + protected Stream> getKnownItems() { + return Stream.of(egg); + } + + @Override + protected Stream> getKnownBlocks() { + return Stream.empty(); + } + + @Override + public String getName() { + return "forge_spawn_egg_test_model_generator"; + } + })); test.onGameTest(helper -> helper.startSequence() .thenExecute(() -> helper.setBlock(1, 1, 1, Blocks.IRON_BLOCK))