testserver/patches/server/0442-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-11-12 20:57:41 +00:00
index 92beb137d86ae89d90b1963a024c0be308d81a42..e377dd95b7824804611d0e4ce825576ed533e73e 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-11-12 20:57:41 +00:00
public <T> Dynamic<T> store(DynamicOps<T> ops) {
- return new Dynamic<>(ops, ops.createList(this.unpack().map((entry) -> {
+ return new Dynamic<>(ops, ops.createList(this.decompress().stream().map((entry) -> { // Paper - remove streams from reputation
return entry.store(ops);
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;
2022-11-12 20:57:41 +00:00
+ // Paper end
2021-06-11 12:02:28 +00:00
}
public Stream<GossipContainer.GossipEntry> unpack(UUID target) {