mirror of
https://github.com/BX-Team/DivineMC.git
synced 2025-12-19 14:59:25 +00:00
review
This commit is contained in:
@@ -26,23 +26,23 @@ index 04875840085541ebfc7014868beec49bb7ab9976..bbfb1de1a03c4208406feb803a2f378d
|
|||||||
|
|
||||||
super.onSyncedDataUpdated(key);
|
super.onSyncedDataUpdated(key);
|
||||||
diff --git a/net/minecraft/world/entity/ai/Brain.java b/net/minecraft/world/entity/ai/Brain.java
|
diff --git a/net/minecraft/world/entity/ai/Brain.java b/net/minecraft/world/entity/ai/Brain.java
|
||||||
index 99ced3cb7d3d4c7a80d890689d7585fa9acd17f6..56b8a46a9e9e99829c28a11d5068096603b03980 100644
|
index 99ced3cb7d3d4c7a80d890689d7585fa9acd17f6..9277b5da6065a5500e40727815083da25b9c9327 100644
|
||||||
--- a/net/minecraft/world/entity/ai/Brain.java
|
--- a/net/minecraft/world/entity/ai/Brain.java
|
||||||
+++ b/net/minecraft/world/entity/ai/Brain.java
|
+++ b/net/minecraft/world/entity/ai/Brain.java
|
||||||
@@ -45,16 +45,74 @@ public class Brain<E extends LivingEntity> {
|
@@ -45,16 +45,75 @@ public class Brain<E extends LivingEntity> {
|
||||||
static final Logger LOGGER = LogUtils.getLogger();
|
static final Logger LOGGER = LogUtils.getLogger();
|
||||||
private final Supplier<Codec<Brain<E>>> codec;
|
private final Supplier<Codec<Brain<E>>> codec;
|
||||||
private static final int SCHEDULE_UPDATE_DELAY = 20;
|
private static final int SCHEDULE_UPDATE_DELAY = 20;
|
||||||
- private final Map<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> memories = Maps.newHashMap();
|
- private final Map<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> memories = Maps.newHashMap();
|
||||||
- public final Map<SensorType<? extends Sensor<? super E>>, Sensor<? super E>> sensors = Maps.newLinkedHashMap();
|
- public final Map<SensorType<? extends Sensor<? super E>>, Sensor<? super E>> sensors = Maps.newLinkedHashMap();
|
||||||
- private final Map<Integer, Map<Activity, Set<BehaviorControl<? super E>>>> availableBehaviorsByPriority = Maps.newTreeMap();
|
+ // DivineMC start - Optimize entity brain
|
||||||
+
|
+ private Map<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> memories = Maps.newConcurrentMap();
|
||||||
+ private Map<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> memories = Maps.newConcurrentMap(); // DivineMC - concurrent map
|
+ public Map<SensorType<? extends Sensor<? super E>>, Sensor<? super E>> sensors = Maps.newLinkedHashMap();
|
||||||
+ public Map<SensorType<? extends Sensor<? super E>>, Sensor<? super E>> sensors = Maps.newLinkedHashMap(); // DivineMC - linked hash map
|
private final Map<Integer, Map<Activity, Set<BehaviorControl<? super E>>>> availableBehaviorsByPriority = Maps.newTreeMap();
|
||||||
+ private final Map<Integer, Map<Activity, Set<BehaviorControl<? super E>>>> availableBehaviorsByPriority = Maps.newTreeMap(); // DivineMC - tree map
|
|
||||||
private Schedule schedule = Schedule.EMPTY;
|
private Schedule schedule = Schedule.EMPTY;
|
||||||
- private final Map<Activity, Set<Pair<MemoryModuleType<?>, MemoryStatus>>> activityRequirements = Maps.newHashMap();
|
- private final Map<Activity, Set<Pair<MemoryModuleType<?>, MemoryStatus>>> activityRequirements = Maps.newHashMap();
|
||||||
+ private Map<Activity, Set<Pair<MemoryModuleType<?>, MemoryStatus>>> activityRequirements = Maps.newHashMap(); // DivineMC - hash map
|
+ private Map<Activity, Set<Pair<MemoryModuleType<?>, MemoryStatus>>> activityRequirements = Maps.newHashMap();
|
||||||
|
+ // DivineMC end - Optimize entity brain
|
||||||
private final Map<Activity, Set<MemoryModuleType<?>>> activityMemoriesToEraseWhenStopped = Maps.newHashMap();
|
private final Map<Activity, Set<MemoryModuleType<?>>> activityMemoriesToEraseWhenStopped = Maps.newHashMap();
|
||||||
private Set<Activity> coreActivities = Sets.newHashSet();
|
private Set<Activity> coreActivities = Sets.newHashSet();
|
||||||
private final Set<Activity> activeActivities = Sets.newHashSet();
|
private final Set<Activity> activeActivities = Sets.newHashSet();
|
||||||
@@ -108,7 +108,7 @@ index 99ced3cb7d3d4c7a80d890689d7585fa9acd17f6..56b8a46a9e9e99829c28a11d50680966
|
|||||||
|
|
||||||
public static <E extends LivingEntity> Brain.Provider<E> provider(
|
public static <E extends LivingEntity> Brain.Provider<E> provider(
|
||||||
Collection<? extends MemoryModuleType<?>> memoryTypes, Collection<? extends SensorType<? extends Sensor<? super E>>> sensorTypes
|
Collection<? extends MemoryModuleType<?>> memoryTypes, Collection<? extends SensorType<? extends Sensor<? super E>>> sensorTypes
|
||||||
@@ -146,6 +204,12 @@ public class Brain<E extends LivingEntity> {
|
@@ -146,6 +205,12 @@ public class Brain<E extends LivingEntity> {
|
||||||
for (Brain.MemoryValue<?> memoryValue : memoryValues) {
|
for (Brain.MemoryValue<?> memoryValue : memoryValues) {
|
||||||
memoryValue.setMemoryInternal(this);
|
memoryValue.setMemoryInternal(this);
|
||||||
}
|
}
|
||||||
@@ -121,7 +121,7 @@ index 99ced3cb7d3d4c7a80d890689d7585fa9acd17f6..56b8a46a9e9e99829c28a11d50680966
|
|||||||
}
|
}
|
||||||
|
|
||||||
public <T> DataResult<T> serializeStart(DynamicOps<T> ops) {
|
public <T> DataResult<T> serializeStart(DynamicOps<T> ops) {
|
||||||
@@ -165,6 +229,7 @@ public class Brain<E extends LivingEntity> {
|
@@ -165,6 +230,7 @@ public class Brain<E extends LivingEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public <U> void eraseMemory(MemoryModuleType<U> type) {
|
public <U> void eraseMemory(MemoryModuleType<U> type) {
|
||||||
@@ -129,7 +129,7 @@ index 99ced3cb7d3d4c7a80d890689d7585fa9acd17f6..56b8a46a9e9e99829c28a11d50680966
|
|||||||
this.setMemory(type, Optional.empty());
|
this.setMemory(type, Optional.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,16 +245,33 @@ public class Brain<E extends LivingEntity> {
|
@@ -180,16 +246,33 @@ public class Brain<E extends LivingEntity> {
|
||||||
this.setMemoryInternal(memoryType, memory.map(ExpirableValue::of));
|
this.setMemoryInternal(memoryType, memory.map(ExpirableValue::of));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +168,7 @@ index 99ced3cb7d3d4c7a80d890689d7585fa9acd17f6..56b8a46a9e9e99829c28a11d50680966
|
|||||||
public <U> Optional<U> getMemory(MemoryModuleType<U> type) {
|
public <U> Optional<U> getMemory(MemoryModuleType<U> type) {
|
||||||
Optional<? extends ExpirableValue<?>> optional = this.memories.get(type);
|
Optional<? extends ExpirableValue<?>> optional = this.memories.get(type);
|
||||||
if (optional == null) {
|
if (optional == null) {
|
||||||
@@ -251,19 +333,7 @@ public class Brain<E extends LivingEntity> {
|
@@ -251,19 +334,7 @@ public class Brain<E extends LivingEntity> {
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@VisibleForDebug
|
@VisibleForDebug
|
||||||
public List<BehaviorControl<? super E>> getRunningBehaviors() {
|
public List<BehaviorControl<? super E>> getRunningBehaviors() {
|
||||||
@@ -189,7 +189,7 @@ index 99ced3cb7d3d4c7a80d890689d7585fa9acd17f6..56b8a46a9e9e99829c28a11d50680966
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void useDefaultActivity() {
|
public void useDefaultActivity() {
|
||||||
@@ -294,6 +364,7 @@ public class Brain<E extends LivingEntity> {
|
@@ -294,6 +365,7 @@ public class Brain<E extends LivingEntity> {
|
||||||
this.activeActivities.clear();
|
this.activeActivities.clear();
|
||||||
this.activeActivities.addAll(this.coreActivities);
|
this.activeActivities.addAll(this.coreActivities);
|
||||||
this.activeActivities.add(activity);
|
this.activeActivities.add(activity);
|
||||||
@@ -197,7 +197,7 @@ index 99ced3cb7d3d4c7a80d890689d7585fa9acd17f6..56b8a46a9e9e99829c28a11d50680966
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,11 +454,13 @@ public class Brain<E extends LivingEntity> {
|
@@ -383,11 +455,13 @@ public class Brain<E extends LivingEntity> {
|
||||||
.computeIfAbsent(activity, activity1 -> Sets.newLinkedHashSet())
|
.computeIfAbsent(activity, activity1 -> Sets.newLinkedHashSet())
|
||||||
.add((BehaviorControl<? super E>)pair.getSecond());
|
.add((BehaviorControl<? super E>)pair.getSecond());
|
||||||
}
|
}
|
||||||
@@ -211,7 +211,7 @@ index 99ced3cb7d3d4c7a80d890689d7585fa9acd17f6..56b8a46a9e9e99829c28a11d50680966
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isActive(Activity activity) {
|
public boolean isActive(Activity activity) {
|
||||||
@@ -404,6 +477,7 @@ public class Brain<E extends LivingEntity> {
|
@@ -404,6 +478,7 @@ public class Brain<E extends LivingEntity> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,7 +219,7 @@ index 99ced3cb7d3d4c7a80d890689d7585fa9acd17f6..56b8a46a9e9e99829c28a11d50680966
|
|||||||
return brain;
|
return brain;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -438,31 +512,38 @@ public class Brain<E extends LivingEntity> {
|
@@ -438,31 +513,38 @@ public class Brain<E extends LivingEntity> {
|
||||||
|
|
||||||
for (BehaviorControl<? super E> behaviorControl : this.getRunningBehaviors()) {
|
for (BehaviorControl<? super E> behaviorControl : this.getRunningBehaviors()) {
|
||||||
behaviorControl.doStop(level, owner, gameTime);
|
behaviorControl.doStop(level, owner, gameTime);
|
||||||
@@ -421,3 +421,30 @@ index 70b32e0d06f9b8b7999df5fdfd773c09394e23fb..997cff138d5c99b1be9224cb3c96bdfe
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack createHorn() {
|
public ItemStack createHorn() {
|
||||||
|
diff --git a/net/minecraft/world/entity/schedule/Activity.java b/net/minecraft/world/entity/schedule/Activity.java
|
||||||
|
index 5a143bb6fabba3dc4e2272afb0be636d5722ea22..f17cc8135121f1a97f13bf83a0205e7fcb08b431 100644
|
||||||
|
--- a/net/minecraft/world/entity/schedule/Activity.java
|
||||||
|
+++ b/net/minecraft/world/entity/schedule/Activity.java
|
||||||
|
@@ -32,10 +32,12 @@ public class Activity {
|
||||||
|
public static final Activity DIG = register("dig");
|
||||||
|
private final String name;
|
||||||
|
private final int hashCode;
|
||||||
|
+ public final int id; // DivineMC - Cache registry ID
|
||||||
|
|
||||||
|
- private Activity(String name) {
|
||||||
|
+ private Activity(String name, int id) {
|
||||||
|
this.name = name;
|
||||||
|
this.hashCode = name.hashCode();
|
||||||
|
+ this.id = id; // DivineMC - Cache registry ID
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
@@ -43,7 +45,7 @@ public class Activity {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Activity register(String key) {
|
||||||
|
- return Registry.register(BuiltInRegistries.ACTIVITY, key, new Activity(key));
|
||||||
|
+ return Registry.register(BuiltInRegistries.ACTIVITY, key, new Activity(key, BuiltInRegistries.ACTIVITY.size())); // DivineMC - Cache registry ID
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user