Skip to content

Commit

Permalink
Don't add the inventory id to the stack on the client side for recipe…
Browse files Browse the repository at this point in the history
… output as it will be a different id than actually gets added from the server
  • Loading branch information
pupnewfster committed Oct 29, 2023
1 parent 609b030 commit 06e4304
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,27 @@
import net.minecraft.nbt.Tag;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.fml.util.thread.EffectiveSide;
import net.minecraftforge.server.ServerLifecycleHooks;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@MethodsReturnNonnullByDefault
@ParametersAreNotNullByDefault
public class PersonalStorageManager {

private static final Map<UUID, PersonalStorageData> STORAGE_BY_PLAYER_UUID = new HashMap<>();

private static Optional<PersonalStorageData> forOwner(UUID playerUUID) {
if (EffectiveSide.get().isClient()) {
return Optional.empty();
}
return Optional.of(STORAGE_BY_PLAYER_UUID.computeIfAbsent(playerUUID, uuid->MekanismSavedData.createSavedData(PersonalStorageData::new, "personal_storage" + File.separator + uuid)));
return Optional.of(STORAGE_BY_PLAYER_UUID.computeIfAbsent(playerUUID, uuid -> MekanismSavedData.createSavedData(PersonalStorageData::new, "personal_storage" + File.separator + uuid)));
}

/**
* Only call on the server. Gets or creates an inventory for the supplied stack
*
* @param stack Personal storage ItemStack (type not checked) - will be modified if it didn't have an inventory id
*
* @return the existing or new inventory
*/
public static Optional<AbstractPersonalStorageItemInventory> getInventoryFor(ItemStack stack) {
Expand All @@ -53,7 +54,7 @@ public static Optional<AbstractPersonalStorageItemInventory> getInventoryFor(Ite
return Optional.empty();
}
UUID invId = getInventoryId(stack);
return forOwner(owner).map(data->{
return forOwner(owner).map(data -> {
AbstractPersonalStorageItemInventory storageItemInventory = data.getOrAddInventory(invId);
//TODO - After 1.20: Remove legacy loading
ListTag legacyData = ItemDataUtils.getList(stack, NBTConstants.ITEMS);
Expand All @@ -73,18 +74,18 @@ public static boolean createInventoryFor(ItemStack stack, List<IInventorySlot> c
return false;
}
//Get a new inventory id
UUID invId = getInventoryId(stack);
forOwner(owner).ifPresent(inv->inv.addInventory(invId, contents));
forOwner(owner).ifPresent(inv -> inv.addInventory(getInventoryId(stack), contents));
return true;
}

/**
* Only call on the server
* <p>
* 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 inventory
* 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
* inventory
*
* @param stack Personal storage ItemStack
*
* @return the existing or converted inventory, or an empty optional if none exists in saved data nor legacy data
*/
public static Optional<AbstractPersonalStorageItemInventory> getInventoryIfPresent(ItemStack stack) {
Expand All @@ -99,7 +100,7 @@ public static void deleteInventory(ItemStack stack) {
UUID owner = SecurityUtils.get().getOwnerUUID(stack);
UUID invId = getInventoryIdNullable(stack);
if (owner != null && invId != null) {
forOwner(owner).ifPresent(handler->handler.removeInventory(invId));
forOwner(owner).ifPresent(handler -> handler.removeInventory(invId));
}
}

Expand Down

0 comments on commit 06e4304

Please sign in to comment.