diff --git a/src/main/java/li/cil/oc/api/API.java b/src/main/java/li/cil/oc/api/API.java index a5c222af8..9e34d2846 100644 --- a/src/main/java/li/cil/oc/api/API.java +++ b/src/main/java/li/cil/oc/api/API.java @@ -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; diff --git a/src/main/java/li/cil/oc/api/Network.java b/src/main/java/li/cil/oc/api/Network.java index ce7d6d05d..458467f7f 100644 --- a/src/main/java/li/cil/oc/api/Network.java +++ b/src/main/java/li/cil/oc/api/Network.java @@ -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; diff --git a/src/main/java/li/cil/oc/api/component/TextBuffer.java b/src/main/java/li/cil/oc/api/component/TextBuffer.java index ed0120c15..0903a7961 100644 --- a/src/main/java/li/cil/oc/api/component/TextBuffer.java +++ b/src/main/java/li/cil/oc/api/component/TextBuffer.java @@ -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); - // ----------------------------------------------------------------------- // /** diff --git a/src/main/java/li/cil/oc/api/detail/Builder.java b/src/main/java/li/cil/oc/api/detail/Builder.java index eedf6647e..10affbbac 100644 --- a/src/main/java/li/cil/oc/api/detail/Builder.java +++ b/src/main/java/li/cil/oc/api/detail/Builder.java @@ -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}. diff --git a/src/main/java/li/cil/oc/api/detail/NetworkAPI.java b/src/main/java/li/cil/oc/api/detail/NetworkAPI.java index 50f94567b..b28b82e42 100644 --- a/src/main/java/li/cil/oc/api/detail/NetworkAPI.java +++ b/src/main/java/li/cil/oc/api/detail/NetworkAPI.java @@ -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; diff --git a/src/main/java/li/cil/oc/api/event/RobotAnalyzeEvent.java b/src/main/java/li/cil/oc/api/event/RobotAnalyzeEvent.java index 4b902117d..b1497ab40 100644 --- a/src/main/java/li/cil/oc/api/event/RobotAnalyzeEvent.java +++ b/src/main/java/li/cil/oc/api/event/RobotAnalyzeEvent.java @@ -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; } } diff --git a/src/main/java/li/cil/oc/api/event/RobotAttackEntityEvent.java b/src/main/java/li/cil/oc/api/event/RobotAttackEntityEvent.java index 4eead6627..9d647ebd3 100644 --- a/src/main/java/li/cil/oc/api/event/RobotAttackEntityEvent.java +++ b/src/main/java/li/cil/oc/api/event/RobotAttackEntityEvent.java @@ -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); } } } diff --git a/src/main/java/li/cil/oc/api/event/RobotBreakBlockEvent.java b/src/main/java/li/cil/oc/api/event/RobotBreakBlockEvent.java index 94288e25e..2630e95ee 100644 --- a/src/main/java/li/cil/oc/api/event/RobotBreakBlockEvent.java +++ b/src/main/java/li/cil/oc/api/event/RobotBreakBlockEvent.java @@ -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; } } diff --git a/src/main/java/li/cil/oc/api/event/RobotEvent.java b/src/main/java/li/cil/oc/api/event/RobotEvent.java index 074e4b6f4..0173809df 100644 --- a/src/main/java/li/cil/oc/api/event/RobotEvent.java +++ b/src/main/java/li/cil/oc/api/event/RobotEvent.java @@ -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; } } diff --git a/src/main/java/li/cil/oc/api/event/RobotExhaustionEvent.java b/src/main/java/li/cil/oc/api/event/RobotExhaustionEvent.java index 56ae85d26..ac906ef61 100644 --- a/src/main/java/li/cil/oc/api/event/RobotExhaustionEvent.java +++ b/src/main/java/li/cil/oc/api/event/RobotExhaustionEvent.java @@ -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; } } diff --git a/src/main/java/li/cil/oc/api/event/RobotMoveEvent.java b/src/main/java/li/cil/oc/api/event/RobotMoveEvent.java index 29e90be63..909628058 100644 --- a/src/main/java/li/cil/oc/api/event/RobotMoveEvent.java +++ b/src/main/java/li/cil/oc/api/event/RobotMoveEvent.java @@ -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); } } } diff --git a/src/main/java/li/cil/oc/api/event/RobotPlaceBlockEvent.java b/src/main/java/li/cil/oc/api/event/RobotPlaceBlockEvent.java index d481268bd..10b32b963 100644 --- a/src/main/java/li/cil/oc/api/event/RobotPlaceBlockEvent.java +++ b/src/main/java/li/cil/oc/api/event/RobotPlaceBlockEvent.java @@ -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); } } } diff --git a/src/main/java/li/cil/oc/api/event/RobotPlaceInAirEvent.java b/src/main/java/li/cil/oc/api/event/RobotPlaceInAirEvent.java index 01c193777..81a4b8f18 100644 --- a/src/main/java/li/cil/oc/api/event/RobotPlaceInAirEvent.java +++ b/src/main/java/li/cil/oc/api/event/RobotPlaceInAirEvent.java @@ -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); } /** diff --git a/src/main/java/li/cil/oc/api/event/RobotRenderEvent.java b/src/main/java/li/cil/oc/api/event/RobotRenderEvent.java index 58afc6a76..e3fcc1a57 100644 --- a/src/main/java/li/cil/oc/api/event/RobotRenderEvent.java +++ b/src/main/java/li/cil/oc/api/event/RobotRenderEvent.java @@ -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; } diff --git a/src/main/java/li/cil/oc/api/event/RobotUsedToolEvent.java b/src/main/java/li/cil/oc/api/event/RobotUsedToolEvent.java index de6bfb512..d907379ac 100644 --- a/src/main/java/li/cil/oc/api/event/RobotUsedToolEvent.java +++ b/src/main/java/li/cil/oc/api/event/RobotUsedToolEvent.java @@ -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); } } } diff --git a/src/main/java/li/cil/oc/api/internal/Agent.java b/src/main/java/li/cil/oc/api/internal/Agent.java new file mode 100644 index 000000000..33f39078f --- /dev/null +++ b/src/main/java/li/cil/oc/api/internal/Agent.java @@ -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. + *
+ * 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. + * + * Note that this may be the common OpenComputers fake player. + * + * @return the fake player for the agent. + */ + EntityPlayer player(); +} diff --git a/src/main/java/li/cil/oc/api/internal/Drone.java b/src/main/java/li/cil/oc/api/internal/Drone.java index 717ac5105..16604aa8b 100644 --- a/src/main/java/li/cil/oc/api/internal/Drone.java +++ b/src/main/java/li/cil/oc/api/internal/Drone.java @@ -18,7 +18,7 @@ import net.minecraft.util.Vec3; * i.e. without having to link against internal classes. This also means * that you should not implement this. */ -public interface Drone extends EnvironmentHost, Rotatable, Tiered { +public interface Drone extends Agent, EnvironmentHost, Rotatable, Tiered { /** * The machine currently hosted by this drone. */ diff --git a/src/main/java/li/cil/oc/api/internal/Robot.java b/src/main/java/li/cil/oc/api/internal/Robot.java index 397f02a09..f3ac45874 100644 --- a/src/main/java/li/cil/oc/api/internal/Robot.java +++ b/src/main/java/li/cil/oc/api/internal/Robot.java @@ -31,25 +31,12 @@ import net.minecraftforge.fluids.IFluidTank; * * This interface is not meant to be implemented, 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. - * - * 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. * diff --git a/src/main/java/li/cil/oc/api/internal/Server.java b/src/main/java/li/cil/oc/api/internal/Server.java index e24953df8..4894d33d2 100644 --- a/src/main/java/li/cil/oc/api/internal/Server.java +++ b/src/main/java/li/cil/oc/api/internal/Server.java @@ -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 you should not implement this. */ -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(); } diff --git a/src/main/java/li/cil/oc/api/machine/MachineHost.java b/src/main/java/li/cil/oc/api/machine/MachineHost.java index c234d8e04..4f7532712 100644 --- a/src/main/java/li/cil/oc/api/machine/MachineHost.java +++ b/src/main/java/li/cil/oc/api/machine/MachineHost.java @@ -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. - * - * 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 diff --git a/src/main/java/li/cil/oc/api/network/WirelessEndpoint.java b/src/main/java/li/cil/oc/api/network/WirelessEndpoint.java index 72d14b0a4..c5de36d3d 100644 --- a/src/main/java/li/cil/oc/api/network/WirelessEndpoint.java +++ b/src/main/java/li/cil/oc/api/network/WirelessEndpoint.java @@ -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); } diff --git a/src/main/java/li/cil/oc/api/prefab/TileEntityEnvironment.java b/src/main/java/li/cil/oc/api/prefab/TileEntityEnvironment.java index 75f83ac41..1f467dde0 100644 --- a/src/main/java/li/cil/oc/api/prefab/TileEntityEnvironment.java +++ b/src/main/java/li/cil/oc/api/prefab/TileEntityEnvironment.java @@ -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(). diff --git a/src/main/scala/li/cil/oc/common/component/TextBuffer.scala b/src/main/scala/li/cil/oc/common/component/TextBuffer.scala index 4c9a1d243..0b46c8c40 100644 --- a/src/main/scala/li/cil/oc/common/component/TextBuffer.scala +++ b/src/main/scala/li/cil/oc/common/component/TextBuffer.scala @@ -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) } diff --git a/src/main/scala/li/cil/oc/common/entity/Drone.scala b/src/main/scala/li/cil/oc/common/entity/Drone.scala index a42ae9be4..754921ef2 100644 --- a/src/main/scala/li/cil/oc/common/entity/Drone.scala +++ b/src/main/scala/li/cil/oc/common/entity/Drone.scala @@ -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) {} diff --git a/src/main/scala/li/cil/oc/common/event/AngelUpgradeHandler.scala b/src/main/scala/li/cil/oc/common/event/AngelUpgradeHandler.scala index 7e0a82e21..f1d6220d0 100644 --- a/src/main/scala/li/cil/oc/common/event/AngelUpgradeHandler.scala +++ b/src/main/scala/li/cil/oc/common/event/AngelUpgradeHandler.scala @@ -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"))) } } diff --git a/src/main/scala/li/cil/oc/common/event/ChunkloaderUpgradeHandler.scala b/src/main/scala/li/cil/oc/common/event/ChunkloaderUpgradeHandler.scala index 785b253bc..2578ae2df 100644 --- a/src/main/scala/li/cil/oc/common/event/ChunkloaderUpgradeHandler.scala +++ b/src/main/scala/li/cil/oc/common/event/ChunkloaderUpgradeHandler.scala @@ -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) { diff --git a/src/main/scala/li/cil/oc/common/event/ExperienceUpgradeHandler.scala b/src/main/scala/li/cil/oc/common/event/ExperienceUpgradeHandler.scala index 2a81f3b16..e3ab3f8d1 100644 --- a/src/main/scala/li/cil/oc/common/event/ExperienceUpgradeHandler.scala +++ b/src/main/scala/li/cil/oc/common/event/ExperienceUpgradeHandler.scala @@ -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 _ => +// } +// } } } diff --git a/src/main/scala/li/cil/oc/common/event/RobotCommonHandler.scala b/src/main/scala/li/cil/oc/common/event/RobotCommonHandler.scala index c347c0140..906796aa2 100644 --- a/src/main/scala/li/cil/oc/common/event/RobotCommonHandler.scala +++ b/src/main/scala/li/cil/oc/common/event/RobotCommonHandler.scala @@ -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) } } diff --git a/src/main/scala/li/cil/oc/common/event/WirelessNetworkCardHandler.scala b/src/main/scala/li/cil/oc/common/event/WirelessNetworkCardHandler.scala index a22c33cf9..fb73bdda9 100644 --- a/src/main/scala/li/cil/oc/common/event/WirelessNetworkCardHandler.scala +++ b/src/main/scala/li/cil/oc/common/event/WirelessNetworkCardHandler.scala @@ -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 _ => +// } +// } } } diff --git a/src/main/scala/li/cil/oc/common/item/Tablet.scala b/src/main/scala/li/cil/oc/common/item/Tablet.scala index 6b95a776b..255c68586 100644 --- a/src/main/scala/li/cil/oc/common/item/Tablet.scala +++ b/src/main/scala/li/cil/oc/common/item/Tablet.scala @@ -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) diff --git a/src/main/scala/li/cil/oc/common/tileentity/RobotProxy.scala b/src/main/scala/li/cil/oc/common/tileentity/RobotProxy.scala index 6a340d663..c5ed7fca6 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/RobotProxy.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/RobotProxy.scala @@ -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 // ----------------------------------------------------------------------- // diff --git a/src/main/scala/li/cil/oc/common/tileentity/traits/Computer.scala b/src/main/scala/li/cil/oc/common/tileentity/traits/Computer.scala index fe804d4ea..a9384d4fb 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/traits/Computer.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/traits/Computer.scala @@ -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() diff --git a/src/main/scala/li/cil/oc/integration/cofh/energy/EventHandlerRedstoneFlux.scala b/src/main/scala/li/cil/oc/integration/cofh/energy/EventHandlerRedstoneFlux.scala index 19265667d..91e9406ae 100644 --- a/src/main/scala/li/cil/oc/integration/cofh/energy/EventHandlerRedstoneFlux.scala +++ b/src/main/scala/li/cil/oc/integration/cofh/energy/EventHandlerRedstoneFlux.scala @@ -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 diff --git a/src/main/scala/li/cil/oc/integration/gregtech/EventHandlerGregTech.scala b/src/main/scala/li/cil/oc/integration/gregtech/EventHandlerGregTech.scala index 382b2d50e..ae349f30c 100644 --- a/src/main/scala/li/cil/oc/integration/gregtech/EventHandlerGregTech.scala +++ b/src/main/scala/li/cil/oc/integration/gregtech/EventHandlerGregTech.scala @@ -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 diff --git a/src/main/scala/li/cil/oc/integration/ic2/EventHandlerIndustrialCraft2.scala b/src/main/scala/li/cil/oc/integration/ic2/EventHandlerIndustrialCraft2.scala index 22f207a9f..9591b6e19 100644 --- a/src/main/scala/li/cil/oc/integration/ic2/EventHandlerIndustrialCraft2.scala +++ b/src/main/scala/li/cil/oc/integration/ic2/EventHandlerIndustrialCraft2.scala @@ -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 diff --git a/src/main/scala/li/cil/oc/integration/tcon/EventHandlerTinkersConstruct.scala b/src/main/scala/li/cil/oc/integration/tcon/EventHandlerTinkersConstruct.scala index 466084e5e..a6e93e1a2 100644 --- a/src/main/scala/li/cil/oc/integration/tcon/EventHandlerTinkersConstruct.scala +++ b/src/main/scala/li/cil/oc/integration/tcon/EventHandlerTinkersConstruct.scala @@ -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 diff --git a/src/main/scala/li/cil/oc/server/component/Server.scala b/src/main/scala/li/cil/oc/server/component/Server.scala index d43b4c511..e558cb666 100644 --- a/src/main/scala/li/cil/oc/server/component/Server.scala +++ b/src/main/scala/li/cil/oc/server/component/Server.scala @@ -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() // ----------------------------------------------------------------------- // diff --git a/src/main/scala/li/cil/oc/server/machine/Machine.scala b/src/main/scala/li/cil/oc/server/machine/Machine.scala index 39b481079..86ab29fe4 100644 --- a/src/main/scala/li/cil/oc/server/machine/Machine.scala +++ b/src/main/scala/li/cil/oc/server/machine/Machine.scala @@ -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 }