diff --git a/resources/assets/darkcore/textures/gui/GuiGrey.png b/resources/assets/darkcore/textures/gui/GuiGrey.png new file mode 100644 index 000000000..ce0447979 Binary files /dev/null and b/resources/assets/darkcore/textures/gui/GuiGrey.png differ diff --git a/resources/assets/darkcore/textures/gui/gui@.png b/resources/assets/darkcore/textures/gui/gui@.png new file mode 100644 index 000000000..6c22f4491 Binary files /dev/null and b/resources/assets/darkcore/textures/gui/gui@.png differ diff --git a/resources/assets/darkcore/textures/gui/gui_base.png b/resources/assets/darkcore/textures/gui/gui_base.png new file mode 100644 index 000000000..7c84c09d5 Binary files /dev/null and b/resources/assets/darkcore/textures/gui/gui_base.png differ diff --git a/resources/assets/darkcore/textures/gui/gui_button.png b/resources/assets/darkcore/textures/gui/gui_button.png new file mode 100644 index 000000000..2d9436765 Binary files /dev/null and b/resources/assets/darkcore/textures/gui/gui_button.png differ diff --git a/resources/assets/darkcore/textures/gui/gui_empty.png b/resources/assets/darkcore/textures/gui/gui_empty.png new file mode 100644 index 000000000..06739375c Binary files /dev/null and b/resources/assets/darkcore/textures/gui/gui_empty.png differ diff --git a/resources/assets/darkcore/textures/gui/gui_grey.png b/resources/assets/darkcore/textures/gui/gui_grey.png new file mode 100644 index 000000000..aa9b68bd5 Binary files /dev/null and b/resources/assets/darkcore/textures/gui/gui_grey.png differ diff --git a/resources/assets/darkcore/textures/gui/gui_message_box.png b/resources/assets/darkcore/textures/gui/gui_message_box.png new file mode 100644 index 000000000..72d97cbc9 Binary files /dev/null and b/resources/assets/darkcore/textures/gui/gui_message_box.png differ diff --git a/src/com/builtbroken/minecraft/prefab/TileEntityEnergyMachine.java b/src/com/builtbroken/minecraft/prefab/TileEntityEnergyMachine.java index 307431515..ff5d56ed6 100644 --- a/src/com/builtbroken/minecraft/prefab/TileEntityEnergyMachine.java +++ b/src/com/builtbroken/minecraft/prefab/TileEntityEnergyMachine.java @@ -10,8 +10,11 @@ import net.minecraft.nbt.NBTTagFloat; import net.minecraft.nbt.NBTTagLong; import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.oredict.OreDictionary; +import universalelectricity.api.CompatibilityModule; import universalelectricity.api.energy.IEnergyContainer; import universalelectricity.api.energy.IEnergyInterface; +import universalelectricity.api.vector.Vector3; +import universalelectricity.api.vector.VectorHelper; import com.builtbroken.minecraft.interfaces.IPowerLess; @@ -103,7 +106,7 @@ public abstract class TileEntityEnergyMachine extends TileEntityMachine implemen @Override public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive) { - if (!this.runPowerLess() && receive > 0 && this.canConnect(from)) + if (!this.runPowerLess() && receive > 0 && this.getInputDirections().contains(from)) { long prevEnergyStored = this.getEnergy(from); long newStoredEnergy = Math.min(this.getEnergy(from) + receive, this.getEnergyCapacity(from)); @@ -151,6 +154,17 @@ public abstract class TileEntityEnergyMachine extends TileEntityMachine implemen return 0; } + protected void produce() + { + for (ForgeDirection direction : this.getOutputDirections()) + { + if (this.onExtractEnergy(direction.getOpposite(), CompatibilityModule.receiveEnergy(VectorHelper.getTileEntityFromSide(this.worldObj, new Vector3(this), direction), direction, this.onExtractEnergy(direction.getOpposite(), this.JOULES_PER_TICK, false), true), true) > 0) + { + break; + } + } + } + /* ******************************************** * Electricity connection logic ***********************************************/ diff --git a/src/com/builtbroken/minecraft/prefab/invgui/GuiInvMachineBase.java b/src/com/builtbroken/minecraft/prefab/invgui/GuiInvMachineBase.java deleted file mode 100644 index 78add6eac..000000000 --- a/src/com/builtbroken/minecraft/prefab/invgui/GuiInvMachineBase.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.builtbroken.minecraft.prefab.invgui; - -/** Same as the GuiMachineBase but supports inventory pages - * - * @author DarkGuardsman */ -public class GuiInvMachineBase -{ - -} diff --git a/src/com/builtbroken/minecraft/tilenetwork/IPathCallBack.java b/src/com/builtbroken/minecraft/tilenetwork/IPathCallBack.java new file mode 100644 index 000000000..ecfcfd4cf --- /dev/null +++ b/src/com/builtbroken/minecraft/tilenetwork/IPathCallBack.java @@ -0,0 +1,25 @@ +package com.builtbroken.minecraft.tilenetwork; + +import java.util.Set; + +import universalelectricity.api.vector.Vector3; + +public interface IPathCallBack +{ + /** + * @param finder - The Pathfinder object. + * @param currentNode - The node being iterated through. + * @return A set of nodes connected to the currentNode. Essentially one should return a set of + * neighboring nodes. + */ + public Set getConnectedNodes(Pathfinder finder, Vector3 currentNode); + + /** + * Called when looping through nodes. + * + * @param finder - The Pathfinder. + * @param node - The node being searched. + * @return True to stop the path finding operation. + */ + public boolean onSearch(Pathfinder finder, Vector3 node); +} \ No newline at end of file diff --git a/src/com/builtbroken/minecraft/tilenetwork/Pathfinder.java b/src/com/builtbroken/minecraft/tilenetwork/Pathfinder.java new file mode 100644 index 000000000..c66d151ce --- /dev/null +++ b/src/com/builtbroken/minecraft/tilenetwork/Pathfinder.java @@ -0,0 +1,79 @@ +package com.builtbroken.minecraft.tilenetwork; + +import java.util.HashSet; +import java.util.Set; + +import universalelectricity.api.vector.Vector3; + +/** + * A class that allows flexible pathfinding for different positions. Compared to AStar pathfinding, + * this version is faster but does not calculated the most optimal path. + * + * @author Calclavia + * + */ +public class Pathfinder +{ + /** + * A pathfinding call back interface used to call back on paths. + */ + public IPathCallBack callBackCheck; + + /** + * A list of nodes that the pathfinder already went through. + */ + public Set closedSet; + + /** + * The resulted path found by the pathfinder. Could be null if no path was found. + */ + public Set results; + + public Pathfinder(IPathCallBack callBack) + { + this.callBackCheck = callBack; + this.reset(); + } + + /** + * @return True on success finding, false on failure. + */ + public boolean findNodes(Vector3 currentNode) + { + this.closedSet.add(currentNode); + + if (this.callBackCheck.onSearch(this, currentNode)) + { + return false; + } + + for (Vector3 node : this.callBackCheck.getConnectedNodes(this, currentNode)) + { + if (!this.closedSet.contains(node)) + { + if (this.findNodes(node)) + { + return true; + } + } + } + + return false; + } + + /** + * Called to execute the pathfinding operation. + */ + public Pathfinder init(Vector3 startNode) + { + this.findNodes(startNode); + return this; + } + + public Pathfinder reset() + { + this.closedSet = new HashSet(); + this.results = new HashSet(); + return this; + } +} diff --git a/src/com/builtbroken/minecraft/tilenetwork/PathfinderAStar.java b/src/com/builtbroken/minecraft/tilenetwork/PathfinderAStar.java new file mode 100644 index 000000000..cb31aa5e7 --- /dev/null +++ b/src/com/builtbroken/minecraft/tilenetwork/PathfinderAStar.java @@ -0,0 +1,175 @@ +package com.builtbroken.minecraft.tilenetwork; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; + +import net.minecraftforge.common.ForgeDirection; +import universalelectricity.api.vector.Vector3; + +/** + * An advanced version of pathfinding to find the shortest path between two points. Uses the A* + * Pathfinding algorithm. + * + * @author Calclavia + * + */ +public class PathfinderAStar extends Pathfinder +{ + /** + * A pathfinding call back interface used to call back on paths. + */ + public IPathCallBack callBackCheck; + + /** + * The set of tentative nodes to be evaluated, initially containing the start node + */ + public Set openSet; + + /** + * The map of navigated nodes storing the data of which position came from which in the format + * of: X came from Y. + */ + public HashMap navigationMap; + + /** + * Score values, used to determine the score for a path to evaluate how optimal the path is. + * G-Score is the cost along the best known path while F-Score is the total cost. + */ + public HashMap gScore, fScore; + + /** + * The node in which the pathfinder is trying to reach. + */ + public Vector3 goal; + + public PathfinderAStar(IPathCallBack callBack, Vector3 goal) + { + super(callBack); + this.goal = goal; + } + + @Override + public boolean findNodes(Vector3 start) + { + this.openSet.add(start); + this.gScore.put(start, 0d); + this.fScore.put(start, this.gScore.get(start) + getHeuristicEstimatedCost(start, this.goal)); + + while (!this.openSet.isEmpty()) + { + // Current is the node in openset having the lowest f_score[] value + Vector3 currentNode = null; + + double lowestFScore = 0; + + for (Vector3 node : this.openSet) + { + if (currentNode == null || this.fScore.get(node) < lowestFScore) + { + currentNode = node; + lowestFScore = this.fScore.get(node); + } + } + + if (currentNode == null) + { + break; + } + + if (this.callBackCheck.onSearch(this, currentNode)) + { + return false; + } + + if (currentNode.equals(this.goal)) + { + this.results = reconstructPath(this.navigationMap, goal); + return true; + } + + this.openSet.remove(currentNode); + this.closedSet.add(currentNode); + + for (Vector3 neighbor : getNeighborNodes(currentNode)) + { + double tentativeGScore = this.gScore.get(currentNode) + currentNode.distance(neighbor); + + if (this.closedSet.contains(neighbor)) + { + if (tentativeGScore >= this.gScore.get(neighbor)) + { + continue; + } + } + + if (!this.openSet.contains(neighbor) || tentativeGScore < this.gScore.get(neighbor)) + { + this.navigationMap.put(neighbor, currentNode); + this.gScore.put(neighbor, tentativeGScore); + this.fScore.put(neighbor, gScore.get(neighbor) + getHeuristicEstimatedCost(neighbor, goal)); + this.openSet.add(neighbor); + } + } + } + + return false; + } + + @Override + public Pathfinder reset() + { + this.openSet = new HashSet(); + this.navigationMap = new HashMap(); + return super.reset(); + } + + /** + * A recursive function to back track and find the path in which we have analyzed. + */ + public Set reconstructPath(HashMap nagivationMap, Vector3 current_node) + { + Set path = new HashSet(); + path.add(current_node); + + if (nagivationMap.containsKey(current_node)) + { + path.addAll(reconstructPath(nagivationMap, nagivationMap.get(current_node))); + return path; + } + else + { + return path; + } + } + + /** + * @return An estimated cost between two points. + */ + public double getHeuristicEstimatedCost(Vector3 start, Vector3 goal) + { + return start.distance(goal); + } + + /** + * @return A Set of neighboring Vector3 positions. + */ + public Set getNeighborNodes(Vector3 vector) + { + if (this.callBackCheck != null) + { + return this.callBackCheck.getConnectedNodes(this, vector); + } + else + { + Set neighbors = new HashSet(); + + for (int i = 0; i < 6; i++) + { + neighbors.add(vector.clone().modifyPositionFromSide(ForgeDirection.getOrientation(i))); + } + + return neighbors; + } + } +} diff --git a/src/com/builtbroken/minecraft/tilenetwork/prefab/NetworkPathFinder.java b/src/com/builtbroken/minecraft/tilenetwork/prefab/NetworkPathFinder.java index bb25b757b..ac433bab2 100644 --- a/src/com/builtbroken/minecraft/tilenetwork/prefab/NetworkPathFinder.java +++ b/src/com/builtbroken/minecraft/tilenetwork/prefab/NetworkPathFinder.java @@ -6,10 +6,10 @@ import java.util.Set; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import universalelectricity.api.vector.Vector3; -import universalelectricity.core.path.IPathCallBack; -import universalelectricity.core.path.Pathfinder; import com.builtbroken.minecraft.tilenetwork.INetworkPart; +import com.builtbroken.minecraft.tilenetwork.IPathCallBack; +import com.builtbroken.minecraft.tilenetwork.Pathfinder; /** Check if a conductor connects with another. */ public class NetworkPathFinder extends Pathfinder diff --git a/src/com/builtbroken/minecraft/tilenetwork/prefab/NetworkTileEntities.java b/src/com/builtbroken/minecraft/tilenetwork/prefab/NetworkTileEntities.java index f0b89b79f..4d1d98421 100644 --- a/src/com/builtbroken/minecraft/tilenetwork/prefab/NetworkTileEntities.java +++ b/src/com/builtbroken/minecraft/tilenetwork/prefab/NetworkTileEntities.java @@ -9,10 +9,10 @@ import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; import universalelectricity.api.vector.Vector3; import universalelectricity.api.vector.VectorHelper; -import universalelectricity.core.path.Pathfinder; import com.builtbroken.minecraft.tilenetwork.INetworkPart; import com.builtbroken.minecraft.tilenetwork.ITileNetwork; +import com.builtbroken.minecraft.tilenetwork.Pathfinder; public class NetworkTileEntities implements ITileNetwork {