Keen:New Component Modding Guide: Difference between revisions

From Medieval Engineers Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{SEO|image_url=http://www.medievalengineerswiki.com/images/b/b7/KeenLogoBig.png|description=We introduce a multitude of new entity components, as well as an upgrade to the subpart animation system to be more generic and easy to use.}}
{{Keen:OCH}}
Hello engineers,
Hello engineers,


Line 9: Line 13:
===MyEntityFXComponent===
===MyEntityFXComponent===
The Entity FX component provides light, particle and sound effects to a block. See Data/CubeBlocks/Props/TorchStand.sbc for an example.
The Entity FX component provides light, particle and sound effects to a block. See Data/CubeBlocks/Props/TorchStand.sbc for an example.
<source lang="xml">
<syntaxhighlight lang="xml" line>
   <Definition xsi:type="MyObjectBuilder_EntityFXComponentDefinition">
   <Definition xsi:type="MyObjectBuilder_EntityFXComponentDefinition">
     <Id Type="MyObjectBuilder_EntityFXComponent" Subtype="TorchStand" />
     <Id Type="MyObjectBuilder_EntityFXComponent" Subtype="TorchStand" />
Line 18: Line 22:
     </Effects>
     </Effects>
   </Definition>
   </Definition>
</source>
</syntaxhighlight>
The Effects contains a list of effects, as well as which events toggles them on and off and which dummy they respond to. Finally, they refer to the effect as defined in Data/FX/Effects.sbc.
The Effects contains a list of effects, as well as which events toggles them on and off and which dummy they respond to. Finally, they refer to the effect as defined in Data/FX/Effects.sbc.


Line 24: Line 28:
===MotionEventsComponent===
===MotionEventsComponent===
The MotionEventsComponent is a simple component that can fire events on the entity depending on how fast it is moving. Look at Data/CubeBlocks/Miscellaneous/Projectiles.sbc for an example.
The MotionEventsComponent is a simple component that can fire events on the entity depending on how fast it is moving. Look at Data/CubeBlocks/Miscellaneous/Projectiles.sbc for an example.
<source lang="xml">
<syntaxhighlight lang="xml" line>
   <Definition xsi:type="MyObjectBuilder_MotionEventsComponentDefinition">
   <Definition xsi:type="MyObjectBuilder_MotionEventsComponentDefinition">
     <Id Type="MyObjectBuilder_MotionEventsComponent" Subtype="CatapultProjectile"/>
     <Id Type="MyObjectBuilder_MotionEventsComponent" Subtype="CatapultProjectile"/>
Line 30: Line 34:
     <VelocityEvent Speed="20" Threshold="Above" Name="MovingFast"/>
     <VelocityEvent Speed="20" Threshold="Above" Name="MovingFast"/>
   </Definition>
   </Definition>
</source>
</syntaxhighlight>
Each velocity event checks if the speed goes from either above to below a speed, or from below to above a speed, and then fires the event in Name on the object.
Each velocity event checks if the speed goes from either above to below a speed, or from below to above a speed, and then fires the event in Name on the object.


Line 36: Line 40:
===MyCraftingComponentBlock===
===MyCraftingComponentBlock===
The CraftingComponentBlock component adds crafting functionality to a block that relies on the presence of fuel. This is used for the bonfire and the furnace. See Data/CubeBlocks/Production/Bonfire.sbc for an example.
The CraftingComponentBlock component adds crafting functionality to a block that relies on the presence of fuel. This is used for the bonfire and the furnace. See Data/CubeBlocks/Production/Bonfire.sbc for an example.
<source lang="xml">
<syntaxhighlight lang="xml" line>
   <Definition xsi:type="MyObjectBuilder_CraftingComponentDefinition">
   <Definition xsi:type="MyObjectBuilder_CraftingComponentQueuedDefinition">
     <Id Type="CraftingComponent" Subtype="BonFire"/>
     <Id Type="CraftingComponentQueued" Subtype="BonFire"/>
     <CraftingCategories>
     <CraftingCategories>
      <Category>Campfire</Category>
       <Category>Meals</Category>
       <Category>Meals</Category>
     </CraftingCategories>
     </CraftingCategories>
     <CraftingInventory>BonfireInventory</CraftingInventory>
    <InputInventory>BonfireInventory</InputInventory>
    <OutputInventory>BonfireInventory</OutputInventory>
     <CraftingInventory>ProcessingInventory</CraftingInventory>
     <ProductionQueueSize>4</ProductionQueueSize>
     <ProductionQueueSize>4</ProductionQueueSize>
     <CraftingSpeedMultiplier>1</CraftingSpeedMultiplier>
     <CraftingSpeedMultiplier>1</CraftingSpeedMultiplier>
     <ConstrainInventory>true</ConstrainInventory>
     <ConstrainInventory>true</ConstrainInventory>
    <PowerRequired>All</PowerRequired>
   </Definition>
   </Definition>
</source>
</syntaxhighlight>
CarftingCategories lists the categories of crafting recipes that can be crafted. CraftingInventory references an inventory component of the bonfire that is used for crafting. (Any block can have multiple inventories, this sets which one is used for crafting). ProductionQueueSize sets how long can crafting queue get. CraftingSpeedMultiplier can modify speed that recipes are being built with. This way you can make faster crafting stations. ConstrainInventory set to true will only allow items in its inventory, that are used for crafting by that block, or produced by this block.
;CarftingCategories: lists the categories of crafting recipes that can be crafted.  
 
;CraftingInventory: references an inventory component of the bonfire that is used for crafting. (Any block can have multiple inventories, this sets which one is used for crafting).  
 
;ProductionQueueSize: sets how long can crafting queue get.  
 
;CraftingSpeedMultiplier: can modify speed that recipes are being built with. This way you can make faster crafting stations.  


;ConstrainInventory: set to true will only allow items in its inventory, that are used for crafting by that block, or produced by this block.


For more information about crafting blocks see the [[Official_Content/Crafting|crafting guide]].


For more information about crafting blocks see the [[Keen:Crafting|crafting guide]].


===StockpileComponent===
===StockpileComponent===
The StockpileComponent component adds the ability to display the inventory items in the world on to the entity per subpart points. This component requires the CubeBlockSubpartComponent to be present. Look at Data/CubeBlocks/Storage/WoodenShelf.sbc for an example.
The StockpileComponent component adds the ability to display the inventory items in the world on to the entity per subpart points. This component requires the CubeBlockSubpartComponent to be present. Look at Data/CubeBlocks/Storage/WoodenShelf.sbc for an example.
<source lang="xml">
<syntaxhighlight lang="xml" line>
   <Definition xsi:type="MyObjectBuilder_StockpileComponentDefinition">
   <Definition xsi:type="MyObjectBuilder_StockpileComponentDefinition">
     <Id Type="MyObjectBuilder_StockpileComponent" Subtype="WoodenShelf" />
     <Id Type="MyObjectBuilder_StockpileComponent" Subtype="WoodenShelf" />
Line 62: Line 77:
     <MaxNumberOfSubparts>3</MaxNumberOfSubparts>
     <MaxNumberOfSubparts>3</MaxNumberOfSubparts>
   </Definition>
   </Definition>
</source>
</syntaxhighlight>
The SubpartNameFormat specifies the numerated subpart names that are used for the system, and MaxNumberOfSubparts specifies the limit of visible subparts to try and assign contents to.
The SubpartNameFormat specifies the numerated subpart names that are used for the system, and MaxNumberOfSubparts specifies the limit of visible subparts to try and assign contents to.


Line 68: Line 83:
===CrankComponent===
===CrankComponent===
The CrankComponent simply specifies the sound and angular speed and torque properties of a handcrank object. Look at Data/CubeBlocks/Mechanical/TurnWheel.sbc for an example.
The CrankComponent simply specifies the sound and angular speed and torque properties of a handcrank object. Look at Data/CubeBlocks/Mechanical/TurnWheel.sbc for an example.
<source lang="xml">
<syntaxhighlight lang="xml" line>
   <Definition xsi:type="MyObjectBuilder_CrankComponentDefinition">
   <Definition xsi:type="MyObjectBuilder_CrankComponentDefinition">
     <Id Type="CrankComponent" Subtype="TurnCrossSmall" />
     <Id Type="CrankComponent" Subtype="TurnCrossSmall" />
Line 75: Line 90:
     <ActionSound>GearWheel</ActionSound>
     <ActionSound>GearWheel</ActionSound>
   </Definition>
   </Definition>
</source>
</syntaxhighlight>
AngularImpulse specifies the physical strength of the rotation, AngularVelocityLimit limits the rotation speed and ActionSound specifies the sound played while rotating.
AngularImpulse specifies the physical strength of the rotation, AngularVelocityLimit limits the rotation speed and ActionSound specifies the sound played while rotating.


Line 81: Line 96:
===LockableRopeComponent===
===LockableRopeComponent===
The LockableRopeComponent specifies the lockable rope drum properties for when you want to make an object that behaves exactly like the lockable rope drum. Look at Data/CubeBlocks/Mechanical/RopeDrum.sbc for an example.
The LockableRopeComponent specifies the lockable rope drum properties for when you want to make an object that behaves exactly like the lockable rope drum. Look at Data/CubeBlocks/Mechanical/RopeDrum.sbc for an example.
<source lang="xml">
<syntaxhighlight lang="xml" line>
   <Definition xsi:type="MyObjectBuilder_LockableRopeComponentDefinition">
   <Definition xsi:type="MyObjectBuilder_LockableRopeComponentDefinition">
     <Id Type="MyObjectBuilder_LockableRopeComponent" Subtype="LockableDrumSmall" />
     <Id Type="MyObjectBuilder_LockableRopeComponent" Subtype="LockableDrumSmall" />
Line 88: Line 103:
     <DefaultMaxRopeLength>40</DefaultMaxRopeLength>
     <DefaultMaxRopeLength>40</DefaultMaxRopeLength>
   </Definition>
   </Definition>
</source>
</syntaxhighlight>
MinRopeLength and MaxRopeLength specify how long a rope can be, and DefaultMaxRopeLength specifies the default rope length when the drum is fully unwinded.
MinRopeLength and MaxRopeLength specify how long a rope can be, and DefaultMaxRopeLength specifies the default rope length when the drum is fully unwinded.


Line 94: Line 109:
===TorsionSpringComponent===
===TorsionSpringComponent===
The TorsionSpringComponent component specifies torsion spring properties. Look at Data/CubeBlocks/Mechanical/TorsionSpring.sbc for an example.
The TorsionSpringComponent component specifies torsion spring properties. Look at Data/CubeBlocks/Mechanical/TorsionSpring.sbc for an example.
<source lang="xml">
<syntaxhighlight lang="xml" line>
   <Definition xsi:type="MyObjectBuilder_TorsionSpringComponentDefinition">
   <Definition xsi:type="MyObjectBuilder_TorsionSpringComponentDefinition">
     <Id Type="MyObjectBuilder_TorsionSpringComponent" Subtype="RopePowerSmallCogWheel1"/>
     <Id Type="MyObjectBuilder_TorsionSpringComponent" Subtype="RopePowerSmallCogWheel1"/>
Line 101: Line 116:
     <MaxFrictionTorque>30</MaxFrictionTorque>
     <MaxFrictionTorque>30</MaxFrictionTorque>
   </Definition>
   </Definition>
</source>
</syntaxhighlight>
MaxAngularImpulse specifies the maximum strength the block can provide, the MaxAngle is the maximum angle it rotates and MaxFrictionTorque is the maximum torque friction.
MaxAngularImpulse specifies the maximum strength the block can provide, the MaxAngle is the maximum angle it rotates and MaxFrictionTorque is the maximum torque friction.



Latest revision as of 20:22, 18 July 2022



Hello engineers,

With 0.4.14 we introduce a multitude of new entity components, as well as an upgrade to the subpart animation system to be more generic and easy to use.


Version: 0.4.14

New Entity Components

MyEntityFXComponent

The Entity FX component provides light, particle and sound effects to a block. See Data/CubeBlocks/Props/TorchStand.sbc for an example.

  <Definition xsi:type="MyObjectBuilder_EntityFXComponentDefinition">
    <Id Type="MyObjectBuilder_EntityFXComponent" Subtype="TorchStand" />
    <Effects>
      <Effect StartEvent="On" StopEvent="Off" Dummy="detector_fire">
        <EffectId Type="MyObjectBuilder_EffectDefinition" Subtype="Torch"/>
      </Effect>
    </Effects>
  </Definition>

The Effects contains a list of effects, as well as which events toggles them on and off and which dummy they respond to. Finally, they refer to the effect as defined in Data/FX/Effects.sbc.


MotionEventsComponent

The MotionEventsComponent is a simple component that can fire events on the entity depending on how fast it is moving. Look at Data/CubeBlocks/Miscellaneous/Projectiles.sbc for an example.

  <Definition xsi:type="MyObjectBuilder_MotionEventsComponentDefinition">
    <Id Type="MyObjectBuilder_MotionEventsComponent" Subtype="CatapultProjectile"/>
    <VelocityEvent Speed="20" Threshold="Below" Name="MovingSlow"/>
    <VelocityEvent Speed="20" Threshold="Above" Name="MovingFast"/>
  </Definition>

Each velocity event checks if the speed goes from either above to below a speed, or from below to above a speed, and then fires the event in Name on the object.


MyCraftingComponentBlock

The CraftingComponentBlock component adds crafting functionality to a block that relies on the presence of fuel. This is used for the bonfire and the furnace. See Data/CubeBlocks/Production/Bonfire.sbc for an example.

  <Definition xsi:type="MyObjectBuilder_CraftingComponentQueuedDefinition">
    <Id Type="CraftingComponentQueued" Subtype="BonFire"/>
    <CraftingCategories>
      <Category>Campfire</Category>
      <Category>Meals</Category>
    </CraftingCategories>
    <InputInventory>BonfireInventory</InputInventory>
    <OutputInventory>BonfireInventory</OutputInventory>
    <CraftingInventory>ProcessingInventory</CraftingInventory>
    <ProductionQueueSize>4</ProductionQueueSize>
    <CraftingSpeedMultiplier>1</CraftingSpeedMultiplier>
    <ConstrainInventory>true</ConstrainInventory>
    <PowerRequired>All</PowerRequired>
  </Definition>
CarftingCategories
lists the categories of crafting recipes that can be crafted.
CraftingInventory
references an inventory component of the bonfire that is used for crafting. (Any block can have multiple inventories, this sets which one is used for crafting).
ProductionQueueSize
sets how long can crafting queue get.
CraftingSpeedMultiplier
can modify speed that recipes are being built with. This way you can make faster crafting stations.
ConstrainInventory
set to true will only allow items in its inventory, that are used for crafting by that block, or produced by this block.


For more information about crafting blocks see the crafting guide.

StockpileComponent

The StockpileComponent component adds the ability to display the inventory items in the world on to the entity per subpart points. This component requires the CubeBlockSubpartComponent to be present. Look at Data/CubeBlocks/Storage/WoodenShelf.sbc for an example.

  <Definition xsi:type="MyObjectBuilder_StockpileComponentDefinition">
    <Id Type="MyObjectBuilder_StockpileComponent" Subtype="WoodenShelf" />
    <SubpartNameFormat>Inventory_Slot_{0:00}</SubpartNameFormat>
    <MaxNumberOfSubparts>3</MaxNumberOfSubparts>
  </Definition>

The SubpartNameFormat specifies the numerated subpart names that are used for the system, and MaxNumberOfSubparts specifies the limit of visible subparts to try and assign contents to.


CrankComponent

The CrankComponent simply specifies the sound and angular speed and torque properties of a handcrank object. Look at Data/CubeBlocks/Mechanical/TurnWheel.sbc for an example.

  <Definition xsi:type="MyObjectBuilder_CrankComponentDefinition">
    <Id Type="CrankComponent" Subtype="TurnCrossSmall" />
    <AngularImpulse>25</AngularImpulse>
    <AngularVelocityLimit>4</AngularVelocityLimit>
    <ActionSound>GearWheel</ActionSound>
  </Definition>

AngularImpulse specifies the physical strength of the rotation, AngularVelocityLimit limits the rotation speed and ActionSound specifies the sound played while rotating.


LockableRopeComponent

The LockableRopeComponent specifies the lockable rope drum properties for when you want to make an object that behaves exactly like the lockable rope drum. Look at Data/CubeBlocks/Mechanical/RopeDrum.sbc for an example.

  <Definition xsi:type="MyObjectBuilder_LockableRopeComponentDefinition">
    <Id Type="MyObjectBuilder_LockableRopeComponent" Subtype="LockableDrumSmall" />
    <MinRopeLength>0.7</MinRopeLength>
    <MaxRopeLength>70</MaxRopeLength>
    <DefaultMaxRopeLength>40</DefaultMaxRopeLength>
  </Definition>

MinRopeLength and MaxRopeLength specify how long a rope can be, and DefaultMaxRopeLength specifies the default rope length when the drum is fully unwinded.


TorsionSpringComponent

The TorsionSpringComponent component specifies torsion spring properties. Look at Data/CubeBlocks/Mechanical/TorsionSpring.sbc for an example.

  <Definition xsi:type="MyObjectBuilder_TorsionSpringComponentDefinition">
    <Id Type="MyObjectBuilder_TorsionSpringComponent" Subtype="RopePowerSmallCogWheel1"/>
    <MaxAngularImpulse>800</MaxAngularImpulse>
    <MaxAngle>135</MaxAngle>
    <MaxFrictionTorque>30</MaxFrictionTorque>
  </Definition>

MaxAngularImpulse specifies the maximum strength the block can provide, the MaxAngle is the maximum angle it rotates and MaxFrictionTorque is the maximum torque friction.


New event system

We changed the way the components interact with each other. This system provides a more elegant approach to handling events so that we do not need as many entity components to create specific effects without requiring programming.

Some examples exist in the definitions, for example, the CatapultProjectile, in Data/CubeBlocks/Miscellaneous/Projectiles.sbc. The MotionEvent component generates some events, and the EntityFXComponent listens to these events and plays an effect.

More components will be converted to integrate with this system in the future to allow, for example, the crafting blocks to trigger animations. This way you can see the SpinningWheel spin while it’s being operated, etc.