Json block behaviors OmniRotatable: Difference between revisions

From Vintage Story Wiki
(→‎Purpose: compare with WrenchOrientable)
(→‎Usage: use loadFromPropertiesCombine)
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Purpose ==
== Purpose ==


The <code>OmniRotatable</code> behavior selects an orientation variant of a block when the block is placed. The orientation variant is selected based on the orientation of the player. Note that [[Json_block_behaviors_WrenchOrientable|WrenchOrientable]] behavior is similar, but it allows the variant to be changed after the block is placed with the wrench tool.
The <code>OmniRotatable</code> [[Modding:Json_Block_Behaviors|behavior]] selects an [[Modding:Block_Orientation|orientation variant]] of a block when the block is placed. The orientation variant is selected based on the orientation of the player. Note that [[Json_block_behaviors_WrenchOrientable|WrenchOrientable]] behavior is similar, but it allows the variant to be changed after the block is placed with the wrench tool.


There are several meaningful ways to define a group of orientation variants for a block. Each orientation group type has different variant group requirements and different properties for the OmniRotatable behavior. Where possible, the examples below use [[Json:block:worldvariantgroups|world properties]] to assist in defining the variant states, but this is optional; the states may be directly listed instead.
== Used by blocks ==
* brickslabs
* clayshinglelabs
* cobblestoneslab
* glassslab
* mudbrickslab
* plankslab
* polishedrockslab
* quartzslab
* stonebrickslab
* trapdoor
 
== Usage ==
There are several meaningful ways to define a group of orientation variants for a block. Each orientation type has different variant code requirements and different properties for the OmniRotatable behavior. Where possible, the examples below use [[Json:block:worldvariantgroups|world properties]] to assist in defining the variant states, but this is optional; the states may be directly listed instead.
<table class="wikitable">
<table class="wikitable">
   <tr style="background-color: rgba(0,0,0,0.2);">
   <tr style="background-color: rgba(0,0,0,0.2);">
     <th style="background-color: rgba(0,0,0,0.2);">Orientation group type</th>
     <th style="background-color: rgba(0,0,0,0.2);">Orientation type</th>
     <th style="background-color: rgba(0,0,0,0.2);">Required variant groups</th>
     <th style="background-color: rgba(0,0,0,0.2);">Required variant codes</th>
     <th style="background-color: rgba(0,0,0,0.2);">Example block</th>
     <th style="background-color: rgba(0,0,0,0.2);">Example block</th>
     <th style="background-color: rgba(0,0,0,0.2);">Example variant group definition</th>
     <th style="background-color: rgba(0,0,0,0.2);">Example variant definition</th>
     <th style="background-color: rgba(0,0,0,0.2);">Required behavior properties</th>
     <th style="background-color: rgba(0,0,0,0.2);">Required behavior properties</th>
   </tr>
   </tr>
   <tr>
   <tr>
     <td>Face 6 directions</td>
     <td>All faces</td>
     <td>
     <td>
* <code>rot</code> variant group with the states "north", "east", "south", "west", "up", and "down"
* <code>rot</code> variant code with the states "north", "east", "south", "west", "up", and "down"
     </td>
     </td>
     <td>slab</td>
     <td>slab</td>
     <td><code>{ code:"rot", states: ["up", "down"], loadFromProperties: "abstract/horizontalorientation" }</code></td>
     <td>
<syntaxhighlight lang="json">
{
  code:"rot",
  loadFromPropertiesCombine: ["abstract/horizontalorientation", "abstract/verticalorientation"]
}
</syntaxhighlight>
    </td>
     <td><code>{ name: "OmniRotatable", properties: {rotateSides: "true"} }</code></td>
     <td><code>{ name: "OmniRotatable", properties: {rotateSides: "true"} }</code></td>
   </tr>
   </tr>
   <tr>
   <tr>
     <td>Face up/down</td>
     <td>Verticals</td>
     <td>
     <td>
* <code>rot</code> variant group with the states "up" and "down"
* <code>rot</code> variant code with the states "up" and "down"
     </td>
     </td>
     <td>none</td>
     <td>none</td>
     <td><code>{ code:"rot", loadFromProperties: "abstract/verticalorientation" }</code></td>
     <td>
<syntaxhighlight lang="json">
{
  code:"rot",
  loadFromProperties: "abstract/verticalorientation"
}
</syntaxhighlight>
    </td>
     <td><code>{ name: "OmniRotatable", properties: {rotateV: "true"} }</code></td>
     <td><code>{ name: "OmniRotatable", properties: {rotateV: "true"} }</code></td>
   </tr>
   </tr>
   <tr>
   <tr>
     <td>Face horizontally</td>
     <td>Horizontals</td>
     <td>
     <td>
* <code>rot</code> variant group with the states "north", "east", "south", and "west"
* <code>rot</code> variant code with the states "north", "east", "south", and "west"
     </td>
     </td>
     <td>none</td>
     <td>none</td>
     <td><code>{ code:"rot", loadFromProperties: "abstract/horizontalorientation" }</code></td>
     <td>
