From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Patrick Hemmer Date: Tue, 11 Aug 2020 22:11:53 +0300 Subject: [PATCH] Use block distance in portal search radius Original author: Patrick Hemmer Previously when searching for a portal, the server would use the search radius to determine which chunks it needs to search, and then would consider any portal within those chunks as a match, even if it is outside the search radius. This changes it so that the portal list is filtered to only include portals within the configured search radius (ignoring the Y coordinate). Ported to Yatopia and added per world config option by MrIvanPlays diff --git a/src/main/java/de/minebench/origami/OrigamiConfig.java b/src/main/java/de/minebench/origami/OrigamiConfig.java index 7fc45446218ee6a31abca2e16d192efff5e4aaf9..39b9372eee675b4d9ec0f41d72f149aa160cbb04 100644 --- a/src/main/java/de/minebench/origami/OrigamiConfig.java +++ b/src/main/java/de/minebench/origami/OrigamiConfig.java @@ -172,6 +172,11 @@ public final class OrigamiConfig { && pillagerCollisions && ironGolemCollisions && miscCollisions && itemCollisions && waterCreatureCollisions && waterAmbientCollisions; } + + public boolean useBlockDistanceInPortalSearchRadius = false; + private void useBlockDistanceInPortalSearchRadius() { + useBlockDistanceInPortalSearchRadius = getBoolean("use-block-distance-in-portal-search-radius", false); + } // Yatopia end } diff --git a/src/main/java/net/minecraft/server/PortalTravelAgent.java b/src/main/java/net/minecraft/server/PortalTravelAgent.java index 6b2465bfe540af5d609160e6d232564b1d6c0617..3c6fb2dfd4d7e8951ea5e0b93eb5b28d2078f51b 100644 --- a/src/main/java/net/minecraft/server/PortalTravelAgent.java +++ b/src/main/java/net/minecraft/server/PortalTravelAgent.java @@ -29,6 +29,15 @@ public class PortalTravelAgent { return villageplacerecord.f().getY(); }); java.util.List list = villageplace.b(type -> type == VillagePlaceType.v, blockposition, i, VillagePlace.Occupancy.ANY).collect(java.util.stream.Collectors.toList()); + // Yatopia start - fix portal bug + if (world.origamiConfig.useBlockDistanceInPortalSearchRadius) { + list.removeIf(villagePlaceRecord -> { + BlockPosition portalPosition = villagePlaceRecord.getPosition(); + return Math.abs(portalPosition.getX() - blockposition.getX()) > i + || Math.abs(portalPosition.getZ() - blockposition.getZ()) > i; + }); + } + // Yatopia end Optional optional = Optional.empty(); if (!list.isEmpty()) { list.sort(comparator);