Started reworking API for 1.5.

This commit is contained in:
Florian Nücke 2015-02-03 16:59:04 +01:00
parent 806dda8827
commit 298d97639e
38 changed files with 184 additions and 211 deletions

View File

@ -1,6 +1,10 @@
package li.cil.oc.api;
import li.cil.oc.api.detail.*;
import li.cil.oc.api.detail.DriverAPI;
import li.cil.oc.api.detail.FileSystemAPI;
import li.cil.oc.api.detail.ItemAPI;
import li.cil.oc.api.detail.MachineAPI;
import li.cil.oc.api.detail.NetworkAPI;
/**
* Central reference for the API.
@ -11,7 +15,7 @@ import li.cil.oc.api.detail.*;
*/
public class API {
public static final String ID_OWNER = "OpenComputers|Core";
public static final String VERSION = "4.2.4";
public static final String VERSION = "5.0.0-alpha";
public static DriverAPI driver = null;
public static FileSystemAPI fileSystem = null;

View File

@ -1,7 +1,11 @@
package li.cil.oc.api;
import li.cil.oc.api.detail.Builder;
import li.cil.oc.api.network.*;
import li.cil.oc.api.network.Environment;
import li.cil.oc.api.network.Node;
import li.cil.oc.api.network.Packet;
import li.cil.oc.api.network.Visibility;
import li.cil.oc.api.network.WirelessEndpoint;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;

View File

@ -357,8 +357,8 @@ public interface TextBuffer extends ManagedEnvironment, Persistable {
* values.
*
* @param column the horizontal index.
* @param row the vertical index.
* @param text the text to write.
* @param row the vertical index.
* @param text the text to write.
*/
void rawSetText(int column, int row, char[][] text);
@ -379,8 +379,8 @@ public interface TextBuffer extends ManagedEnvironment, Persistable {
* values.
*
* @param column the horizontal index.
* @param row the vertical index.
* @param color the foreground color data to write.
* @param row the vertical index.
* @param color the foreground color data to write.
*/
void rawSetForeground(int column, int row, int[][] color);
@ -401,8 +401,8 @@ public interface TextBuffer extends ManagedEnvironment, Persistable {
* values.
*
* @param column the horizontal index.
* @param row the vertical index.
* @param color the background color data to write.
* @param row the vertical index.
* @param color the background color data to write.
*/
void rawSetBackground(int column, int row, int[][] color);
@ -558,24 +558,6 @@ public interface TextBuffer extends ManagedEnvironment, Persistable {
*/
void mouseScroll(double x, double y, int delta, EntityPlayer player);
// TODO Remove deprecated overloads in 1.5.
/** @deprecated Use the floating-point variant instead. */
@Deprecated
void mouseDown(int x, int y, int button, EntityPlayer player);
/** @deprecated Use the floating-point variant instead. */
@Deprecated
void mouseDrag(int x, int y, int button, EntityPlayer player);
/** @deprecated Use the floating-point variant instead. */
@Deprecated
void mouseUp(int x, int y, int button, EntityPlayer player);
/** @deprecated Use the floating-point variant instead. */
@Deprecated
void mouseScroll(int x, int y, int delta, EntityPlayer player);
// ----------------------------------------------------------------------- //
/**

View File

@ -1,6 +1,10 @@
package li.cil.oc.api.detail;
import li.cil.oc.api.network.*;
import li.cil.oc.api.network.Component;
import li.cil.oc.api.network.ComponentConnector;
import li.cil.oc.api.network.Connector;
import li.cil.oc.api.network.Node;
import li.cil.oc.api.network.Visibility;
/**
* Used for building {@link Node}s via {@link li.cil.oc.api.Network#newNode}.

View File

@ -1,6 +1,10 @@
package li.cil.oc.api.detail;
import li.cil.oc.api.network.*;
import li.cil.oc.api.network.Environment;
import li.cil.oc.api.network.Node;
import li.cil.oc.api.network.Packet;
import li.cil.oc.api.network.Visibility;
import li.cil.oc.api.network.WirelessEndpoint;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;

View File

@ -1,6 +1,6 @@
package li.cil.oc.api.event;
import li.cil.oc.api.internal.Robot;
import li.cil.oc.api.internal.Agent;
import net.minecraft.entity.player.EntityPlayer;
/**
@ -14,8 +14,8 @@ public class RobotAnalyzeEvent extends RobotEvent {
*/
public final EntityPlayer player;
public RobotAnalyzeEvent(Robot robot, EntityPlayer player) {
super(robot);
public RobotAnalyzeEvent(Agent agent, EntityPlayer player) {
super(agent);
this.player = player;
}
}

View File

@ -1,7 +1,7 @@
package li.cil.oc.api.event;
import cpw.mods.fml.common.eventhandler.Cancelable;
import li.cil.oc.api.internal.Robot;
import li.cil.oc.api.internal.Agent;
import net.minecraft.entity.Entity;
public class RobotAttackEntityEvent extends RobotEvent {
@ -10,8 +10,8 @@ public class RobotAttackEntityEvent extends RobotEvent {
*/
public final Entity target;
protected RobotAttackEntityEvent(Robot robot, Entity target) {
super(robot);
protected RobotAttackEntityEvent(Agent agent, Entity target) {
super(agent);
this.target = target;
}
@ -22,8 +22,8 @@ public class RobotAttackEntityEvent extends RobotEvent {
*/
@Cancelable
public static class Pre extends RobotAttackEntityEvent {
public Pre(Robot robot, Entity target) {
super(robot, target);
public Pre(Agent agent, Entity target) {
super(agent, target);
}
}
@ -31,8 +31,8 @@ public class RobotAttackEntityEvent extends RobotEvent {
* Fired after a robot has attacked an entity.
*/
public static class Post extends RobotAttackEntityEvent {
public Post(Robot robot, Entity target) {
super(robot, target);
public Post(Agent agent, Entity target) {
super(agent, target);
}
}
}

View File

@ -1,12 +1,12 @@
package li.cil.oc.api.event;
import cpw.mods.fml.common.eventhandler.Cancelable;
import li.cil.oc.api.internal.Robot;
import li.cil.oc.api.internal.Agent;
import net.minecraft.world.World;
public abstract class RobotBreakBlockEvent extends RobotEvent {
protected RobotBreakBlockEvent(Robot robot) {
super(robot);
protected RobotBreakBlockEvent(Agent agent) {
super(agent);
}
/**
@ -31,8 +31,8 @@ public abstract class RobotBreakBlockEvent extends RobotEvent {
*/
private double breakTime;
public Pre(Robot robot, World world, int x, int y, int z, double breakTime) {
super(robot);
public Pre(Agent agent, World world, int x, int y, int z, double breakTime) {
super(agent);
this.world = world;
this.x = x;
this.y = y;
@ -71,8 +71,8 @@ public abstract class RobotBreakBlockEvent extends RobotEvent {
*/
public final double experience;
public Post(Robot robot, double experience) {
super(robot);
public Post(Agent agent, double experience) {
super(agent);
this.experience = experience;
}
}

View File

@ -1,7 +1,7 @@
package li.cil.oc.api.event;
import cpw.mods.fml.common.eventhandler.Event;
import li.cil.oc.api.internal.Robot;
import li.cil.oc.api.internal.Agent;
/**
* Base class for events generated by robots.
@ -10,9 +10,9 @@ public abstract class RobotEvent extends Event {
/**
* The robot for which this event was fired.
*/
public final Robot robot;
public final Agent agent;
protected RobotEvent(Robot robot) {
this.robot = robot;
protected RobotEvent(Agent agent) {
this.agent = agent;
}
}

View File

@ -1,6 +1,6 @@
package li.cil.oc.api.event;
import li.cil.oc.api.internal.Robot;
import li.cil.oc.api.internal.Agent;
/**
* Fired when a robot performed an action that would cause exhaustion for a
@ -12,8 +12,8 @@ public class RobotExhaustionEvent extends RobotEvent {
*/
public final double exhaustion;
public RobotExhaustionEvent(Robot robot, double exhaustion) {
super(robot);
public RobotExhaustionEvent(Agent agent, double exhaustion) {
super(agent);
this.exhaustion = exhaustion;
}
}

View File

@ -1,7 +1,7 @@
package li.cil.oc.api.event;
import cpw.mods.fml.common.eventhandler.Cancelable;
import li.cil.oc.api.internal.Robot;
import li.cil.oc.api.internal.Agent;
import net.minecraftforge.common.util.ForgeDirection;
public abstract class RobotMoveEvent extends RobotEvent {
@ -10,8 +10,8 @@ public abstract class RobotMoveEvent extends RobotEvent {
*/
public final ForgeDirection direction;
protected RobotMoveEvent(Robot robot, ForgeDirection direction) {
super(robot);
protected RobotMoveEvent(Agent agent, ForgeDirection direction) {
super(agent);
this.direction = direction;
}
@ -22,8 +22,8 @@ public abstract class RobotMoveEvent extends RobotEvent {
*/
@Cancelable
public static class Pre extends RobotMoveEvent {
public Pre(Robot robot, ForgeDirection direction) {
super(robot, direction);
public Pre(Agent agent, ForgeDirection direction) {
super(agent, direction);
}
}
@ -31,8 +31,8 @@ public abstract class RobotMoveEvent extends RobotEvent {
* Fired after a robot moved.
*/
public static class Post extends RobotMoveEvent {
public Post(Robot robot, ForgeDirection direction) {
super(robot, direction);
public Post(Agent agent, ForgeDirection direction) {
super(agent, direction);
}
}
}

View File

@ -1,7 +1,7 @@
package li.cil.oc.api.event;
import cpw.mods.fml.common.eventhandler.Cancelable;
import li.cil.oc.api.internal.Robot;
import li.cil.oc.api.internal.Agent;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
@ -21,8 +21,8 @@ public abstract class RobotPlaceBlockEvent extends RobotEvent {
*/
public final int x, y, z;
protected RobotPlaceBlockEvent(Robot robot, ItemStack stack, World world, int x, int y, int z) {
super(robot);
protected RobotPlaceBlockEvent(Agent agent, ItemStack stack, World world, int x, int y, int z) {
super(agent);
this.stack = stack;
this.world = world;
this.x = x;
@ -37,8 +37,8 @@ public abstract class RobotPlaceBlockEvent extends RobotEvent {
*/
@Cancelable
public static class Pre extends RobotPlaceBlockEvent {
public Pre(Robot robot, ItemStack stack, World world, int x, int y, int z) {
super(robot, stack, world, x, y, z);
public Pre(Agent agent, ItemStack stack, World world, int x, int y, int z) {
super(agent, stack, world, x, y, z);
}
}
@ -46,8 +46,8 @@ public abstract class RobotPlaceBlockEvent extends RobotEvent {
* Fired after a robot placed a block.
*/
public static class Post extends RobotPlaceBlockEvent {
public Post(Robot robot, ItemStack stack, World world, int x, int y, int z) {
super(robot, stack, world, x, y, z);
public Post(Agent agent, ItemStack stack, World world, int x, int y, int z) {
super(agent, stack, world, x, y, z);
}
}
}

View File

@ -1,6 +1,6 @@
package li.cil.oc.api.event;
import li.cil.oc.api.internal.Robot;
import li.cil.oc.api.internal.Agent;
/**
* This event is fired when a robot tries to place a block and has no point of
@ -13,8 +13,8 @@ import li.cil.oc.api.internal.Robot;
public class RobotPlaceInAirEvent extends RobotEvent {
private boolean isAllowed = false;
public RobotPlaceInAirEvent(Robot robot) {
super(robot);
public RobotPlaceInAirEvent(Agent agent) {
super(agent);
}
/**

View File

@ -1,7 +1,7 @@
package li.cil.oc.api.event;
import cpw.mods.fml.common.eventhandler.Cancelable;
import li.cil.oc.api.internal.Robot;
import li.cil.oc.api.internal.Agent;
import org.lwjgl.util.vector.Vector3f;
import org.lwjgl.util.vector.Vector4f;
@ -29,8 +29,8 @@ public class RobotRenderEvent extends RobotEvent {
*/
public final MountPoint[] mountPoints;
public RobotRenderEvent(Robot robot, MountPoint[] mountPoints) {
super(robot);
public RobotRenderEvent(Agent agent, MountPoint[] mountPoints) {
super(agent);
this.mountPoints = mountPoints;
}

View File

@ -1,6 +1,6 @@
package li.cil.oc.api.event;
import li.cil.oc.api.internal.Robot;
import li.cil.oc.api.internal.Agent;
import net.minecraft.item.ItemStack;
public class RobotUsedToolEvent extends RobotEvent {
@ -11,8 +11,8 @@ public class RobotUsedToolEvent extends RobotEvent {
protected double damageRate;
protected RobotUsedToolEvent(Robot robot, ItemStack toolBeforeUse, ItemStack toolAfterUse, double damageRate) {
super(robot);
protected RobotUsedToolEvent(Agent agent, ItemStack toolBeforeUse, ItemStack toolAfterUse, double damageRate) {
super(agent);
this.toolBeforeUse = toolBeforeUse;
this.toolAfterUse = toolAfterUse;
this.damageRate = damageRate;
@ -36,8 +36,8 @@ public class RobotUsedToolEvent extends RobotEvent {
* experience upgrade, for example.
*/
public static class ComputeDamageRate extends RobotUsedToolEvent {
public ComputeDamageRate(Robot robot, ItemStack toolBeforeUse, ItemStack toolAfterUse, double damageRate) {
super(robot, toolBeforeUse, toolAfterUse, damageRate);
public ComputeDamageRate(Agent agent, ItemStack toolBeforeUse, ItemStack toolAfterUse, double damageRate) {
super(agent, toolBeforeUse, toolAfterUse, damageRate);
}
/**
@ -63,8 +63,8 @@ public class RobotUsedToolEvent extends RobotEvent {
* durability is stored in the item's NBT tag.
*/
public static class ApplyDamageRate extends RobotUsedToolEvent {
public ApplyDamageRate(Robot robot, ItemStack toolBeforeUse, ItemStack toolAfterUse, double damageRate) {
super(robot, toolBeforeUse, toolAfterUse, damageRate);
public ApplyDamageRate(Agent agent, ItemStack toolBeforeUse, ItemStack toolAfterUse, double damageRate) {
super(agent, toolBeforeUse, toolAfterUse, damageRate);
}
}
}

View File

@ -0,0 +1,22 @@
package li.cil.oc.api.internal;
import net.minecraft.entity.player.EntityPlayer;
/**
* General marker interface for autonomous agents such as robots and drones.
*/
public interface Agent {
/**
* Returns the fake player used to represent the agent as an entity for
* certain actions that require one.
* <p/>
* This will automatically be positioned and rotated to represent the
* agent's current position and rotation in the world. Use this to trigger
* events involving the agent that require a player entity.
* <p/>
* Note that this <em>may</em> be the common OpenComputers fake player.
*
* @return the fake player for the agent.
*/
EntityPlayer player();
}

View File

@ -18,7 +18,7 @@ import net.minecraft.util.Vec3;
* i.e. without having to link against internal classes. This also means
* that <em>you should not implement this</em>.
*/
public interface Drone extends EnvironmentHost, Rotatable, Tiered {
public interface Drone extends Agent, EnvironmentHost, Rotatable, Tiered {
/**
* The machine currently hosted by this drone.
*/

View File

@ -31,25 +31,12 @@ import net.minecraftforge.fluids.IFluidTank;
* <p/>
* This interface is <em>not meant to be implemented</em>, just used.
*/
public interface Robot extends Environment, EnvironmentHost, Rotatable, Tiered, ISidedInventory, IFluidHandler {
public interface Robot extends Agent, Environment, EnvironmentHost, Rotatable, Tiered, ISidedInventory, IFluidHandler {
/**
* The machine currently hosted by this robot.
*/
Machine machine();
/**
* Returns the fake player used to represent the robot as an entity for
* certain actions that require one.
* <p/>
* This will automatically be positioned and rotated to represent the
* robot's current position and rotation in the world. Use this to trigger
* events involving the robot that require a player entity, and for more
* in-depth interaction with the robots' inventory.
*
* @return the fake player for the robot.
*/
EntityPlayer player();
/**
* The number of hot-swappable component slots in this robot.
* <p/>

View File

@ -20,7 +20,7 @@ import li.cil.oc.api.machine.Machine;
* via the API, i.e. without having to link against internal classes. This
* also means that <em>you should not implement this</em>.
*/
public interface Server extends EnvironmentHost {
public interface Server extends EnvironmentHost, Tiered {
/**
* The machine currently hosted by this server.
*/
@ -35,9 +35,4 @@ public interface Server extends EnvironmentHost {
* The slot of the server rack this server is in.
*/
int slot();
/**
* The tier of the server.
*/
int tier();
}

View File

@ -72,16 +72,6 @@ public interface MachineHost extends EnvironmentHost {
*/
int componentSlot(String address);
/**
* This is called by the machine when its state changed (which can be
* multiple times per actual game tick), to notify the owner that it should
* save its state on the next world save.
* <p/>
* This method is called from executor threads, so it must be thread-safe.
*/
// TODO Merge with {@link EnvironmentHost#markChanged} in 1.5
void markForSaving();
/**
* This is called on the owner when the machine's {@link Environment#onConnect(Node)}
* method gets called. This can be useful for reacting to network events

View File

@ -37,11 +37,11 @@ public interface WirelessEndpoint {
/**
* Makes the endpoint receive a single packet.
*
* @param packet the packet to receive.
* @param sender the endpoint that sent the message. This is not
* necessarily the original sender of the packet, just
* the last point it went through, such as an access
* point, for example.
* @param packet the packet to receive.
* @param sender the endpoint that sent the message. This is not
* necessarily the original sender of the packet, just
* the last point it went through, such as an access
* point, for example.
*/
void receivePacket(Packet packet, WirelessEndpoint sender);
}

View File

@ -6,6 +6,7 @@ import li.cil.oc.api.network.Message;
import li.cil.oc.api.network.Node;
import li.cil.oc.api.network.Visibility;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.gui.IUpdatePlayerListBox;
import net.minecraft.tileentity.TileEntity;
/**
@ -17,7 +18,7 @@ import net.minecraft.tileentity.TileEntity;
* network as an index structure to find other nodes connected to them.
*/
@SuppressWarnings("UnusedDeclaration")
public abstract class TileEntityEnvironment extends TileEntity implements Environment {
public abstract class TileEntityEnvironment extends TileEntity implements Environment, IUpdatePlayerListBox {
/**
* This must be set in subclasses to the node that is used to represent
* this tile entity.
@ -96,8 +97,7 @@ public abstract class TileEntityEnvironment extends TileEntity implements Enviro
// ----------------------------------------------------------------------- //
@Override
public void updateEntity() {
super.updateEntity();
public void update() {
// On the first update, try to add our node to nearby networks. We do
// this in the update logic, not in validate() because we need to access
// neighboring tile entities, which isn't possible in validate().

View File

@ -415,20 +415,6 @@ class TextBuffer(val host: EnvironmentHost) extends prefab.ManagedEnvironment wi
override def mouseScroll(x: Double, y: Double, delta: Int, player: EntityPlayer) =
proxy.mouseScroll(x, y, delta, player)
// TODO Remove in 1.5
override def mouseDown(x: Int, y: Int, button: Int, player: EntityPlayer) =
mouseDown(x, y, button, player)
override def mouseDrag(x: Int, y: Int, button: Int, player: EntityPlayer) =
mouseDrag(x, y, button, player)
override def mouseUp(x: Int, y: Int, button: Int, player: EntityPlayer) =
mouseUp(x, y, button, player)
override def mouseScroll(x: Int, y: Int, delta: Int, player: EntityPlayer) =
mouseScroll(x, y, delta, player)
def copyToAnalyzer(line: Int, player: EntityPlayer): Unit = {
proxy.copyToAnalyzer(line, player)
}

View File

@ -34,6 +34,8 @@ import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.util.Vec3
import net.minecraft.world.World
import net.minecraft.world.WorldServer
import net.minecraftforge.common.util.FakePlayerFactory
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids.IFluidTank
@ -117,6 +119,8 @@ class Drone(val world: World) extends Entity(world) with MachineHost with intern
override def tier = info.tier
override def player(): EntityPlayer = FakePlayerFactory.get(world.asInstanceOf[WorldServer], Settings.get.fakePlayerProfile)
// ----------------------------------------------------------------------- //
// Forward context stuff to our machine. Interface needed for some components
// to work correctly (such as the chunkloader upgrade).
@ -213,8 +217,6 @@ class Drone(val world: World) extends Entity(world) with MachineHost with intern
override def componentSlot(address: String) = -1 // TODO
override def markForSaving() {}
override def onMachineConnect(node: Node) {}
override def onMachineDisconnect(node: Node) {}

View File

@ -7,8 +7,9 @@ import li.cil.oc.api.event.RobotPlaceInAirEvent
object AngelUpgradeHandler {
@SubscribeEvent
def onPlaceInAir(e: RobotPlaceInAirEvent) {
val startComponents = 1 + e.robot.containerCount + e.robot.inventorySize
e.setAllowed(((1 to e.robot.containerCount) ++ (startComponents until startComponents + e.robot.componentCount)).
exists(slot => api.Items.get(e.robot.getStackInSlot(slot)) == api.Items.get("angelUpgrade")))
// TODO Generalize Agent interface for access to their components.
// val startComponents = 1 + e.robot.containerCount + e.robot.inventorySize
// e.setAllowed(((1 to e.robot.containerCount) ++ (startComponents until startComponents + e.robot.componentCount)).
// exists(slot => api.Items.get(e.robot.getStackInSlot(slot)) == api.Items.get("angelUpgrade")))
}
}

View File

@ -55,12 +55,13 @@ object ChunkloaderUpgradeHandler extends LoadingCallback {
@SubscribeEvent
def onMove(e: RobotMoveEvent.Post) {
for (slot <- 0 until e.robot.getSizeInventory) {
e.robot.getComponentInSlot(slot) match {
case loader: UpgradeChunkloader => updateLoadedChunk(loader)
case _ =>
}
}
// TODO Generalize Agent interface for access to their components.
// for (slot <- 0 until e.robot.getSizeInventory) {
// e.robot.getComponentInSlot(slot) match {
// case loader: UpgradeChunkloader => updateLoadedChunk(loader)
// case _ =>
// }
// }
}
def updateLoadedChunk(loader: UpgradeChunkloader) {

View File

@ -4,6 +4,7 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent
import li.cil.oc.Localization
import li.cil.oc.Settings
import li.cil.oc.api.event._
import li.cil.oc.api.internal.Agent
import li.cil.oc.api.internal.Robot
import li.cil.oc.server.component
import org.lwjgl.opengl.GL11
@ -11,7 +12,7 @@ import org.lwjgl.opengl.GL11
object ExperienceUpgradeHandler {
@SubscribeEvent
def onRobotAnalyze(e: RobotAnalyzeEvent) {
val (level, experience) = getLevelAndExperience(e.robot)
val (level, experience) = getLevelAndExperience(e.agent)
// This is basically a 'does it have an experience upgrade' check.
if (experience != 0.0) {
e.player.addChatMessage(Localization.Analyzer.RobotXp(experience, level))
@ -20,45 +21,46 @@ object ExperienceUpgradeHandler {
@SubscribeEvent
def onRobotComputeDamageRate(e: RobotUsedToolEvent.ComputeDamageRate) {
e.setDamageRate(e.getDamageRate * math.max(0, 1 - getLevel(e.robot) * Settings.get.toolEfficiencyPerLevel))
e.setDamageRate(e.getDamageRate * math.max(0, 1 - getLevel(e.agent) * Settings.get.toolEfficiencyPerLevel))
}
@SubscribeEvent
def onRobotBreakBlockPre(e: RobotBreakBlockEvent.Pre) {
val boost = math.max(0, 1 - getLevel(e.robot) * Settings.get.harvestSpeedBoostPerLevel)
val boost = math.max(0, 1 - getLevel(e.agent) * Settings.get.harvestSpeedBoostPerLevel)
e.setBreakTime(e.getBreakTime * boost)
}
@SubscribeEvent
def onRobotAttackEntityPost(e: RobotAttackEntityEvent.Post) {
if (e.robot.getComponentInSlot(e.robot.selectedSlot()) != null && e.target.isDead) {
addExperience(e.robot, Settings.get.robotActionXp)
}
// TODO Generalize Agent interface for access to their components.
// if (e.robot.getComponentInSlot(e.robot.selectedSlot()) != null && e.target.isDead) {
// addExperience(e.robot, Settings.get.robotActionXp)
// }
}
@SubscribeEvent
def onRobotBreakBlockPost(e: RobotBreakBlockEvent.Post) {
addExperience(e.robot, e.experience * Settings.get.robotOreXpRate + Settings.get.robotActionXp)
addExperience(e.agent, e.experience * Settings.get.robotOreXpRate + Settings.get.robotActionXp)
}
@SubscribeEvent
def onRobotPlaceBlockPost(e: RobotPlaceBlockEvent.Post) {
addExperience(e.robot, Settings.get.robotActionXp)
addExperience(e.agent, Settings.get.robotActionXp)
}
@SubscribeEvent
def onRobotMovePost(e: RobotMoveEvent.Post) {
addExperience(e.robot, Settings.get.robotExhaustionXpRate * 0.01)
addExperience(e.agent, Settings.get.robotExhaustionXpRate * 0.01)
}
@SubscribeEvent
def onRobotExhaustion(e: RobotExhaustionEvent) {
addExperience(e.robot, Settings.get.robotExhaustionXpRate * e.exhaustion)
addExperience(e.agent, Settings.get.robotExhaustionXpRate * e.exhaustion)
}
@SubscribeEvent
def onRobotRender(e: RobotRenderEvent) {
val level = if (e.robot != null) getLevel(e.robot) else 0
val level = if (e.agent != null) getLevel(e.agent) else 0
if (level > 19) {
GL11.glColor3f(0.4f, 1, 1)
}
@ -70,39 +72,42 @@ object ExperienceUpgradeHandler {
}
}
private def getLevel(robot: Robot) = {
private def getLevel(agent: Agent) = {
var level = 0
for (index <- 0 until robot.getSizeInventory) {
robot.getComponentInSlot(index) match {
case upgrade: component.UpgradeExperience =>
level += upgrade.level
case _ =>
}
}
// TODO Generalize Agent interface for access to their components.
// for (index <- 0 until agent.getSizeInventory) {
// agent.getComponentInSlot(index) match {
// case upgrade: component.UpgradeExperience =>
// level += upgrade.level
// case _ =>
// }
// }
level
}
private def getLevelAndExperience(robot: Robot) = {
private def getLevelAndExperience(agent: Agent) = {
var level = 0
var experience = 0.0
for (index <- 0 until robot.getSizeInventory) {
robot.getComponentInSlot(index) match {
case upgrade: component.UpgradeExperience =>
level += upgrade.level
experience += upgrade.experience
case _ =>
}
}
// TODO Generalize Agent interface for access to their components.
// for (index <- 0 until agent.getSizeInventory) {
// agent.getComponentInSlot(index) match {
// case upgrade: component.UpgradeExperience =>
// level += upgrade.level
// experience += upgrade.experience
// case _ =>
// }
// }
(level, experience)
}
private def addExperience(robot: Robot, amount: Double) {
for (index <- 0 until robot.getSizeInventory) {
robot.getComponentInSlot(index) match {
case upgrade: component.UpgradeExperience =>
upgrade.addExperience(amount)
case _ =>
}
}
private def addExperience(agent: Agent, amount: Double) {
// TODO Generalize Agent interface for access to their components.
// for (index <- 0 until agent.getSizeInventory) {
// agent.getComponentInSlot(index) match {
// case upgrade: component.UpgradeExperience =>
// upgrade.addExperience(amount)
// case _ =>
// }
// }
}
}

View File

@ -10,7 +10,7 @@ object RobotCommonHandler {
val damage = e.toolAfterUse.getItemDamage - e.toolBeforeUse.getItemDamage
if (damage > 0) {
val actualDamage = damage * e.getDamageRate
val repairedDamage = if (e.robot.player.getRNG.nextDouble() > 0.5) damage - math.floor(actualDamage).toInt else damage - math.ceil(actualDamage).toInt
val repairedDamage = if (e.agent.player.getRNG.nextDouble() > 0.5) damage - math.floor(actualDamage).toInt else damage - math.ceil(actualDamage).toInt
e.toolAfterUse.setItemDamage(e.toolAfterUse.getItemDamage - repairedDamage)
}
}

View File

@ -8,12 +8,13 @@ import li.cil.oc.server.component.WirelessNetworkCard
object WirelessNetworkCardHandler {
@SubscribeEvent
def onMove(e: RobotMoveEvent.Post) {
val startComponents = 1 + e.robot.containerCount + e.robot.inventorySize
for (slot <- (1 to e.robot.containerCount) ++ (startComponents until startComponents + e.robot.componentCount)) {
e.robot.getComponentInSlot(slot) match {
case card: WirelessNetworkCard => api.Network.updateWirelessNetwork(card)
case _ =>
}
}
// TODO Generalize Agent interface for access to their components.
// val startComponents = 1 + e.robot.containerCount + e.robot.inventorySize
// for (slot <- (1 to e.robot.containerCount) ++ (startComponents until startComponents + e.robot.componentCount)) {
// e.robot.getComponentInSlot(slot) match {
// case card: WirelessNetworkCard => api.Network.updateWirelessNetwork(card)
// case _ =>
// }
// }
}
}

View File

@ -345,8 +345,6 @@ class TabletWrapper(var stack: ItemStack, var player: EntityPlayer) extends Comp
override def componentSlot(address: String) = components.indexWhere(_.exists(env => env.node != null && env.node.address == address))
override def markForSaving() {}
override def onMachineConnect(node: Node) = onConnect(node)
override def onMachineDisconnect(node: Node) = onDisconnect(node)

View File

@ -262,8 +262,6 @@ class RobotProxy(val robot: Robot) extends traits.Computer with traits.PowerInfo
// ----------------------------------------------------------------------- //
override def markForSaving() = robot.markForSaving()
override def hasRedstoneCard = robot.hasRedstoneCard
// ----------------------------------------------------------------------- //

View File

@ -39,8 +39,6 @@ trait Computer extends Environment with ComponentInventory with Rotatable with B
private var _isRunning = false
private var markChunkDirty = false
private val _users = mutable.Set.empty[String]
protected def runSound = Option("computer_running")
@ -87,8 +85,6 @@ trait Computer extends Environment with ComponentInventory with Rotatable with B
null
}
override def markForSaving() = markChunkDirty = true
override def installedComponents = components collect {
case Some(component) => component
}
@ -118,11 +114,6 @@ trait Computer extends Environment with ComponentInventory with Rotatable with B
// GPU which would otherwise loose track of its screen).
machine.update()
if (markChunkDirty) {
markChunkDirty = false
world.markTileEntityChunkModified(x, y, z, this)
}
if (_isRunning != machine.isRunning) {
_isRunning = machine.isRunning
markDirty()

View File

@ -14,7 +14,7 @@ object EventHandlerRedstoneFlux {
if (damage > 0) {
val actualDamage = damage * e.getDamageRate
val repairedDamage =
if (e.robot.player.getRNG.nextDouble() > 0.5)
if (e.agent.player.getRNG.nextDouble() > 0.5)
damage - math.floor(actualDamage).toInt
else
damage - math.ceil(actualDamage).toInt

View File

@ -15,7 +15,7 @@ object EventHandlerGregTech {
if (damage > 0) {
val actualDamage = damage * e.getDamageRate
val repairedDamage =
if (e.robot.player.getRNG.nextDouble() > 0.5)
if (e.agent.player.getRNG.nextDouble() > 0.5)
damage - math.floor(actualDamage).toInt
else
damage - math.ceil(actualDamage).toInt

View File

@ -28,7 +28,7 @@ object EventHandlerIndustrialCraft2 {
if (damage > 0) {
val actualDamage = damage * e.getDamageRate
val repairedDamage =
if (e.robot.player.getRNG.nextDouble() > 0.5)
if (e.agent.player.getRNG.nextDouble() > 0.5)
damage - math.floor(actualDamage).toInt
else
damage - math.ceil(actualDamage).toInt

View File

@ -16,7 +16,7 @@ object EventHandlerTinkersConstruct {
if (damage > 0) {
val actualDamage = damage * e.getDamageRate
val repairedDamage =
if (e.robot.player.getRNG.nextDouble() > 0.5)
if (e.agent.player.getRNG.nextDouble() > 0.5)
damage - math.floor(actualDamage).toInt
else
damage - math.ceil(actualDamage).toInt

View File

@ -94,8 +94,6 @@ class Server(val rack: tileentity.ServerRack, val slot: Int) extends Environment
override def world = rack.world
override def markForSaving() = rack.markForSaving()
override def markChanged() = rack.markChanged()
// ----------------------------------------------------------------------- //

View File

@ -168,7 +168,7 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach
}
case Machine.State.Paused if remainingPause > 0 =>
remainingPause = 0
host.markForSaving()
host.markChanged()
true
case Machine.State.Stopping =>
switchTo(Machine.State.Restarting)
@ -196,7 +196,7 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach
state.push(Machine.State.Paused)
}
remainingPause = ticksToPause
host.markForSaving()
host.markChanged()
return true
}))
}
@ -772,7 +772,7 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach
remainIdle = 0
// Mark state change in owner, to send it to clients.
host.markForSaving()
host.markChanged()
})
// ----------------------------------------------------------------------- //
@ -789,7 +789,7 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach
}
// Mark state change in owner, to send it to clients.
host.markForSaving()
host.markChanged()
result
}