<syntaxhighlight lang="json">
{
  code:"rot",
  loadFromProperties: "abstract/horizontalorientation"
}
</syntaxhighlight>
    </td>
     <td><code>{ name: "OmniRotatable", properties: {rotateH: "true"} }</code></td>
     <td><code>{ name: "OmniRotatable", properties: {rotateH: "true"} }</code></td>
   </tr>
   </tr>
   <tr>
   <tr>
     <td>Face horizontally and flip vertically</td>
     <td>Horizontal Vertical</td>
     <td>
     <td>
* <code>rot</code> variant group with the states "north", "east", "south", and "west"
* <code>rot</code> variant code with the states "north", "east", "south", and "west"
* <code>v</code> variant group with the states "up" and "down"
* <code>v</code> variant code with the states "up" and "down"
     </td>
     </td>
     <td>none</td>
     <td>none</td>
     <td><code>{ code:"rot", loadFromProperties: "abstract/horizontalorientation"}, { code:"v", loadFromProperties: "abstract/verticalorientation" }</code></td>
     <td>
<syntaxhighlight lang="json">
{
  code:"rot",
  loadFromProperties: "abstract/horizontalorientation"
},
{
  code:"v",
  loadFromProperties: "abstract/verticalorientation"
}
</syntaxhighlight>
    </td>
     <td><code>{ name: "OmniRotatable", properties: {rotateH: "true", rotateV: "true"} }</code></td>
     <td><code>{ name: "OmniRotatable", properties: {rotateH: "true", rotateV: "true"} }</code></td>
   </tr>
   </tr>
   <tr>
   <tr>
     <td>Face 6 directions and rotate along axis</td>
     <td>2 Axis</td>
     <td>
     <td>
* <code>rot</code> variant group with the states "north", "east", "south", and "west"
* <code>rot</code> variant code with the states "north", "east", "south", and "west"
* <code>v</code> variant group with the states "up", "down", "left", and "right"
* <code>v</code> variant code with the states "up", "down", "left", and "right"
     </td>
     </td>
     <td>trapdoor</td>
     <td>trapdoor</td>
     <td><code>{ code:"rot", loadFromProperties: "abstract/horizontalorientation"}, { code:"v", states: ["left", "right"], loadFromProperties: "abstract/verticalorientation" }</code></td>
     <td>
<syntaxhighlight lang="json">
{
  code:"rot",
  loadFromProperties: "abstract/horizontalorientation"
},
{
  code:"v", states: ["left", "right"],
  loadFromProperties: "abstract/verticalorientation"
}
</syntaxhighlight>
    </td>
     <td><code>{ name: "OmniRotatable", properties: {rotateH: "true", rotateV: "true", rotateV4: "true"} }</code></td>
     <td><code>{ name: "OmniRotatable", properties: {rotateH: "true", rotateV: "true", rotateV4: "true"} }</code></td>
   </tr>
   </tr>
</table>
</table>


Additionally, the behavior adds a placement mode to items. The behavior shows the placement mode when the item is hovered over in the inventory or hotbar. The placement modes are auto, horizontal, and vertical. Auto is the default. The horizontal and vertical modes only work correctly for face 6 directions blocks.
Additionally, the behavior adds a placement mode to items. The behavior shows the placement mode when the item is hovered over in the inventory or hotbar. The placement modes are auto, horizontal, and vertical. Auto is the default. The horizontal and vertical modes only work correctly for the all faces type.


The behavior changes the placement mode when it detects that the block was created through crafting, and the first item in the recipe was an orientable block. So to allow changing the placement mode, add a 1x1 recipe that takes the block as input and produces it as output. The placement mode changes in the following cycle: auto to horizontal, horizontal to vertical, and vertical to auto.
The behavior changes the placement mode when it detects that the block was created through crafting, and the first item in the recipe was an orientable block. So to allow changing the placement mode, add a 1x1 recipe that takes the block as input and produces it as output. The placement mode changes in the following cycle: auto to horizontal, horizontal to vertical, and vertical to auto.


== Properties ==
== Properties ==
; <code>rotateSides</code>&#58; (boolean) : Enables face 6 directions mode.
; <code>rotateSides</code>&#58; (boolean) : Enables the all faces type.
; <code>rotateH</code>&#58; (boolean) : Enables orienting along the 4 cardinal directions.
; <code>rotateH</code>&#58; (boolean) : Enables orienting along the 4 cardinal directions.
; <code>rotateV</code>&#58; (boolean) : Enables orienting up or down.
; <code>rotateV</code>&#58; (boolean) : Enables orienting up or down.
; <code>rotateV4</code>&#58; (boolean) : This can only be used if <code>rotateV</code> is also enabled. It extends the <code>rotateV</code> mode to also use the "left" and "right" values for the vertical variant group.
; <code>rotateV4</code>&#58; (boolean) : This can only be used if <code>rotateV</code> is also enabled. It extends the <code>rotateV</code> mode to also use the "left" and "right" values for the vertical variant code.
; <code>facing</code>&#58; (string, default "player") : Tells the block what it should orient to. Typically "block" is used, since the player almost always is building against another block.
; <code>facing</code>&#58; (string, default "player") : Tells the block what it should orient to. Typically "block" is used, since the player almost always is building against another block.
; <code>dropChance</code>&#58; (float, default 1) : Values less than 1 reduce the chances of the block getting dropped when it is broken. Values 1 and above do not affect the drop rate.
; <code>dropChance</code>&#58; (float, default 1) : Values less than 1 reduce the chances of the block getting dropped when it is broken. Values 1 and above do not affect the drop rate.


