Interface ITurtleUpgrade
- All Superinterfaces:
UpgradeBase
- All Known Implementing Classes:
AbstractTurtleUpgrade
Turtle upgrades are defined in two stages. First, one creates a ITurtleUpgrade
subclass and corresponding
TurtleUpgradeSerialiser
instance, which are then registered in a Forge registry.
You then write a JSON file in your mod's data/ folder. This is then parsed when the world is loaded, and
the upgrade registered internally. See the documentation in TurtleUpgradeSerialiser
for details on this process
and where files should be located.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault IPeripheral
createPeripheral
(ITurtleAccess turtle, TurtleSide side) Will only be called for peripheral upgrades.default net.minecraft.nbt.CompoundTag
getPersistedData
(net.minecraft.nbt.CompoundTag upgradeData) Get upgrade data that should be persisted when the turtle was broken.getType()
Return whether this turtle adds a tool or a peripheral to the turtle.default void
update
(ITurtleAccess turtle, TurtleSide side) Called once per tick for each turtle which has the upgrade equipped.default TurtleCommandResult
useTool
(ITurtleAccess turtle, TurtleSide side, TurtleVerb verb, net.minecraft.core.Direction direction) Will only be called for Tool turtle.Methods inherited from interface dan200.computercraft.api.upgrades.UpgradeBase
getCraftingItem, getUnlocalisedAdjective, getUpgradeData, getUpgradeID, getUpgradeItem, isItemSuitable
-
Method Details
-
getType
TurtleUpgradeType getType()Return whether this turtle adds a tool or a peripheral to the turtle.- Returns:
- The type of upgrade this is.
- See Also:
-
createPeripheral
Will only be called for peripheral upgrades. Creates a peripheral for a turtle being placed using this upgrade.The peripheral created will be stored for the lifetime of the upgrade and will be passed as an argument to
update(ITurtleAccess, TurtleSide)
. It will be attached, detached and have methods called in the same manner as a Computer peripheral.- Parameters:
turtle
- Access to the turtle that the peripheral is being created for.side
- Which side of the turtle (left or right) that the upgrade resides on.- Returns:
- The newly created peripheral. You may return
null
if this upgrade is a Tool and this method is not expected to be called.
-
useTool
default TurtleCommandResult useTool(ITurtleAccess turtle, TurtleSide side, TurtleVerb verb, net.minecraft.core.Direction direction) Will only be called for Tool turtle. Called when turtle.dig() or turtle.attack() is called by the turtle, and the tool is required to do some work.Conforming implementations should fire loader-specific events when using the tool, for instance Forge's
AttackEntityEvent
.- Parameters:
turtle
- Access to the turtle that the tool resides on.side
- Which side of the turtle (left or right) the tool resides on.verb
- Which action (dig or attack) the turtle is being called on to perform.direction
- Which world direction the action should be performed in, relative to the turtles position. This will either be up, down, or the direction the turtle is facing, depending on whether dig, digUp or digDown was called.- Returns:
- Whether the turtle was able to perform the action, and hence whether the
turtle.dig()
orturtle.attack()
lua method should return true. If true is returned, the tool will perform a swinging animation. You may returnnull
if this turtle is a Peripheral and this method is not expected to be called.
-
update
Called once per tick for each turtle which has the upgrade equipped.- Parameters:
turtle
- Access to the turtle that the upgrade resides on.side
- Which side of the turtle (left or right) the upgrade resides on.
-
getPersistedData
default net.minecraft.nbt.CompoundTag getPersistedData(net.minecraft.nbt.CompoundTag upgradeData) Get upgrade data that should be persisted when the turtle was broken.This method should be overridden when you don't need to store all upgrade data by default. For instance, if you store peripheral state in the upgrade data, which should be lost when the turtle is broken.
- Parameters:
upgradeData
- Data that currently stored for this upgrade- Returns:
- Filtered version of this data.
-