Rename IStorageObject to IStorageStack
This commit is contained in:
parent
0806794722
commit
7e9d7ca8f8
@ -1,6 +1,5 @@
|
|||||||
package ru.dbotthepony.mc.otm;
|
package ru.dbotthepony.mc.otm;
|
||||||
|
|
||||||
import net.minecraft.server.level.ServerLevel;
|
|
||||||
import net.minecraft.world.item.CreativeModeTab;
|
import net.minecraft.world.item.CreativeModeTab;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
@ -31,7 +30,7 @@ import ru.dbotthepony.mc.otm.item.ItemPortableCondensationDrive;
|
|||||||
import ru.dbotthepony.mc.otm.matter.MatterGrid;
|
import ru.dbotthepony.mc.otm.matter.MatterGrid;
|
||||||
import ru.dbotthepony.mc.otm.matter.MatterRegistry;
|
import ru.dbotthepony.mc.otm.matter.MatterRegistry;
|
||||||
import ru.dbotthepony.mc.otm.network.MatteryNetworking;
|
import ru.dbotthepony.mc.otm.network.MatteryNetworking;
|
||||||
import ru.dbotthepony.mc.otm.storage.ItemStackObject;
|
import ru.dbotthepony.mc.otm.storage.ItemStackStack;
|
||||||
import ru.dbotthepony.mc.otm.storage.StorageObjectRegistry;
|
import ru.dbotthepony.mc.otm.storage.StorageObjectRegistry;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -168,7 +167,7 @@ public class OverdriveThatMatters {
|
|||||||
|
|
||||||
MatterRegistry.registerInitialItems();
|
MatterRegistry.registerInitialItems();
|
||||||
|
|
||||||
StorageObjectRegistry.register(ItemStackObject.class, ItemStackObject.EMPTY);
|
StorageObjectRegistry.register(ItemStackStack.class, ItemStackStack.EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupClient(final FMLClientSetupEvent event) {
|
private void setupClient(final FMLClientSetupEvent event) {
|
||||||
|
@ -11,26 +11,20 @@ import net.minecraft.world.entity.player.Player;
|
|||||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraftforge.common.capabilities.Capability;
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
import net.minecraftforge.common.util.LazyOptional;
|
import net.minecraftforge.common.util.LazyOptional;
|
||||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
|
||||||
import ru.dbotthepony.mc.otm.Registry;
|
import ru.dbotthepony.mc.otm.Registry;
|
||||||
import ru.dbotthepony.mc.otm.capability.AbstractStorageGridCell;
|
import ru.dbotthepony.mc.otm.capability.AbstractStorageGridCell;
|
||||||
import ru.dbotthepony.mc.otm.capability.IStorageGridCell;
|
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryMachineEnergyStorage;
|
import ru.dbotthepony.mc.otm.capability.MatteryMachineEnergyStorage;
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainer;
|
import ru.dbotthepony.mc.otm.container.MatteryContainer;
|
||||||
import ru.dbotthepony.mc.otm.menu.DriveRackMenu;
|
import ru.dbotthepony.mc.otm.menu.DriveRackMenu;
|
||||||
import ru.dbotthepony.mc.otm.storage.IStorageIdentity;
|
|
||||||
import ru.dbotthepony.mc.otm.storage.ItemStackObject;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.ParametersAreNonnullByDefault;
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@MethodsReturnNonnullByDefault
|
@MethodsReturnNonnullByDefault
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
|
@ -4,7 +4,7 @@ import net.minecraft.MethodsReturnNonnullByDefault;
|
|||||||
import net.minecraftforge.common.util.LazyOptional;
|
import net.minecraftforge.common.util.LazyOptional;
|
||||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
||||||
import ru.dbotthepony.mc.otm.storage.IStorageIdentity;
|
import ru.dbotthepony.mc.otm.storage.IStorageIdentity;
|
||||||
import ru.dbotthepony.mc.otm.storage.IStorageObject;
|
import ru.dbotthepony.mc.otm.storage.IStorageStack;
|
||||||
import ru.dbotthepony.mc.otm.storage.StorageGrid;
|
import ru.dbotthepony.mc.otm.storage.StorageGrid;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -26,7 +26,7 @@ public class AbstractStorageGridCell implements IStorageGridCell {
|
|||||||
return Collections.unmodifiableList(components);
|
return Collections.unmodifiableList(components);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends IStorageObject, U extends IStorageIdentity<T>> U computeIfAbsent(Class<T> identity, Supplier<U> provider) {
|
public <T extends IStorageStack, U extends IStorageIdentity<T>> U computeIfAbsent(Class<T> identity, Supplier<U> provider) {
|
||||||
for (var component : components) {
|
for (var component : components) {
|
||||||
if (component.storageIdentity() == identity) {
|
if (component.storageIdentity() == identity) {
|
||||||
return (U) component;
|
return (U) component;
|
||||||
|
@ -4,20 +4,15 @@ import net.minecraft.MethodsReturnNonnullByDefault;
|
|||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraftforge.common.util.INBTSerializable;
|
|
||||||
import ru.dbotthepony.mc.otm.menu.DriveViewerMenu;
|
|
||||||
import ru.dbotthepony.mc.otm.storage.*;
|
import ru.dbotthepony.mc.otm.storage.*;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import javax.annotation.ParametersAreNonnullByDefault;
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
@MethodsReturnNonnullByDefault
|
@MethodsReturnNonnullByDefault
|
||||||
public interface IMatteryDrive extends IStorageComponent<ItemStackObject> {
|
public interface IMatteryDrive extends IStorageComponent<ItemStackStack> {
|
||||||
record StoredStack(ItemStack stack, UUID id) {};
|
record StoredStack(ItemStack stack, UUID id) {};
|
||||||
|
|
||||||
List<StoredStack> getItems();
|
List<StoredStack> getItems();
|
||||||
|
@ -9,14 +9,12 @@ import net.minecraft.world.item.Item;
|
|||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.Items;
|
import net.minecraft.world.item.Items;
|
||||||
import net.minecraftforge.registries.RegistryManager;
|
import net.minecraftforge.registries.RegistryManager;
|
||||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
|
||||||
import ru.dbotthepony.mc.otm.storage.IStorageListener;
|
import ru.dbotthepony.mc.otm.storage.IStorageListener;
|
||||||
import ru.dbotthepony.mc.otm.storage.IStorageTuple;
|
import ru.dbotthepony.mc.otm.storage.IStorageTuple;
|
||||||
import ru.dbotthepony.mc.otm.storage.ItemStackObject;
|
import ru.dbotthepony.mc.otm.storage.ItemStackStack;
|
||||||
import ru.dbotthepony.mc.otm.storage.StorageTuple;
|
import ru.dbotthepony.mc.otm.storage.StorageTuple;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import javax.annotation.ParametersAreNonnullByDefault;
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -175,7 +173,7 @@ public class MatteryDrive implements IMatteryDrive {
|
|||||||
items_by_id.put(state.id(), state);
|
items_by_id.put(state.id(), state);
|
||||||
|
|
||||||
for (var listener : listeners2) {
|
for (var listener : listeners2) {
|
||||||
listener.addObject(new ItemStackObject(state.stack()), state.id(), this);
|
listener.addObject(new ItemStackStack(state.stack()), state.id(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
markDirty();
|
markDirty();
|
||||||
@ -187,9 +185,9 @@ public class MatteryDrive implements IMatteryDrive {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStackObject insertObject(ItemStackObject obj, boolean simulate) {
|
public ItemStackStack insertObject(ItemStackStack obj, boolean simulate) {
|
||||||
var get = insertItem(obj.stack(), simulate);
|
var get = insertItem(obj.stack(), simulate);
|
||||||
return get.isEmpty() ? ItemStackObject.EMPTY : new ItemStackObject(get);
|
return get.isEmpty() ? ItemStackStack.EMPTY : new ItemStackStack(get);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@ -324,49 +322,49 @@ public class MatteryDrive implements IMatteryDrive {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<ItemStackObject> storageIdentity() {
|
public Class<ItemStackStack> storageIdentity() {
|
||||||
return ItemStackObject.class;
|
return ItemStackStack.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStackObject getStoredObject(UUID id) {
|
public ItemStackStack getStoredObject(UUID id) {
|
||||||
var get = getItem(id);
|
var get = getItem(id);
|
||||||
return get.isEmpty() ? ItemStackObject.EMPTY : new ItemStackObject(get);
|
return get.isEmpty() ? ItemStackStack.EMPTY : new ItemStackStack(get);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStackObject extractObject(UUID id, BigDecimal amount, boolean simulate) {
|
public ItemStackStack extractObject(UUID id, BigDecimal amount, boolean simulate) {
|
||||||
var get = extractItem(id, amount.intValue(), simulate);
|
var get = extractItem(id, amount.intValue(), simulate);
|
||||||
return get.isEmpty() ? ItemStackObject.EMPTY : new ItemStackObject(get);
|
return get.isEmpty() ? ItemStackStack.EMPTY : new ItemStackStack(get);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<IStorageTuple<ItemStackObject>> getStorageObjects() {
|
public List<IStorageTuple<ItemStackStack>> getStorageObjects() {
|
||||||
int amount = 0;
|
int amount = 0;
|
||||||
|
|
||||||
for (var listing : items.values())
|
for (var listing : items.values())
|
||||||
amount += listing.size();
|
amount += listing.size();
|
||||||
|
|
||||||
var list = new ArrayList<IStorageTuple<ItemStackObject>>(amount);
|
var list = new ArrayList<IStorageTuple<ItemStackStack>>(amount);
|
||||||
|
|
||||||
for (var listing : items.values()) {
|
for (var listing : items.values()) {
|
||||||
for (var stack : listing) {
|
for (var stack : listing) {
|
||||||
list.add(new StorageTuple<>(stack.id(), new ItemStackObject(stack.stack())));
|
list.add(new StorageTuple<>(stack.id(), new ItemStackStack(stack.stack())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final HashSet<IStorageListener<ItemStackObject>> listeners2 = new HashSet<>();
|
protected final HashSet<IStorageListener<ItemStackStack>> listeners2 = new HashSet<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addListener(IStorageListener<ItemStackObject> listener) {
|
public boolean addListener(IStorageListener<ItemStackStack> listener) {
|
||||||
return listeners2.add(listener);
|
return listeners2.add(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean removeListener(IStorageListener<ItemStackObject> listener) {
|
public boolean removeListener(IStorageListener<ItemStackStack> listener) {
|
||||||
return listeners2.remove(listener);
|
return listeners2.remove(listener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
package ru.dbotthepony.mc.otm.menu;
|
package ru.dbotthepony.mc.otm.menu;
|
||||||
|
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
|
||||||
import ru.dbotthepony.mc.otm.Registry;
|
import ru.dbotthepony.mc.otm.Registry;
|
||||||
import ru.dbotthepony.mc.otm.block.entity.BlockEntityDriveRack;
|
|
||||||
import ru.dbotthepony.mc.otm.block.entity.BlockEntityItemMonitor;
|
import ru.dbotthepony.mc.otm.block.entity.BlockEntityItemMonitor;
|
||||||
import ru.dbotthepony.mc.otm.menu.data.INetworkedItemViewSupplier;
|
import ru.dbotthepony.mc.otm.menu.data.INetworkedItemViewSupplier;
|
||||||
import ru.dbotthepony.mc.otm.menu.data.InteractPacket;
|
|
||||||
import ru.dbotthepony.mc.otm.menu.data.NetworkedItemView;
|
import ru.dbotthepony.mc.otm.menu.data.NetworkedItemView;
|
||||||
import ru.dbotthepony.mc.otm.storage.ItemStackObject;
|
import ru.dbotthepony.mc.otm.storage.ItemStackStack;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
@ -31,7 +28,7 @@ public class ItemMonitorMenu extends PoweredMatteryMenu implements INetworkedIte
|
|||||||
view = new NetworkedItemView(inventory.player, this, tile == null);
|
view = new NetworkedItemView(inventory.player, this, tile == null);
|
||||||
|
|
||||||
if (tile != null) {
|
if (tile != null) {
|
||||||
view.setComponent(tile.cell.getStorageGrid().getVirtualComponent(ItemStackObject.class));
|
view.setComponent(tile.cell.getStorageGrid().getVirtualComponent(ItemStackStack.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
addBatterySlot();
|
addBatterySlot();
|
||||||
|
@ -29,7 +29,7 @@ import static net.minecraft.client.gui.screens.Screen.hasShiftDown;
|
|||||||
|
|
||||||
@MethodsReturnNonnullByDefault
|
@MethodsReturnNonnullByDefault
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
public class NetworkedItemView implements IStorageListener<ItemStackObject> {
|
public class NetworkedItemView implements IStorageListener<ItemStackStack> {
|
||||||
public final boolean remote;
|
public final boolean remote;
|
||||||
public final MatteryMenu menu;
|
public final MatteryMenu menu;
|
||||||
public final Player ply;
|
public final Player ply;
|
||||||
@ -47,7 +47,7 @@ public class NetworkedItemView implements IStorageListener<ItemStackObject> {
|
|||||||
|
|
||||||
private List<NetworkedItem> view_cache;
|
private List<NetworkedItem> view_cache;
|
||||||
|
|
||||||
protected IStorageComponent<ItemStackObject> provider;
|
protected IStorageComponent<ItemStackStack> provider;
|
||||||
|
|
||||||
public NetworkedItemView(Player ply, MatteryMenu menu, boolean remote) {
|
public NetworkedItemView(Player ply, MatteryMenu menu, boolean remote) {
|
||||||
this.remote = remote;
|
this.remote = remote;
|
||||||
@ -63,7 +63,7 @@ public class NetworkedItemView implements IStorageListener<ItemStackObject> {
|
|||||||
MatteryNetworking.send(null, new InteractPacket(menu.containerId, index >= list.size() ? -1 : list.get(index).id(), type, action));
|
MatteryNetworking.send(null, new InteractPacket(menu.containerId, index >= list.size() ? -1 : list.get(index).id(), type, action));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setComponent(@Nullable IStorageComponent<ItemStackObject> provider) {
|
public void setComponent(@Nullable IStorageComponent<ItemStackStack> provider) {
|
||||||
if (provider == this.provider)
|
if (provider == this.provider)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ public class NetworkedItemView implements IStorageListener<ItemStackObject> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addObject(ItemStackObject stack, UUID id, IStorageView<ItemStackObject> provider) {
|
public void addObject(ItemStackStack stack, UUID id, IStorageView<ItemStackStack> provider) {
|
||||||
addObject(stack.stack(), id);
|
addObject(stack.stack(), id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,7 +238,7 @@ public class NetworkedItemView implements IStorageListener<ItemStackObject> {
|
|||||||
int amount = calculateIOAmount(carried.getCount());
|
int amount = calculateIOAmount(carried.getCount());
|
||||||
|
|
||||||
if (amount == carried.getCount()) {
|
if (amount == carried.getCount()) {
|
||||||
var leftover = provider.insertObject(new ItemStackObject(menu.getCarried()), false);
|
var leftover = provider.insertObject(new ItemStackStack(menu.getCarried()), false);
|
||||||
menu.setCarried(leftover.stack());
|
menu.setCarried(leftover.stack());
|
||||||
doneIOAmount(amount - leftover.stack().getCount());
|
doneIOAmount(amount - leftover.stack().getCount());
|
||||||
|
|
||||||
@ -248,7 +248,7 @@ public class NetworkedItemView implements IStorageListener<ItemStackObject> {
|
|||||||
var copy = carried.copy();
|
var copy = carried.copy();
|
||||||
copy.setCount(amount);
|
copy.setCount(amount);
|
||||||
|
|
||||||
var leftover = provider.insertObject(new ItemStackObject(copy), false);
|
var leftover = provider.insertObject(new ItemStackStack(copy), false);
|
||||||
doneIOAmount(amount - leftover.stack().getCount());
|
doneIOAmount(amount - leftover.stack().getCount());
|
||||||
|
|
||||||
leftover.setCount(carried.getCount() - amount + leftover.getCountInt());
|
leftover.setCount(carried.getCount() - amount + leftover.getCountInt());
|
||||||
@ -261,7 +261,7 @@ public class NetworkedItemView implements IStorageListener<ItemStackObject> {
|
|||||||
var copy = menu.getCarried().copy();
|
var copy = menu.getCarried().copy();
|
||||||
copy.setCount(1);
|
copy.setCount(1);
|
||||||
|
|
||||||
if (calculateIOAmount(1) == 1 && provider.insertObject(new ItemStackObject(copy), false).isEmpty()) {
|
if (calculateIOAmount(1) == 1 && provider.insertObject(new ItemStackStack(copy), false).isEmpty()) {
|
||||||
menu.getCarried().shrink(1);
|
menu.getCarried().shrink(1);
|
||||||
doneIOAmount(1);
|
doneIOAmount(1);
|
||||||
MatteryNetworking.send((ServerPlayer) ply, new SetCarriedPacket(menu.getCarried()));
|
MatteryNetworking.send((ServerPlayer) ply, new SetCarriedPacket(menu.getCarried()));
|
||||||
|
@ -3,10 +3,9 @@ package ru.dbotthepony.mc.otm.storage;
|
|||||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||||
|
|
||||||
import javax.annotation.ParametersAreNonnullByDefault;
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@MethodsReturnNonnullByDefault
|
@MethodsReturnNonnullByDefault
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
public interface IStorageComponent<T extends IStorageObject> extends IStorageView<T>, IStorageConsumer<T> {
|
public interface IStorageComponent<T extends IStorageStack> extends IStorageView<T>, IStorageConsumer<T> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,6 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
|||||||
|
|
||||||
@MethodsReturnNonnullByDefault
|
@MethodsReturnNonnullByDefault
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
public interface IStorageConsumer<T extends IStorageObject> extends IStorageIdentity<T> {
|
public interface IStorageConsumer<T extends IStorageStack> extends IStorageIdentity<T> {
|
||||||
T insertObject(T obj, boolean simulate);
|
T insertObject(T obj, boolean simulate);
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,6 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
|||||||
|
|
||||||
@MethodsReturnNonnullByDefault
|
@MethodsReturnNonnullByDefault
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
public interface IStorageIdentity<T extends IStorageObject> {
|
public interface IStorageIdentity<T extends IStorageStack> {
|
||||||
Class<T> storageIdentity();
|
Class<T> storageIdentity();
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package ru.dbotthepony.mc.otm.storage;
|
package ru.dbotthepony.mc.otm.storage;
|
||||||
|
|
||||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
|
|
||||||
import javax.annotation.ParametersAreNonnullByDefault;
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
@ -9,7 +8,7 @@ import java.util.UUID;
|
|||||||
|
|
||||||
@MethodsReturnNonnullByDefault
|
@MethodsReturnNonnullByDefault
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
public interface IStorageListener<T extends IStorageObject> {
|
public interface IStorageListener<T extends IStorageStack> {
|
||||||
void addObject(T stack, UUID id, IStorageView<T> provider);
|
void addObject(T stack, UUID id, IStorageView<T> provider);
|
||||||
void changeObject(UUID id, BigDecimal new_count);
|
void changeObject(UUID id, BigDecimal new_count);
|
||||||
void removeObject(UUID id);
|
void removeObject(UUID id);
|
||||||
|
@ -2,7 +2,6 @@ package ru.dbotthepony.mc.otm.storage;
|
|||||||
|
|
||||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import javax.annotation.ParametersAreNonnullByDefault;
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -16,8 +15,8 @@ import java.util.Optional;
|
|||||||
*/
|
*/
|
||||||
@MethodsReturnNonnullByDefault
|
@MethodsReturnNonnullByDefault
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
public interface IStorageObject {
|
public interface IStorageStack {
|
||||||
IStorageObject copy();
|
IStorageStack copy();
|
||||||
|
|
||||||
void setCount(BigDecimal value);
|
void setCount(BigDecimal value);
|
||||||
BigDecimal getCount();
|
BigDecimal getCount();
|
||||||
@ -53,7 +52,7 @@ public interface IStorageObject {
|
|||||||
* this include tags, mapping IDs, capabilities, excluding amount;
|
* this include tags, mapping IDs, capabilities, excluding amount;
|
||||||
* behavior is pretty much the same as ItemStack.isSameItemSameTags
|
* behavior is pretty much the same as ItemStack.isSameItemSameTags
|
||||||
*/
|
*/
|
||||||
boolean sameItem(IStorageObject other);
|
boolean sameItem(IStorageStack other);
|
||||||
|
|
||||||
default void grow(BigDecimal amount) {
|
default void grow(BigDecimal amount) {
|
||||||
setCount(getCount().add(amount));
|
setCount(getCount().add(amount));
|
@ -6,7 +6,7 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
|||||||
|
|
||||||
@MethodsReturnNonnullByDefault
|
@MethodsReturnNonnullByDefault
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
public interface IStorageTrigger<T extends IStorageObject> extends IStorageIdentity<T> {
|
public interface IStorageTrigger<T extends IStorageStack> extends IStorageIdentity<T> {
|
||||||
boolean addListener(IStorageListener<T> listener);
|
boolean addListener(IStorageListener<T> listener);
|
||||||
boolean removeListener(IStorageListener<T> listener);
|
boolean removeListener(IStorageListener<T> listener);
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ package ru.dbotthepony.mc.otm.storage;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public interface IStorageTuple<T extends IStorageObject> {
|
public interface IStorageTuple<T extends IStorageStack> {
|
||||||
UUID id();
|
UUID id();
|
||||||
T object();
|
T object();
|
||||||
}
|
}
|
||||||
|
@ -3,16 +3,14 @@ package ru.dbotthepony.mc.otm.storage;
|
|||||||
|
|
||||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import javax.annotation.ParametersAreNonnullByDefault;
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@MethodsReturnNonnullByDefault
|
@MethodsReturnNonnullByDefault
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
public interface IStorageView<T extends IStorageObject> extends IStorageTrigger<T> {
|
public interface IStorageView<T extends IStorageStack> extends IStorageTrigger<T> {
|
||||||
/**
|
/**
|
||||||
* @param id identifier of object
|
* @param id identifier of object
|
||||||
* @return stored object (not a copy). Do not edit it.
|
* @return stored object (not a copy). Do not edit it.
|
||||||
|
@ -9,12 +9,12 @@ import java.util.Optional;
|
|||||||
|
|
||||||
@MethodsReturnNonnullByDefault
|
@MethodsReturnNonnullByDefault
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
public record ItemStackObject(ItemStack stack) implements IStorageObject {
|
public record ItemStackStack(ItemStack stack) implements IStorageStack {
|
||||||
public static final ItemStackObject EMPTY = new ItemStackObject(ItemStack.EMPTY);
|
public static final ItemStackStack EMPTY = new ItemStackStack(ItemStack.EMPTY);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IStorageObject copy() {
|
public IStorageStack copy() {
|
||||||
return new ItemStackObject(stack.copy());
|
return new ItemStackStack(stack.copy());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -51,11 +51,11 @@ public record ItemStackObject(ItemStack stack) implements IStorageObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean sameItem(IStorageObject other) {
|
public boolean sameItem(IStorageStack other) {
|
||||||
if (other == this)
|
if (other == this)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (other instanceof ItemStackObject obj)
|
if (other instanceof ItemStackStack obj)
|
||||||
return ItemStack.isSameItemSameTags(stack, obj.stack);
|
return ItemStack.isSameItemSameTags(stack, obj.stack);
|
||||||
|
|
||||||
return false;
|
return false;
|
@ -7,9 +7,7 @@ import net.minecraftforge.common.util.LazyOptional;
|
|||||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
||||||
import ru.dbotthepony.mc.otm.capability.IStorageGridCell;
|
import ru.dbotthepony.mc.otm.capability.IStorageGridCell;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import javax.annotation.ParametersAreNonnullByDefault;
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@MethodsReturnNonnullByDefault
|
@MethodsReturnNonnullByDefault
|
||||||
@ -17,11 +15,11 @@ import java.util.*;
|
|||||||
public class StorageGrid {
|
public class StorageGrid {
|
||||||
private final HashSet<IStorageGridCell> cells = new HashSet<>();
|
private final HashSet<IStorageGridCell> cells = new HashSet<>();
|
||||||
|
|
||||||
private final HashMap<Class<? extends IStorageObject>, VirtualComponent<? extends IStorageObject>> virtual_components = new HashMap<>();
|
private final HashMap<Class<? extends IStorageStack>, VirtualComponent<? extends IStorageStack>> virtual_components = new HashMap<>();
|
||||||
|
|
||||||
public StorageGrid() {}
|
public StorageGrid() {}
|
||||||
|
|
||||||
public <T extends IStorageObject> T insertObject(Class<T> type, T object, boolean simulate) {
|
public <T extends IStorageStack> T insertObject(Class<T> type, T object, boolean simulate) {
|
||||||
return getVirtualComponent(type).insertObject(object, simulate);
|
return getVirtualComponent(type).insertObject(object, simulate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +29,7 @@ public class StorageGrid {
|
|||||||
* @return a virtual IStorageComponent<T>, or null if storage grid contain no view for provided type
|
* @return a virtual IStorageComponent<T>, or null if storage grid contain no view for provided type
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T extends IStorageObject> VirtualComponent<T> getVirtualComponent(final Class<T> type) {
|
public <T extends IStorageStack> VirtualComponent<T> getVirtualComponent(final Class<T> type) {
|
||||||
return (VirtualComponent<T>) virtual_components.computeIfAbsent(type, (k) -> new VirtualComponent<>(type));
|
return (VirtualComponent<T>) virtual_components.computeIfAbsent(type, (k) -> new VirtualComponent<>(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +37,7 @@ public class StorageGrid {
|
|||||||
return cells.size();
|
return cells.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends IStorageObject> void add(IStorageIdentity<T> identity) {
|
public <T extends IStorageStack> void add(IStorageIdentity<T> identity) {
|
||||||
getVirtualComponent(identity.storageIdentity()).add(identity);
|
getVirtualComponent(identity.storageIdentity()).add(identity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +73,7 @@ public class StorageGrid {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends IStorageObject> void remove(IStorageIdentity<T> identity) {
|
public <T extends IStorageStack> void remove(IStorageIdentity<T> identity) {
|
||||||
getVirtualComponent(identity.storageIdentity()).remove(identity);
|
getVirtualComponent(identity.storageIdentity()).remove(identity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,9 +4,9 @@ import java.util.HashMap;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class StorageObjectRegistry {
|
public class StorageObjectRegistry {
|
||||||
private static final HashMap<Class<? extends IStorageObject>, StorageObjectTuple<? extends IStorageObject>> REGISTRY = new HashMap<>();
|
private static final HashMap<Class<? extends IStorageStack>, StorageObjectTuple<? extends IStorageStack>> REGISTRY = new HashMap<>();
|
||||||
|
|
||||||
public static <T extends IStorageObject> boolean register(Class<T> identity, T empty) {
|
public static <T extends IStorageStack> boolean register(Class<T> identity, T empty) {
|
||||||
final var tuple = new StorageObjectTuple<>(identity, empty);
|
final var tuple = new StorageObjectTuple<>(identity, empty);
|
||||||
final boolean removed = REGISTRY.remove(identity) != null;
|
final boolean removed = REGISTRY.remove(identity) != null;
|
||||||
REGISTRY.put(identity, tuple);
|
REGISTRY.put(identity, tuple);
|
||||||
@ -15,11 +15,11 @@ public class StorageObjectRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T extends IStorageObject> StorageObjectTuple<T> get(Class<T> identity) {
|
public static <T extends IStorageStack> StorageObjectTuple<T> get(Class<T> identity) {
|
||||||
return (StorageObjectTuple<T>) REGISTRY.get(identity);
|
return (StorageObjectTuple<T>) REGISTRY.get(identity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends IStorageObject> StorageObjectTuple<T> getOrError(Class<T> identity) {
|
public static <T extends IStorageStack> StorageObjectTuple<T> getOrError(Class<T> identity) {
|
||||||
return Objects.requireNonNull(get(identity), "No storage mapping present for " + identity.toString());
|
return Objects.requireNonNull(get(identity), "No storage mapping present for " + identity.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package ru.dbotthepony.mc.otm.storage;
|
package ru.dbotthepony.mc.otm.storage;
|
||||||
|
|
||||||
public record StorageObjectTuple<T extends IStorageObject>(Class<T> identity, T empty) {
|
public record StorageObjectTuple<T extends IStorageStack>(Class<T> identity, T empty) {
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (obj instanceof StorageObjectTuple tuple)
|
if (obj instanceof StorageObjectTuple tuple)
|
||||||
|
@ -2,5 +2,5 @@ package ru.dbotthepony.mc.otm.storage;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public record StorageTuple<T extends IStorageObject>(UUID id, T object) implements IStorageTuple<T> {
|
public record StorageTuple<T extends IStorageStack>(UUID id, T object) implements IStorageTuple<T> {
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@ import java.util.function.Supplier;
|
|||||||
|
|
||||||
@MethodsReturnNonnullByDefault
|
@MethodsReturnNonnullByDefault
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
public class VirtualComponent<T extends IStorageObject> implements IStorageComponent<T>, IStorageListener<T> {
|
public class VirtualComponent<T extends IStorageStack> implements IStorageComponent<T>, IStorageListener<T> {
|
||||||
public record LocalTuple<T extends IStorageObject>(T object, UUID id, List<RemoteTuple<T>> tuples) implements IStorageTuple<T> {
|
public record LocalTuple<T extends IStorageStack>(T object, UUID id, List<RemoteTuple<T>> tuples) implements IStorageTuple<T> {
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
return obj instanceof LocalTuple tuple && tuple.id.equals(id) || obj instanceof UUID id && this.id.equals(id);
|
return obj instanceof LocalTuple tuple && tuple.id.equals(id) || obj instanceof UUID id && this.id.equals(id);
|
||||||
@ -25,7 +25,7 @@ public class VirtualComponent<T extends IStorageObject> implements IStorageCompo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public record RemoteTuple<T extends IStorageObject>(T object, UUID remote_id, IStorageView<T> provider, LocalTuple<T> local) {
|
public record RemoteTuple<T extends IStorageStack>(T object, UUID remote_id, IStorageView<T> provider, LocalTuple<T> local) {
|
||||||
public T extract(BigDecimal amount, boolean simulate) {
|
public T extract(BigDecimal amount, boolean simulate) {
|
||||||
return provider.extractObject(remote_id, amount, simulate);
|
return provider.extractObject(remote_id, amount, simulate);
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ public class VirtualComponent<T extends IStorageObject> implements IStorageCompo
|
|||||||
this.identity = StorageObjectRegistry.getOrError(identity);
|
this.identity = StorageObjectRegistry.getOrError(identity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends IStorageObject> Supplier<VirtualComponent<T>> factory(Class<T> identity) {
|
public static <T extends IStorageStack> Supplier<VirtualComponent<T>> factory(Class<T> identity) {
|
||||||
return () -> new VirtualComponent<>(identity);
|
return () -> new VirtualComponent<>(identity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user