Added a disk list command that can give disks of an owner as well.

This commit is contained in:
raoulvdberge
2020-09-05 17:39:41 +02:00
parent be91d5ba93
commit 6bed059e95
29 changed files with 225 additions and 48 deletions

View File

@@ -1,7 +1,9 @@
# Refined Storage Changelog # Refined Storage Changelog
### 1.9.5 ### 1.9.5
- Re-implemented the /refinedstorage createdisk command (raoulvdberge) - Re-implemented the /refinedstorage disk create <player> <id> command (raoulvdberge)
- Added the /refinedstorage disk list command (raoulvdberge)
- Added the /refinedstorage disk list <player> command (raoulvdberge)
- Added JEI ghost ingredient dragging support (raoulvdberge) - Added JEI ghost ingredient dragging support (raoulvdberge)
### 1.9.4 ### 1.9.4

View File

@@ -22,12 +22,14 @@ import com.refinedmods.refinedstorage.api.storage.externalstorage.IExternalStora
import com.refinedmods.refinedstorage.api.util.IComparer; import com.refinedmods.refinedstorage.api.util.IComparer;
import com.refinedmods.refinedstorage.api.util.IQuantityFormatter; import com.refinedmods.refinedstorage.api.util.IQuantityFormatter;
import com.refinedmods.refinedstorage.api.util.IStackList; import com.refinedmods.refinedstorage.api.util.IStackList;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.world.server.ServerWorld; import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@@ -154,18 +156,20 @@ public interface IRSAPI {
/** /**
* @param world the world * @param world the world
* @param capacity the capacity * @param capacity the capacity
* @param owner the owner or null if no owner
* @return a storage disk * @return a storage disk
*/ */
@Nonnull @Nonnull
IStorageDisk<ItemStack> createDefaultItemDisk(ServerWorld world, int capacity); IStorageDisk<ItemStack> createDefaultItemDisk(ServerWorld world, int capacity, @Nullable PlayerEntity owner);
/** /**
* @param world the world * @param world the world
* @param capacity the capacity in mB * @param capacity the capacity in mB
* @param owner the owner or null if no owner
* @return a fluid storage disk * @return a fluid storage disk
*/ */
@Nonnull @Nonnull
IStorageDisk<FluidStack> createDefaultFluidDisk(ServerWorld world, int capacity); IStorageDisk<FluidStack> createDefaultFluidDisk(ServerWorld world, int capacity, @Nullable PlayerEntity owner);
/** /**
* Creates crafting request info for an item. * Creates crafting request info for an item.

View File

@@ -5,6 +5,7 @@ import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.UUID;
/** /**
* Represents a storage disk. * Represents a storage disk.
@@ -17,6 +18,12 @@ public interface IStorageDisk<T> extends IStorage<T> {
*/ */
int getCapacity(); int getCapacity();
/**
* @return the id of the owner, or null if not present
*/
@Nullable
UUID getOwner();
/** /**
* When this storage disk is inserted into a storage disk container, it has to adjust to the container's settings * When this storage disk is inserted into a storage disk container, it has to adjust to the container's settings
* and use the following parameters instead. * and use the following parameters instead.

View File

@@ -4,6 +4,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.world.server.ServerWorld; import net.minecraft.world.server.ServerWorld;
import javax.annotation.Nullable;
import java.util.UUID; import java.util.UUID;
/** /**
@@ -35,7 +36,8 @@ public interface IStorageDiskFactory<T> {
* *
* @param world the world * @param world the world
* @param capacity the capacity * @param capacity the capacity
* @param owner the owner, or null if no owner
* @return the storage disk * @return the storage disk
*/ */
IStorageDisk<T> create(ServerWorld world, int capacity); IStorageDisk<T> create(ServerWorld world, int capacity, @Nullable UUID owner);
} }

View File

