From 9029c04dd23c03e53d0054b7e514e8b30631d4e1 Mon Sep 17 00:00:00 2001 From: Hea3veN Date: Mon, 9 Feb 2015 21:59:52 -0300 Subject: [PATCH 1/4] fix the robot smoke particle causing fps drops in certain cases --- common/buildcraft/robots/EntityRobotEnergyParticle.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/buildcraft/robots/EntityRobotEnergyParticle.java b/common/buildcraft/robots/EntityRobotEnergyParticle.java index 015d25b3..1ff71d7d 100755 --- a/common/buildcraft/robots/EntityRobotEnergyParticle.java +++ b/common/buildcraft/robots/EntityRobotEnergyParticle.java @@ -81,7 +81,7 @@ public class EntityRobotEnergyParticle extends EntityFX { if (this.posY == this.prevPosY) { this.motionX *= 1.1D; - this.motionY *= 1.1D; + this.motionY = 0.001D; this.motionZ *= 1.1D; } From 7a3822f4f657b166091f2af27379ba1c41a02af3 Mon Sep 17 00:00:00 2001 From: Hea3veN Date: Mon, 9 Feb 2015 22:01:37 -0300 Subject: [PATCH 2/4] make robots face where they are traveling to --- common/buildcraft/robots/ai/AIRobotGotoBlock.java | 2 ++ common/buildcraft/robots/ai/AIRobotPumpBlock.java | 5 ----- common/buildcraft/robots/ai/AIRobotStraightMoveTo.java | 1 + 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/common/buildcraft/robots/ai/AIRobotGotoBlock.java b/common/buildcraft/robots/ai/AIRobotGotoBlock.java index cb043a35..67a5fdf7 100755 --- a/common/buildcraft/robots/ai/AIRobotGotoBlock.java +++ b/common/buildcraft/robots/ai/AIRobotGotoBlock.java @@ -41,6 +41,7 @@ public class AIRobotGotoBlock extends AIRobotGoto { finalX = x; finalY = y; finalZ = z; + robot.aimItemAt((int) Math.floor(finalX), (int) Math.floor(finalY), (int) Math.floor(finalZ)); } public AIRobotGotoBlock(EntityRobotBase robot, int x, int y, int z, double iMaxDistance) { @@ -55,6 +56,7 @@ public class AIRobotGotoBlock extends AIRobotGoto { finalX = path.getLast().x; finalY = path.getLast().y; finalZ = path.getLast().z; + robot.aimItemAt((int) Math.floor(finalX), (int) Math.floor(finalY), (int) Math.floor(finalZ)); setNextInPath(); } diff --git a/common/buildcraft/robots/ai/AIRobotPumpBlock.java b/common/buildcraft/robots/ai/AIRobotPumpBlock.java index 98d30685..7c541ac9 100644 --- a/common/buildcraft/robots/ai/AIRobotPumpBlock.java +++ b/common/buildcraft/robots/ai/AIRobotPumpBlock.java @@ -66,11 +66,6 @@ public class AIRobotPumpBlock extends AIRobot { } - @Override - public void end() { - robot.aimItemAt(0, 1, 0); - } - @Override public int getEnergyCost() { return 20; diff --git a/common/buildcraft/robots/ai/AIRobotStraightMoveTo.java b/common/buildcraft/robots/ai/AIRobotStraightMoveTo.java index d08a2ca2..34e7c7d4 100755 --- a/common/buildcraft/robots/ai/AIRobotStraightMoveTo.java +++ b/common/buildcraft/robots/ai/AIRobotStraightMoveTo.java @@ -26,6 +26,7 @@ public class AIRobotStraightMoveTo extends AIRobotGoto { x = ix; y = iy; z = iz; + robot.aimItemAt((int) Math.floor(x), (int) Math.floor(y), (int) Math.floor(z)); } @Override From 90da2ea4d96b531d8b98bfaea299f51a7e5d9983 Mon Sep 17 00:00:00 2001 From: Hea3veN Date: Sat, 14 Feb 2015 15:59:15 -0300 Subject: [PATCH 3/4] robots drop their inventory when destroyed --- common/buildcraft/robots/EntityRobot.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/common/buildcraft/robots/EntityRobot.java b/common/buildcraft/robots/EntityRobot.java index 426144d9..a8411579 100644 --- a/common/buildcraft/robots/EntityRobot.java +++ b/common/buildcraft/robots/EntityRobot.java @@ -948,6 +948,14 @@ public class EntityRobot extends EntityRobotBase implements NBTUtils.getItemData(robotStack).setTag("board", originalBoardNBT); NBTUtils.getItemData(robotStack).setInteger("energy", battery.getEnergyStored()); entityDropItem(robotStack, 0); + if (itemInUse != null) { + entityDropItem(itemInUse, 0); + } + for (ItemStack element : inv) { + if (element != null) { + entityDropItem(element, 0); + } + } getRegistry().killRobot(this); } From efbf47ba496862a5201cb66bae95ba7644437a74 Mon Sep 17 00:00:00 2001 From: Hea3veN Date: Sat, 14 Feb 2015 16:11:45 -0300 Subject: [PATCH 4/4] fix the PathFindingSearch algorithm pathfinding multiple times the same block --- .../core/utils/concurrency/PathFinding.java | 14 +++++ .../utils/concurrency/PathFindingSearch.java | 57 +++++++++++++------ .../robots/ai/AIRobotSearchBlock.java | 2 +- 3 files changed, 55 insertions(+), 18 deletions(-) diff --git a/common/buildcraft/core/utils/concurrency/PathFinding.java b/common/buildcraft/core/utils/concurrency/PathFinding.java index 427414c7..76e78b82 100755 --- a/common/buildcraft/core/utils/concurrency/PathFinding.java +++ b/common/buildcraft/core/utils/concurrency/PathFinding.java @@ -34,6 +34,7 @@ public class PathFinding implements IIterableAlgorithm { private IBlockFilter pathFound; private IZone zone; private double maxDistanceToEnd = 0; + private float maxTotalDistance = 0; private HashMap openList = new HashMap(); private HashMap closedList = new HashMap(); @@ -65,6 +66,13 @@ public class PathFinding implements IIterableAlgorithm { maxDistanceToEnd = iMaxDistanceToEnd; } + public PathFinding(World iWorld, BlockIndex iStart, BlockIndex iEnd, double iMaxDistanceToEnd, + float iMaxTotalDistance) { + this(iWorld, iStart, iEnd, iMaxDistanceToEnd); + + maxTotalDistance = iMaxTotalDistance; + } + @Override public void iterate() { iterate(PATH_ITERATIONS); @@ -147,6 +155,12 @@ public class PathFinding implements IIterableAlgorithm { nextNode.totalWeight = nextNode.movementCost + nextNode.destinationCost; + if (maxTotalDistance > 0 && nextNode.totalWeight > maxTotalDistance) { + if (!closedList.containsKey(nextNode.index)) { + closedList.put(nextNode.index, nextNode); + } + continue; + } if (closedList.containsKey(nextNode.index)) { continue; } else if (openList.containsKey(nextNode.index)) { diff --git a/common/buildcraft/core/utils/concurrency/PathFindingSearch.java b/common/buildcraft/core/utils/concurrency/PathFindingSearch.java index 340d8236..f4b0626d 100644 --- a/common/buildcraft/core/utils/concurrency/PathFindingSearch.java +++ b/common/buildcraft/core/utils/concurrency/PathFindingSearch.java @@ -32,6 +32,7 @@ public class PathFindingSearch implements IIterableAlgorithm { private List pathFinders; private IBlockFilter pathFound; private IZone zone; + private float maxDistance; private int searchRadius; private int searchX; @@ -39,11 +40,14 @@ public class PathFindingSearch implements IIterableAlgorithm { private int searchZ; private int searchHeight; + public PathFindingSearch(World iWorld, BlockIndex iStart, IBlockFilter iPathFound, float iMaxDistance, IZone iZone) { world = iWorld; start = iStart; pathFound = iPathFound; + maxDistance = iMaxDistance; + pathFinders = new LinkedList(); searchRadius = 1; searchX = -1; @@ -67,32 +71,51 @@ public class PathFindingSearch implements IIterableAlgorithm { int currZ = start.z + searchZ; if (0 <= currY && currY <= searchHeight) { if (isTarget(currX, currY, currZ)) { - pathFinders.add(new PathFinding(world, start, new BlockIndex(currX, currY, currZ))); + pathFinders.add(new PathFinding(world, start, new BlockIndex(currX, currY, currZ), 0, maxDistance)); } } - searchY += 1; - if (searchY > searchRadius) { - searchY = -searchRadius; - searchZ += 1; - if (searchZ > searchRadius) { - searchZ = -searchRadius; - searchX += 1; - if (searchX > searchRadius) { - searchRadius += 1; - searchX = -searchRadius; - searchY = -searchRadius; - searchZ = -searchRadius; - } - } - searchHeight = getSearchHeight(start.x + searchX, start.z + searchZ); - } + nextSearchStep(); + if (pathFinders.size() >= 5) { return; } } } + private void nextSearchStep() { + // Step through each block in a hollow cube of size (searchRadius * 2 -1), if done + // add 1 to the radius and start over. + + // Step to the next Y + if (Math.abs(searchX) == searchRadius || Math.abs(searchZ) == searchRadius) { + searchY += 1; + } else { + searchY += searchRadius * 2; + } + + if (searchY > searchRadius) { + // Step to the next Z + searchY = -searchRadius; + searchZ += 1; + + if (searchZ > searchRadius) { + // Step to the next X + searchZ = -searchRadius; + searchX += 1; + + if (searchX > searchRadius) { + // Step to the next radius + searchRadius += 1; + searchX = -searchRadius; + searchY = -searchRadius; + searchZ = -searchRadius; + } + } + searchHeight = getSearchHeight(start.x + searchX, start.z + searchZ); + } + } + private boolean isTarget(int x, int y, int z) { if (zone != null && !zone.contains(x, y, z)) { return false; diff --git a/common/buildcraft/robots/ai/AIRobotSearchBlock.java b/common/buildcraft/robots/ai/AIRobotSearchBlock.java index 054a3d96..2a5c67cc 100755 --- a/common/buildcraft/robots/ai/AIRobotSearchBlock.java +++ b/common/buildcraft/robots/ai/AIRobotSearchBlock.java @@ -39,7 +39,7 @@ public class AIRobotSearchBlock extends AIRobot { @Override public void start() { - blockScanner = new PathFindingSearch(robot.worldObj, new BlockIndex(robot), pathFound, 64, robot.getZoneToWork()); + blockScanner = new PathFindingSearch(robot.worldObj, new BlockIndex(robot), pathFound, 96, robot.getZoneToWork()); blockScannerJob = new IterableAlgorithmRunner(blockScanner, 40000); blockScannerJob.start(); }