Skip to content

Commit b182c8c

Browse files
authored
Merge pull request #358 from FTBTeam/bugfix/scale-entity-icons
[1.21] Add support for default image size to fix large resource packs
2 parents bcfb327 + 0b52653 commit b182c8c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+212
-19
lines changed

common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/SliceCreationGUI.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public void drawBackground(GuiGraphics graphics, Theme theme, int x, int y, int
168168
for (SliceControlBox controlBox : sliceControlBoxes) {
169169
slices.add(new EntityImageIcon.ChildIconData(Optional.empty(), controlBox.createSlice(), Optional.of(new EntityImageIcon.Offset(controlBox.offsetXText.getIntValue(), controlBox.offsetYText.getIntValue()))));
170170
}
171-
new EntityImageIcon(sliceControlBox.texture, sliceControlBox.createSlice(), slices).draw(graphics, x + 2, y + 2, imageSizeX.getIntValue(), imageSizeY.getIntValue());
171+
new EntityImageIcon(sliceControlBox.texture, sliceControlBox.createSlice(), slices, null).draw(graphics, x + 2, y + 2, imageSizeX.getIntValue(), imageSizeY.getIntValue());
172172
}
173173

174174
@Override
@@ -329,6 +329,7 @@ private SimpleButton createExportButton() {
329329
box.createSlice(),
330330
Optional.of(new EntityImageIcon.Offset(box.offsetXText.getIntValue(), box.offsetYText.getIntValue())))).toList(),
331331
EntityIcons.WidthHeight.DEFAULT,
332+
Optional.empty(),
332333
1,
333334
true);
334335

common/src/main/java/dev/ftb/mods/ftbchunks/client/mapicon/EntityIcons.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected Map<EntityType<?>, EntityIconSettings> prepare(ResourceManager resourc
8181
ResourceLocation rl = FTBChunksAPI.rl(basePath + ".png");
8282
Optional<Resource> pic = resourceManager.getResource(rl);
8383
if (pic.isPresent()) {
84-
entityIconSettings = new EntityIconSettings(false, Optional.of(rl), Optional.empty(), List.of(), WidthHeight.DEFAULT, 1D, true);
84+
entityIconSettings = new EntityIconSettings(false, Optional.of(rl), Optional.empty(), List.of(), WidthHeight.DEFAULT, Optional.empty(), 1D, true);
8585
}
8686
}
8787

@@ -159,7 +159,7 @@ public static Optional<EntityIconSettings> getSettings(EntityType<?> entityType)
159159
private static Icon getOrCreateIcon(EntityType<?> entityType, ResourceLocation texture, EntityIconSettings settings) {
160160
return ICON_CACHE
161161
.computeIfAbsent(entityType, i -> new HashMap<>())
162-
.computeIfAbsent(texture, t -> new EntityImageIcon(t, settings.mainSlice.orElse(null), settings.children));
162+
.computeIfAbsent(texture, t -> new EntityImageIcon(t, settings.mainSlice.orElse(null), settings.children, settings.defaultImageSize.orElse(null)));
163163
}
164164

