24
24
import net .minecraft .nbt .Tag ;
25
25
import net .minecraft .world .item .ItemStack ;
26
26
import net .minecraftforge .fml .util .thread .EffectiveSide ;
27
- import net .minecraftforge .server .ServerLifecycleHooks ;
28
27
import org .jetbrains .annotations .NotNull ;
29
28
import org .jetbrains .annotations .Nullable ;
30
29
31
30
@ MethodsReturnNonnullByDefault
32
31
@ ParametersAreNotNullByDefault
33
32
public class PersonalStorageManager {
33
+
34
34
private static final Map <UUID , PersonalStorageData > STORAGE_BY_PLAYER_UUID = new HashMap <>();
35
35
36
36
private static Optional <PersonalStorageData > forOwner (UUID playerUUID ) {
37
37
if (EffectiveSide .get ().isClient ()) {
38
38
return Optional .empty ();
39
39
}
40
- return Optional .of (STORAGE_BY_PLAYER_UUID .computeIfAbsent (playerUUID , uuid -> MekanismSavedData .createSavedData (PersonalStorageData ::new , "personal_storage" + File .separator + uuid )));
40
+ return Optional .of (STORAGE_BY_PLAYER_UUID .computeIfAbsent (playerUUID , uuid -> MekanismSavedData .createSavedData (PersonalStorageData ::new , "personal_storage" + File .separator + uuid )));
41
41
}
42
42
43
43
/**
44
44
* Only call on the server. Gets or creates an inventory for the supplied stack
45
45
*
46
46
* @param stack Personal storage ItemStack (type not checked) - will be modified if it didn't have an inventory id
47
+ *
47
48
* @return the existing or new inventory
48
49
*/
49
50
public static Optional <AbstractPersonalStorageItemInventory > getInventoryFor (ItemStack stack ) {
@@ -53,7 +54,7 @@ public static Optional<AbstractPersonalStorageItemInventory> getInventoryFor(Ite
53
54
return Optional .empty ();
54
55
}
55
56
UUID invId = getInventoryId (stack );
56
- return forOwner (owner ).map (data -> {
57
+ return forOwner (owner ).map (data -> {
57
58
AbstractPersonalStorageItemInventory storageItemInventory = data .getOrAddInventory (invId );
58
59
//TODO - After 1.20: Remove legacy loading
59
60
ListTag legacyData = ItemDataUtils .getList (stack , NBTConstants .ITEMS );
@@ -73,18 +74,18 @@ public static boolean createInventoryFor(ItemStack stack, List<IInventorySlot> c
73
74
return false ;
74
75
}
75
76
//Get a new inventory id
76
- UUID invId = getInventoryId (stack );
77
- forOwner (owner ).ifPresent (inv ->inv .addInventory (invId , contents ));
77
+ forOwner (owner ).ifPresent (inv -> inv .addInventory (getInventoryId (stack ), contents ));
78
78
return true ;
79
79
}
80
80
81
81
/**
82
82
* Only call on the server
83
83
* <p>
84
- * Version of {@link #getInventoryFor(ItemStack)} which will NOT create an inventory if none exists already.
85
- * The stack will only be modified if it contained a legacy inventory
84
+ * Version of {@link #getInventoryFor(ItemStack)} which will NOT create an inventory if none exists already. The stack will only be modified if it contained a legacy
85
+ * inventory
86
86
*
87
87
* @param stack Personal storage ItemStack
88
+ *
88
89
* @return the existing or converted inventory, or an empty optional if none exists in saved data nor legacy data
89
90
*/
90
91
public static Optional <AbstractPersonalStorageItemInventory > getInventoryIfPresent (ItemStack stack ) {
@@ -99,7 +100,7 @@ public static void deleteInventory(ItemStack stack) {
99
100
UUID owner = SecurityUtils .get ().getOwnerUUID (stack );
100
101
UUID invId = getInventoryIdNullable (stack );
101
102
if (owner != null && invId != null ) {
102
- forOwner (owner ).ifPresent (handler -> handler .removeInventory (invId ));
103
+ forOwner (owner ).ifPresent (handler -> handler .removeInventory (invId ));
103
104
}
104
105
}
105
106
0 commit comments