From 4de1ccb42ee904d9d2b68bf35d2bb826e33d4fad Mon Sep 17 00:00:00 2001 From: Zailer43 Date: Sat, 22 Jun 2024 21:09:42 -0300 Subject: [PATCH] Fix issue in banner editor where colors were incorrectly changing if there were 2 identical layouts * When attempting to change the color of a layout, if there was another identical one before it, the color of the first layout was changed instead of the one clicked on --- .../java/fzmm/zailer/me/builders/BannerBuilder.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/fzmm/zailer/me/builders/BannerBuilder.java b/src/main/java/fzmm/zailer/me/builders/BannerBuilder.java index ce0511a4..eab690ab 100644 --- a/src/main/java/fzmm/zailer/me/builders/BannerBuilder.java +++ b/src/main/java/fzmm/zailer/me/builders/BannerBuilder.java @@ -127,12 +127,23 @@ public void removeLayer(BannerPatternsComponent.Layer layer) { } public void replaceColor(BannerPatternsComponent.Layer layer, DyeColor color) { - int index = this.layers.indexOf(layer); + // avoid using List#indexOf because what is needed in this case is the reference, + // otherwise you will get the wrong index + int index = this.indexOf(layer); if (index != -1) { this.layers.set(index, new BannerPatternsComponent.Layer(layer.pattern(), color)); } } + private int indexOf(BannerPatternsComponent.Layer layer) { + for (int i = 0; i != this.layers.size(); i++) { + if (this.layers.get(i) == layer) { + return i; + } + } + return -1; + } + public void replaceColors(DyeColor colorToReplace, DyeColor newColor) { for (int i = 0; i != this.layers.size(); i++) { if (this.layers.get(i).color() == colorToReplace) {