diff --git a/src/main/java/net/minecraftforge/client/model/ItemTextureQuadConverter.java b/src/main/java/net/minecraftforge/client/model/ItemTextureQuadConverter.java index 35f8eb4c19..185a15b624 100644 --- a/src/main/java/net/minecraftforge/client/model/ItemTextureQuadConverter.java +++ b/src/main/java/net/minecraftforge/client/model/ItemTextureQuadConverter.java @@ -80,60 +80,67 @@ public final class ItemTextureQuadConverter float hScale = 16f / (float)h; List quads = Lists.newArrayList(); - // the upper left x-position of the current quad - int start = -1; - for (int y = 0; y < h; y++) + // the y-position of the current batch of quads + int startY = 0; + for (int y = 1; y <= h; y++) { - for (int x = 0; x < w; x++) + if (y < h) { - // current pixel - boolean isVisible = !template.isPixelTransparent(0, x, y); - - // no current quad but found a new one - if (start < 0 && isVisible) + // we check if the visibility of the next row matches the one for the current row + // if they are, we can extend the quad downwards + boolean sameRow = true; + for (int x = 0; x < w; x++) { - start = x; - } - // got a current quad, but it ends here - if (start >= 0 && !isVisible) - { - // we now check if the visibility of the next row matches the one fo the current row - // if they are, we can extend the quad downwards - int endY = y + 1; - boolean sameRow = true; - while (sameRow && endY < h) + if (template.isPixelTransparent(0, x, y) != template.isPixelTransparent(0, x, startY)) { - for (int i = 0; i < w; i++) - { - if (template.isPixelTransparent(0, i, y) != template.isPixelTransparent(0, i, endY)) - { - sameRow = false; - break; - } - } - if (sameRow) - { - endY++; - } + sameRow = false; + break; + } + } + + if (sameRow) + continue; // continue to search for rows with same visibility + } + + // all rows from startX (inclusive) to x (exclusive) have same visibility + // create a batch of quads + // the upper left x-position of the current quad + int startX = -1; + for (int x = 0; x <= w; x++) + { + if (x < w) + { + // current pixel + boolean isVisible = !template.isPixelTransparent(0, x, startY); + + // no current quad but found a new one + if (startX < 0 && isVisible) + { + startX = x; } + if (isVisible) + continue; // continue to search for visible pixels in the current quad + } + + // got a current quad, but it ends here + if (startX >= 0) + { // create the quad quads.add(genQuad(transform, - (float)start * wScale, - (float)y * hScale, + (float)startX * wScale, + (float)startY * hScale, (float)x * wScale, - (float)endY * hScale, + (float)y * hScale, z, sprite, facing, color, tint, luminosity)); - // update Y if all the rows match. no need to rescan - if (endY - y > 1) - { - y = endY - 1; - } // clear current quad - start = -1; + startX = -1; } } + + // next batch of quads start at the current line + startY = y; } return quads; @@ -155,60 +162,67 @@ public final class ItemTextureQuadConverter float hScale = 16f / (float)h; List quads = Lists.newArrayList(); - // the upper left y-position of the current quad - int start = -1; - for (int x = 0; x < w; x++) + // the x-position of the current batch of quads + int startX = 0; + for (int x = 1; x <= w; x++) { - for (int y = 0; y < h; y++) + if (x < w) { - // current pixel - boolean isVisible = !template.isPixelTransparent(0, x, y); - - // no current quad but found a new one - if (start < 0 && isVisible) + // we check if the visibility of the next column matches the one for the current row + // if they are, we can extend the quad downwards + boolean sameColumn = true; + for (int y = 0; y < h; y++) { - start = y; - } - // got a current quad, but it ends here - if (start >= 0 && !isVisible) - { - // we now check if the visibility of the next column matches the one fo the current row - // if they are, we can extend the quad downwards - int endX = x + 1; - boolean sameColumn = true; - while (sameColumn && endX < w) + if (template.isPixelTransparent(0, x, y) != template.isPixelTransparent(0, startX, y)) { - for (int i = 0; i < h; i++) - { - if (template.isPixelTransparent(0, x, i) != template.isPixelTransparent(0, endX, i)) - { - sameColumn = false; - break; - } - } - if (sameColumn) - { - endX++; - } + sameColumn = false; + break; + } + } + + if (sameColumn) + continue; // continue to search for columns with same visibility + } + + // all columns from startY (inclusive) to y (exclusive) have same visibility + // create a batch of quads + // the upper left y-position of the current quad + int startY = -1; + for (int y = 0; y <= h; y++) + { + if (y < h) + { + // current pixel + boolean isVisible = !template.isPixelTransparent(0, startX, y); + + // no current quad but found a new one + if (startY < 0 && isVisible) + { + startY = y; } + if (isVisible) + continue; // continue to search for visible pixels in the current quad + } + + // got a current quad, but it ends here + if (startY >= 0) + { // create the quad quads.add(genQuad(transform, + (float)startX * wScale, + (float)startY * hScale, (float)x * wScale, - (float)start * hScale, - (float)endX * wScale, (float)y * hScale, z, sprite, facing, color, tint, luminosity)); - // update X if all the columns match. no need to rescan - if (endX - x > 1) - { - x = endX - 1; - } // clear current quad - start = -1; + startY = -1; } } + + // next batch of quads start at the current column + startX = x; } return quads; diff --git a/src/test/java/net/minecraftforge/debug/client/model/DynBucketModelTest.java b/src/test/java/net/minecraftforge/debug/client/model/DynBucketModelTest.java new file mode 100644 index 0000000000..76b535a26b --- /dev/null +++ b/src/test/java/net/minecraftforge/debug/client/model/DynBucketModelTest.java @@ -0,0 +1,26 @@ +package net.minecraftforge.debug.client.model; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; +import net.minecraftforge.eventbus.api.IEventBus; +import net.minecraftforge.fml.RegistryObject; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.minecraftforge.registries.DeferredRegister; +import net.minecraftforge.registries.ForgeRegistries; + +@Mod(DynBucketModelTest.MODID) +public class DynBucketModelTest +{ + public static final String MODID = "dyn_bucket_model_test"; + public static final DeferredRegister ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID); + + public static final RegistryObject DRIP_BUCKET = ITEMS.register("drip_bucket", () -> new Item(new Item.Properties().group(ItemGroup.MISC))); + public static final RegistryObject LAVA_OBSIDIAN = ITEMS.register("lava_obsidian", () -> new Item(new Item.Properties().group(ItemGroup.MISC))); + + public DynBucketModelTest() + { + IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); + ITEMS.register(modEventBus); + } +} diff --git a/src/test/resources/META-INF/mods.toml b/src/test/resources/META-INF/mods.toml index e29db42b77..45d5bc4823 100644 --- a/src/test/resources/META-INF/mods.toml +++ b/src/test/resources/META-INF/mods.toml @@ -64,6 +64,8 @@ license="LGPL v2.1" modId="chunk_data_event_save_null_world_test" [[mods]] modId="composite_model_test" +[[mods]] + modId="dyn_bucket_model_test" [[mods]] modId="music_disc_test" [[mods]] diff --git a/src/test/resources/assets/dyn_bucket_model_test/models/item/drip_bucket.json b/src/test/resources/assets/dyn_bucket_model_test/models/item/drip_bucket.json new file mode 100644 index 0000000000..686748e710 --- /dev/null +++ b/src/test/resources/assets/dyn_bucket_model_test/models/item/drip_bucket.json @@ -0,0 +1,9 @@ +{ + "parent": "forge:item/default", + "loader": "forge:bucket", + "textures": { + "base": "minecraft:item/bucket", + "fluid": "dyn_bucket_model_test:item/drip_bucket" + }, + "fluid": "lava" +} \ No newline at end of file diff --git a/src/test/resources/assets/dyn_bucket_model_test/models/item/lava_obsidian.json b/src/test/resources/assets/dyn_bucket_model_test/models/item/lava_obsidian.json new file mode 100644 index 0000000000..94c7c4af4b --- /dev/null +++ b/src/test/resources/assets/dyn_bucket_model_test/models/item/lava_obsidian.json @@ -0,0 +1,9 @@ +{ + "parent": "forge:item/default", + "loader": "forge:bucket", + "textures": { + "base": "minecraft:block/obsidian", + "fluid": "dyn_bucket_model_test:item/lava_obsidian" + }, + "fluid": "lava" +} \ No newline at end of file diff --git a/src/test/resources/assets/dyn_bucket_model_test/textures/item/drip_bucket.png b/src/test/resources/assets/dyn_bucket_model_test/textures/item/drip_bucket.png new file mode 100644 index 0000000000..8d0e0b4399 Binary files /dev/null and b/src/test/resources/assets/dyn_bucket_model_test/textures/item/drip_bucket.png differ diff --git a/src/test/resources/assets/dyn_bucket_model_test/textures/item/lava_obsidian.png b/src/test/resources/assets/dyn_bucket_model_test/textures/item/lava_obsidian.png new file mode 100644 index 0000000000..1773e74373 Binary files /dev/null and b/src/test/resources/assets/dyn_bucket_model_test/textures/item/lava_obsidian.png differ