Skip to content
stefvanschie edited this page Jun 7, 2021 · 3 revisions

Languages: Dutch (Nederlands)

The pattern pane allows you to specify a pattern based on which the pane will be filled with the corresponding items. This allows you to easily specify complex arrangements of items, which would otherwise require a tedious amount of manual placement. A pattern for the pane is created by specifying multiple lines of characters in which each character represents some item. For example, the following pattern has a border of items, a single item in the center and the center row is taken up by a different item yet.

111111111
100020001
111111111

To create a pattern you call the constructor and specify the pattern by multiple strings, wherein each string represents a single row in the pattern.

Pattern pattern = new Pattern(
    "111111111",
    "100020001",
    "111111111"
);

You can then use this in creating your pane, by calling the standard constructor for the PatternPane. Keep in mind that the dimensions of your pattern and the pane have to match.

PatternPane pane = new PatternPane(0, 0, 9, 3, pattern);

To make our pane show any item, we have to tell which character corresponds to which item. We can do this by binding a specific item to a character on the pane.

pane.bindItem('1', new GuiItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE)));

Now all ones in our pattern will correspond to a gray stained glass pane. Any character appearing in the pattern that is not bound to a character will simply not be shown.

You can also flip the items in the pane horizontally or vertically or both at the same time. When flipping the items horizontally all items are moved along the x-axis and when flipping the items vertically all items are moved along the y-axis. You can flip the pane horizontally and vertically respectively as follows:

pane.flipHorizontally(true);
pane.flipVertically(true);

You can also specify a rotation for square panes. There are four different rotations; 0, 90, 180, 270. These rotations are in degrees. Each rotation is applied clockwise, if you want a counter-clockwise rotation, you'll have to calculate the amount of degrees the pane would be rotated if you went clockwise. You can set the rotation as follows:

pane.setRotation(90);

This will have set the rotation of the pane to ninety degrees.

XML

Everything shown at Panes can be used on the Pattern Pane as well.

The element name for a Pattern Pane is patternpane so use that when you want a Pattern Pane inside your XML file.

<patternpane x="0" y="0" length="9" height="3"/>

Every single pattern must have a pattern element inside of it, representing the pattern that is used for the pattern pane. Inside this pattern tag, you can have one or more row tags, with the characters used for that row in it as plain text.

<patternpane x="0" y="0" length="9" height="3">
  <pattern>
    <row>111111111</row>
    <row>100020001</row>
    <row>111111111</row>
  </pattern>
</patternpane>

Optional attributes

To bind items you can add a binding element. The character it is bound to is represented by a char attribute. Inside this binding element you place the item you want to bind it to. This can be any item as seen on the Gui Item page.

<patternpane x="0" y="0" length="9" height="3">
  <pattern>
    <row>111111111</row>
    <row>100020001</row>
    <row>111111111</row>
  </pattern>
  <binding char="1">
    <item type="stone" />
  </binding>
</patternpane>

You can also flip the pane horizontally and/or vertically by adding the following attributes to your pane:

<patternpane x="0" y="0" length="9" height="3" flipHorizontally="true"/>
<patternpane x="0" y="0" length="9" height="3" flipVertically="true"/>

And you can also set the rotation by adding the rotate attribute to the pane with the amount of degrees as value. By default the pane has no rotation (0 degrees).

<patternpane x="0" y="0" length="9" height="3" rotation="90"/>
Clone this wiki locally