Paper/patches/unapplied/server/0428-Remove-streams-from-classes-related-villager-gossip.patch

73 Zeilen
3.5 KiB
Diff

2021-06-11 14:02:28 +02: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
2023-09-22 19:59:56 +02:00
index 76dffb2705e5207db96895f82f1c7c5638f817c6..097007c1c25ba55d9916fc820dd1d1149d81f6f4 100644
2021-06-11 14:02:28 +02: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-12-07 21:16:54 +01:00
@@ -61,8 +61,22 @@ public class GossipContainer {
2021-06-11 14:02:28 +02:00
});
}
+ // Paper start - Remove streams from reputation
+ private List<GossipContainer.GossipEntry> decompress() {
2022-06-08 07:46:52 +02:00
+ List<GossipContainer.GossipEntry> list = new it.unimi.dsi.fastutil.objects.ObjectArrayList<>();
2022-12-07 21:16:54 +01:00
+ for (Map.Entry<UUID, GossipContainer.EntityGossips> entry : this.gossips.entrySet()) {
2021-06-11 14:02:28 +02:00
+ for (GossipContainer.GossipEntry cur : entry.getValue().decompress(entry.getKey())) {
2022-12-07 21:16:54 +01:00
+ if (cur.weightedValue() != 0) {
2021-06-11 14:02:28 +02:00
+ list.add(cur);
2022-12-07 21:16:54 +01:00
+ }
2021-06-11 14:02:28 +02:00
+ }
+ }
+ return list;
+ }
+ // Paper end
+
2022-06-08 07:46:52 +02:00
private Collection<GossipContainer.GossipEntry> selectGossipsForTransfer(RandomSource random, int count) {
2022-12-07 21:16:54 +01:00
- List<GossipContainer.GossipEntry> list = this.unpack().toList();
2022-06-08 07:46:52 +02:00
+ List<GossipContainer.GossipEntry> list = this.decompress(); // Paper - Remove streams from reputation
2021-06-11 14:02:28 +02:00
if (list.isEmpty()) {
return Collections.emptyList();
2021-06-14 11:46:59 +02:00
} else {
2022-12-07 21:16:54 +01:00
@@ -156,7 +170,7 @@ public class GossipContainer {
2021-06-11 14:02:28 +02:00
}
2022-12-07 21:16:54 +01:00
public <T> T store(DynamicOps<T> ops) {
- return GossipContainer.GossipEntry.LIST_CODEC.encodeStart(ops, this.unpack().toList()).resultOrPartial((error) -> {
+ return GossipContainer.GossipEntry.LIST_CODEC.encodeStart(ops, this.decompress()).resultOrPartial((error) -> {
LOGGER.warn("Failed to serialize gossips: {}", (Object)error);
}).orElseGet(ops::emptyList);
2021-06-11 14:02:28 +02:00
}
2022-12-07 21:16:54 +01:00
@@ -184,11 +198,23 @@ public class GossipContainer {
2021-06-14 11:46:59 +02:00
final Object2IntMap<GossipType> entries = new Object2IntOpenHashMap<>();
2021-06-11 14:02:28 +02:00
public int weightedValue(Predicate<GossipType> gossipTypeFilter) {
- return this.entries.object2IntEntrySet().stream().filter((entry) -> {
- return gossipTypeFilter.test(entry.getKey());
- }).mapToInt((entry) -> {
2021-06-14 11:46:59 +02:00
- return entry.getIntValue() * (entry.getKey()).weight;
2021-06-11 14:02:28 +02:00
- }).sum();
+ // Paper start - Remove streams from reputation
+ int weight = 0;
2021-06-14 11:46:59 +02:00
+ for (Object2IntMap.Entry<GossipType> entry : entries.object2IntEntrySet()) {
2021-06-11 14:02:28 +02:00
+ if (gossipTypeFilter.test(entry.getKey())) {
2021-06-16 19:48:25 +02:00
+ weight += entry.getIntValue() * entry.getKey().weight;
2021-06-11 14:02:28 +02:00
+ }
+ }
+ return weight;
+ }
+
+ public List<GossipContainer.GossipEntry> decompress(UUID uuid) {
2022-06-08 07:46:52 +02:00
+ List<GossipContainer.GossipEntry> list = new it.unimi.dsi.fastutil.objects.ObjectArrayList<>();
2021-06-14 11:46:59 +02:00
+ for (Object2IntMap.Entry<GossipType> entry : entries.object2IntEntrySet()) {
2021-06-11 14:02:28 +02:00
+ list.add(new GossipContainer.GossipEntry(uuid, entry.getKey(), entry.getIntValue()));
+ }
+ return list;
2022-11-12 21:57:41 +01:00
+ // Paper end
2021-06-11 14:02:28 +02:00
}
public Stream<GossipContainer.GossipEntry> unpack(UUID target) {