From 1e022c99bd88c47aeaedcdae92ad8d2b25bc6a19 Mon Sep 17 00:00:00 2001 From: MrIvanPlays Date: Sun, 9 Aug 2020 22:32:20 +0300 Subject: [PATCH] Optimize BehaviorController --- .../0032-Optimize-BehaviorController.patch | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 patches/server/0032-Optimize-BehaviorController.patch diff --git a/patches/server/0032-Optimize-BehaviorController.patch b/patches/server/0032-Optimize-BehaviorController.patch new file mode 100644 index 00000000..4461c9d4 --- /dev/null +++ b/patches/server/0032-Optimize-BehaviorController.patch @@ -0,0 +1,108 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: MrIvanPlays +Date: Sun, 9 Aug 2020 22:27:52 +0300 +Subject: [PATCH] Optimize BehaviorController + + +diff --git a/src/main/java/net/minecraft/server/BehaviorController.java b/src/main/java/net/minecraft/server/BehaviorController.java +index ae2905b403a63396d9cdc61444586ea5548f2974..ac1deaa9e15cdd05f34b8ee413be826855432a86 100644 +--- a/src/main/java/net/minecraft/server/BehaviorController.java ++++ b/src/main/java/net/minecraft/server/BehaviorController.java +@@ -53,13 +53,16 @@ public class BehaviorController { + + mutableobject.setValue((new MapCodec>() { + public Stream keys(DynamicOps dynamicops) { +- return collection.stream().flatMap((memorymoduletype) -> { +- return SystemUtils.a(memorymoduletype.getSerializer().map((codec) -> { +- return IRegistry.MEMORY_MODULE_TYPE.getKey(memorymoduletype); +- })); +- }).map((minecraftkey) -> { +- return dynamicops.createString(minecraftkey.toString()); +- }); ++ // Yatopia start ++ // about previous impl: WHY ? WHO DID THIS TO YOU? ++ Collection candidates = new java.util.ArrayList<>(); ++ for (MemoryModuleType moduleType : collection) { ++ moduleType.getSerializer() ++ .map(c -> IRegistry.MEMORY_MODULE_TYPE.getKey(moduleType)) ++ .ifPresent(key -> candidates.add(dynamicops.createString(key.toString()))); ++ } ++ return candidates.stream(); ++ // Yatopia end + } + + public DataResult> decode(DynamicOps dynamicops, MapLike maplike) { +@@ -71,23 +74,17 @@ public class BehaviorController { + return this.a(memorymoduletype, dynamicops, pair.getSecond()); + }); + +- mutableobject1.setValue(((DataResult) mutableobject1.getValue()).apply2(Builder::add, dataresult1)); ++ mutableobject1.setValue((mutableobject1.getValue()).apply2(Builder::add, dataresult1)); // Yatopia - decompile fix + }); +- DataResult dataresult = (DataResult) mutableobject1.getValue(); +- Logger logger = BehaviorController.LOGGER; ++ DataResult>> dataresult = mutableobject1.getValue(); // Yatopia - decompile fix + +- logger.getClass(); +- ImmutableList> immutablelist = (ImmutableList) dataresult.resultOrPartial(logger::error).map(Builder::build).orElseGet(ImmutableList::of); +- Collection collection2 = collection; +- Collection collection3 = collection1; +- MutableObject mutableobject2 = mutableobject; ++ ImmutableList> immutablelist = dataresult.resultOrPartial(BehaviorController.LOGGER::error).map(Builder::build).orElseGet(ImmutableList::of); // Yatopia - decompile fix + +- mutableobject.getClass(); +- return DataResult.success(new BehaviorController<>(collection2, collection3, immutablelist, mutableobject2::getValue)); ++ return DataResult.success(new BehaviorController<>(collection, collection1, immutablelist, mutableobject::getValue)); // Yatopia - decompile fix + } + + private DataResult> a(MemoryModuleType memorymoduletype, DynamicOps dynamicops, T t0) { +- return ((DataResult) memorymoduletype.getSerializer().map(DataResult::success).orElseGet(() -> { ++ return (memorymoduletype.getSerializer().map(DataResult::success).orElseGet(() -> { // Yatopia - decompile fix + return DataResult.error("No codec for memory: " + memorymoduletype); + })).flatMap((codec) -> { + return codec.parse(dynamicops, t0); +@@ -97,9 +94,9 @@ public class BehaviorController { + } + + public RecordBuilder encode(BehaviorController behaviorcontroller, DynamicOps dynamicops, RecordBuilder recordbuilder) { +- behaviorcontroller.j().forEach((behaviorcontroller_a) -> { ++ for (BehaviorController.a behaviorcontroller_a : behaviorcontroller.memoriesList()) { // Yatopia + behaviorcontroller_a.a(dynamicops, recordbuilder); +- }); ++ } // Yatopia + return recordbuilder; + } + }).fieldOf("memories").codec()); +@@ -158,6 +155,14 @@ public class BehaviorController { + return ((Codec) this.b.get()).encodeStart(dynamicops, this); + } + ++ // Yatopia start ++ private List> memoriesList() { ++ List> ret = new java.util.ArrayList<>(); ++ for (Map.Entry, Optional>> entry : memories.entrySet()) { ++ ret.add(BehaviorController.a.b(entry.getKey(), (Optional) entry.getValue())); ++ } ++ return ret; ++ } + private Stream> j() { + return this.memories.entrySet().stream().map((entry) -> { + return BehaviorController.a.b((MemoryModuleType) entry.getKey(), (Optional) entry.getValue()); +@@ -196,7 +201,7 @@ public class BehaviorController { + } + + public Optional getMemory(MemoryModuleType memorymoduletype) { +- return ((Optional) this.memories.get(memorymoduletype)).map(ExpirableMemory::c); ++ return (Optional) this.memories.get(memorymoduletype).map(ExpirableMemory::c); // Yatopia - Decompile fix + } + + public boolean b(MemoryModuleType memorymoduletype, U u0) { +@@ -535,7 +540,7 @@ public class BehaviorController { + private final MemoryModuleType a; + private final Optional> b; + +- private static BehaviorController.a b(MemoryModuleType memorymoduletype, Optional> optional) { ++ private static BehaviorController.a b(MemoryModuleType memorymoduletype, Optional> optional) { // Yatopia - decompile fix + return new BehaviorController.a<>(memorymoduletype, optional); + } +