9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2025-12-29 11:59:17 +00:00

Return nether portal fix (maybe can use)

This commit is contained in:
violetc
2023-01-24 12:39:52 +08:00
parent 4659bdffaf
commit aa70eb4f9e
6 changed files with 315 additions and 11 deletions

View File

@@ -30,6 +30,49 @@ index 46954db7ecd35ac4018fdf476df7c8020d7ce6c8..044c51ebb058fc36074fd178929e3279
public PlayerAreaMap() {
super();
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 1eaab1f6923e6aa34b643293347348e5cc19af3c..15f850f9ae1d4e45c445c5301cb167eda0287e2c 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -398,6 +398,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
private UUID originWorld;
public boolean freezeLocked = false; // Paper - Freeze Tick Lock API
public boolean collidingWithWorldBorder; // Paper
+ private CompoundTag leavesData = new CompoundTag(); // Leaves - Leaves ex data
public void setOrigin(@javax.annotation.Nonnull Location location) {
this.origin = location.toVector();
@@ -2292,6 +2293,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
nbt.putBoolean("Paper.FreezeLock", true);
}
// Paper end
+ nbt.put("Leaves.Data", leavesData); // Leaves - leaves ex data
return nbt;
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT");
@@ -2459,6 +2461,11 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
freezeLocked = nbt.getBoolean("Paper.FreezeLock");
}
// Paper end
+ // Leaves start - leaves ex data
+ if (nbt.contains("Leaves.Data")) {
+ leavesData = nbt.getCompound("Leaves.Data");
+ }
+ // Leaves start - leaves ex data
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Loading entity NBT");
@@ -4551,4 +4558,10 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
return ((net.minecraft.server.level.ServerChunkCache) level.getChunkSource()).isPositionTicking(this);
}
// Paper end
+
+ // Leaves start - leaves ex data
+ public CompoundTag getLeavesData() {
+ return leavesData;
+ }
+ // Leaves end - leaves ex data
}
diff --git a/src/main/java/top/leavesmc/leaves/LeavesLogger.java b/src/main/java/top/leavesmc/leaves/LeavesLogger.java
new file mode 100644
index 0000000000000000000000000000000000000000..890b91a95719f18a75bc2c2176ef5cb9f2bf4274

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Fix gravity block duper
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 7555b04dcf274bb624b89f2eb9ff80da0056de4e..6c7a3432eed5a6dea56bf414d7d6ce1aff3acda7 100644
index 15f850f9ae1d4e45c445c5301cb167eda0287e2c..43873929f11e373186190b3ae831dc68bfa69616 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -511,36 +511,8 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
@@ -512,36 +512,8 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
return chunkMap.playerEntityTrackerTrackMaps[type.ordinal()].getObjectsInRange(MCUtil.getCoordinateKey(this));
}
// Paper end - optimise entity tracking
@@ -46,7 +46,7 @@ index 7555b04dcf274bb624b89f2eb9ff80da0056de4e..6c7a3432eed5a6dea56bf414d7d6ce1a
public Entity(EntityType<?> type, Level world) {
this.id = Entity.ENTITY_COUNTER.incrementAndGet();
@@ -2927,7 +2899,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
@@ -2934,7 +2906,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
}
this.processPortalCooldown();
@@ -56,7 +56,7 @@ index 7555b04dcf274bb624b89f2eb9ff80da0056de4e..6c7a3432eed5a6dea56bf414d7d6ce1a
}
diff --git a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
index 72f1866226269396ba0f0c1be269e237925d9322..f7585c4cbe9b22b6ddfe928763314e1f7af711c4 100644
index eacb8a407fe99af2c13f23c12b5544696bda8890..169a93fe103fb795b6c8b49bb8c19b8643132316 100644
--- a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
+++ b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
@@ -63,7 +63,7 @@ public class FallingBlockEntity extends Entity {

View File

@@ -6,10 +6,10 @@ Subject: [PATCH] Reduce entity allocations
This patch is Powered by Pufferfish(https://github.com/pufferfish-gg/Pufferfish)
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index a4f32bb4d474c97e9b924e1d275f640ddfedc31f..fdd166d99e80c56ba317596e2e50960aae7b87a2 100644
index 2433315c13e2da90f4f208d180d487c984a087ea..818952b1268688cf13a8ab22d38f05336bf740ad 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -414,6 +414,8 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
@@ -415,6 +415,8 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
return this.originWorld;
}
// Paper end

View File

@@ -6,10 +6,10 @@ Subject: [PATCH] Remove streams from getting nearby players
This patch is Powered by Pufferfish(https://github.com/pufferfish-gg/Pufferfish)
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index fdd166d99e80c56ba317596e2e50960aae7b87a2..ebf7b1a91c0882f61696a16bf4dc5adf62072033 100644
index 818952b1268688cf13a8ab22d38f05336bf740ad..c55eb9ef7217405c35661dbe03ae6be8f28576e9 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -490,25 +490,50 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
@@ -491,25 +491,50 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
this.isLegacyTrackingEntity = isLegacyTrackingEntity;
}

View File

@@ -6,10 +6,10 @@ Subject: [PATCH] Reduce entity fluid lookups if no fluids
This patch is Powered by Pufferfish(https://github.com/pufferfish-gg/Pufferfish)
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index ebf7b1a91c0882f61696a16bf4dc5adf62072033..fa9ec5f51ed7762677d3bcee9f727cb9db902fb0 100644
index c55eb9ef7217405c35661dbe03ae6be8f28576e9..78a0b3c00860a8433fe0e4b27e51fdd683793c2e 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -4091,16 +4091,18 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
@@ -4098,16 +4098,18 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
}
public boolean updateFluidHeightAndDoFluidPushing(TagKey<Fluid> tag, double speed) {
@@ -35,7 +35,7 @@ index ebf7b1a91c0882f61696a16bf4dc5adf62072033..fa9ec5f51ed7762677d3bcee9f727cb9
double d1 = 0.0D;
boolean flag = this.isPushedByFluid();
boolean flag1 = false;
@@ -4108,38 +4110,123 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
@@ -4115,38 +4117,123 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
int k1 = 0;
BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos();

View File

@@ -0,0 +1,261 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <58360096+s-yh-china@users.noreply.github.com>
Date: Tue, 24 Jan 2023 12:38:42 +0800
Subject: [PATCH] Return nether portal fix
This patch is powered by NetherPortalFix(https://github.com/TwelveIterationMods/NetherPortalFix)
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index fb3f205ca2d462e492ca74218a69c5b9923dfdbb..372beee61e982998a255a69ae1958ff021313529 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -177,6 +177,7 @@ import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.inventory.MainHand;
import top.leavesmc.leaves.bot.ServerBot;
+import top.leavesmc.leaves.util.ReturnPortalManager;
// CraftBukkit end
public class ServerPlayer extends Player {
@@ -1226,6 +1227,24 @@ public class ServerPlayer extends Player {
PlayerChangedWorldEvent changeEvent = new PlayerChangedWorldEvent(this.getBukkitEntity(), worldserver1.getWorld());
this.level.getCraftServer().getPluginManager().callEvent(changeEvent);
// CraftBukkit end
+ // Leaves start - nether portal fix
+ if (top.leavesmc.leaves.LeavesConfig.netherPortalFix) {
+ final ResourceKey<Level> fromDim = worldserver1.dimension();
+ final ResourceKey<Level> toDim = getLevel().dimension();
+ final ResourceKey<Level> OVERWORLD = Level.OVERWORLD;
+ final ResourceKey<Level> THE_NETHER = Level.NETHER;
+ if (!((fromDim != OVERWORLD || toDim != THE_NETHER) && (fromDim != THE_NETHER || toDim != OVERWORLD))) {
+ BlockPos lastPos = this.lastPos;
+ if (lastPos != null) {
+ BlockUtil.FoundRectangle fromPortal = ReturnPortalManager.findPortalAt(this, fromDim, lastPos);
+ BlockPos toPos = this.blockPosition();
+ if (fromPortal != null) {
+ ReturnPortalManager.storeReturnPortal(this, toDim, toPos, fromPortal);
+ }
+ }
+ }
+ }
+ // Leaves end - nether portal fix
}
// Paper start
if (this.isBlocking()) {
@@ -1278,6 +1297,30 @@ public class ServerPlayer extends Player {
protected Optional<BlockUtil.FoundRectangle> getExitPortal(ServerLevel worldserver, BlockPos blockposition, boolean flag, WorldBorder worldborder, int searchRadius, boolean canCreatePortal, int createRadius) { // CraftBukkit
Optional<BlockUtil.FoundRectangle> optional = super.getExitPortal(worldserver, blockposition, flag, worldborder, searchRadius, canCreatePortal, createRadius); // CraftBukkit
+ // Leaves start - nether portal fix
+ if (top.leavesmc.leaves.LeavesConfig.netherPortalFix) {
+ BlockPos fromPos = blockPosition();
+ final ResourceKey<Level> fromDim = level.dimension();
+ final ResourceKey<Level> toDim = level.dimension();
+ final ResourceKey<Level> OVERWORLD = Level.OVERWORLD;
+ final ResourceKey<Level> THE_NETHER = Level.NETHER;
+ boolean isTeleportBetweenNetherAndOverworld = (fromDim == OVERWORLD && toDim == THE_NETHER)
+ || (fromDim == THE_NETHER && toDim == OVERWORLD);
+ if (isInsidePortal && isTeleportBetweenNetherAndOverworld) {
+ ReturnPortalManager.ReturnPortal returnPortal = ReturnPortalManager.findReturnPortal(this, fromDim, fromPos);
+ if (returnPortal != null) {
+ MinecraftServer server = getServer();
+ if (server != null) {
+ Level toLevel = server.getLevel(toDim);
+ if (toLevel != null) {
+ return Optional.of(returnPortal.rectangle());
+ }
+ }
+ }
+ }
+ }
+ // Leaves end - nether portal fix
+
if (optional.isPresent() || !canCreatePortal) { // CraftBukkit
return optional;
} else {
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index 428eb52ba1e8055e27e9154c7f39977d914d7be0..9bd0c11901aa88e9bf5a036711647e1131d995fa 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -27,6 +27,8 @@ import java.util.UUID;
import java.util.function.Function;
import java.util.function.Predicate;
import javax.annotation.Nullable;
+
+import net.minecraft.BlockUtil;
import net.minecraft.ChatFormatting;
import net.minecraft.FileUtil;
import net.minecraft.commands.CommandSourceStack;
@@ -125,6 +127,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
+import top.leavesmc.leaves.util.ReturnPortalManager;
// CraftBukkit end
public abstract class PlayerList {
@@ -957,6 +960,24 @@ public abstract class PlayerList {
if (fromWorld != location.getWorld()) {
PlayerChangedWorldEvent event = new PlayerChangedWorldEvent(entityplayer.getBukkitEntity(), fromWorld);
server.server.getPluginManager().callEvent(event);
+ // Leaves start - nether portal fix
+ if (top.leavesmc.leaves.LeavesConfig.netherPortalFix) {
+ final ResourceKey<Level> fromDim = entityplayer.getLevel().dimension();
+ final ResourceKey<Level> toDim = entityplayer1.getLevel().dimension();
+ final ResourceKey<Level> OVERWORLD = Level.OVERWORLD;
+ final ResourceKey<Level> THE_NETHER = Level.NETHER;
+ if (!((fromDim != OVERWORLD || toDim != THE_NETHER) && (fromDim != THE_NETHER || toDim != OVERWORLD))) {
+ BlockPos lastPos = entityplayer1.lastPos;
+ if (lastPos != null) {
+ BlockUtil.FoundRectangle fromPortal = ReturnPortalManager.findPortalAt(entityplayer1, fromDim, lastPos);
+ BlockPos toPos = entityplayer1.blockPosition();
+ if (fromPortal != null) {
+ ReturnPortalManager.storeReturnPortal(entityplayer1, toDim, toPos, fromPortal);
+ }
+ }
+ }
+ }
+ // Leaves end - nether portal fix
}
// Save player file again if they were disconnected
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 7647b8bb3117d005dd616b29e7310f8328973b7f..eaeac639924098b86da57e2a87efc2afb9e0d439 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -245,7 +245,7 @@ public abstract class LivingEntity extends Entity {
protected ItemStack useItem;
protected int useItemRemaining;
protected int fallFlyTicks;
- private BlockPos lastPos;
+ public BlockPos lastPos; // Leaves - private -> public
private Optional<BlockPos> lastClimbablePos;
@Nullable
private DamageSource lastDamageSource;
diff --git a/src/main/java/top/leavesmc/leaves/LeavesConfig.java b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
index fdca60bb67c1ab574b3623ea83872608ade6951f..17ffd0ae638f44b1bcf945640e430e9b753ba3f9 100644
--- a/src/main/java/top/leavesmc/leaves/LeavesConfig.java
+++ b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
@@ -466,6 +466,11 @@ public final class LeavesConfig {
doMcTechnicalMode(mcTechnicalMode);
}
+ public static boolean netherPortalFix = false;
+ private static void netherPortalFix() {
+ netherPortalFix = getBoolean("settings.modify.return-nether-portal-fix", netherPortalFix);
+ }
+
private static void doMcTechnicalMode(boolean is) {
if (is) {
GlobalConfiguration.get().unsupportedSettings.allowPistonDuplication = true;
diff --git a/src/main/java/top/leavesmc/leaves/util/ReturnPortalManager.java b/src/main/java/top/leavesmc/leaves/util/ReturnPortalManager.java
new file mode 100644
index 0000000000000000000000000000000000000000..f0452ad7adb8d2a52f7bfe239765dfbca6ba2523
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/util/ReturnPortalManager.java
@@ -0,0 +1,105 @@
+package top.leavesmc.leaves.util;
+
+import net.minecraft.BlockUtil;
+import net.minecraft.core.BlockPos;
+import net.minecraft.core.registries.Registries;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.nbt.ListTag;
+import net.minecraft.nbt.Tag;
+import net.minecraft.resources.ResourceKey;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.server.level.ServerLevel;
+import net.minecraft.server.level.ServerPlayer;
+import net.minecraft.world.entity.player.Player;
+import net.minecraft.world.level.Level;
+import net.minecraft.world.level.portal.PortalForcer;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.UUID;
+
+// Powered by NetherPortalFix(https://github.com/TwelveIterationMods/NetherPortalFix)
+public class ReturnPortalManager {
+
+ private static final int MAX_PORTAL_DISTANCE_SQ = 16;
+ private static final String RETURN_PORTAL_LIST = "ReturnPortalList";
+ private static final String RETURN_PORTAL_UID = "UID";
+ private static final String FROM_DIM = "FromDim";
+ private static final String FROM_POS = "FromPos";
+ private static final String TO_MIN_CORNER = "ToMinCorner";
+ private static final String TO_AXIS_1_SIZE = "ToAxis1Size";
+ private static final String TO_AXIS_2_SIZE = "ToAxis2Size";
+
+ public static BlockUtil.FoundRectangle findPortalAt(Player player, ResourceKey<Level> dim, BlockPos pos) {
+ MinecraftServer server = player.level.getServer();
+ if (server != null) {
+ ServerLevel fromWorld = server.getLevel(dim);
+ if (fromWorld != null) {
+ PortalForcer portalForcer = fromWorld.getPortalForcer();
+ return portalForcer.findPortalAround(pos, false, fromWorld.getWorldBorder()).orElse(null);
+ }
+ }
+
+ return null;
+ }
+
+ public static ListTag getPlayerPortalList(Player player) {
+ CompoundTag data = player.getLeavesData();
+ ListTag list = data.getList(RETURN_PORTAL_LIST, Tag.TAG_COMPOUND);
+ data.put(RETURN_PORTAL_LIST, list);
+ return list;
+ }
+
+ @Nullable
+ public static ReturnPortal findReturnPortal(ServerPlayer player, ResourceKey<Level> fromDim, BlockPos fromPos) {
+ ListTag portalList = getPlayerPortalList(player);
+ for (Tag entry : portalList) {
+ CompoundTag portal = (CompoundTag) entry;
+ ResourceKey<Level> entryFromDim = ResourceKey.create(Registries.DIMENSION, new ResourceLocation(portal.getString(FROM_DIM)));
+ if (entryFromDim == fromDim) {
+ BlockPos portalTrigger = BlockPos.of(portal.getLong(FROM_POS));
+ if (portalTrigger.distSqr(fromPos) <= MAX_PORTAL_DISTANCE_SQ) {
+ UUID uid = portal.hasUUID(RETURN_PORTAL_UID) ? portal.getUUID(RETURN_PORTAL_UID) : UUID.randomUUID();
+ BlockPos minCorner = BlockPos.of(portal.getLong(TO_MIN_CORNER));
+ int axis1Size = portal.getInt(TO_AXIS_1_SIZE);
+ int axis2Size = portal.getInt(TO_AXIS_2_SIZE);
+ return new ReturnPortal(uid, new BlockUtil.FoundRectangle(minCorner, axis1Size, axis2Size));
+ }
+ }
+ }
+
+ return null;
+ }
+
+ public static void storeReturnPortal(ServerPlayer player, ResourceKey<Level> fromDim, BlockPos fromPos, BlockUtil.FoundRectangle toPortal) {
+ ListTag portalList = getPlayerPortalList(player);
+ ReturnPortal returnPortal = findReturnPortal(player, fromDim, fromPos);
+ if (returnPortal != null) {
+ removeReturnPortal(player, returnPortal);
+ }
+
+ CompoundTag portalCompound = new CompoundTag();
+ portalCompound.putUUID(RETURN_PORTAL_UID, UUID.randomUUID());
+ portalCompound.putString(FROM_DIM, String.valueOf(fromDim.location()));
+ portalCompound.putLong(FROM_POS, fromPos.asLong());
+ portalCompound.putLong(TO_MIN_CORNER, toPortal.minCorner.asLong());
+ portalCompound.putInt(TO_AXIS_1_SIZE, toPortal.axis1Size);
+ portalCompound.putInt(TO_AXIS_2_SIZE, toPortal.axis2Size);
+ portalList.add(portalCompound);
+ }
+
+ public static void removeReturnPortal(ServerPlayer player, ReturnPortal portal) {
+ // This doesn't check if it's the right toDim, but it's probably so rare for positions to actually overlap that I don't care
+ ListTag portalList = getPlayerPortalList(player);
+ for (int i = 0; i < portalList.size(); i++) {
+ CompoundTag entry = (CompoundTag) portalList.get(i);
+ if (entry.hasUUID(RETURN_PORTAL_UID) && entry.getUUID(RETURN_PORTAL_UID).equals(portal.uid())) {
+ portalList.remove(i);
+ break;
+ }
+ }
+ }
+
+ public record ReturnPortal(UUID uid, BlockUtil.FoundRectangle rectangle) {
+ }
+}