From a35d9d2c759badf8501e6149f3ed3f2019401902 Mon Sep 17 00:00:00 2001 From: Minecraftschurli Date: Tue, 28 Nov 2023 13:33:51 +0100 Subject: [PATCH] Rename and fix custom sprite source test --- ...STest.java => CustomSpriteSourceTest.java} | 75 +++++++++--------- tests/src/main/resources/META-INF/mods.toml | 2 +- .../models/item/test_item.json | 4 +- .../textures}/test_item.png | Bin .../textures/item/test_item.png.mcmeta | 5 -- .../assets/minecraft/atlases/blocks.json | 8 ++ 6 files changed, 48 insertions(+), 46 deletions(-) rename tests/src/main/java/net/neoforged/neoforge/debug/client/{CustomTASTest.java => CustomSpriteSourceTest.java} (52%) rename tests/src/main/resources/assets/{custom_tas_test => custom_sprite_source_test}/models/item/test_item.json (53%) rename tests/src/main/resources/assets/{custom_tas_test/textures/item => custom_sprite_source_test/textures}/test_item.png (100%) delete mode 100644 tests/src/main/resources/assets/custom_tas_test/textures/item/test_item.png.mcmeta create mode 100644 tests/src/main/resources/assets/minecraft/atlases/blocks.json diff --git a/tests/src/main/java/net/neoforged/neoforge/debug/client/CustomTASTest.java b/tests/src/main/java/net/neoforged/neoforge/debug/client/CustomSpriteSourceTest.java similarity index 52% rename from tests/src/main/java/net/neoforged/neoforge/debug/client/CustomTASTest.java rename to tests/src/main/java/net/neoforged/neoforge/debug/client/CustomSpriteSourceTest.java index 34a7a47fff..93f4e0313f 100644 --- a/tests/src/main/java/net/neoforged/neoforge/debug/client/CustomTASTest.java +++ b/tests/src/main/java/net/neoforged/neoforge/debug/client/CustomSpriteSourceTest.java @@ -10,7 +10,8 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import java.util.Optional; -import net.minecraft.client.renderer.texture.*; +import net.minecraft.client.renderer.texture.SpriteContents; +import net.minecraft.client.renderer.texture.SpriteTicker; import net.minecraft.client.renderer.texture.atlas.SpriteSource; import net.minecraft.client.renderer.texture.atlas.SpriteSourceType; import net.minecraft.client.resources.metadata.animation.FrameSize; @@ -21,6 +22,7 @@ import net.minecraft.server.packs.resources.ResourceMetadata; import net.minecraft.util.RandomSource; import net.minecraft.world.item.Item; +import net.neoforged.bus.api.IEventBus; import net.neoforged.fml.common.Mod; import net.neoforged.fml.javafmlmod.FMLJavaModLoadingContext; import net.neoforged.fml.loading.FMLLoader; @@ -29,39 +31,41 @@ import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; -@Mod(CustomTASTest.MOD_ID) -public class CustomTASTest { +@Mod(CustomSpriteSourceTest.MOD_ID) +public class CustomSpriteSourceTest { private static final boolean ENABLED = true; - static final String MOD_ID = "custom_tas_test"; + static final String MOD_ID = "custom_sprite_source_test"; private static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(MOD_ID); private static final Holder TEST_ITEM = ITEMS.registerSimpleItem("test_item"); - public CustomTASTest() { - if (ENABLED) { - if (FMLLoader.getDist().isClient()) { - FMLJavaModLoadingContext.get().getModEventBus().addListener(this::registerTextureAtlasSpriteLoaders); - } - ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus()); + public CustomSpriteSourceTest() { + if (!ENABLED) return; + IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); + if (FMLLoader.getDist().isClient()) { + modEventBus.addListener(this::registerTextureAtlasSpriteLoaders); } + ITEMS.register(modEventBus); } private static SpriteSourceType tasLoader; private void registerTextureAtlasSpriteLoaders(RegisterSpriteSourceTypesEvent event) { - tasLoader = event.register(new ResourceLocation(MOD_ID, "tas_loader"), TasLoader.CODEC); + tasLoader = event.register(new ResourceLocation(MOD_ID, "custom_sprite_source"), CustomSpriteSource.CODEC); } - private record TasLoader(ResourceLocation id) implements SpriteSource { + private record CustomSpriteSource(ResourceLocation id) implements SpriteSource { private static final Logger LOGGER = LogUtils.getLogger(); - private static final Codec CODEC = RecordCodecBuilder.create(inst -> inst.group( - ResourceLocation.CODEC.fieldOf("id").forGetter(TasLoader::id)).apply(inst, TasLoader::new)); + private static final Codec CODEC = RecordCodecBuilder.create(inst -> inst.group( + ResourceLocation.CODEC.fieldOf("id").forGetter(CustomSpriteSource::id) + ).apply(inst, CustomSpriteSource::new)); @Override public void run(ResourceManager manager, Output output) { - ResourceLocation resourcelocation = TEXTURE_ID_CONVERTER.idToFile(this.id()); + ResourceLocation id = this.id(); + ResourceLocation resourcelocation = TEXTURE_ID_CONVERTER.idToFile(id); Optional optional = manager.getResource(resourcelocation); if (optional.isPresent()) { - output.add(this.id(), spriteResourceLoader -> spriteResourceLoader.loadSprite(resourcelocation, optional.get(), this::loadContents)); + output.add(id, spriteResourceLoader -> spriteResourceLoader.loadSprite(id, optional.get(), CustomSpriteContents::new)); } else { LOGGER.warn("Missing sprite: {}", resourcelocation); } @@ -72,35 +76,30 @@ public SpriteSourceType type() { return tasLoader; } - public SpriteContents loadContents(ResourceLocation name, FrameSize frameSize, NativeImage image, ResourceMetadata metadata) { - final class TASSpriteContents extends SpriteContents { - - public TASSpriteContents(ResourceLocation p_249787_, FrameSize p_251031_, NativeImage p_252131_, ResourceMetadata p_294742_) { - super(p_249787_, p_251031_, p_252131_, p_294742_); - } + static final class CustomSpriteContents extends SpriteContents { - @Override - public @NotNull SpriteTicker createTicker() { - return new Ticker(); - } + public CustomSpriteContents(ResourceLocation p_249787_, FrameSize p_251031_, NativeImage p_252131_, ResourceMetadata p_294742_) { + super(p_249787_, p_251031_, p_252131_, p_294742_); + } - class Ticker implements SpriteTicker { - final RandomSource random = RandomSource.create(); + @Override + public @NotNull SpriteTicker createTicker() { + return new Ticker(); + } - @Override - public void tickAndUpload(int p_248847_, int p_250486_) { - TASSpriteContents.this.byMipLevel[0].fillRect(0, 0, 16, 16, 0xFF000000 | random.nextInt(0xFFFFFF)); - TASSpriteContents.this.uploadFirstFrame(p_248847_, p_250486_); - } + class Ticker implements SpriteTicker { + final RandomSource random = RandomSource.create(); - @Override - public void close() { + @Override + public void tickAndUpload(int p_248847_, int p_250486_) { + CustomSpriteContents.this.byMipLevel[0].fillRect(0, 0, 16, 16, 0xFF000000 | random.nextInt(0xFFFFFF)); + CustomSpriteContents.this.uploadFirstFrame(p_248847_, p_250486_); + } - } + @Override + public void close() { } } - - return new TASSpriteContents(name, frameSize, image, metadata); } } } diff --git a/tests/src/main/resources/META-INF/mods.toml b/tests/src/main/resources/META-INF/mods.toml index 95420f83cf..967aaca239 100644 --- a/tests/src/main/resources/META-INF/mods.toml +++ b/tests/src/main/resources/META-INF/mods.toml @@ -166,7 +166,7 @@ modId="fishing_bobber_event_test" [[mods]] modId="custom_respawn_test" [[mods]] -modId="custom_tas_test" +modId="custom_sprite_source_test" [[mods]] modId="dimension_settings_test" [[mods]] diff --git a/tests/src/main/resources/assets/custom_tas_test/models/item/test_item.json b/tests/src/main/resources/assets/custom_sprite_source_test/models/item/test_item.json similarity index 53% rename from tests/src/main/resources/assets/custom_tas_test/models/item/test_item.json rename to tests/src/main/resources/assets/custom_sprite_source_test/models/item/test_item.json index 0b8b342d5f..6f333d2f25 100644 --- a/tests/src/main/resources/assets/custom_tas_test/models/item/test_item.json +++ b/tests/src/main/resources/assets/custom_sprite_source_test/models/item/test_item.json @@ -1,6 +1,6 @@ { "parent": "minecraft:item/handheld", "textures": { - "layer0": "custom_tas_test:item/test_item" + "layer0": "custom_sprite_source_test:test_item" } -} \ No newline at end of file +} diff --git a/tests/src/main/resources/assets/custom_tas_test/textures/item/test_item.png b/tests/src/main/resources/assets/custom_sprite_source_test/textures/test_item.png similarity index 100% rename from tests/src/main/resources/assets/custom_tas_test/textures/item/test_item.png rename to tests/src/main/resources/assets/custom_sprite_source_test/textures/test_item.png diff --git a/tests/src/main/resources/assets/custom_tas_test/textures/item/test_item.png.mcmeta b/tests/src/main/resources/assets/custom_tas_test/textures/item/test_item.png.mcmeta deleted file mode 100644 index 2c5786ad33..0000000000 --- a/tests/src/main/resources/assets/custom_tas_test/textures/item/test_item.png.mcmeta +++ /dev/null @@ -1,5 +0,0 @@ -{ - "forge": { - "loader": "custom_tas_test:tas_loader" - } -} \ No newline at end of file diff --git a/tests/src/main/resources/assets/minecraft/atlases/blocks.json b/tests/src/main/resources/assets/minecraft/atlases/blocks.json new file mode 100644 index 0000000000..2b01793150 --- /dev/null +++ b/tests/src/main/resources/assets/minecraft/atlases/blocks.json @@ -0,0 +1,8 @@ +{ + "sources": [ + { + "type": "custom_sprite_source_test:custom_sprite_source", + "id": "custom_sprite_source_test:test_item" + } + ] +} \ No newline at end of file