mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-21 04:22:32 +00:00
Prevent farms on a chunk edge from loading unloaded chunks
This commit is contained in:
1 parent
79c56311c2
commit
d35075d681
3 files changed
+46
-27
No files matched your search
@@ -11,6 +11,7 @@
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -512,11 +513,11 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
// Set the maximum allowed extent.
|
||||
allowedExtent = Math.max(sizeNorthSouth, sizeEastWest) * Config.farmSize + 1;
|
||||
|
||||
createTargets(worldObj, targets, targetStart, allowedExtent, sizeNorthSouth, sizeEastWest);
|
||||
createTargets(worldObj, targets, targetStart, allowedExtent, sizeNorthSouth, sizeEastWest, min, max);
|
||||
setExtents(worldObj, targets);
|
||||
}
|
||||
|
||||
private static void createTargets(World world, Map<FarmDirection, List<FarmTarget>> targets, BlockPos targetStart, final int allowedExtent, final int farmSizeNorthSouth, final int farmSizeEastWest) {
|
||||
private static void createTargets(World world, Map<FarmDirection, List<FarmTarget>> targets, BlockPos targetStart, final int allowedExtent, final int farmSizeNorthSouth, final int farmSizeEastWest, BlockPos minFarmCoord, BlockPos maxFarmCoord) {
|
||||
|
||||
for (FarmDirection farmSide : FarmDirection.values()) {
|
||||
|
||||
@@ -532,7 +533,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
|
||||
FarmDirection layoutDirection = getLayoutDirection(farmSide);
|
||||
|
||||
BlockPos targetLocation = FarmHelper.getFarmMultiblockCorner(world, targetStart, farmSide, layoutDirection);
|
||||
BlockPos targetLocation = FarmHelper.getFarmMultiblockCorner(targetStart, farmSide, layoutDirection, minFarmCoord, maxFarmCoord);
|
||||
BlockPos firstLocation = targetLocation.offset(farmSide.getFacing());
|
||||
BlockPos firstGroundPosition = getGroundPosition(world, firstLocation);
|
||||
if (firstGroundPosition == null) {
|
||||
@@ -545,9 +546,8 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
targetLocation = targetLocation.offset(farmSide.getFacing());
|
||||
BlockPos groundLocation = new BlockPos(targetLocation.getX(), groundHeight, targetLocation.getZ());
|
||||
|
||||
int targetLimit = targetMaxLimit;
|
||||
if (!Config.squareFarms) {
|
||||
targetLimit = targetMaxLimit - i - 1;
|
||||
if (!world.isBlockLoaded(groundLocation)) {
|
||||
break;
|
||||
}
|
||||
|
||||
IBlockState blockState = world.getBlockState(groundLocation);
|
||||
@@ -555,6 +555,11 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
break;
|
||||
}
|
||||
|
||||
int targetLimit = targetMaxLimit;
|
||||
if (!Config.squareFarms) {
|
||||
targetLimit = targetMaxLimit - i - 1;
|
||||
}
|
||||
|
||||
FarmTarget target = new FarmTarget(targetLocation, layoutDirection, targetLimit);
|
||||
farmSideTargets.add(target);
|
||||
}
|
||||
@@ -563,7 +568,12 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static BlockPos getGroundPosition(World world, BlockPos targetPosition) {
|
||||
if (!world.isBlockLoaded(targetPosition)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (int yOffset = 2; yOffset > -4; yOffset--) {
|
||||
BlockPos position = targetPosition.add(0, yOffset, 0);
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
@@ -571,6 +581,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
return position;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user