Skip to content

Commit

Permalink
Merge pull request #144 from FTBTeam/1.20.1/dev
Browse files Browse the repository at this point in the history
1.20.1/dev
  • Loading branch information
desht authored Feb 6, 2025
2 parents b0ac147 + fb40674 commit 31d7de0
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,16 @@ public boolean hasPixelBuffer() {
return true;
}

@Override
@Nullable
public PixelBuffer createPixelBuffer() {
try {
return PixelBuffer.from(Minecraft.getInstance().getResourceManager().getResource(new ResourceLocation(id.getNamespace(), "textures/" + id.getPath() + ".png")).orElseThrow().open());
} catch (Exception ex) {
return null;
}
}
@Override
@Nullable
public PixelBuffer createPixelBuffer() {
try {
ResourceLocation loc = new ResourceLocation(id.getNamespace(), "textures/" + id.getPath() + ".png");
return PixelBuffer.from(Minecraft.getInstance().getResourceManager().getResource(loc).orElseThrow().open());
} catch (Exception ex) {
return null;
}
}

@Override
public int getPixelBufferFrameCount() {
Expand All @@ -100,6 +101,13 @@ public AtlasSpriteIcon copy() {
return new AtlasSpriteIcon(id);
}

@Override
public double aspectRatio() {
var sprite = Minecraft.getInstance().getModelManager().getAtlas(InventoryMenu.BLOCK_ATLAS).getSprite(id);

return (double) sprite.contents().width() / (double) sprite.contents().height();
}

@Override
public AtlasSpriteIcon withColor(Color4I color) {
return new AtlasSpriteIcon(id, color);
Expand Down
64 changes: 38 additions & 26 deletions common/src/main/java/dev/ftb/mods/ftblibrary/icon/Icon.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,29 +285,41 @@ public boolean hasPixelBuffer() {
return false;
}

/**
* @return null if failed to load
*/
@Nullable
public PixelBuffer createPixelBuffer() {
return null;
}

/**
* The number of animation frames in a pixel-buffer icon. Note: not to be confused with {@link IconAnimation},
* which is a collection of individual icons. This is for icons with animated textures.
*
* @return the number of frames
*/
public int getPixelBufferFrameCount() {
return 1;
}

@Nullable
public Object getIngredient() {
return null;
}

protected void setProperties(IconProperties properties) {
}
}
/**
* @return null if this icon does not have a pixel buffer, or if it failed to load
*/
@Nullable
public PixelBuffer createPixelBuffer() {
return null;
}

/**
* The number of animation frames in a pixel-buffer icon. Note: not to be confused with {@link IconAnimation},
* which is a collection of individual icons. This returns 1 for most icon types, but icons with animated
* textures (currently only atlas sprite icons) may have multiple frames.
*
* @return the number of frames
*/
public int getPixelBufferFrameCount() {
return 1;
}

/**
* Get the aspect ratio of the icon, which is the width divided by height. For most icon types this is always 1.0,
* since icons do not in general know what size they are (they're scaled when drawn). However, for atlas sprite
* and image icons, the underlying image's aspect ratio is returned.
*
* @return the aspect ratio of the icon
*/
public double aspectRatio() {
return 1.0;
}

@Nullable
public Object getIngredient() {
return null;
}

protected void setProperties(IconProperties properties) {
}
}
15 changes: 11 additions & 4 deletions common/src/main/java/dev/ftb/mods/ftblibrary/icon/ImageIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,15 @@ public PixelBuffer createPixelBuffer() {
}
}

@Override
public ResourceLocation getResourceLocation() {
return texture;
}
@Override
public double aspectRatio() {
if (maxV == minV) return 1.0;

return (maxU - minU) / (maxV - minV);
}

@Override
public ResourceLocation getResourceLocation() {
return texture;
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.daemon=false
mod_id=ftblibrary
archives_base_name=ftb-library
maven_group=dev.ftb.mods
mod_version=2001.2.8
mod_version=2001.2.9
mod_author=FTB Team
minecraft_version=1.20.1
architectury_version=9.0.8
Expand Down

0 comments on commit 31d7de0

Please sign in to comment.