@@ -39,6 +39,7 @@ import com.refinedmods.refinedstorage.apiimpl.util.Comparer;
import com.refinedmods.refinedstorage.apiimpl.util.FluidStackList; import com.refinedmods.refinedstorage.apiimpl.util.FluidStackList;
import com.refinedmods.refinedstorage.apiimpl.util.ItemStackList; import com.refinedmods.refinedstorage.apiimpl.util.ItemStackList;
import com.refinedmods.refinedstorage.apiimpl.util.QuantityFormatter; import com.refinedmods.refinedstorage.apiimpl.util.QuantityFormatter;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.INBT; import net.minecraft.nbt.INBT;
@@ -52,6 +53,7 @@ import org.apache.logging.log4j.Logger;
import org.objectweb.asm.Type; import org.objectweb.asm.Type;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -215,22 +217,22 @@ public class API implements IRSAPI {
@Override @Override
@Nonnull @Nonnull
public IStorageDisk<ItemStack> createDefaultItemDisk(ServerWorld world, int capacity) { public IStorageDisk<ItemStack> createDefaultItemDisk(ServerWorld world, int capacity, @Nullable PlayerEntity owner) {
if (world == null) { if (world == null) {
throw new IllegalArgumentException("World cannot be null"); throw new IllegalArgumentException("World cannot be null");
} }
return new ItemStorageDisk(world, capacity); return new ItemStorageDisk(world, capacity, owner == null ? null : owner.getGameProfile().getId());
} }
@Override @Override
@Nonnull @Nonnull
public IStorageDisk<FluidStack> createDefaultFluidDisk(ServerWorld world, int capacity) { public IStorageDisk<FluidStack> createDefaultFluidDisk(ServerWorld world, int capacity, @Nullable PlayerEntity owner) {
if (world == null) { if (world == null) {
throw new IllegalArgumentException("World cannot be null"); throw new IllegalArgumentException("World cannot be null");
} }
return new FluidStorageDisk(world, capacity); return new FluidStorageDisk(world, capacity, owner == null ? null : owner.getGameProfile().getId());
} }
@Override @Override

View File

@@ -79,8 +79,8 @@ public class CraftingTask implements ICraftingTask, NodeListener {
this.id = UUID.randomUUID(); this.id = UUID.randomUUID();
this.nodes = nodes; this.nodes = nodes;
this.internalStorage = new ItemStorageDisk(null, -1); this.internalStorage = new ItemStorageDisk(null, -1, null);
this.internalFluidStorage = new FluidStorageDisk(null, -1); this.internalFluidStorage = new FluidStorageDisk(null, -1, null);
this.toExtractInitial = toExtractInitial; this.toExtractInitial = toExtractInitial;
this.toExtractInitialFluids = toExtractInitialFluids; this.toExtractInitialFluids = toExtractInitialFluids;

View File

@@ -15,6 +15,7 @@ import net.minecraftforge.fluids.FluidStack;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Collection; import java.util.Collection;
import java.util.UUID;
public class FluidDriveWrapperStorageDisk implements IStorageDisk<FluidStack> { public class FluidDriveWrapperStorageDisk implements IStorageDisk<FluidStack> {
private final DiskDriveNetworkNode diskDrive; private final DiskDriveNetworkNode diskDrive;
@@ -85,6 +86,12 @@ public class FluidDriveWrapperStorageDisk implements IStorageDisk<FluidStack> {
return parent.getCapacity(); return parent.getCapacity();
} }
@Nullable
@Override
public UUID getOwner() {
return parent.getOwner();
}
@Override @Override
public void setSettings(@Nullable IStorageDiskListener listener, IStorageDiskContainerContext context) { public void setSettings(@Nullable IStorageDiskListener listener, IStorageDiskContainerContext context) {
parent.setSettings(listener, context); parent.setSettings(listener, context);

View File

@@ -15,6 +15,7 @@ import net.minecraftforge.items.ItemHandlerHelper;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Collection; import java.util.Collection;
import java.util.UUID;
public class ItemDriveWrapperStorageDisk implements IStorageDisk<ItemStack> { public class ItemDriveWrapperStorageDisk implements IStorageDisk<ItemStack> {
private final DiskDriveNetworkNode diskDrive; private final DiskDriveNetworkNode diskDrive;
@@ -85,6 +86,12 @@ public class ItemDriveWrapperStorageDisk implements IStorageDisk<ItemStack> {
return parent.getCapacity(); return parent.getCapacity();
} }
@Nullable
@Override
public UUID getOwner() {
return parent.getOwner();
}
@Override @Override
public void setSettings(@Nullable IStorageDiskListener listener, IStorageDiskContainerContext context) { public void setSettings(@Nullable IStorageDiskListener listener, IStorageDiskContainerContext context) {
parent.setSettings(listener, context); parent.setSettings(listener, context);

View File

@@ -16,6 +16,7 @@ import net.minecraftforge.fluids.FluidStack;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Collection; import java.util.Collection;
import java.util.UUID;
public class StorageDiskFluidManipulatorWrapper implements IStorageDisk<FluidStack> { public class StorageDiskFluidManipulatorWrapper implements IStorageDisk<FluidStack> {
private final DiskManipulatorNetworkNode diskManipulator; private final DiskManipulatorNetworkNode diskManipulator;
@@ -45,6 +46,12 @@ public class StorageDiskFluidManipulatorWrapper implements IStorageDisk<FluidSta
return parent.getCapacity(); return parent.getCapacity();
} }
@Nullable
@Override
public UUID getOwner() {
return parent.getOwner();
}
@Override @Override
public void setSettings(@Nullable IStorageDiskListener listener, IStorageDiskContainerContext context) { public void setSettings(@Nullable IStorageDiskListener listener, IStorageDiskContainerContext context) {
parent.setSettings(listener, context); parent.setSettings(listener, context);

View File

@@ -16,6 +16,7 @@ import net.minecraftforge.items.ItemHandlerHelper;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Collection; import java.util.Collection;
import java.util.UUID;
public class StorageDiskItemManipulatorWrapper implements IStorageDisk<ItemStack> { public class StorageDiskItemManipulatorWrapper implements IStorageDisk<ItemStack> {
private final DiskManipulatorNetworkNode diskManipulator; private final DiskManipulatorNetworkNode diskManipulator;
@@ -45,6 +46,12 @@ public class StorageDiskItemManipulatorWrapper implements IStorageDisk<ItemStack
return parent.getCapacity(); return parent.getCapacity();
} }
@Nullable
@Override
public UUID getOwner() {
return parent.getOwner();
}
@Override @Override
public void setSettings(@Nullable IStorageDiskListener listener, IStorageDiskContainerContext context) { public void setSettings(@Nullable IStorageDiskListener listener, IStorageDiskContainerContext context) {
parent.setSettings(listener, context); parent.setSettings(listener, context);

View File

@@ -24,6 +24,7 @@ import com.refinedmods.refinedstorage.tile.config.IPrioritizable;
import com.refinedmods.refinedstorage.tile.config.IWhitelistBlacklist; import com.refinedmods.refinedstorage.tile.config.IWhitelistBlacklist;
import com.refinedmods.refinedstorage.util.AccessTypeUtils; import com.refinedmods.refinedstorage.util.AccessTypeUtils;
import com.refinedmods.refinedstorage.util.FluidStorageBlockUtils; import com.refinedmods.refinedstorage.util.FluidStorageBlockUtils;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
@@ -36,6 +37,7 @@ import net.minecraftforge.fluids.FluidStack;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import javax.annotation.Nullable;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@@ -107,7 +109,7 @@ public class FluidStorageNetworkNode extends NetworkNode implements IStorageScre
@Override @Override
public void addFluidStorages(List<IStorage<FluidStack>> storages) { public void addFluidStorages(List<IStorage<FluidStack>> storages) {
if (storage == null) { if (storage == null) {
loadStorage(); loadStorage(null);
} }
storages.add(storage); storages.add(storage);
@@ -134,15 +136,15 @@ public class FluidStorageNetworkNode extends NetworkNode implements IStorageScre
if (tag.hasUniqueId(NBT_ID)) { if (tag.hasUniqueId(NBT_ID)) {
storageId = tag.getUniqueId(NBT_ID); storageId = tag.getUniqueId(NBT_ID);
loadStorage(); loadStorage(null);
} }
} }
public void loadStorage() { public void loadStorage(@Nullable PlayerEntity owner) {
IStorageDisk disk = API.instance().getStorageDiskManager((ServerWorld) world).get(storageId); IStorageDisk disk = API.instance().getStorageDiskManager((ServerWorld) world).get(storageId);
if (disk == null) { if (disk == null) {
API.instance().getStorageDiskManager((ServerWorld) world).set(storageId, disk = API.instance().createDefaultFluidDisk((ServerWorld) world, type.getCapacity())); API.instance().getStorageDiskManager((ServerWorld) world).set(storageId, disk = API.instance().createDefaultFluidDisk((ServerWorld) world, type.getCapacity(), owner));
API.instance().getStorageDiskManager((ServerWorld) world).markForSaving(); API.instance().getStorageDiskManager((ServerWorld) world).markForSaving();
} }

View File

@@ -14,6 +14,7 @@ import net.minecraftforge.fluids.FluidStack;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Collection; import java.util.Collection;
import java.util.UUID;
public class FluidStorageWrapperStorageDisk implements IStorageDisk<FluidStack> { public class FluidStorageWrapperStorageDisk implements IStorageDisk<FluidStack> {
private final FluidStorageNetworkNode storage; private final FluidStorageNetworkNode storage;
@@ -71,6 +72,12 @@ public class FluidStorageWrapperStorageDisk implements IStorageDisk<FluidStack>
return parent.getCapacity(); return parent.getCapacity();
} }
@Nullable
@Override
public UUID getOwner() {
return parent.getOwner();
}
@Override @Override
public void setSettings(@Nullable IStorageDiskListener listener, IStorageDiskContainerContext context) { public void setSettings(@Nullable IStorageDiskListener listener, IStorageDiskContainerContext context) {
parent.setSettings(listener, context); parent.setSettings(listener, context);

View File

@@ -14,6 +14,7 @@ import net.minecraftforge.items.ItemHandlerHelper;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Collection; import java.util.Collection;
import java.util.UUID;
public class ItemStorageWrapperStorageDisk implements IStorageDisk<ItemStack> { public class ItemStorageWrapperStorageDisk implements IStorageDisk<ItemStack> {
private final StorageNetworkNode storage; private final StorageNetworkNode storage;
@@ -71,6 +72,12 @@ public class ItemStorageWrapperStorageDisk implements IStorageDisk<ItemStack> {
return parent.getCapacity(); return parent.getCapacity();
} }
@Nullable
@Override
public UUID getOwner() {
return parent.getOwner();
}
@Override @Override
public void setSettings(@Nullable IStorageDiskListener listener, IStorageDiskContainerContext context) { public void setSettings(@Nullable IStorageDiskListener listener, IStorageDiskContainerContext context) {
parent.setSettings(listener, context); parent.setSettings(listener, context);

View File

@@ -25,6 +25,7 @@ import com.refinedmods.refinedstorage.tile.config.IWhitelistBlacklist;
import com.refinedmods.refinedstorage.util.AccessTypeUtils; import com.refinedmods.refinedstorage.util.AccessTypeUtils;
import com.refinedmods.refinedstorage.util.StackUtils; import com.refinedmods.refinedstorage.util.StackUtils;
import com.refinedmods.refinedstorage.util.StorageBlockUtils; import com.refinedmods.refinedstorage.util.StorageBlockUtils;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
@@ -37,6 +38,7 @@ import net.minecraftforge.fluids.FluidStack;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import javax.annotation.Nullable;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@@ -102,7 +104,7 @@ public class StorageNetworkNode extends NetworkNode implements IStorageScreen, I
@Override @Override
public void addItemStorages(List<IStorage<ItemStack>> storages) { public void addItemStorages(List<IStorage<ItemStack>> storages) {
if (storage == null) { if (storage == null) {
loadStorage(); loadStorage(null);
} }
storages.add(storage); storages.add(storage);
@@ -134,15 +136,15 @@ public class StorageNetworkNode extends NetworkNode implements IStorageScreen, I
if (tag.hasUniqueId(NBT_ID)) { if (tag.hasUniqueId(NBT_ID)) {
storageId = tag.getUniqueId(NBT_ID); storageId = tag.getUniqueId(NBT_ID);
loadStorage(); loadStorage(null);
} }
} }
public void loadStorage() { public void loadStorage(@Nullable PlayerEntity owner) {
IStorageDisk disk = API.instance().getStorageDiskManager((ServerWorld) world).get(storageId); IStorageDisk disk = API.instance().getStorageDiskManager((ServerWorld) world).get(storageId);
if (disk == null) { if (disk == null) {
API.instance().getStorageDiskManager((ServerWorld) world).set(storageId, disk = API.instance().createDefaultItemDisk((ServerWorld) world, type.getCapacity())); API.instance().getStorageDiskManager((ServerWorld) world).set(storageId, disk = API.instance().createDefaultItemDisk((ServerWorld) world, type.getCapacity(), owner));
API.instance().getStorageDiskManager((ServerWorld) world).markForSaving(); API.instance().getStorageDiskManager((ServerWorld) world).markForSaving();
} }

View File

@@ -20,25 +20,29 @@ import net.minecraftforge.fluids.FluidStack;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Collection; import java.util.Collection;
import java.util.UUID;
public class FluidStorageDisk implements IStorageDisk<FluidStack> { public class FluidStorageDisk implements IStorageDisk<FluidStack> {
public static final String NBT_VERSION = "Version"; public static final String NBT_VERSION = "Version";
public static final String NBT_CAPACITY = "Capacity"; public static final String NBT_CAPACITY = "Capacity";
public static final String NBT_FLUIDS = "Fluids"; public static final String NBT_FLUIDS = "Fluids";
public static final String NBT_OWNER = "Owner";
public static final int VERSION = 1; public static final int VERSION = 1;
@Nullable @Nullable
private final ServerWorld world; private final ServerWorld world;
private final int capacity; private final int capacity;
private final Multimap<Fluid, FluidStack> stacks = ArrayListMultimap.create(); private final Multimap<Fluid, FluidStack> stacks = ArrayListMultimap.create();
private final UUID owner;
@Nullable @Nullable
private IStorageDiskListener listener; private IStorageDiskListener listener;
private IStorageDiskContainerContext context; private IStorageDiskContainerContext context;
public FluidStorageDisk(@Nullable ServerWorld world, int capacity) { public FluidStorageDisk(@Nullable ServerWorld world, int capacity, @Nullable UUID owner) {
this.world = world; this.world = world;
this.capacity = capacity; this.capacity = capacity;
this.owner = owner;
} }
@Override @Override
@@ -55,6 +59,10 @@ public class FluidStorageDisk implements IStorageDisk<FluidStack> {
tag.put(NBT_FLUIDS, list); tag.put(NBT_FLUIDS, list);
tag.putInt(NBT_CAPACITY, capacity); tag.putInt(NBT_CAPACITY, capacity);
if (owner != null) {
tag.putUniqueId(NBT_OWNER, owner);
}
return tag; return tag;
} }
@@ -173,6 +181,12 @@ public class FluidStorageDisk implements IStorageDisk<FluidStack> {
return capacity; return capacity;
} }
@Nullable
@Override
public UUID getOwner() {
return owner;
}
@Override @Override
public int getCacheDelta(int storedPreInsertion, int size, @Nullable FluidStack remainder) { public int getCacheDelta(int storedPreInsertion, int size, @Nullable FluidStack remainder) {
if (getAccessType() == AccessType.INSERT) { if (getAccessType() == AccessType.INSERT) {

View File

@@ -21,25 +21,29 @@ import net.minecraftforge.items.ItemHandlerHelper;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Collection; import java.util.Collection;
import java.util.UUID;
public class ItemStorageDisk implements IStorageDisk<ItemStack> { public class ItemStorageDisk implements IStorageDisk<ItemStack> {
public static final String NBT_VERSION = "Version"; public static final String NBT_VERSION = "Version";
public static final String NBT_CAPACITY = "Capacity"; public static final String NBT_CAPACITY = "Capacity";
public static final String NBT_ITEMS = "Items"; public static final String NBT_ITEMS = "Items";
public static final String NBT_OWNER = "Owner";
public static final int VERSION = 1; public static final int VERSION = 1;
@Nullable @Nullable
private final ServerWorld world; private final ServerWorld world;
private final int capacity; private final int capacity;
private final Multimap<Item, ItemStack> stacks = ArrayListMultimap.create(); private final Multimap<Item, ItemStack> stacks = ArrayListMultimap.create();
private final UUID owner;
@Nullable @Nullable
private IStorageDiskListener listener; private IStorageDiskListener listener;
private IStorageDiskContainerContext context; private IStorageDiskContainerContext context;
public ItemStorageDisk(@Nullable ServerWorld world, int capacity) { public ItemStorageDisk(@Nullable ServerWorld world, int capacity, @Nullable UUID owner) {
this.world = world; this.world = world;
this.capacity = capacity; this.capacity = capacity;
this.owner = owner;
} }
@Override @Override
@@ -56,6 +60,10 @@ public class ItemStorageDisk implements IStorageDisk<ItemStack> {
tag.put(NBT_ITEMS, list); tag.put(NBT_ITEMS, list);
tag.putInt(NBT_CAPACITY, capacity); tag.putInt(NBT_CAPACITY, capacity);
if (owner != null) {
tag.putUniqueId(NBT_OWNER, owner);
}
return tag; return tag;
} }
@@ -179,6 +187,12 @@ public class ItemStorageDisk implements IStorageDisk<ItemStack> {
return capacity; return capacity;
} }
@Nullable
@Override
public UUID getOwner() {
return owner;
}
@Override @Override
public void setSettings(@Nullable IStorageDiskListener listener, IStorageDiskContainerContext context) { public void setSettings(@Nullable IStorageDiskListener listener, IStorageDiskContainerContext context) {
this.listener = listener; this.listener = listener;

View File

@@ -13,6 +13,7 @@ import net.minecraftforge.fluids.FluidStack;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Collection; import java.util.Collection;
import java.util.UUID;
public class PortableFluidStorageDisk implements IStorageDisk<FluidStack> { public class PortableFluidStorageDisk implements IStorageDisk<FluidStack> {
private final IStorageDisk<FluidStack> parent; private final IStorageDisk<FluidStack> parent;
@@ -28,6 +29,12 @@ public class PortableFluidStorageDisk implements IStorageDisk<FluidStack> {
return parent.getCapacity(); return parent.getCapacity();
} }
@Nullable
@Override
public UUID getOwner() {
return parent.getOwner();
}
@Override @Override
public void setSettings(@Nullable IStorageDiskListener listener, IStorageDiskContainerContext context) { public void setSettings(@Nullable IStorageDiskListener listener, IStorageDiskContainerContext context) {
parent.setSettings(listener, context); parent.setSettings(listener, context);

View File

@@ -13,6 +13,7 @@ import net.minecraft.util.ResourceLocation;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Collection; import java.util.Collection;
import java.util.UUID;
public class PortableItemStorageDisk implements IStorageDisk<ItemStack> { public class PortableItemStorageDisk implements IStorageDisk<ItemStack> {
private final IStorageDisk<ItemStack> parent; private final IStorageDisk<ItemStack> parent;
@@ -28,6 +29,12 @@ public class PortableItemStorageDisk implements IStorageDisk<ItemStack> {
return parent.getCapacity(); return parent.getCapacity();
} }
@Nullable
@Override
public UUID getOwner() {
return parent.getOwner();
}
@Override @Override
public void setSettings(@Nullable IStorageDiskListener listener, IStorageDiskContainerContext context) { public void setSettings(@Nullable IStorageDiskListener listener, IStorageDiskContainerContext context) {
parent.setSettings(listener, context); parent.setSettings(listener, context);

View File

@@ -14,6 +14,7 @@ import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.util.Constants; import net.minecraftforge.common.util.Constants;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import javax.annotation.Nullable;
import java.util.UUID; import java.util.UUID;
public class FluidStorageDiskFactory implements IStorageDiskFactory<FluidStack> { public class FluidStorageDiskFactory implements IStorageDiskFactory<FluidStack> {
@@ -21,7 +22,11 @@ public class FluidStorageDiskFactory implements IStorageDiskFactory<FluidStack>
@Override @Override
public IStorageDisk<FluidStack> createFromNbt(ServerWorld world, CompoundNBT tag) { public IStorageDisk<FluidStack> createFromNbt(ServerWorld world, CompoundNBT tag) {
FluidStorageDisk disk = new FluidStorageDisk(world, tag.getInt(FluidStorageDisk.NBT_CAPACITY)); FluidStorageDisk disk = new FluidStorageDisk(
world,
tag.getInt(FluidStorageDisk.NBT_CAPACITY),
tag.contains(FluidStorageDisk.NBT_OWNER) ? tag.getUniqueId(FluidStorageDisk.NBT_OWNER) : null
);
ListNBT list = tag.getList(FluidStorageDisk.NBT_FLUIDS, Constants.NBT.TAG_COMPOUND); ListNBT list = tag.getList(FluidStorageDisk.NBT_FLUIDS, Constants.NBT.TAG_COMPOUND);
@@ -63,7 +68,7 @@ public class FluidStorageDiskFactory implements IStorageDiskFactory<FluidStack>
} }
@Override @Override
public IStorageDisk<FluidStack> create(ServerWorld world, int capacity) { public IStorageDisk<FluidStack> create(ServerWorld world, int capacity, @Nullable UUID owner) {
return new FluidStorageDisk(world, capacity); return new FluidStorageDisk(world, capacity, owner);
} }
} }

View File

@@ -4,12 +4,9 @@ import com.refinedmods.refinedstorage.RS;
import com.refinedmods.refinedstorage.RSItems; import com.refinedmods.refinedstorage.RSItems;
import com.refinedmods.refinedstorage.api.storage.disk.IStorageDisk; import com.refinedmods.refinedstorage.api.storage.disk.IStorageDisk;
import com.refinedmods.refinedstorage.api.storage.disk.IStorageDiskFactory; import com.refinedmods.refinedstorage.api.storage.disk.IStorageDiskFactory;
import com.refinedmods.refinedstorage.apiimpl.API;
import com.refinedmods.refinedstorage.apiimpl.storage.ItemStorageType;
import com.refinedmods.refinedstorage.apiimpl.storage.disk.ItemStorageDisk; import com.refinedmods.refinedstorage.apiimpl.storage.disk.ItemStorageDisk;
import com.refinedmods.refinedstorage.item.StorageDiskItem; import com.refinedmods.refinedstorage.item.StorageDiskItem;
import com.refinedmods.refinedstorage.util.StackUtils; import com.refinedmods.refinedstorage.util.StackUtils;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.ListNBT; import net.minecraft.nbt.ListNBT;
@@ -17,6 +14,7 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.world.server.ServerWorld; import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.util.Constants; import net.minecraftforge.common.util.Constants;
import javax.annotation.Nullable;
import java.util.UUID; import java.util.UUID;
public class ItemStorageDiskFactory implements IStorageDiskFactory<ItemStack> { public class ItemStorageDiskFactory implements IStorageDiskFactory<ItemStack> {
@@ -24,7 +22,11 @@ public class ItemStorageDiskFactory implements IStorageDiskFactory<ItemStack> {
@Override @Override
public IStorageDisk<ItemStack> createFromNbt(ServerWorld world, CompoundNBT tag) { public IStorageDisk<ItemStack> createFromNbt(ServerWorld world, CompoundNBT tag) {
ItemStorageDisk disk = new ItemStorageDisk(world, tag.getInt(ItemStorageDisk.NBT_CAPACITY)); ItemStorageDisk disk = new ItemStorageDisk(
world,
tag.getInt(ItemStorageDisk.NBT_CAPACITY),
tag.contains(ItemStorageDisk.NBT_OWNER) ? tag.getUniqueId(ItemStorageDisk.NBT_OWNER) : null
);
ListNBT list = tag.getList(ItemStorageDisk.NBT_ITEMS, Constants.NBT.TAG_COMPOUND); ListNBT list = tag.getList(ItemStorageDisk.NBT_ITEMS, Constants.NBT.TAG_COMPOUND);
@@ -66,7 +68,7 @@ public class ItemStorageDiskFactory implements IStorageDiskFactory<ItemStack> {
} }
@Override @Override
public IStorageDisk<ItemStack> create(ServerWorld world, int capacity) { public IStorageDisk<ItemStack> create(ServerWorld world, int capacity, @Nullable UUID owner) {
return new ItemStorageDisk(world, capacity); return new ItemStorageDisk(world, capacity, owner);
} }
} }

View File

@@ -48,7 +48,7 @@ public class FluidStorageBlock extends NetworkNodeBlock {
storage.setStorageId(stack.getTag().getUniqueId(FluidStorageNetworkNode.NBT_ID)); storage.setStorageId(stack.getTag().getUniqueId(FluidStorageNetworkNode.NBT_ID));
} }
storage.loadStorage(); storage.loadStorage(player instanceof PlayerEntity ? (PlayerEntity) player : null);
} }
// Call this after loading the storage, so the network discovery can use the loaded storage. // Call this after loading the storage, so the network discovery can use the loaded storage.

View File

@@ -48,7 +48,7 @@ public class StorageBlock extends NetworkNodeBlock {
storage.setStorageId(stack.getTag().getUniqueId(StorageNetworkNode.NBT_ID)); storage.setStorageId(stack.getTag().getUniqueId(StorageNetworkNode.NBT_ID));
} }
storage.loadStorage(); storage.loadStorage(entity instanceof PlayerEntity ? (PlayerEntity) entity : null);
} }
// Call this after loading the storage, so the network discovery can use the loaded storage. // Call this after loading the storage, so the network discovery can use the loaded storage.

View File

@@ -1,4 +1,4 @@
package com.refinedmods.refinedstorage.command; package com.refinedmods.refinedstorage.command.disk;
import com.mojang.brigadier.Command; import com.mojang.brigadier.Command;
import com.mojang.brigadier.builder.ArgumentBuilder; import com.mojang.brigadier.builder.ArgumentBuilder;
@@ -7,6 +7,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.refinedmods.refinedstorage.api.storage.disk.IStorageDisk; import com.refinedmods.refinedstorage.api.storage.disk.IStorageDisk;
import com.refinedmods.refinedstorage.api.storage.disk.IStorageDiskFactory; import com.refinedmods.refinedstorage.api.storage.disk.IStorageDiskFactory;
import com.refinedmods.refinedstorage.apiimpl.API; import com.refinedmods.refinedstorage.apiimpl.API;
import com.refinedmods.refinedstorage.command.StorageDiskIdSuggestionProvider;
import com.refinedmods.refinedstorage.render.Styles; import com.refinedmods.refinedstorage.render.Styles;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands; import net.minecraft.command.Commands;
@@ -24,7 +25,7 @@ import java.util.UUID;
public class CreateDiskCommand implements Command<CommandSource> { public class CreateDiskCommand implements Command<CommandSource> {
public static ArgumentBuilder<CommandSource, ?> register() { public static ArgumentBuilder<CommandSource, ?> register() {
return Commands.literal("createdisk") return Commands.literal("create")
.requires(cs -> cs.hasPermissionLevel(2)) .requires(cs -> cs.hasPermissionLevel(2))
.then(Commands.argument("player", EntityArgument.player()) .then(Commands.argument("player", EntityArgument.player())
.then(Commands.argument("id", UUIDArgument.func_239194_a_()).suggests(new StorageDiskIdSuggestionProvider()) .then(Commands.argument("id", UUIDArgument.func_239194_a_()).suggests(new StorageDiskIdSuggestionProvider())

View File

@@ -0,0 +1,26 @@
package com.refinedmods.refinedstorage.command.disk;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.refinedmods.refinedstorage.apiimpl.API;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraft.util.text.StringTextComponent;
public class ListDiskCommand implements Command<CommandSource> {
public static ArgumentBuilder<CommandSource, ?> register() {
return Commands.literal("list").executes(new ListDiskCommand()).then(ListDiskForPlayerCommand.register());
}
@Override
public int run(CommandContext<CommandSource> context) {
API.instance().getStorageDiskManager(context.getSource().getWorld())
.getAll()
.keySet()
.forEach(id -> context.getSource().sendFeedback(new StringTextComponent(id.toString()), false));
return 0;
}
}

View File

@@ -0,0 +1,35 @@
package com.refinedmods.refinedstorage.command.disk;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.refinedmods.refinedstorage.apiimpl.API;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraft.command.arguments.EntityArgument;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.text.StringTextComponent;
import java.util.Map;
public class ListDiskForPlayerCommand implements Command<CommandSource> {
public static ArgumentBuilder<CommandSource, ?> register() {
return Commands.argument("player", EntityArgument.player()).executes(new ListDiskForPlayerCommand());
}
@Override
public int run(CommandContext<CommandSource> context) throws CommandSyntaxException {
PlayerEntity player = EntityArgument.getPlayer(context, "player");
API.instance().getStorageDiskManager(context.getSource().getWorld())
.getAll()
.entrySet()
.stream()
.filter(entry -> player.getGameProfile().getId().equals(entry.getValue().getOwner()))
.map(Map.Entry::getKey)
.forEach(id -> context.getSource().sendFeedback(new StringTextComponent(id.toString()), false));
return 0;
}
}

View File

@@ -1,4 +1,4 @@
package com.refinedmods.refinedstorage.command; package com.refinedmods.refinedstorage.command.pattern;
import com.mojang.brigadier.Command; import com.mojang.brigadier.Command;
import com.mojang.brigadier.builder.ArgumentBuilder; import com.mojang.brigadier.builder.ArgumentBuilder;
@@ -17,7 +17,7 @@ import net.minecraftforge.fluids.FluidStack;
public class PatternDumpCommand implements Command<CommandSource> { public class PatternDumpCommand implements Command<CommandSource> {
public static ArgumentBuilder<CommandSource, ?> register() { public static ArgumentBuilder<CommandSource, ?> register() {
return Commands.literal("patterndump") return Commands.literal("dump")
.requires(cs -> cs.hasPermissionLevel(0)) .requires(cs -> cs.hasPermissionLevel(0))
.executes(new PatternDumpCommand()); .executes(new PatternDumpCommand());
} }

View File

@@ -46,10 +46,10 @@ public class FluidStorageDiskItem extends Item implements IStorageDiskProvider {
public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) { public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
super.inventoryTick(stack, world, entity, slot, selected); super.inventoryTick(stack, world, entity, slot, selected);
if (!world.isRemote && !stack.hasTag()) { if (!world.isRemote && !stack.hasTag() && entity instanceof PlayerEntity) {
UUID id = UUID.randomUUID(); UUID id = UUID.randomUUID();
API.instance().getStorageDiskManager((ServerWorld) world).set(id, API.instance().createDefaultFluidDisk((ServerWorld) world, getCapacity(stack))); API.instance().getStorageDiskManager((ServerWorld) world).set(id, API.instance().createDefaultFluidDisk((ServerWorld) world, getCapacity(stack), (PlayerEntity) entity));
API.instance().getStorageDiskManager((ServerWorld) world).markForSaving(); API.instance().getStorageDiskManager((ServerWorld) world).markForSaving();
setId(stack, id); setId(stack, id);

View File

@@ -46,10 +46,10 @@ public class StorageDiskItem extends Item implements IStorageDiskProvider {
public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) { public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
super.inventoryTick(stack, world, entity, slot, selected); super.inventoryTick(stack, world, entity, slot, selected);
if (!world.isRemote && !stack.hasTag()) { if (!world.isRemote && !stack.hasTag() && entity instanceof PlayerEntity) {
UUID id = UUID.randomUUID(); UUID id = UUID.randomUUID();
API.instance().getStorageDiskManager((ServerWorld) world).set(id, API.instance().createDefaultItemDisk((ServerWorld) world, getCapacity(stack))); API.instance().getStorageDiskManager((ServerWorld) world).set(id, API.instance().createDefaultItemDisk((ServerWorld) world, getCapacity(stack), (PlayerEntity) entity));
API.instance().getStorageDiskManager((ServerWorld) world).markForSaving(); API.instance().getStorageDiskManager((ServerWorld) world).markForSaving();
setId(stack, id); setId(stack, id);

View File

@@ -1,8 +1,9 @@
package com.refinedmods.refinedstorage.setup; package com.refinedmods.refinedstorage.setup;
import com.refinedmods.refinedstorage.RS; import com.refinedmods.refinedstorage.RS;
import com.refinedmods.refinedstorage.command.CreateDiskCommand; import com.refinedmods.refinedstorage.command.disk.CreateDiskCommand;
import com.refinedmods.refinedstorage.command.PatternDumpCommand; import com.refinedmods.refinedstorage.command.disk.ListDiskCommand;
import com.refinedmods.refinedstorage.command.pattern.PatternDumpCommand;
import net.minecraft.command.Commands; import net.minecraft.command.Commands;
import net.minecraftforge.event.RegisterCommandsEvent; import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
@@ -10,7 +11,9 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
public class ServerSetup { public class ServerSetup {
@SubscribeEvent @SubscribeEvent
public void onRegisterCommands(RegisterCommandsEvent e) { public void onRegisterCommands(RegisterCommandsEvent e) {
e.getDispatcher().register(Commands.literal(RS.ID).then(PatternDumpCommand.register())); e.getDispatcher().register(Commands.literal(RS.ID).then(Commands.literal("pattern").then(PatternDumpCommand.register())));
e.getDispatcher().register(Commands.literal(RS.ID).then(CreateDiskCommand.register())); e.getDispatcher().register(Commands.literal(RS.ID).then(Commands.literal("disk")
.then(CreateDiskCommand.register())
.then(ListDiskCommand.register())));
} }
} }