Skip to content

Commit

Permalink
Energy based, configurable (and potentially deadly) buff system: nano…
Browse files Browse the repository at this point in the history
…machines!

Also made Grog consumable, closing #410.
  • Loading branch information
fnuecke committed Sep 17, 2015
1 parent 4e4e5d3 commit 8f3a0a5
Show file tree
Hide file tree
Showing 51 changed files with 1,896 additions and 40 deletions.
Binary file modified assets/items.psd
Binary file not shown.
3 changes: 2 additions & 1 deletion src/main/java/li/cil/oc/api/API.java
Expand Up @@ -12,13 +12,14 @@
*/
public class API {
public static final String ID_OWNER = "OpenComputers|Core";
public static final String VERSION = "5.5.4";
public static final String VERSION = "5.5.5";

public static DriverAPI driver = null;
public static FileSystemAPI fileSystem = null;
public static ItemAPI items = null;
public static MachineAPI machine = null;
public static ManualAPI manual = null;
public static NanomachinesAPI nanomachines = null;
public static NetworkAPI network = null;

public static Config config = null;
Expand Down
100 changes: 100 additions & 0 deletions src/main/java/li/cil/oc/api/Nanomachines.java
@@ -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() {
}
}
66 changes: 66 additions & 0 deletions src/main/java/li/cil/oc/api/detail/NanomachinesAPI.java
@@ -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);
}
50 changes: 50 additions & 0 deletions src/main/java/li/cil/oc/api/nanomachines/Behavior.java
@@ -0,0 +1,50 @@
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#createBehavior}.
*/
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.
*/
void onDisable();

/**
* Called each tick while this behavior is active.
*/
void update();
}
66 changes: 66 additions & 0 deletions src/main/java/li/cil/oc/api/nanomachines/BehaviorProvider.java
@@ -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);
}

0 comments on commit 8f3a0a5

Please sign in to comment.