mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
1. Wet the drys 2. Dry the wets 3. Wet the drys 4. Dry the wets 5. Wet the drys 6. Now dust the wets
214 lines
11 KiB
Diff
214 lines
11 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
|
|
Date: Wed, 23 Oct 2024 23:54:00 +0800
|
|
Subject: [PATCH] Asynchronous locator
|
|
|
|
Original license: MIT
|
|
Original project: https://github.com/thebrightspark/AsyncLocator
|
|
|
|
diff --git a/net/minecraft/server/commands/LocateCommand.java b/net/minecraft/server/commands/LocateCommand.java
|
|
index 13bcd8653d766cd0b754a22e9aab261fbc62b0a5..e3e7c4e4da0bc95b015bb84e470477782bdb691c 100644
|
|
--- a/net/minecraft/server/commands/LocateCommand.java
|
|
+++ b/net/minecraft/server/commands/LocateCommand.java
|
|
@@ -109,6 +109,38 @@ public class LocateCommand {
|
|
BlockPos blockPos = BlockPos.containing(source.getPosition());
|
|
ServerLevel level = source.getLevel();
|
|
Stopwatch stopwatch = Stopwatch.createStarted(Util.TICKER);
|
|
+ // Leaf start - Asynchronous locator
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncLocator.enabled) {
|
|
+ net.minecraft.commands.CommandSource locatorSource = source.source;
|
|
+ if (locatorSource instanceof net.minecraft.server.level.ServerPlayer || locatorSource instanceof net.minecraft.server.MinecraftServer) {
|
|
+ BlockPos originPos = BlockPos.containing(source.getPosition());
|
|
+
|
|
+ org.dreeam.leaf.async.locate.AsyncLocator.locate(source.getLevel(), holderSet, originPos, 100, false)
|
|
+ .thenOnServerThread(pair -> {
|
|
+ stopwatch.stop();
|
|
+ if (pair != null) {
|
|
+ showLocateResult(
|
|
+ source,
|
|
+ structure,
|
|
+ originPos,
|
|
+ pair,
|
|
+ "commands.locate.structure.success",
|
|
+ false,
|
|
+ stopwatch.elapsed()
|
|
+ );
|
|
+ } else {
|
|
+ source.sendFailure(
|
|
+ Component.literal(
|
|
+ ERROR_STRUCTURE_NOT_FOUND.create(structure.asPrintable()).getMessage()
|
|
+ )
|
|
+ );
|
|
+ }
|
|
+ });
|
|
+
|
|
+ return 0;
|
|
+ }
|
|
+ }
|
|
+ // Leaf end - Asynchronous locator
|
|
Pair<BlockPos, Holder<Structure>> pair = level.getChunkSource().getGenerator().findNearestMapStructure(level, holderSet, blockPos, 100, false);
|
|
stopwatch.stop();
|
|
if (pair == null) {
|
|
diff --git a/net/minecraft/world/entity/animal/Dolphin.java b/net/minecraft/world/entity/animal/Dolphin.java
|
|
index 7003b532182737a745491e397a967b72e6b308aa..3ed9652510976770f5661dd7b317f27f046700d4 100644
|
|
--- a/net/minecraft/world/entity/animal/Dolphin.java
|
|
+++ b/net/minecraft/world/entity/animal/Dolphin.java
|
|
@@ -500,6 +500,10 @@ public class Dolphin extends AgeableWaterCreature {
|
|
static class DolphinSwimToTreasureGoal extends Goal {
|
|
private final Dolphin dolphin;
|
|
private boolean stuck;
|
|
+ // Leaf start - Asynchronous locator
|
|
+ @Nullable
|
|
+ private org.dreeam.leaf.async.locate.AsyncLocator.LocateTask<?> asyncLocator$locateTask;
|
|
+ // Leaf end - Asynchronous locator
|
|
|
|
DolphinSwimToTreasureGoal(Dolphin dolphin) {
|
|
this.dolphin = dolphin;
|
|
@@ -519,6 +523,11 @@ public class Dolphin extends AgeableWaterCreature {
|
|
|
|
@Override
|
|
public boolean canContinueToUse() {
|
|
+ // Leaf start - Asynchronous locator
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncLocator.enabled && this.asyncLocator$locateTask != null) {
|
|
+ return true;
|
|
+ }
|
|
+ // Leaf end - Asynchronous locator
|
|
BlockPos treasurePos = this.dolphin.getTreasurePos();
|
|
return !BlockPos.containing(treasurePos.getX(), this.dolphin.getY(), treasurePos.getZ()).closerToCenterThan(this.dolphin.position(), 4.0)
|
|
&& !this.stuck
|
|
@@ -532,6 +541,22 @@ public class Dolphin extends AgeableWaterCreature {
|
|
this.stuck = false;
|
|
this.dolphin.getNavigation().stop();
|
|
BlockPos blockPos = this.dolphin.blockPosition();
|
|
+ // Leaf start - Asynchronous locator
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncLocator.enabled) {
|
|
+ asyncLocator$locateTask = org.dreeam.leaf.async.locate.AsyncLocator.locate(serverLevel, StructureTags.DOLPHIN_LOCATED, blockPos, 50, false)
|
|
+ .thenOnServerThread(pos -> {
|
|
+ asyncLocator$locateTask = null;
|
|
+ if (pos != null) {
|
|
+ this.dolphin.setTreasurePos(pos);
|
|
+ serverLevel.broadcastEntityEvent(this.dolphin, (byte) 38);
|
|
+ } else {
|
|
+ this.stuck = true;
|
|
+ }
|
|
+ });
|
|
+
|
|
+ return;
|
|
+ }
|
|
+ // Leaf end - Asynchronous locator
|
|
BlockPos blockPos1 = serverLevel.findNearestMapStructure(StructureTags.DOLPHIN_LOCATED, blockPos, 50, false);
|
|
if (blockPos1 != null) {
|
|
this.dolphin.setTreasurePos(blockPos1);
|
|
@@ -544,6 +569,12 @@ public class Dolphin extends AgeableWaterCreature {
|
|
|
|
@Override
|
|
public void stop() {
|
|
+ // Leaf start - Asynchronous locator
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncLocator.enabled && this.asyncLocator$locateTask != null) {
|
|
+ this.asyncLocator$locateTask.cancel();
|
|
+ this.asyncLocator$locateTask = null;
|
|
+ }
|
|
+ // Leaf end - Asynchronous locator
|
|
BlockPos treasurePos = this.dolphin.getTreasurePos();
|
|
if (BlockPos.containing(treasurePos.getX(), this.dolphin.getY(), treasurePos.getZ()).closerToCenterThan(this.dolphin.position(), 4.0) || this.stuck
|
|
)
|
|
@@ -554,6 +585,11 @@ public class Dolphin extends AgeableWaterCreature {
|
|
|
|
@Override
|
|
public void tick() {
|
|
+ // Leaf start - Asynchronous locator
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncLocator.enabled && this.asyncLocator$locateTask != null) {
|
|
+ return;
|
|
+ }
|
|
+ // Leaf end - Asynchronous locator
|
|
Level level = this.dolphin.level();
|
|
if (this.dolphin.closeToNextPos() || this.dolphin.getNavigation().isDone()) {
|
|
Vec3 vec3 = Vec3.atCenterOf(this.dolphin.getTreasurePos());
|
|
diff --git a/net/minecraft/world/entity/projectile/EyeOfEnder.java b/net/minecraft/world/entity/projectile/EyeOfEnder.java
|
|
index 01a9bad80a30a7879a69b800258b616b4d986108..d4f49e40461a165ebd6635e9fec8fe56d7f1acf6 100644
|
|
--- a/net/minecraft/world/entity/projectile/EyeOfEnder.java
|
|
+++ b/net/minecraft/world/entity/projectile/EyeOfEnder.java
|
|
@@ -26,6 +26,7 @@ public class EyeOfEnder extends Entity implements ItemSupplier {
|
|
public double tz;
|
|
public int life;
|
|
public boolean surviveAfterDeath;
|
|
+ public boolean asyncLocator$locateTaskOngoing = false; // Leaf - Asynchronous locator
|
|
|
|
public EyeOfEnder(EntityType<? extends EyeOfEnder> entityType, Level level) {
|
|
super(entityType, level);
|
|
@@ -112,6 +113,11 @@ public class EyeOfEnder extends Entity implements ItemSupplier {
|
|
@Override
|
|
public void tick() {
|
|
super.tick();
|
|
+ // Leaf start - Asynchronous locator
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncLocator.enabled && this.asyncLocator$locateTaskOngoing) {
|
|
+ return;
|
|
+ }
|
|
+ // Leaf end - Asynchronous locator
|
|
Vec3 deltaMovement = this.getDeltaMovement();
|
|
double d = this.getX() + deltaMovement.x;
|
|
double d1 = this.getY() + deltaMovement.y;
|
|
diff --git a/net/minecraft/world/item/EnderEyeItem.java b/net/minecraft/world/item/EnderEyeItem.java
|
|
index 02f2c38b5f9a503097dea44d5c79518b03b63f9a..a7aa09d7c9d5f95706349e426cd54a79e963c6f9 100644
|
|
--- a/net/minecraft/world/item/EnderEyeItem.java
|
|
+++ b/net/minecraft/world/item/EnderEyeItem.java
|
|
@@ -103,14 +103,47 @@ public class EnderEyeItem extends Item {
|
|
} else {
|
|
player.startUsingItem(hand);
|
|
if (level instanceof ServerLevel serverLevel) {
|
|
- BlockPos blockPos = serverLevel.findNearestMapStructure(StructureTags.EYE_OF_ENDER_LOCATED, player.blockPosition(), 100, false);
|
|
+ // Leaf start - Asynchronous locator
|
|
+ BlockPos blockPos;
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncLocator.enabled) {
|
|
+ blockPos = BlockPos.ZERO;
|
|
+ } else {
|
|
+ blockPos = serverLevel.findNearestMapStructure(StructureTags.EYE_OF_ENDER_LOCATED, player.blockPosition(), 100, false);
|
|
+ }
|
|
+ // Leaf end - Asynchronous locator
|
|
if (blockPos == null) {
|
|
return InteractionResult.CONSUME;
|
|
}
|
|
|
|
EyeOfEnder eyeOfEnder = new EyeOfEnder(level, player.getX(), player.getY(0.5), player.getZ());
|
|
+
|
|
+ // Leaf start - Asynchronous locator
|
|
+ final boolean isAsyncLocatorEnabled = org.dreeam.leaf.config.modules.async.AsyncLocator.enabled;
|
|
+
|
|
+ if (isAsyncLocatorEnabled) {
|
|
+ eyeOfEnder.asyncLocator$locateTaskOngoing = true;
|
|
+ org.dreeam.leaf.async.locate.AsyncLocator.locate(
|
|
+ serverLevel,
|
|
+ StructureTags.EYE_OF_ENDER_LOCATED,
|
|
+ player.blockPosition(),
|
|
+ 100,
|
|
+ false
|
|
+ ).thenOnServerThread(pos -> {
|
|
+ eyeOfEnder.asyncLocator$locateTaskOngoing = false;
|
|
+ if (pos != null) {
|
|
+ eyeOfEnder.signalTo(pos);
|
|
+ CriteriaTriggers.USED_ENDER_EYE.trigger((ServerPlayer) player, pos);
|
|
+ player.awardStat(Stats.ITEM_USED.get(this));
|
|
+ } else {
|
|
+ // Set the entity's life to long enough that it dies
|
|
+ eyeOfEnder.life = Integer.MAX_VALUE - 100;
|
|
+ }
|
|
+ });
|
|
+ }
|
|
+ // Leaf end - Asynchronous locator
|
|
+
|
|
eyeOfEnder.setItem(itemInHand);
|
|
- eyeOfEnder.signalTo(blockPos);
|
|
+ if (!isAsyncLocatorEnabled) eyeOfEnder.signalTo(blockPos); // Leaf - Asynchronous locator
|
|
level.gameEvent(GameEvent.PROJECTILE_SHOOT, eyeOfEnder.position(), GameEvent.Context.of(player));
|
|
// CraftBukkit start
|
|
if (!level.addFreshEntity(eyeOfEnder)) {
|
|
@@ -124,7 +157,7 @@ public class EnderEyeItem extends Item {
|
|
float f = Mth.lerp(level.random.nextFloat(), 0.33F, 0.5F);
|
|
level.playSound(null, player.getX(), player.getY(), player.getZ(), SoundEvents.ENDER_EYE_LAUNCH, SoundSource.NEUTRAL, 1.0F, f);
|
|
itemInHand.consume(1, player);
|
|
- player.awardStat(Stats.ITEM_USED.get(this));
|
|
+ if (!isAsyncLocatorEnabled) player.awardStat(Stats.ITEM_USED.get(this)); // Leaf - Asynchronous locator
|
|
}
|
|
|
|
return InteractionResult.SUCCESS_SERVER;
|