Skip to content

Commit

Permalink
fix: add stretch_inner to NineSlice Gui-Meta
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Jan 24, 2025
1 parent d06da3f commit 64830e0
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ public interface GuiScaling extends Examinable {
* @param height The number of pixels for the sprite to cover
* on-screen across its height, must be positive
* @param border The border sizes
* @param stretchInner If the texture should be stretched instead of tiled
* @return The created {@link GuiScaling} instance
* @sinceMinecraft 1.20.2
* @sincePackFormat 18
* @since 1.2.0
*/
static @NotNull NineSliceGuiScaling nineSlice(final int width, final int height, final @NotNull GuiBorder border) {
return new NineSliceGuiScalingImpl(width, height, border);
static @NotNull NineSliceGuiScaling nineSlice(final int width, final int height, final @NotNull GuiBorder border, final boolean stretchInner) {
return new NineSliceGuiScalingImpl(width, height, border, stretchInner);
}

/**
Expand All @@ -95,12 +96,13 @@ public interface GuiScaling extends Examinable {
* @param height The number of pixels for the sprite to cover
* on-screen across its height, must be positive
* @param border The border size for all sides
* @param stretchInner If the texture should be stretched instead of tiled
* @return The created {@link GuiScaling} instance
* @sinceMinecraft 1.20.2
* @sincePackFormat 18
* @since 1.2.0
*/
static @NotNull NineSliceGuiScaling nineSlice(final int width, final int height, final int border) {
return new NineSliceGuiScalingImpl(width, height, GuiBorder.border(border));
static @NotNull NineSliceGuiScaling nineSlice(final int width, final int height, final int border, final boolean stretchInner) {
return new NineSliceGuiScalingImpl(width, height, GuiBorder.border(border), stretchInner);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*
* @sinceMinecraft 1.20.2
* @sincePackFormat 18
* @see GuiScaling#nineSlice(int, int, GuiBorder)
* @see GuiScaling#nineSlice(int, int, GuiBorder, boolean)
* @since 1.2.0
*/
@ApiStatus.NonExtendable
Expand Down Expand Up @@ -71,4 +71,14 @@ public interface NineSliceGuiScaling extends GuiScaling {
* @since 1.2.0
*/
@NotNull GuiBorder border();

/**
* Returns if inner parts of texture is stretched instead of tiled
*
* @return if inner parts are stretched
* @sinceMinecraft 1.21.2
* @sincePackFormat 42
* @since 1.7.7
*/
boolean stretchInner();
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ final class NineSliceGuiScalingImpl implements NineSliceGuiScaling {
private final int width;
private final int height;
private final GuiBorder border;
private final boolean stretchInner;

NineSliceGuiScalingImpl(final int width, final int height, final @NotNull GuiBorder border) {
NineSliceGuiScalingImpl(final int width, final int height, final @NotNull GuiBorder border, final boolean stretchInner) {
this.width = width;
this.height = height;
this.border = requireNonNull(border, "border");
this.stretchInner = stretchInner;
validate();
}

Expand Down Expand Up @@ -71,12 +73,18 @@ public int height() {
return border;
}

@Override
public boolean stretchInner() {
return stretchInner;
}

@Override
public @NotNull Stream<? extends ExaminableProperty> examinableProperties() {
return Stream.of(
ExaminableProperty.of("width", width),
ExaminableProperty.of("height", height),
ExaminableProperty.of("border", border)
ExaminableProperty.of("border", border),
ExaminableProperty.of("stretch_inner", stretchInner)
);
}

Expand All @@ -92,14 +100,16 @@ public boolean equals(final @Nullable Object o) {
final NineSliceGuiScalingImpl that = (NineSliceGuiScalingImpl) o;
if (width != that.width) return false;
if (height != that.height) return false;
return border.equals(that.border);
if (!border.equals(that.border)) return false;
return stretchInner == that.stretchInner;
}

@Override
public int hashCode() {
int result = width;
result = 31 * result + height;
result = 31 * result + border.hashCode();
result = 31 * result + (stretchInner ? 1 : 0);
return result;
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group=team.unnamed
version=1.7.4
version=1.7.7-SNAPSHOT
description=A resource-pack library for Minecraft: Java Edition.
repositoryName=ossrh
snapshotRepository=https\://s01.oss.sonatype.org/content/repositories/snapshots/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ final class GuiMetaCodec implements MetadataPartCodec<GuiMeta> {
border = GuiBorder.border(top, bottom, left, right);
}
}
return GuiMeta.of(GuiScaling.nineSlice(width, height, border));
final boolean stretchInner = GsonUtil.getBoolean(scalingNode, "stretch_inner", false);
return GuiMeta.of(GuiScaling.nineSlice(width, height, border, stretchInner));
}
default:
throw new IllegalArgumentException("Unknown gui scaling type: " + typeString);
Expand Down Expand Up @@ -129,6 +130,7 @@ public void write(final @NotNull JsonWriter writer, final @NotNull GuiMeta value
.name("right").value(right)
.endObject();
}
writer.name("stretch_inner").value(nineSlice.stretchInner());
}
writer.endObject();
writer.endObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ class GuiMetaTest {
@Test
void test_deserialization() throws IOException {
final Map<String, GuiScaling> expectations = new HashMap<>();
expectations.put("button.png.mcmeta", GuiScaling.nineSlice(200, 20, 3));
expectations.put("button_disabled.png.mcmeta", GuiScaling.nineSlice(200, 20, 1));
expectations.put("slider_handle.png.mcmeta", GuiScaling.nineSlice(8, 20, GuiBorder.border(2, 3, 2, 2)));
expectations.put("slider_handle_highlighted.png.mcmeta", GuiScaling.nineSlice(8, 20, GuiBorder.border(2, 3, 2, 2)));
expectations.put("button.png.mcmeta", GuiScaling.nineSlice(200, 20, 3, true));
expectations.put("button_disabled.png.mcmeta", GuiScaling.nineSlice(200, 20, 1, false));
expectations.put("slider_handle.png.mcmeta", GuiScaling.nineSlice(8, 20, GuiBorder.border(2, 3, 2, 2), false));
expectations.put("slider_handle_highlighted.png.mcmeta", GuiScaling.nineSlice(8, 20, GuiBorder.border(2, 3, 2, 2), false));
expectations.put("stretch_custom.png.mcmeta", GuiScaling.stretch());
expectations.put("tile_custom.png.mcmeta", GuiScaling.tile(8, 20));
expectations.put("tile_custom_2.png.mcmeta", GuiScaling.tile(200, 20));
expectations.put("tile_custom_3.png.mcmeta", GuiScaling.tile(200, 26));
expectations.put("title_box.png.mcmeta", GuiScaling.nineSlice(200, 26, 10));
expectations.put("title_box.png.mcmeta", GuiScaling.nineSlice(200, 26, 10, false));

for (final Map.Entry<String, GuiScaling> entry : expectations.entrySet()) {
final Metadata metadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"type": "nine_slice",
"width": 200,
"height": 20,
"border": 3
"border": 3,
"stretch_inner": true
}
}
}

0 comments on commit 64830e0

Please sign in to comment.