9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-23 17:09:29 +00:00
Files
Leaf/patches/server/0022-Petal-Reduce-sensor-work.patch
2023-07-17 08:44:45 +08:00

61 lines
3.5 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: peaches94 <peachescu94@gmail.com>
Date: Sun, 10 Jul 2022 15:44:38 -0500
Subject: [PATCH] Petal: Reduce sensor work
Original license: GPL v3
Original project: https://github.com/Bloom-host/Petal
this patch is focused around the sensors used for ai
delete the line of sight cache less often and use a faster nearby comparison
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index fe493fd87d8435035d17dae59d4ad2645feedfa3..dbe3948a2d1e33e55f628f50d2900cb5f2dcb592 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -1036,22 +1036,24 @@ public abstract class LivingEntity extends Entity implements Attackable {
}
if (entity != null) {
- ItemStack itemstack = this.getItemBySlot(EquipmentSlot.HEAD);
+ // petal start - only do itemstack lookup if we need to
+ //ItemStack itemstack = this.getItemBySlot(EquipmentSlot.HEAD);
EntityType<?> entitytypes = entity.getType();
// Purpur start
- if (entitytypes == EntityType.SKELETON && itemstack.is(Items.SKELETON_SKULL)) {
+ if (entitytypes == EntityType.SKELETON && this.getItemBySlot(EquipmentSlot.HEAD).is(Items.SKELETON_SKULL)) {
d0 *= entity.level().purpurConfig.skeletonHeadVisibilityPercent;
}
- else if (entitytypes == EntityType.ZOMBIE && itemstack.is(Items.ZOMBIE_HEAD)) {
+ else if (entitytypes == EntityType.ZOMBIE && this.getItemBySlot(EquipmentSlot.HEAD).is(Items.ZOMBIE_HEAD)) {
d0 *= entity.level().purpurConfig.zombieHeadVisibilityPercent;
}
- else if (entitytypes == EntityType.CREEPER && itemstack.is(Items.CREEPER_HEAD)) {
+ else if (entitytypes == EntityType.CREEPER && this.getItemBySlot(EquipmentSlot.HEAD).is(Items.CREEPER_HEAD)) {
d0 *= entity.level().purpurConfig.creeperHeadVisibilityPercent;
}
- else if ((entitytypes == EntityType.PIGLIN || entitytypes == EntityType.PIGLIN_BRUTE) && itemstack.is(Items.PIGLIN_HEAD)) {
+ else if ((entitytypes == EntityType.PIGLIN || entitytypes == EntityType.PIGLIN_BRUTE) && this.getItemBySlot(EquipmentSlot.HEAD).is(Items.PIGLIN_HEAD)) {
d0 *= entity.level().purpurConfig.piglinHeadVisibilityPercent;
}
+ // petal end
// Purpur end
// Purpur start
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index c276cfd153627d6ec13314fa84b7e591ef40a67a..6227bec25a6f5cd10ef6771c1149a485f13c4eeb 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -931,8 +931,8 @@ public abstract class Mob extends LivingEntity implements Targeting {
return;
}
// Paper end);
- this.sensing.tick();
- int i = this.level().getServer().getTickCount() + this.getId();
+ int i = this.level().getServer().getTickCount() + this.getId(); // petal - move up
+ if (i % 10 == 0) this.sensing.tick(); // petal - only refresh line of sight cache every half second
if (i % 2 != 0 && this.tickCount > 1) {
if (this.targetSelector.inactiveTick(this.activatedPriority, false)) // Pufferfish - use this to alternate ticking