{{Navbox/modding|Vintage Story}}
{{Navbox/modding|Vintage Story}}

Latest revision as of 07:07, 24 November 2023

Purpose

The OmniRotatable behavior selects an orientation variant of a block when the block is placed. The orientation variant is selected based on the orientation of the player. Note that WrenchOrientable behavior is similar, but it allows the variant to be changed after the block is placed with the wrench tool.

Used by blocks

  • brickslabs
  • clayshinglelabs
  • cobblestoneslab
  • glassslab
  • mudbrickslab
  • plankslab
  • polishedrockslab
  • quartzslab
  • stonebrickslab
  • trapdoor

Usage

There are several meaningful ways to define a group of orientation variants for a block. Each orientation type has different variant code requirements and different properties for the OmniRotatable behavior. Where possible, the examples below use world properties to assist in defining the variant states, but this is optional; the states may be directly listed instead.

Orientation type Required variant codes Example block Example variant definition Required behavior properties
All faces
  • rot variant code with the states "north", "east", "south", "west", "up", and "down"
slab
{
  code:"rot",
  loadFromPropertiesCombine: ["abstract/horizontalorientation", "abstract/verticalorientation"]
}
{ name: "OmniRotatable", properties: {rotateSides: "true"} }
Verticals
  • rot variant code with the states "up" and "down"
none
{
  code:"rot",
  loadFromProperties: "abstract/verticalorientation"
}
{ name: "OmniRotatable", properties: {rotateV: "true"} }
Horizontals
  • rot variant code with the states "north", "east", "south", and "west"
none
{
  code:"rot",
  loadFromProperties: "abstract/horizontalorientation"
}
{ name: "OmniRotatable", properties: {rotateH: "true"} }
Horizontal Vertical
  • rot variant code with the states "north", "east", "south", and "west"
  • v variant code with the states "up" and "down"
none
{
  code:"rot",
  loadFromProperties: "abstract/horizontalorientation"
},
{
  code:"v",
  loadFromProperties: "abstract/verticalorientation"
}
{ name: "OmniRotatable", properties: {rotateH: "true", rotateV: "true"} }
2 Axis
  • rot variant code with the states "north", "east", "south", and "west"
  • v variant code with the states "up", "down", "left", and "right"
trapdoor
{
  code:"rot",
  loadFromProperties: "abstract/horizontalorientation"
},
{
  code:"v", states: ["left", "right"],
  loadFromProperties: "abstract/verticalorientation"
}
{ name: "OmniRotatable", properties: {rotateH: "true", rotateV: "true", rotateV4: "true"} }

Additionally, the behavior adds a placement mode to items. The behavior shows the placement mode when the item is hovered over in the inventory or hotbar. The placement modes are auto, horizontal, and vertical. Auto is the default. The horizontal and vertical modes only work correctly for the all faces type.

The behavior changes the placement mode when it detects that the block was created through crafting, and the first item in the recipe was an orientable block. So to allow changing the placement mode, add a 1x1 recipe that takes the block as input and produces it as output. The placement mode changes in the following cycle: auto to horizontal, horizontal to vertical, and vertical to auto.

Properties

rotateSides: (boolean)
Enables the all faces type.
rotateH: (boolean)
Enables orienting along the 4 cardinal directions.
rotateV: (boolean)
Enables orienting up or down.
rotateV4: (boolean)
This can only be used if rotateV is also enabled. It extends the rotateV mode to also use the "left" and "right" values for the vertical variant code.
facing: (string, default "player")
Tells the block what it should orient to. Typically "block" is used, since the player almost always is building against another block.
dropChance: (float, default 1)
Values less than 1 reduce the chances of the block getting dropped when it is broken. Values 1 and above do not affect the drop rate.
Icon Sign.png

Wondering where some links have gone?
The modding navbox is going through some changes! Check out Navigation Box Updates for more info and help finding specific pages.

Modding
Modding Introduction Getting Started Theme Pack
Content Modding Content Mods Developing a Content Mod Basic Tutorials Intermediate Tutorials Advanced Tutorials Content Mod Concepts
Code Modding Code Mods Setting up your Development Environment
Property Overview ItemEntityEntity BehaviorsBlockBlock BehaviorsBlock ClassesBlock EntitiesBlock Entity BehaviorsCollectible BehaviorsWorld properties
Workflows & Infrastructure Modding Efficiency TipsMod-engine compatibilityMod ExtensibilityVS Engine
Additional Resources Community Resources Modding API Updates Programming Languages List of server commandsList of client commandsClient startup parametersServer startup parameters
Example ModsAPI DocsGitHub Repository