Skip to content

Commit 5225433

Browse files
committed
Fix client not updating DeityHelper
1 parent ab76a61 commit 5225433

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

src/main/java/rpggods/client/screen/FavorScreen.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,13 @@ public class FavorScreen extends ContainerScreen<FavorContainer> {
125125

126126
// Data
127127
private static final List<ResourceLocation> deityList = new ArrayList<>();
128+
// Key: deity ID; Value: Altar Entity instance
128129
private static final Map<ResourceLocation, AltarEntity> entityMap = new HashMap<>();
130+
// Key: deity ID; Value: List of Offerings by ID and value
129131
private static final Map<ResourceLocation, List<ImmutablePair<ResourceLocation, Offering>>> offeringMap = new HashMap();
132+
// Key: deity ID; Value: List of Trade Offerings by ID and value
130133
private static final Map<ResourceLocation, List<ImmutablePair<ResourceLocation, Offering>>> tradeMap = new HashMap();
134+
// Key: deity ID; Value: List of Sacrifices by ID and value
131135
private static final Map<ResourceLocation, List<ImmutablePair<ResourceLocation, Sacrifice>>> sacrificeMap = new HashMap();
132136
// Key: deity ID; Value: Map of perk level to list of available perks
133137
private static final Map<ResourceLocation, Map<Integer, List<Perk>>> perkMap = new HashMap();
@@ -198,6 +202,17 @@ public FavorScreen(FavorContainer screenContainer, PlayerInventory inv, ITextCom
198202
}
199203
// add deity to list
200204
deityList.add(deityHelper.id);
205+
// add entries to all lists for this deity
206+
offeringMap.put(d.getId(), Lists.newArrayList());
207+
tradeMap.put(d.getId(), Lists.newArrayList());
208+
sacrificeMap.put(d.getId(), Lists.newArrayList());
209+
// add entries to perk map based on favor level min and max
210+
FavorLevel favorLevel = favor.getFavor(d.getId());
211+
Map<Integer, List<Perk>> perkSubMap = new HashMap<>();
212+
for(int i = favorLevel.getMin(), j = favorLevel.getMax(); i <= j; i++) {
213+
perkSubMap.put(i, Lists.newArrayList());
214+
}
215+
perkMap.put(deityHelper.id, perkSubMap);
201216
// add all offerings to map using deity helper (so we can skip offerings that were invalid)
202217
for(List<ResourceLocation> entry : deityHelper.offeringMap.values()) {
203218
for(ResourceLocation offeringId : entry) {
@@ -206,7 +221,7 @@ public FavorScreen(FavorContainer screenContainer, PlayerInventory inv, ITextCom
206221
// determine which map to use (offering or trade)
207222
Map<ResourceLocation, List<ImmutablePair<ResourceLocation, Offering>>> map = offering.getTrade().isPresent() ? tradeMap : offeringMap;
208223
// add the offering to the map
209-
map.computeIfAbsent(Offering.getDeity(deityHelper.id), id -> Lists.newArrayList()).add(ImmutablePair.of(deityHelper.id, offering));
224+
map.get(d.getId()).add(ImmutablePair.of(deityHelper.id, offering));
210225
});
211226
}
212227
}
@@ -216,7 +231,7 @@ public FavorScreen(FavorContainer screenContainer, PlayerInventory inv, ITextCom
216231
Optional<Sacrifice> optional = RPGGods.SACRIFICE.get(sacrificeId);
217232
optional.ifPresent(sacrifice -> {
218233
// add the sacrifice to the map
219-
sacrificeMap.computeIfAbsent(Sacrifice.getDeity(deityHelper.id), id -> Lists.newArrayList()).add(ImmutablePair.of(deityHelper.id, sacrifice));
234+
sacrificeMap.get(d.getId()).add(ImmutablePair.of(deityHelper.id, sacrifice));
220235
});
221236
}
222237
}
@@ -230,16 +245,6 @@ public FavorScreen(FavorContainer screenContainer, PlayerInventory inv, ITextCom
230245
if(perk.getIcon().isHidden()) {
231246
continue;
232247
}
233-
// add entry to perk map if absent
234-
if(!perkMap.containsKey(deityHelper.id)) {
235-
// add map with keys for all levels
236-
FavorLevel favorLevel = favor.getFavor(perk.getDeity());
237-
Map<Integer, List<Perk>> map = new HashMap<>();
238-
for(int i = favorLevel.getMin(), j = favorLevel.getMax(); i <= j; i++) {
239-
map.put(i, Lists.newArrayList());
240-
}
241-
perkMap.put(deityHelper.id, map);
242-
}
243248
// determine which level to place the perk
244249
int min = perk.getRange().getMinLevel();
245250
int max = perk.getRange().getMaxLevel();
@@ -248,8 +253,8 @@ public FavorScreen(FavorContainer screenContainer, PlayerInventory inv, ITextCom
248253
else if(min <= 0 && max <= 0) unlock = max;
249254
else unlock = Math.min(Math.abs(min), Math.abs(max));
250255
// actually add the perk to the map
251-
if(perkMap.get(deityHelper.id).containsKey(unlock)) {
252-
perkMap.get(deityHelper.id).get(unlock).add(perk);
256+
if(perkMap.get(d.getId()).containsKey(unlock)) {
257+
perkMap.get(d.getId()).get(unlock).add(perk);
253258
}
254259
}
255260
}

src/main/java/rpggods/network/SAltarPacket.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
import net.minecraftforge.fml.network.NetworkEvent;
1010
import rpggods.RPGGods;
1111
import rpggods.deity.Altar;
12+
import rpggods.deity.Deity;
13+
import rpggods.deity.DeityHelper;
14+
import rpggods.deity.Offering;
1215

1316
import java.util.Optional;
1417
import java.util.function.Supplier;
@@ -70,6 +73,8 @@ public static void handlePacket(final SAltarPacket message, final Supplier<Netwo
7073
if (context.getDirection().getReceptionSide() == LogicalSide.CLIENT) {
7174
context.enqueueWork(() -> {
7275
RPGGods.ALTAR.put(message.altarId, message.altar);
76+
ResourceLocation deityId = message.altar.getDeity().orElse(Deity.EMPTY.getId());
77+
RPGGods.DEITY_HELPER.computeIfAbsent(deityId, DeityHelper::new).add(message.altarId, message.altar);
7378
});
7479
}
7580
context.setPacketHandled(true);

src/main/java/rpggods/network/SOfferingPacket.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import net.minecraftforge.fml.LogicalSide;
99
import net.minecraftforge.fml.network.NetworkEvent;
1010
import rpggods.RPGGods;
11+
import rpggods.deity.DeityHelper;
1112
import rpggods.deity.Offering;
1213

1314
import java.util.Optional;
@@ -70,6 +71,8 @@ public static void handlePacket(final SOfferingPacket message, final Supplier<Ne
7071
if (context.getDirection().getReceptionSide() == LogicalSide.CLIENT) {
7172
context.enqueueWork(() -> {
7273
RPGGods.OFFERING.put(message.offeringId, message.offering);
74+
ResourceLocation deityId = Offering.getDeity(message.offeringId);
75+
RPGGods.DEITY_HELPER.computeIfAbsent(deityId, DeityHelper::new).add(message.offeringId, message.offering);
7376
});
7477
}
7578
context.setPacketHandled(true);

src/main/java/rpggods/network/SSacrificePacket.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import net.minecraftforge.fml.LogicalSide;
99
import net.minecraftforge.fml.network.NetworkEvent;
1010
import rpggods.RPGGods;
11+
import rpggods.deity.DeityHelper;
12+
import rpggods.deity.Offering;
1113
import rpggods.deity.Sacrifice;
1214

1315
import java.util.Optional;
@@ -16,7 +18,7 @@
1618
/**
1719
* Called when datapacks are (re)loaded.
1820
* Sent from the server to the client with a single ResourceLocation ID
19-
* and the corresponding Offering as it was read from JSON.
21+
* and the corresponding Sacrifice as it was read from JSON.
2022
**/
2123
public class SSacrificePacket {
2224

@@ -70,6 +72,8 @@ public static void handlePacket(final SSacrificePacket message, final Supplier<N
7072
if (context.getDirection().getReceptionSide() == LogicalSide.CLIENT) {
7173
context.enqueueWork(() -> {
7274
RPGGods.SACRIFICE.put(message.sacrificeId, message.sacrifice);
75+
ResourceLocation deityId = Sacrifice.getDeity(message.sacrificeId);
76+
RPGGods.DEITY_HELPER.computeIfAbsent(deityId, DeityHelper::new).add(message.sacrificeId, message.sacrifice);
7377
});
7478
}
7579
context.setPacketHandled(true);

0 commit comments

Comments
 (0)