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

82 Zeilen
4.1 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
2022-12-07 21:16:54 +01:00
index 4e7b7a3910840908b73c80faf9a83b728186f775..f64da4c3bd4301453688974182e7793804655d2c 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
@@ -30,7 +30,7 @@ import org.slf4j.Logger;
public class GossipContainer {
private static final Logger LOGGER = LogUtils.getLogger();
public static final int DISCARD_THRESHOLD = 2;
- private final Map<UUID, GossipContainer.EntityGossips> gossips = Maps.newHashMap(); public Map<UUID, GossipContainer.EntityGossips> getReputations() { return this.gossips; } // Paper - add getter for reputations
+ private final Map<UUID, GossipContainer.EntityGossips> gossips = Maps.newHashMap();
@VisibleForDebug
public Map<UUID, Object2IntMap<GossipType>> getGossipEntries() {
@@ -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) {