165165
@Override
@@ -175,12 +175,13 @@ public record EntityIconSettings(
175175
Optional<EntityImageIcon.Slice> mainSlice,
176176
List<EntityImageIcon.ChildIconData> children,
177177
WidthHeight widthHeight,
178+
Optional<EntityIcons.WidthHeight> defaultImageSize,
178179
double scale,
179180
boolean defaultEnabled) {
180181

181182
private static final EntityIconSettings OLD_HIDDEN = new EntityIconSettings(
182183
false, Optional.empty(), Optional.empty(),
183-
List.of(), WidthHeight.DEFAULT, 1D, true
184+
List.of(), WidthHeight.DEFAULT, Optional.empty(), 1D, true
184185
);
185186

186187
public static final Codec<EntityIconSettings> CODEC = RecordCodecBuilder.<EntityIconSettings>create(builder ->
@@ -190,6 +191,7 @@ public record EntityIconSettings(
190191
EntityImageIcon.Slice.CODEC.optionalFieldOf("slice").forGetter(entityIconData -> entityIconData.mainSlice),
191192
EntityImageIcon.ChildIconData.CODEC.listOf().optionalFieldOf("children", List.of()).forGetter(entityIconData -> entityIconData.children),
192193
WidthHeight.CODEC.optionalFieldOf("size", WidthHeight.DEFAULT).forGetter(s -> s.widthHeight),
194+
WidthHeight.CODEC.optionalFieldOf("default_image_size").forGetter(s -> s.defaultImageSize),
193195
Codec.DOUBLE.optionalFieldOf("scale", 1D).forGetter(s -> s.scale),
194196
Codec.BOOL.optionalFieldOf("default_enabled", true).forGetter(s -> s.defaultEnabled))
195197
.apply(builder, EntityIconSettings::new)

common/src/main/java/dev/ftb/mods/ftbchunks/client/mapicon/EntityImageIcon.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ public class EntityImageIcon extends Icon {
2020
private final List<ChildIconData> children;
2121
private final Icon mainIcon;
2222
private final List<Icon> childIcons;
23+
@Nullable
24+
private final EntityIcons.WidthHeight defaultImageSize;
2325

24-
public EntityImageIcon(ResourceLocation mainTexture, @Nullable Slice mainSlice, List<ChildIconData> children) {
26+
public EntityImageIcon(ResourceLocation mainTexture, @Nullable Slice mainSlice, List<ChildIconData> children, @Nullable EntityIcons.WidthHeight defaultImageSize) {
2527
this.mainSlice = mainSlice;
2628
this.children = children;
29+
this.defaultImageSize = defaultImageSize;
2730

2831
mainIcon = createIcon(mainTexture, mainSlice);
2932
childIcons = children.stream().map(childIconData -> createIcon(childIconData.texture.orElse(mainTexture), childIconData.slice)).toList();
@@ -101,9 +104,21 @@ private Icon createIcon(ResourceLocation texture, @Nullable Slice slice) {
101104
try {
102105
ImageIcon imageIcon = new ImageIcon(texture);
103106
if (slice != null) {
107+
104108
int textureWidth = load.getImage().getWidth();
105109
int textureHeight = load.getImage().getHeight();
106-
return imageIcon.withUV(slice.x, slice.y, slice.width, slice.height, textureWidth, textureHeight);
110+
if (defaultImageSize != null) {
111+
int defaultTextureWidth = defaultImageSize.width();
112+
int defaultTextureHeight = defaultImageSize.height();
113+
114+
float scaleX = (float) textureWidth / defaultTextureWidth;
115+
float scaleY = (float) textureHeight / defaultTextureHeight;
116+
return imageIcon.withUV(slice.x * scaleX, slice.y * scaleY, slice.width * scaleX, slice.height * scaleY, textureWidth, textureHeight);
117+
} else {
118+
return imageIcon.withUV(slice.x, slice.y, slice.width, slice.height, textureWidth, textureHeight);
119+
}
120+
121+
107122
}
108123
return imageIcon;
109124
} catch (Exception e) {

common/src/main/resources/assets/ftbchunks/textures/faces/minecraft/allay.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@
55
"y": 5,
66
"width": 5,
77
"height": 5
8+
},
9+
"default_image_size": {
10+
"width": 32,
11+
"height": 32
812
}
913
}

common/src/main/resources/assets/ftbchunks/textures/faces/minecraft/armadillo.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@
55
"y": 10,
66
"width": 10,
77
"height": 10
8+
},
9+
"default_image_size": {
10+
"width": 64,
11+
"height": 64
812
}
913
}

common/src/main/resources/assets/ftbchunks/textures/faces/minecraft/bee.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@
55
"y": 10,
66
"width": 9,
77
"height": 7
8+
},
9+
"default_image_size": {
10+
"width": 64,
11+
"height": 64
812
}
913
}

common/src/main/resources/assets/ftbchunks/textures/faces/minecraft/blaze.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@
55
"y": 8,
66
"width": 8,
77
"height": 8
8+
},
9+
"default_image_size": {
10+
"width": 64,
11+
"height": 32
812
}
913
}

common/src/main/resources/assets/ftbchunks/textures/faces/minecraft/breeze.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@
55
"y": 8,
66
"width": 10,
77
"height": 8
8+
},
9+
"default_image_size": {
10+
"width": 32,
11+
"height": 32
812
}
913
}

common/src/main/resources/assets/ftbchunks/textures/faces/minecraft/cave_spider.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@
55
"y": 12,
66
"width": 8,
77
"height": 8
8+
},
9+
"default_image_size": {
10+
"width": 64,
11+
"height": 32
812
}
913
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
22
"default_enabled": false,
3-
"texture": "ftbchunks:textures/faces/minecraft/cod.png"
3+
"texture": "ftbchunks:textures/faces/minecraft/cod.png",
4+
"default_image_size": {
5+
"width": 16,
6+
"height": 16
7+
}
48
}

0 commit comments

Comments
 (0)