public interface SerialInterface
This is used by the serial port module to allow communication with specific blocks where a separate module might be overkill. Used for easier integration with other mods.
A serial interface always acts passively, i.e. it is always called from the serial port module, and never expected to take action autonomously (e.g. from the wrapped block's tile entity's update).
Read and write operations of the serial port module are generally uncoupled, i.e. it not being able to write to the serial interface will not cause it to block and not read from it.
| Modifier and Type | Method and Description |
|---|---|
boolean |
canRead()
Whether the interface can currently be read from.
|
boolean |
canWrite()
Whether the interface can currently be written to.
|
short |
peek()
Called to read the current value from the serial interface.
|
void |
readFromNBT(net.minecraft.nbt.CompoundTag nbt)
Called when a serial port module is created and an earlier interface had
some state to save.
|
void |
reset()
Reset the state of the serial interface.
|
void |
skip()
Called to finish a read from this module.
|
void |
write(short value)
Called to write a single value to the serial interface.
|
void |
writeToNBT(net.minecraft.nbt.CompoundTag nbt)
Called when the serial port module is saved, allows storing state of the
serial interface to be restored using
readFromNBT(CompoundTag). |
boolean canWrite()
If this is true, the serial port module will call write(short)
when it has something to write. If it is false, the serial port module
won't read any values. It is legal to change the returned value between ticks to
cancel an active transfer.
This method is called in each update of the serial port module, which may be multiple times per tick, so this method should be decently efficient and not perform expensive computations.
void write(short value)
This is only called when canWrite() is true, but when
this is the case, this must not fail. If at all, the value shall be
silently dropped.
value - the value written to the serial interface.boolean canRead()
If this is true, the serial port module will call peek()
to begin writing that that value to its ports. Once a write on any port
completes, the serial port module will call skip() to finish
the operation. It is also legal change the returned value between ticks
to cancel an active transfer.
This method is called in each update of the serial port module, which may be multiple times per tick, so this method should be decently efficient and not perform expensive computations.
short peek()
This is only called when canRead() is true, but when
this is the case, this must not fail.
This must not consume the current value. It is legal to change the value returned from this between ticks; the serial port module will notice this and reset any active writes.
void skip()
This is only called when canRead() is true, but when
this is the case, this must not fail.
void reset()
This is called when the TIS-3D computer the serial port module is part of is shut down, either regularly by the controller losing redstone power, or the casing housing the serial port module getting disconnected from its controller. This is also called when the serial port module is removed from its casing.
void writeToNBT(net.minecraft.nbt.CompoundTag nbt)
readFromNBT(CompoundTag).nbt - the tag to write the interface's state to.void readFromNBT(net.minecraft.nbt.CompoundTag nbt)
nbt - the tag to restore the interface's state from.