@Environment(value=CLIENT) public class NinePatch extends java.lang.Object implements BackgroundPainter
Nine-patch textures are separated into nine sections: four corners, four edges and a center part.
The edges and the center are either tiled or stretched, depending on the mode,
to fill the area between the corners. By default, the texture mode is loaded from the texture metadata.
The default mode for that is NinePatch.Mode.STRETCHING.
NinePatch painters have a customizable padding that can be applied.
For example, a GUI panel for a container block might have a padding of 8 pixels, like BackgroundPainter.VANILLA.
You can set the padding using setPadding(int).
The metadata file for a texture has to be placed in the same directory as the texture.
The file name must be X.9patch where X is the texture file name (including .png).
Metadata files use the .properties format with the following keys:
| Key | Value | Description |
|---|---|---|
mode |
stretching | tiling |
The texture filling mode |
| Modifier and Type | Class and Description |
|---|---|
static class |
NinePatch.Mode
The mode of a nine-patch painter defines how it fills the area between the corners.
|
SLOT, VANILLA| Constructor and Description |
|---|
NinePatch(net.minecraft.util.Identifier texture)
Creates a nine-patch background painter with 4 px corners and a 0.25 corner UV.
|
NinePatch(net.minecraft.util.Identifier texture,
int cornerSize,
float cornerUv)
Creates a nine-patch background painter.
|
| Modifier and Type | Method and Description |
|---|---|
int |
getBottomPadding() |
int |
getCornerSize() |
int |
getLeftPadding() |
@Nullable NinePatch.Mode |
getMode() |
int |
getRightPadding() |
net.minecraft.util.Identifier |
getTexture() |
int |
getTopPadding() |
void |
paintBackground(net.minecraft.client.util.math.MatrixStack matrices,
int left,
int top,
WWidget panel)
Paint the specified panel to the screen.
|
NinePatch |
setBottomPadding(int bottomPadding) |
NinePatch |
setLeftPadding(int leftPadding) |
NinePatch |
setMode(@Nullable NinePatch.Mode mode)
Sets the mode of this painter to the specified mode.
|
NinePatch |
setPadding(int padding) |
NinePatch |
setPadding(int vertical,
int horizontal) |
NinePatch |
setPadding(int topPadding,
int leftPadding,
int bottomPadding,
int rightPadding) |
NinePatch |
setRightPadding(int rightPadding) |
NinePatch |
setTopPadding(int topPadding) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcreateColorful, createColorful, createLightDarkVariants, createNinePatch, createNinePatchpublic NinePatch(net.minecraft.util.Identifier texture)
texture - the texture IDpublic NinePatch(net.minecraft.util.Identifier texture,
int cornerSize,
float cornerUv)
texture - the texture IDcornerSize - the size of the corners on the screencornerUv - the fraction of the corners from the whole texturepublic int getTopPadding()
public NinePatch setTopPadding(int topPadding)
public int getLeftPadding()
public NinePatch setLeftPadding(int leftPadding)
public int getBottomPadding()
public NinePatch setBottomPadding(int bottomPadding)
public int getRightPadding()
public NinePatch setRightPadding(int rightPadding)
public NinePatch setPadding(int padding)
public NinePatch setPadding(int vertical, int horizontal)
public NinePatch setPadding(int topPadding, int leftPadding, int bottomPadding, int rightPadding)
public net.minecraft.util.Identifier getTexture()
public int getCornerSize()
@Nullable public @Nullable NinePatch.Mode getMode()
public NinePatch setMode(@Nullable @Nullable NinePatch.Mode mode)
If the mode is not null, it will override the one specified in the texture metadata.
A null mode uses the texture metadata.
public void paintBackground(net.minecraft.client.util.math.MatrixStack matrices,
int left,
int top,
WWidget panel)
BackgroundPainterpaintBackground in interface BackgroundPainterleft - The absolute position of the left of the panel, in gui-screen coordinatestop - The absolute position of the top of the panel, in gui-screen coordinatespanel - The panel being painted