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..4ad7f42158bb945088a4d1c574c63dd6c15fa53c 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,15 @@ 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; + } + // Yatopia end private Stream> j() { return this.memories.entrySet().stream().map((entry) -> { return BehaviorController.a.b((MemoryModuleType) entry.getKey(), (Optional) entry.getValue()); @@ -196,7 +202,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 +541,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); }