public abstract class AbstractModule extends java.lang.Object implements Module
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractModule(Casing casing,
Face face) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
cancelRead()
Cancel reading on all ports.
|
protected void |
cancelWrite()
Cancel writing on all ports.
|
Casing |
getCasing()
|
Face |
getFace()
|
protected net.minecraft.util.Vec3 |
getPlayerLookAt()
Utility method for determining the hit coordinate on the module's face the player is
looking at.
|
protected net.minecraft.util.Vec3 |
hitToUV(net.minecraft.util.Vec3 hitPos)
Project a hit position on the surface of a casing to a UV coordinate on
the face of this module.
|
protected boolean |
isPlayerLookingAt()
Utility method for determining whether the player is currently looking at this module.
|
protected boolean |
isVisible()
Convenience check for determining whether a module is actually visible.
|
boolean |
onActivate(net.minecraft.entity.player.EntityPlayer player,
float hitX,
float hitY,
float hitZ)
Called when a player right-clicks the module while installed in a casing.
|
void |
onData(io.netty.buffer.ByteBuf data)
Called with data sent from the remote instance of the module.
|
void |
onData(net.minecraft.nbt.NBTTagCompound nbt)
Called with NBT data sent from the remote instance of the module.
|
void |
onDisabled()
Called when the multi-block of casings the module is installed in is
disabled, or when the module was removed from an enabled casing.
|
void |
onDisposed()
Called when the
Casing housing the module is being disposed,
e.g. |
void |
onEnabled()
Called when the multi-block of casings the module is installed in is
enabled, or when the module was installed into an enabled casing.
|
void |
onInstalled(net.minecraft.item.ItemStack stack)
Called when the module is being installed into a
Casing. |
void |
onUninstalled(net.minecraft.item.ItemStack stack)
Called after the module was uninstalled from a
Casing. |
void |
onWriteComplete(Port port)
Called from a pipe this module is writing to when the data was read.
|
void |
readFromNBT(net.minecraft.nbt.NBTTagCompound nbt)
Restore the state of the module from the specified NBT compound.
|
void |
render(boolean enabled,
float partialTicks)
Called to allow the module to render dynamic content on the casing it
is installed in.
|
void |
step()
Advance the state of the module.
|
void |
writeToNBT(net.minecraft.nbt.NBTTagCompound nbt)
Save the state of the module to the specified NBT compound.
|
protected void cancelWrite()
protected void cancelRead()
protected boolean isPlayerLookingAt()
protected net.minecraft.util.Vec3 getPlayerLookAt()
Note that this will return the unadjusted X, Y and Z components. To transform this
coordinate to a UV coordinate mapped to the module's face, pass this into
hitToUV(net.minecraft.util.Vec3). Note that this method is overridden in AbstractModuleRotatable
to also take into account the module's rotation.
protected net.minecraft.util.Vec3 hitToUV(net.minecraft.util.Vec3 hitPos)
Note that this is also overridden in AbstractModuleRotatable to
take into account the module's rotation.
hitPos - the hit position to project.getPlayerLookAt(),
onActivate(EntityPlayer, float, float, float)protected boolean isVisible()
This can allow for some optimizations, such as sending state updates much more or infrequently (or not at all) while invisible. If rendering a module's overlay is exceptionally complex,
public void step()
ModuleThis is called by the controller of the system the module is part of each tick the system is running.
public void onInstalled(net.minecraft.item.ItemStack stack)
ModuleCasing.
This is mainly for convenience and having things in one place, you could
just as well restore state in your ModuleProvider's
ModuleProvider.createModule(ItemStack, Casing, Face) method.
This is called before the first Module.onEnabled(), and also before
it is actually set in the containing Casing. Particularly
this means Casing.getModule(Face) for the module's Face
will return null in this callback.
Note that this is only called on the server.
onInstalled in interface Modulestack - the item stack the module was created from.public void onUninstalled(net.minecraft.item.ItemStack stack)
ModuleCasing.
This allows storing any data that should be persisted onto the module's item representation. For most modules this will not apply, since they are generally stateless / reset state when the computer shuts down.
This is called after the last Module.onDisabled() and is equivalent
to a dispose method (i.e. the module will not be used again
after this).
Note that this is only called on the server.
onUninstalled in interface Modulestack - the stack representing the module.public void onEnabled()
ModuleNote that this is only called on the server.
public void onDisabled()
ModuleModules should use this to reset their state, so that cycling power of a controller resets the whole multi-block system.
Note that this is only called on the server.
onDisabled in interface Modulepublic void onDisposed()
ModuleCasing housing the module is being disposed,
e.g. due to a chunk being unloaded.
This is intended for freeing up resources (e.g. allocated texture or
audio memory). Unlike Module.onDisabled() this is only called once
on a module, at the very end of its life. Avoid world interaction in
this callback to avoid loading the chunk again.
This is called on the server and the client.
onDisposed in interface Modulepublic void onWriteComplete(Port port)
ModuleThis allows completing the operation in the same tick in which the read operation was completed. This is particularly useful when writing to multiple ports at a time but the written value may only be read once; in this case the remaining writes can be canceled in this callback.
onWriteComplete in interface Moduleport - the port on which the write operation was completed.public boolean onActivate(net.minecraft.entity.player.EntityPlayer player,
float hitX,
float hitY,
float hitZ)
ModuleThe face is implicitly given by the face the module is installed in, as is the world via the casing's world.
Note that there should be some way in which a click can be ignored, e.g. by a player sneaking, otherwise the module cannot be removed from the casing by hand.
onActivate in interface Moduleplayer - the player that clicked the module.hitX - the relative x position that was clicked.hitY - the relative y position that was clicked.hitZ - the relative z position that was clicked.public void onData(net.minecraft.nbt.NBTTagCompound nbt)
ModuleThis can be called on both the server and the client, depending on which side sent the message (i.e. the client can send messages to the server this way and vice versa).
onData in interface Modulenbt - the received data.Casing.sendData(Face, NBTTagCompound, byte),
Casing.sendData(Face, NBTTagCompound)public void onData(io.netty.buffer.ByteBuf data)
ModuleThis can be called on both the server and the client, depending on which side sent the message (i.e. the client can send messages to the server this way and vice versa).
onData in interface Moduledata - the received data.Casing.sendData(Face, ByteBuf, byte),
Casing.sendData(Face, ByteBuf)public void render(boolean enabled,
float partialTicks)
ModuleThe render state will be adjusted to take into account the face the module is installed in, i.e. rendering from (0, 0, 0) to (1, 1, 0) will render the full quad of face of the casing the module is installed in.
public void readFromNBT(net.minecraft.nbt.NBTTagCompound nbt)
ModulereadFromNBT in interface Modulenbt - the tag to load the state from.public void writeToNBT(net.minecraft.nbt.NBTTagCompound nbt)
ModulewriteToNBT in interface Modulenbt - the tag to save the state to.