testserver/patches/server/0443-Remove-streams-from-cl...

72 lines
3.4 KiB
Diff
Raw Normal View History

2021-06-11 12:02:28 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: JRoy <joshroy126@gmail.com>
Date: Wed, 1 Jul 2020 18:01:49 -0400
Subject: [PATCH] Remove streams from classes related villager gossip
diff --git a/src/main/java/net/minecraft/world/entity/ai/gossip/GossipContainer.java b/src/main/java/net/minecraft/world/entity/ai/gossip/GossipContainer.java
2022-06-08 05:46:52 +00:00
index 0de65462956fa734b6405614e047161696e596fb..aa277479f5552503a202a057b1a3ede379f2bbbf 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/entity/ai/gossip/GossipContainer.java
+++ b/src/main/java/net/minecraft/world/entity/ai/gossip/GossipContainer.java
2022-06-08 05:46:52 +00:00
@@ -58,8 +58,21 @@ public class GossipContainer {
2021-06-11 12:02:28 +00:00
});
}
+ // Paper start - Remove streams from reputation
+ private List<GossipContainer.GossipEntry> decompress() {
2022-06-08 05:46:52 +00:00
+ List<GossipContainer.GossipEntry> list = new it.unimi.dsi.fastutil.objects.ObjectArrayList<>();
2021-06-11 12:02:28 +00:00
+ for (Map.Entry<UUID, GossipContainer.EntityGossips> entry : getReputations().entrySet()) {
+ for (GossipContainer.GossipEntry cur : entry.getValue().decompress(entry.getKey())) {
+ if (cur.weightedValue() != 0)
+ list.add(cur);
+ }
+ }
+ return list;
+ }
+ // Paper end
+
2022-06-08 05:46:52 +00:00
private Collection<GossipContainer.GossipEntry> selectGossipsForTransfer(RandomSource random, int count) {
2021-06-14 09:46:59 +00:00
- List<GossipContainer.GossipEntry> list = this.unpack().collect(Collectors.toList());
2022-06-08 05:46:52 +00:00
+ List<GossipContainer.GossipEntry> list = this.decompress(); // Paper - Remove streams from reputation
2021-06-11 12:02:28 +00:00
if (list.isEmpty()) {
return Collections.emptyList();
2021-06-14 09:46:59 +00:00
} else {
2022-06-08 05:46:52 +00:00
@@ -153,7 +166,7 @@ public class GossipContainer {
2021-06-11 12:02:28 +00:00
}
2022-06-08 05:46:52 +00:00
public <T> Dynamic<T> store(DynamicOps<T> dynamicOps) {
2021-06-14 09:46:59 +00:00
- return new Dynamic<>(dynamicOps, dynamicOps.createList(this.unpack().map((gossipEntry) -> {
2022-06-08 05:46:52 +00:00
+ return new Dynamic<>(dynamicOps, dynamicOps.createList(this.decompress().stream().map((gossipEntry) -> {
return gossipEntry.store(dynamicOps);
2021-06-11 12:02:28 +00:00
}).map(Dynamic::getValue)));
}
2022-06-08 05:46:52 +00:00
@@ -179,11 +192,23 @@ public class GossipContainer {
2021-06-14 09:46:59 +00:00
final Object2IntMap<GossipType> entries = new Object2IntOpenHashMap<>();
2021-06-11 12:02:28 +00:00
public int weightedValue(Predicate<GossipType> gossipTypeFilter) {
- return this.entries.object2IntEntrySet().stream().filter((entry) -> {
- return gossipTypeFilter.test(entry.getKey());
- }).mapToInt((entry) -> {
2021-06-14 09:46:59 +00:00
- return entry.getIntValue() * (entry.getKey()).weight;
2021-06-11 12:02:28 +00:00
- }).sum();
+ // Paper start - Remove streams from reputation
+ int weight = 0;
2021-06-14 09:46:59 +00:00
+ for (Object2IntMap.Entry<GossipType> entry : entries.object2IntEntrySet()) {
2021-06-11 12:02:28 +00:00
+ if (gossipTypeFilter.test(entry.getKey())) {
2021-06-16 17:48:25 +00:00
+ weight += entry.getIntValue() * entry.getKey().weight;
2021-06-11 12:02:28 +00:00
+ }
+ }
+ return weight;
+ }
+
+ public List<GossipContainer.GossipEntry> decompress(UUID uuid) {
2022-06-08 05:46:52 +00:00
+ List<GossipContainer.GossipEntry> list = new it.unimi.dsi.fastutil.objects.ObjectArrayList<>();
2021-06-14 09:46:59 +00:00
+ for (Object2IntMap.Entry<GossipType> entry : entries.object2IntEntrySet()) {
2021-06-11 12:02:28 +00:00
+ list.add(new GossipContainer.GossipEntry(uuid, entry.getKey(), entry.getIntValue()));
+ }
+ return list;
+ // Paper - end
}
public Stream<GossipContainer.GossipEntry> unpack(UUID target) {