Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use loadedTileEntity list #248

Merged
merged 1 commit into from
Jul 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions src/main/rtm-patches/jp/ngt/rtm/rail/BlockMarker.java.pm.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
--- a/jp/ngt/rtm/rail/BlockMarker.java
+++ b/jp/ngt/rtm/rail/BlockMarker.java
@@ -1,10 +1,10 @@
package jp.ngt.rtm.rail;

import java.util.ArrayList;
-import java.util.Comparator;
import java.util.List;
+import java.util.stream.Collectors;
import javax.annotation.Nullable;
import jp.ngt.ngtlib.block.BlockArgHolder;
import jp.ngt.ngtlib.block.BlockContainerCustomWithMeta;
import jp.ngt.ngtlib.block.BlockUtil;
import jp.ngt.ngtlib.math.NGTMath;
@@ -124,10 +124,11 @@
public void makeRailMap(TileEntityMarker marker, int x, int y, int z) {
this.onMarkerActivated(marker.getWorld(), x, y, z, (EntityPlayer)null, false);
Expand All @@ -12,3 +24,52 @@
return false;
} else {
boolean flag = player == null || player.capabilities.isCreativeMode;
@@ -140,37 +141,27 @@
return createRail(world, x, y, z, list, resourcestaterail, makeRail, flag);
}
}

private List<RailPosition> searchAllMarker(World world, int x, int y, int z) {
- List<RailPosition> list = new ArrayList<RailPosition>();
int i = RTMCore.railGeneratingDistance;
int j = i * 2;
+ int dis3 = j * j;
int k = RTMCore.railGeneratingHeight;
int l = k * 2;

- for(int i1 = 0; i1 < j; ++i1) {
- for(int j1 = 0; j1 < l; ++j1) {
- for(int k1 = 0; k1 < j; ++k1) {
- int l1 = x - i + i1;
- int i2 = y - k + j1;
- int j2 = z - i + k1;
- RailPosition railposition = this.getRailPosition(world, l1, i2, j2);
- if (railposition != null) {
- list.add(railposition);
- }
- }
- }
- }
+ List<RailPosition> list = world.loadedTileEntityList.stream()
+ .filter(TileEntityMarker.class::isInstance)
+ .map(TileEntityMarker.class::cast)
+ .filter(tile -> tile.getPos().distanceSqToCenter(x, tile.getY(), z) < dis3)
+ .filter(tile -> Math.abs(tile.getY() - y) < k)
+ .map(TileEntityMarker::getMarkerRP)
+ .sorted(java.util.Comparator.<RailPosition>comparingInt(v -> v.switchType)
+ .thenComparingInt(v -> v.blockY)
+ .thenComparingInt(Object::hashCode))
+ .collect(Collectors.toList());

- list.sort((arg0, arg1) -> {
- if (arg0.switchType != arg1.switchType) {
- return arg1.switchType - arg0.switchType;
- } else {
- return arg0.blockY != arg1.blockY ? arg0.blockY - arg1.blockY : arg0.hashCode() - arg1.hashCode();
- }
- });
return list;
}

public static boolean createRail(World world, int x, int y, int z, List<RailPosition> rps, ResourceStateRail state, boolean makeRail, boolean isCreative) {
if (rps.size() == 2) {