From cd6923a6bd929b4428dd2234b3f4af9ee17da535 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Fri, 9 Jul 2021 22:03:06 +0900 Subject: [PATCH] use loadedTileEntity list ports Kai-Z-JP/KaizPatchX@318b9ee4809564b0ccb93f1337307d69de505d80 --- .../jp/ngt/rtm/rail/BlockMarker.java.pm.patch | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/main/rtm-patches/jp/ngt/rtm/rail/BlockMarker.java.pm.patch b/src/main/rtm-patches/jp/ngt/rtm/rail/BlockMarker.java.pm.patch index 982bb87b..273305c0 100644 --- a/src/main/rtm-patches/jp/ngt/rtm/rail/BlockMarker.java.pm.patch +++ b/src/main/rtm-patches/jp/ngt/rtm/rail/BlockMarker.java.pm.patch @@ -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); @@ -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 searchAllMarker(World world, int x, int y, int z) { +- List list = new ArrayList(); + 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 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.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 rps, ResourceStateRail state, boolean makeRail, boolean isCreative) { + if (rps.size() == 2) {