-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master-MC1.7.10' of github.com:MightyPirates/OpenComput…
…ers into OC1.5-MC1.7.10 Conflicts: build.properties
- Loading branch information
Showing
139 changed files
with
3,115 additions
and
360 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package li.cil.oc.api; | ||
|
||
import li.cil.oc.api.nanomachines.BehaviorProvider; | ||
import li.cil.oc.api.nanomachines.Controller; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
|
||
import java.util.Collections; | ||
|
||
/** | ||
* This API allows interfacing with nanomachines. | ||
* <p/> | ||
* It allows registering custom behavior providers as well as querying for all | ||
* presently registered providers and getting a controller for a player. | ||
*/ | ||
public class Nanomachines { | ||
/** | ||
* Register a new behavior provider. | ||
* <p/> | ||
* When a controller is reconfigured it will draw behaviors from all | ||
* registered providers and build a new random connection graph to | ||
* those behaviors. | ||
* | ||
* @param provider the provider to add. | ||
*/ | ||
public static void addProvider(BehaviorProvider provider) { | ||
if (API.nanomachines != null) | ||
API.nanomachines.addProvider(provider); | ||
} | ||
|
||
/** | ||
* Get a list of all currently registered providers. | ||
* | ||
* @return the list of all currently registered providers. | ||
*/ | ||
public static Iterable<BehaviorProvider> getProviders() { | ||
if (API.nanomachines != null) | ||
return API.nanomachines.getProviders(); | ||
return Collections.emptyList(); | ||
} | ||
|
||
/** | ||
* Check whether a player has a nanomachine controller installed. | ||
* | ||
* @param player the player to check for. | ||
* @return <tt>true</tt> if the player has a controller, <tt>false</tt> otherwise. | ||
*/ | ||
public static boolean hasController(EntityPlayer player) { | ||
if (API.nanomachines != null) | ||
return API.nanomachines.hasController(player); | ||
return false; | ||
} | ||
|
||
/** | ||
* Get the nanomachine controller of the specified player. | ||
* <p/> | ||
* If the player has a controller installed, this will initialize the | ||
* controller if it has not already been loaded. If the player has no | ||
* controller, this will return <tt>null</tt>. | ||
* | ||
* @param player the player to get the controller for. | ||
* @return the controller for the specified player. | ||
*/ | ||
public static Controller getController(EntityPlayer player) { | ||
if (API.nanomachines != null) | ||
return API.nanomachines.getController(player); | ||
return null; | ||
} | ||
|
||
/** | ||
* Install a controller for the specified player if it doesn't already | ||
* have one. | ||
* <p/> | ||
* This will also initialize the controller if it has not already been | ||
* initialized. | ||
* | ||
* @param player the player to install a nanomachine controller for. | ||
*/ | ||
public static Controller installController(EntityPlayer player) { | ||
if (API.nanomachines != null) | ||
return API.nanomachines.installController(player); | ||
return null; | ||
} | ||
|
||
/** | ||
* Uninstall a controller from the specified player if it has one. | ||
* <p/> | ||
* This will disable all active behaviors before disposing the controller. | ||
* | ||
* @param player the player to uninstall a nanomachine controller from. | ||
*/ | ||
public static void uninstallController(EntityPlayer player) { | ||
if (API.nanomachines != null) | ||
API.nanomachines.uninstallController(player); | ||
} | ||
|
||
// ----------------------------------------------------------------------- // | ||
|
||
private Nanomachines() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package li.cil.oc.api.detail; | ||
|
||
import li.cil.oc.api.nanomachines.BehaviorProvider; | ||
import li.cil.oc.api.nanomachines.Controller; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
|
||
public interface NanomachinesAPI { | ||
/** | ||
* Register a new behavior provider. | ||
* <p/> | ||
* When a controller is reconfigured it will draw behaviors from all | ||
* registered providers and build a new random connection graph to | ||
* those behaviors. | ||
* | ||
* @param provider the provider to add. | ||
*/ | ||
void addProvider(BehaviorProvider provider); | ||
|
||
/** | ||
* Get a list of all currently registered providers. | ||
* | ||
* @return the list of all currently registered providers. | ||
*/ | ||
Iterable<BehaviorProvider> getProviders(); | ||
|
||
/** | ||
* Check whether a player has a nanomachine controller installed. | ||
* | ||
* @param player the player to check for. | ||
* @return <tt>true</tt> if the player has a controller, <tt>false</tt> otherwise. | ||
*/ | ||
boolean hasController(EntityPlayer player); | ||
|
||
/** | ||
* Get the nanomachine controller of the specified player. | ||
* <p/> | ||
* If the player has a controller installed, this will initialize the | ||
* controller if it has not already been loaded. If the player has no | ||
* controller, this will return <tt>null</tt>. | ||
* | ||
* @param player the player to get the controller for. | ||
* @return the controller for the specified player. | ||
*/ | ||
Controller getController(EntityPlayer player); | ||
|
||
/** | ||
* Install a controller for the specified player if it doesn't already | ||
* have one. | ||
* <p/> | ||
* This will also initialize the controller if it has not already been | ||
* initialized. | ||
* | ||
* @param player the player to install a nanomachine controller for. | ||
* @return the controller for the specified player. | ||
*/ | ||
Controller installController(EntityPlayer player); | ||
|
||
/** | ||
* Uninstall a controller from the specified player if it has one. | ||
* <p/> | ||
* This will disable all active behaviors before disposing the controller. | ||
* | ||
* @param player the player to uninstall a nanomachine controller from. | ||
*/ | ||
void uninstallController(EntityPlayer player); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package li.cil.oc.api.nanomachines; | ||
|
||
/** | ||
* Implemented by single behaviors. | ||
* <p/> | ||
* If you need a reference to the player this behavior applies to (which you'll | ||
* probably usually want to have), pass it along from {@link BehaviorProvider#createBehaviors}. | ||
*/ | ||
public interface Behavior { | ||
/** | ||
* A short name / description of this behavior. | ||
* <p/> | ||
* You can <em>not</em> use commas (<tt>,</tt>) or double quotes (<tt>"</tt>) | ||
* in the returned string. If you do, they'll automatically be replaced with | ||
* underscores. | ||
* <p/> | ||
* This is entirely optional and may even return <tt>null</tt>. It is made | ||
* accessible via the controller's wireless protocol, to allow better | ||
* automating reconfigurations / determining input mappings. In some cases | ||
* you may not wish to make this possible, in those cases return <tt>null</tt> | ||
* or a random string. | ||
* <p/> | ||
* Again, you can return whatever you like here, it's not used in mod internal | ||
* logic, but only provided to ingame devices as a hint to make configuring | ||
* nanomachines a little easier. | ||
* | ||
* @return the name to provide for this behavior, if any. | ||
*/ | ||
String getNameHint(); | ||
|
||
/** | ||
* Called when this behavior becomes active because all its required inputs | ||
* are now satisfied. | ||
* <p/> | ||
* Use this to initialize permanent effects. | ||
*/ | ||
void onEnable(); | ||
|
||
/** | ||
* Called when this behavior becomes inactive. | ||
* <p/> | ||
* Use this to remove permanent effects. | ||
* | ||
* @param reason the reason the behavior is being disabled. | ||
*/ | ||
void onDisable(DisableReason reason); | ||
|
||
/** | ||
* Called each tick while this behavior is active. | ||
*/ | ||
void update(); | ||
} |
66 changes: 66 additions & 0 deletions
66
src/main/java/li/cil/oc/api/nanomachines/BehaviorProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package li.cil.oc.api.nanomachines; | ||
|
||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.nbt.NBTTagCompound; | ||
|
||
/** | ||
* Implemented by providers for behaviors. | ||
* <p/> | ||
* You may implement one provider for each of your behaviors, or one provider | ||
* for all of your behaviors; it really doesn't matter. This just allows for | ||
* some logical grouping of behaviors, where desired. | ||
* <p/> | ||
* Each behavior provider must be capable or serializing the behaviors it | ||
* creates, and re-create the behavior from its serialized form. It will | ||
* not be given any hints as to whether a provided tag was originally | ||
* produced by it, so you should add a sufficiently unique marker to the | ||
* output NBT to allow identification later on. I recommend generating a | ||
* UUID once, and using that. This is necessary to both save and restore | ||
* neural connection state between saves without breaking the state when | ||
* new behaviors are added, as well as to send states to the client. | ||
*/ | ||
public interface BehaviorProvider { | ||
/** | ||
* Create all behaviors valid for the specified player. | ||
* <p/> | ||
* Note that this is only called on the server side when reconfiguring | ||
* nanomachines. If you have a behavior that actually acts client-only, | ||
* you still need to return it here, as it will be synchronized to the | ||
* client using {@link #writeToNBT} and {@link #readFromNBT}. | ||
* | ||
* @param player the player the behaviors should be created for. | ||
* @return list of new behaviors, may be <tt>null</tt>. | ||
*/ | ||
Iterable<Behavior> createBehaviors(EntityPlayer player); | ||
|
||
/** | ||
* Write a behavior to NBT. | ||
* <p/> | ||
* This will only be called for behaviors originally created by this provider. | ||
* <p/> | ||
* This will only be called on the server. All behaviors not saved will be | ||
* lost when loading again, they will <em>not</em> be regenerated using | ||
* {@link #createBehaviors}, so make sure to save all your behaviors. | ||
* | ||
* @param behavior the behavior to serialize. | ||
* @return the serialized representation of the specified behavior. | ||
*/ | ||
NBTTagCompound writeToNBT(Behavior behavior); | ||
|
||
/** | ||
* Restore a behavior from NBT. | ||
* <p/> | ||
* You are <em>not</em> guaranteed that his nbt belongs to a behavior | ||
* created by this provider! If the NBT cannot be handled, return | ||
* <tt>null</tt>. | ||
* <p/> | ||
* This is called both on the server and the client; on the server it | ||
* is called when restoring a saved player, on the client when | ||
* synchronizing a configuration. | ||
* | ||
* @param player the player the behaviors should be created for. | ||
* @param nbt the tag to restore the behavior from. | ||
* @return the restored behavior, or <tt>null</tt> if unhandled. | ||
*/ | ||
Behavior readFromNBT(EntityPlayer player, NBTTagCompound nbt); | ||
} |
Oops, something went wrong.