Skip to content

Commit 98ce399

Browse files
Fixed team null in blocks sometimes + persistent diminishing per item
1 parent 27a8999 commit 98ce399

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

src/main/java/com/mewo/hbmenhanced/ResearchBlocks/Tier1/TileEntityT1.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ public void writeToNBT(NBTTagCompound compound) {
198198
}
199199
compound.setTag("Items", items);
200200
compound.setTag("researchData", researchData);
201+
compound.setString("Team", team);
201202
}
202203

203204
@Override
@@ -211,7 +212,7 @@ public void readFromNBT(NBTTagCompound compound) {
211212
currentBurnTime = researchData.getInteger("currentBurnTime");
212213
maxResearchProgress = researchData.getInteger("maxResearchProgress");
213214
isBurning = researchData.getBoolean("isBurning");
214-
215+
team = compound.getString("Team");
215216
NBTTagCompound items = compound.hasKey("Items") ? compound.getCompoundTag("Items") : new NBTTagCompound();
216217
for (int i = 0; i < inventory.length; i++) {
217218
if (items.hasKey("Slot" + i)) {

src/main/java/com/mewo/hbmenhanced/ResearchBlocks/Tier3/TileEntityT3.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ public void writeToNBT(NBTTagCompound compound) {
203203
researchData.setInteger("researchProgress", researchProgress);
204204
researchData.setInteger("maxResearchProgress", maxResearchProgress);
205205
compound.setTag("researchData", researchData);
206+
compound.setString("Team", team);
206207
}
207208

208209
@Override
@@ -225,6 +226,7 @@ public void readFromNBT(NBTTagCompound compound) {
225226
isResearching = researchData.getBoolean("isResearching");
226227
researchProgress = researchData.getInteger("researchProgress");
227228
maxResearchProgress = researchData.getInteger("maxResearchProgress");
229+
team = compound.getString("Team");
228230
}
229231

230232
@Override

src/main/java/com/mewo/hbmenhanced/Util/getItemValues.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mewo.hbmenhanced.Util;
22

3+
import com.google.gson.reflect.TypeToken;
34
import com.hbm.items.ModItems;
45
import com.mewo.hbmenhanced.ResearchBlocks.ResearchController.TileEntityResearchController;
56
import com.mewo.hbmenhanced.ResearchBlocks.Tier1.TileEntityT1;
@@ -12,13 +13,33 @@
1213
import net.minecraft.nbt.NBTTagCompound;
1314
import net.minecraft.tileentity.TileEntity;
1415

16+
import java.io.File;
17+
import java.lang.reflect.Type;
1518
import java.util.*;
1619

1720
public class getItemValues {
1821

1922
public static Map<String, Map<String, Integer>> researchCounts = new HashMap<>();
2023
public static Map<String, ResearchValue> Values = new HashMap<>();
2124

25+
public static void loadDiminish() {
26+
File file = new File("config/hbmenhanced/research_diminish.json");
27+
Type type = new TypeToken<Map<String, Map<String, Integer>>>() {}.getType();
28+
Map<String, Map<String, Integer>> loaded = JsonUtil.read(file, type);
29+
if (loaded != null) {
30+
researchCounts = loaded;
31+
System.out.println("[getItemValues] Loaded diminishing values for all teams.");
32+
} else {
33+
System.out.println("[getItemValues] No existing diminishing data found, starting fresh.");
34+
}
35+
}
36+
37+
public static void saveDiminish() {
38+
File file = new File("config/hbmenhanced/research_diminish.json");
39+
JsonUtil.write(file, researchCounts);
40+
System.out.println("[getItemValues] Saved diminishing values for all teams.");
41+
}
42+
2243
// Creates a truly unique identifier for an item including metadata
2344
private static String getUniqueItemKey(Item item, int meta) {
2445
return Item.itemRegistry.getNameForObject(item) + ":" + meta;
@@ -165,6 +186,11 @@ public static void setValues(ResearchValue value, ItemStack outStack, String tea
165186

166187
Map<PointManager.ResearchType, Integer> map = value.getAllPoints();
167188
System.out.println("Map size: " + map.size());
189+
System.out.println(team);
190+
if (team == null) {
191+
System.err.println("[getItemValues] Cannot apply diminishing: team is null. Stack=" + sourceStack);
192+
return;
193+
}
168194
researchCounts.computeIfAbsent(team, t -> new HashMap<>());
169195

170196
for (Map.Entry<PointManager.ResearchType, Integer> entry : map.entrySet()) {
@@ -174,6 +200,7 @@ public static void setValues(ResearchValue value, ItemStack outStack, String tea
174200

175201
int current = researchCounts.get(team).getOrDefault(sourceKey, 0);
176202
researchCounts.get(team).put(sourceKey, current + 1);
203+
getItemValues.saveDiminish();
177204
System.out.println("Applied diminishing for source item: " + sourceKey + " for team: " + team);
178205
}
179206
}

src/main/java/com/mewo/hbmenhanced/hbmenhanced.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public void serverStarting(FMLServerStartingEvent event) {
277277

278278
PointManager manager = new PointManager();
279279
manager.createFile(event.getServer().getEntityWorld());
280-
280+
getItemValues.loadDiminish();
281281
Timer timer = new Timer(true);
282282
timer.scheduleAtFixedRate(new TimerTask() {
283283
@Override

0 commit comments

Comments
 (0)