Don't send hash for grid stacks anymore, but unique id. Prevents collisions. The StackLists now stored an unique id per item/fluid entry.
This commit is contained in:
@@ -1,11 +1,10 @@
|
|||||||
package com.raoulvdberge.refinedstorage.api.network.grid.handler;
|
package com.raoulvdberge.refinedstorage.api.network.grid.handler;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.api.IRSAPI;
|
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the behavior of fluid grids.
|
* Defines the behavior of fluid grids.
|
||||||
@@ -15,10 +14,10 @@ public interface IFluidGridHandler {
|
|||||||
* Called when a player tries to extract a fluid from the grid.
|
* Called when a player tries to extract a fluid from the grid.
|
||||||
*
|
*
|
||||||
* @param player the player that is attempting the extraction
|
* @param player the player that is attempting the extraction
|
||||||
* @param hash the hash of the fluid we're trying to extract, see {@link IRSAPI#getFluidStackHashCode(FluidStack)}
|
* @param id the id of the fluid we're trying to extract, this id is the id from {@link com.raoulvdberge.refinedstorage.api.util.StackListEntry}
|
||||||
* @param shift true if shift click was used, false otherwise
|
* @param shift true if shift click was used, false otherwise
|
||||||
*/
|
*/
|
||||||
void onExtract(ServerPlayerEntity player, int hash, boolean shift);
|
void onExtract(ServerPlayerEntity player, UUID id, boolean shift);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a player tries to insert fluids in the grid.
|
* Called when a player tries to insert fluids in the grid.
|
||||||
@@ -50,18 +49,18 @@ public interface IFluidGridHandler {
|
|||||||
* Called when a player requests the crafting preview window to be opened.
|
* Called when a player requests the crafting preview window to be opened.
|
||||||
*
|
*
|
||||||
* @param player the player
|
* @param player the player
|
||||||
* @param hash the item stack hash
|
* @param id the id of the fluid we're trying to extract, this id is the id from {@link com.raoulvdberge.refinedstorage.api.util.StackListEntry}
|
||||||
* @param quantity the amount of that item that we need a preview for
|
* @param quantity the amount of that item that we need a preview for
|
||||||
* @param noPreview true if the crafting preview window shouldn't be shown, false otherwise
|
* @param noPreview true if the crafting preview window shouldn't be shown, false otherwise
|
||||||
*/
|
*/
|
||||||
void onCraftingPreviewRequested(ServerPlayerEntity player, int hash, int quantity, boolean noPreview);
|
void onCraftingPreviewRequested(ServerPlayerEntity player, UUID id, int quantity, boolean noPreview);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a player requested crafting for an item.
|
* Called when a player requested crafting for an item.
|
||||||
*
|
*
|
||||||
* @param player the player that is requesting the crafting
|
* @param player the player that is requesting the crafting
|
||||||
* @param hash the hash of the item to request a craft for
|
* @param id the id of the fluid we're trying to extract, this id is the id from {@link com.raoulvdberge.refinedstorage.api.util.StackListEntry}
|
||||||
* @param quantity the amount of the item that has to be crafted
|
* @param quantity the amount of the item that has to be crafted
|
||||||
*/
|
*/
|
||||||
void onCraftingRequested(ServerPlayerEntity player, int hash, int quantity);
|
void onCraftingRequested(ServerPlayerEntity player, UUID id, int quantity);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.raoulvdberge.refinedstorage.api.network.grid.handler;
|
package com.raoulvdberge.refinedstorage.api.network.grid.handler;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.api.IRSAPI;
|
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
@@ -19,10 +18,10 @@ public interface IItemGridHandler {
|
|||||||
* Called when a player tries to extract an item from the grid.
|
* Called when a player tries to extract an item from the grid.
|
||||||
*
|
*
|
||||||
* @param player the player that is attempting the extraction
|
* @param player the player that is attempting the extraction
|
||||||
* @param hash the hash of the item we're trying to extract, see {@link IRSAPI#getItemStackHashCode(ItemStack)}
|
* @param id the id of the item we're trying to extract, this id is the id from {@link com.raoulvdberge.refinedstorage.api.util.StackListEntry}
|
||||||
* @param flags how we are extracting, see the flags in {@link IItemGridHandler}
|
* @param flags how we are extracting, see the flags in {@link IItemGridHandler}
|
||||||
*/
|
*/
|
||||||
void onExtract(ServerPlayerEntity player, int hash, int flags);
|
void onExtract(ServerPlayerEntity player, UUID id, int flags);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a player tries to insert an item in the grid.
|
* Called when a player tries to insert an item in the grid.
|
||||||
@@ -55,20 +54,20 @@ public interface IItemGridHandler {
|
|||||||
* Called when a player requests the crafting preview window to be opened.
|
* Called when a player requests the crafting preview window to be opened.
|
||||||
*
|
*
|
||||||
* @param player the player
|
* @param player the player
|
||||||
* @param hash the item stack hash
|
* @param id the id of the item we're trying to extract, this id is the id from {@link com.raoulvdberge.refinedstorage.api.util.StackListEntry}
|
||||||
* @param quantity the amount of that item that we need a preview for
|
* @param quantity the amount of that item that we need a preview for
|
||||||
* @param noPreview true if the crafting preview window shouldn't be shown, false otherwise
|
* @param noPreview true if the crafting preview window shouldn't be shown, false otherwise
|
||||||
*/
|
*/
|
||||||
void onCraftingPreviewRequested(ServerPlayerEntity player, int hash, int quantity, boolean noPreview);
|
void onCraftingPreviewRequested(ServerPlayerEntity player, UUID id, int quantity, boolean noPreview);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a player requested crafting for an item.
|
* Called when a player requested crafting for an item.
|
||||||
*
|
*
|
||||||
* @param player the player that is requesting the crafting
|
* @param player the player that is requesting the crafting
|
||||||
* @param hash the hash of the item to request a craft for
|
* @param id the id of the item we're trying to extract, this id is the id from {@link com.raoulvdberge.refinedstorage.api.util.StackListEntry}
|
||||||
* @param quantity the amount of the item that has to be crafted
|
* @param quantity the amount of the item that has to be crafted
|
||||||
*/
|
*/
|
||||||
void onCraftingRequested(ServerPlayerEntity player, int hash, int quantity);
|
void onCraftingRequested(ServerPlayerEntity player, UUID id, int quantity);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a player wants to cancel a crafting task.
|
* Called when a player wants to cancel a crafting task.
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
package com.raoulvdberge.refinedstorage.api.storage;
|
package com.raoulvdberge.refinedstorage.api.storage;
|
||||||
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import com.raoulvdberge.refinedstorage.api.util.StackListResult;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,15 +23,14 @@ public interface IStorageCacheListener<T> {
|
|||||||
/**
|
/**
|
||||||
* Called when the storage cache changes.
|
* Called when the storage cache changes.
|
||||||
*
|
*
|
||||||
* @param stack the stack
|
* @param delta the delta
|
||||||
* @param size the size, negative if the amount decreases
|
|
||||||
*/
|
*/
|
||||||
void onChanged(@Nonnull T stack, int size);
|
void onChanged(StackListResult<T> delta);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the storage cache changes.
|
* Called when the storage cache changes.
|
||||||
*
|
*
|
||||||
* @param stacks a list of stacks that are changed, with the size changed (negative if the amount decreases)
|
* @param deltas a list of deltas
|
||||||
*/
|
*/
|
||||||
void onChangedBulk(@Nonnull List<Pair<T, Integer>> stacks);
|
void onChangedBulk(List<StackListResult<T>> deltas);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.raoulvdberge.refinedstorage.api.util;
|
|||||||
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A stack list.
|
* A stack list.
|
||||||
@@ -13,32 +14,36 @@ public interface IStackList<T> {
|
|||||||
*
|
*
|
||||||
* @param stack the stack
|
* @param stack the stack
|
||||||
* @param size the size to add
|
* @param size the size to add
|
||||||
|
* @return the result
|
||||||
*/
|
*/
|
||||||
void add(@Nonnull T stack, int size);
|
StackListResult<T> add(@Nonnull T stack, int size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a stack to the list, will merge it with another stack if it already exists in the list.
|
* Adds a stack to the list, will merge it with another stack if it already exists in the list.
|
||||||
*
|
*
|
||||||
* @param stack the stack
|
* @param stack the stack
|
||||||
|
* @return the result
|
||||||
*/
|
*/
|
||||||
void add(@Nonnull T stack);
|
StackListResult<T> add(@Nonnull T stack);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decrements the count of that stack in the list.
|
* Decrements the count of that stack in the list.
|
||||||
*
|
*
|
||||||
* @param stack the stack
|
* @param stack the stack
|
||||||
* @param size the size to remove
|
* @param size the size to remove
|
||||||
* @return true if the remove was successful for the full amount, false otherwise
|
* @return the result, or null if the stack wasn't present
|
||||||
*/
|
*/
|
||||||
boolean remove(@Nonnull T stack, int size);
|
@Nullable
|
||||||
|
StackListResult<T> remove(@Nonnull T stack, int size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decrements the count of that stack in the list.
|
* Decrements the count of that stack in the list.
|
||||||
*
|
*
|
||||||
* @param stack the stack
|
* @param stack the stack
|
||||||
* @return true if the remove was successful for the full amount, false otherwise
|
* @return the result, or null if the stack wasn't present
|
||||||
*/
|
*/
|
||||||
boolean remove(@Nonnull T stack);
|
@Nullable
|
||||||
|
StackListResult<T> remove(@Nonnull T stack);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a stack.
|
* Returns a stack.
|
||||||
@@ -64,11 +69,11 @@ public interface IStackList<T> {
|
|||||||
/**
|
/**
|
||||||
* Returns a stack.
|
* Returns a stack.
|
||||||
*
|
*
|
||||||
* @param hash the hash of the stack to search for
|
* @param id the id of the entry to search for
|
||||||
* @return the stack, or null if no stack was found
|
* @return the stack, or null if no stack was found
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
T get(int hash);
|
T get(UUID id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the list.
|
* Clears the list.
|
||||||
@@ -84,7 +89,7 @@ public interface IStackList<T> {
|
|||||||
* @return a collection of stacks in this list
|
* @return a collection of stacks in this list
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
Collection<T> getStacks();
|
Collection<StackListEntry<T>> getStacks();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return a new copy of this list, with the stacks in it copied as well
|
* @return a new copy of this list, with the stacks in it copied as well
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.api.util;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a stack in a stack list.
|
||||||
|
*
|
||||||
|
* @param <T> the stack type
|
||||||
|
*/
|
||||||
|
public class StackListEntry<T> {
|
||||||
|
private UUID id;
|
||||||
|
private T stack;
|
||||||
|
|
||||||
|
public StackListEntry(T stack) {
|
||||||
|
this.stack = stack;
|
||||||
|
this.id = UUID.randomUUID();
|
||||||
|
}
|
||||||
|
|
||||||
|
public StackListEntry(UUID id, T stack) {
|
||||||
|
this.id = id;
|
||||||
|
this.stack = stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The unique id of the entry.
|
||||||
|
* This id is NOT persisted, nor does it hold any relation to the contained stack.
|
||||||
|
* It is randomly generated.
|
||||||
|
*
|
||||||
|
* @return the id
|
||||||
|
*/
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the stack
|
||||||
|
*/
|
||||||
|
public T getStack() {
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.api.util;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class StackListResult<T> {
|
||||||
|
private T stack;
|
||||||
|
private UUID id;
|
||||||
|
private int change;
|
||||||
|
|
||||||
|
public StackListResult(T stack, UUID id, int change) {
|
||||||
|
this.stack = stack;
|
||||||
|
this.id = id;
|
||||||
|
this.change = change;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getStack() {
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getChange() {
|
||||||
|
return change;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -38,9 +38,9 @@ import com.raoulvdberge.refinedstorage.apiimpl.network.readerwriter.ReaderWriter
|
|||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.readerwriter.ReaderWriterHandlerRegistry;
|
import com.raoulvdberge.refinedstorage.apiimpl.network.readerwriter.ReaderWriterHandlerRegistry;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.*;
|
import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.*;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.util.Comparer;
|
import com.raoulvdberge.refinedstorage.apiimpl.util.Comparer;
|
||||||
|
import com.raoulvdberge.refinedstorage.apiimpl.util.FluidStackList;
|
||||||
|
import com.raoulvdberge.refinedstorage.apiimpl.util.ItemStackList;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.util.QuantityFormatter;
|
import com.raoulvdberge.refinedstorage.apiimpl.util.QuantityFormatter;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.util.StackListFluid;
|
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.util.StackListItem;
|
|
||||||
import com.raoulvdberge.refinedstorage.capability.NetworkNodeProxyCapability;
|
import com.raoulvdberge.refinedstorage.capability.NetworkNodeProxyCapability;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
@@ -154,13 +154,13 @@ public class API implements IRSAPI {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public IStackList<ItemStack> createItemStackList() {
|
public IStackList<ItemStack> createItemStackList() {
|
||||||
return new StackListItem();
|
return new ItemStackList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public IStackList<FluidStack> createFluidStackList() {
|
public IStackList<FluidStack> createFluidStackList() {
|
||||||
return new StackListFluid();
|
return new FluidStackList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -264,6 +264,7 @@ public class API implements IRSAPI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Remove eventually
|
||||||
@Override
|
@Override
|
||||||
public int getItemStackHashCode(ItemStack stack) {
|
public int getItemStackHashCode(ItemStack stack) {
|
||||||
int result = stack.getItem().hashCode();
|
int result = stack.getItem().hashCode();
|
||||||
@@ -304,6 +305,7 @@ public class API implements IRSAPI {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Remove eventually
|
||||||
@Override
|
@Override
|
||||||
public int getFluidStackHashCode(FluidStack stack) {
|
public int getFluidStackHashCode(FluidStack stack) {
|
||||||
int result = stack.getFluid().hashCode();
|
int result = stack.getFluid().hashCode();
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
|
|||||||
import com.raoulvdberge.refinedstorage.api.util.Action;
|
import com.raoulvdberge.refinedstorage.api.util.Action;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.util.StackListEntry;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementError;
|
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementError;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementFluidRender;
|
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementFluidRender;
|
||||||
@@ -180,8 +181,8 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
static ListNBT writeItemStackList(IStackList<ItemStack> stacks) {
|
static ListNBT writeItemStackList(IStackList<ItemStack> stacks) {
|
||||||
ListNBT list = new ListNBT();
|
ListNBT list = new ListNBT();
|
||||||
|
|
||||||
for (ItemStack stack : stacks.getStacks()) {
|
for (StackListEntry<ItemStack> entry : stacks.getStacks()) {
|
||||||
list.add(StackUtils.serializeStackToNbt(stack));
|
list.add(StackUtils.serializeStackToNbt(entry.getStack()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
@@ -206,8 +207,8 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
static ListNBT writeFluidStackList(IStackList<FluidStack> stacks) {
|
static ListNBT writeFluidStackList(IStackList<FluidStack> stacks) {
|
||||||
ListNBT list = new ListNBT();
|
ListNBT list = new ListNBT();
|
||||||
|
|
||||||
for (FluidStack stack : stacks.getStacks()) {
|
for (StackListEntry<FluidStack> entry : stacks.getStacks()) {
|
||||||
list.add(stack.writeToNBT(new CompoundNBT()));
|
list.add(entry.getStack().writeToNBT(new CompoundNBT()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
@@ -542,11 +543,11 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
if (!toExtractInitial.isEmpty()) {
|
if (!toExtractInitial.isEmpty()) {
|
||||||
List<ItemStack> toRemove = new ArrayList<>();
|
List<ItemStack> toRemove = new ArrayList<>();
|
||||||
|
|
||||||
for (ItemStack toExtract : toExtractInitial.getStacks()) {
|
for (StackListEntry<ItemStack> toExtract : toExtractInitial.getStacks()) {
|
||||||
ItemStack result = network.extractItem(toExtract, toExtract.getCount(), Action.PERFORM);
|
ItemStack result = network.extractItem(toExtract.getStack(), toExtract.getStack().getCount(), Action.PERFORM);
|
||||||
|
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
internalStorage.insert(toExtract, result.getCount(), Action.PERFORM);
|
internalStorage.insert(toExtract.getStack(), result.getCount(), Action.PERFORM);
|
||||||
|
|
||||||
toRemove.add(result);
|
toRemove.add(result);
|
||||||
}
|
}
|
||||||
@@ -564,11 +565,11 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
if (!toExtractInitialFluids.isEmpty()) {
|
if (!toExtractInitialFluids.isEmpty()) {
|
||||||
List<FluidStack> toRemove = new ArrayList<>();
|
List<FluidStack> toRemove = new ArrayList<>();
|
||||||
|
|
||||||
for (FluidStack toExtract : toExtractInitialFluids.getStacks()) {
|
for (StackListEntry<FluidStack> toExtract : toExtractInitialFluids.getStacks()) {
|
||||||
FluidStack result = network.extractFluid(toExtract, toExtract.getAmount(), Action.PERFORM);
|
FluidStack result = network.extractFluid(toExtract.getStack(), toExtract.getStack().getAmount(), Action.PERFORM);
|
||||||
|
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
internalFluidStorage.insert(toExtract, result.getAmount(), Action.PERFORM);
|
internalFluidStorage.insert(toExtract.getStack(), result.getAmount(), Action.PERFORM);
|
||||||
|
|
||||||
toRemove.add(result);
|
toRemove.add(result);
|
||||||
}
|
}
|
||||||
@@ -607,10 +608,10 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
|
|
||||||
boolean hasAll = true;
|
boolean hasAll = true;
|
||||||
|
|
||||||
for (ItemStack need : c.getToExtract().getStacks()) {
|
for (StackListEntry<ItemStack> need : c.getToExtract().getStacks()) {
|
||||||
ItemStack result = this.internalStorage.extract(need, need.getCount(), DEFAULT_EXTRACT_FLAGS, Action.SIMULATE);
|
ItemStack result = this.internalStorage.extract(need.getStack(), need.getStack().getCount(), DEFAULT_EXTRACT_FLAGS, Action.SIMULATE);
|
||||||
|
|
||||||
if (result == null || result.getCount() != need.getCount()) {
|
if (result == null || result.getCount() != need.getStack().getCount()) {
|
||||||
hasAll = false;
|
hasAll = false;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -618,10 +619,10 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (hasAll) {
|
if (hasAll) {
|
||||||
for (ItemStack need : c.getToExtract().getStacks()) {
|
for (StackListEntry<ItemStack> need : c.getToExtract().getStacks()) {
|
||||||
ItemStack result = this.internalStorage.extract(need, need.getCount(), DEFAULT_EXTRACT_FLAGS, Action.PERFORM);
|
ItemStack result = this.internalStorage.extract(need.getStack(), need.getStack().getCount(), DEFAULT_EXTRACT_FLAGS, Action.PERFORM);
|
||||||
|
|
||||||
if (result == null || result.getCount() != need.getCount()) {
|
if (result == null || result.getCount() != need.getStack().getCount()) {
|
||||||
throw new IllegalStateException("Extractor check lied");
|
throw new IllegalStateException("Extractor check lied");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -694,13 +695,13 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
} else {
|
} else {
|
||||||
boolean hasAll = true;
|
boolean hasAll = true;
|
||||||
|
|
||||||
for (ItemStack need : p.getItemsToPut().getStacks()) {
|
for (StackListEntry<ItemStack> need : p.getItemsToPut().getStacks()) {
|
||||||
if (p.getPattern().getContainer().getConnectedInventory() == null) {
|
if (p.getPattern().getContainer().getConnectedInventory() == null) {
|
||||||
p.setState(ProcessingState.MACHINE_NONE);
|
p.setState(ProcessingState.MACHINE_NONE);
|
||||||
} else {
|
} else {
|
||||||
ItemStack result = this.internalStorage.extract(need, need.getCount(), DEFAULT_EXTRACT_FLAGS, Action.SIMULATE);
|
ItemStack result = this.internalStorage.extract(need.getStack(), need.getStack().getCount(), DEFAULT_EXTRACT_FLAGS, Action.SIMULATE);
|
||||||
|
|
||||||
if (result == null || result.getCount() != need.getCount()) {
|
if (result == null || result.getCount() != need.getStack().getCount()) {
|
||||||
hasAll = false;
|
hasAll = false;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -714,13 +715,13 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
p.setState(ProcessingState.MACHINE_DOES_NOT_ACCEPT);
|
p.setState(ProcessingState.MACHINE_DOES_NOT_ACCEPT);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (FluidStack need : p.getFluidsToPut().getStacks()) {
|
for (StackListEntry<FluidStack> need : p.getFluidsToPut().getStacks()) {
|
||||||
if (p.getPattern().getContainer().getConnectedFluidInventory() == null) {
|
if (p.getPattern().getContainer().getConnectedFluidInventory() == null) {
|
||||||
p.setState(ProcessingState.MACHINE_NONE);
|
p.setState(ProcessingState.MACHINE_NONE);
|
||||||
} else {
|
} else {
|
||||||
FluidStack result = this.internalFluidStorage.extract(need, need.getAmount(), IComparer.COMPARE_NBT, Action.SIMULATE);
|
FluidStack result = this.internalFluidStorage.extract(need.getStack(), need.getStack().getAmount(), IComparer.COMPARE_NBT, Action.SIMULATE);
|
||||||
|
|
||||||
if (result == null || result.getAmount() != need.getAmount()) {
|
if (result == null || result.getAmount() != need.getStack().getAmount()) {
|
||||||
hasAll = false;
|
hasAll = false;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -735,12 +736,12 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (p.getState() == ProcessingState.READY && hasAll) {
|
if (p.getState() == ProcessingState.READY && hasAll) {
|
||||||
Deque<ItemStack> toInsert = new ArrayDeque<>();
|
Deque<StackListEntry<ItemStack>> toInsert = new ArrayDeque<>();
|
||||||
|
|
||||||
for (ItemStack need : p.getItemsToPut().getStacks()) {
|
for (StackListEntry<ItemStack> need : p.getItemsToPut().getStacks()) {
|
||||||
ItemStack result = this.internalStorage.extract(need, need.getCount(), DEFAULT_EXTRACT_FLAGS, Action.PERFORM);
|
ItemStack result = this.internalStorage.extract(need.getStack(), need.getStack().getCount(), DEFAULT_EXTRACT_FLAGS, Action.PERFORM);
|
||||||
if (result == null || result.getCount() != need.getCount()) {
|
if (result == null || result.getCount() != need.getStack().getCount()) {
|
||||||
throw new IllegalStateException("The internal crafting inventory reported that " + need + " was available but we got " + result);
|
throw new IllegalStateException("The internal crafting inventory reported that " + need.getStack() + " was available but we got " + result);
|
||||||
}
|
}
|
||||||
|
|
||||||
toInsert.add(need);
|
toInsert.add(need);
|
||||||
@@ -750,9 +751,9 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
LOGGER.warn(p.getPattern().getContainer().getConnectedInventory() + " unexpectedly didn't accept items, the remainder has been voided!");
|
LOGGER.warn(p.getPattern().getContainer().getConnectedInventory() + " unexpectedly didn't accept items, the remainder has been voided!");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (FluidStack need : p.getFluidsToPut().getStacks()) {
|
for (StackListEntry<FluidStack> need : p.getFluidsToPut().getStacks()) {
|
||||||
FluidStack result = this.internalFluidStorage.extract(need, need.getAmount(), IComparer.COMPARE_NBT, Action.PERFORM);
|
FluidStack result = this.internalFluidStorage.extract(need.getStack(), need.getStack().getAmount(), IComparer.COMPARE_NBT, Action.PERFORM);
|
||||||
if (result == null || result.getAmount() != need.getAmount()) {
|
if (result == null || result.getAmount() != need.getStack().getAmount()) {
|
||||||
throw new IllegalStateException("The internal crafting inventory reported that " + need + " was available but we got " + result);
|
throw new IllegalStateException("The internal crafting inventory reported that " + need + " was available but we got " + result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -777,12 +778,14 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean insertIntoInventory(@Nullable IItemHandler dest, Deque<ItemStack> stacks, Action action) {
|
private static boolean insertIntoInventory(@Nullable IItemHandler dest, Deque<StackListEntry<ItemStack>> stacks, Action action) {
|
||||||
if (dest == null) {
|
if (dest == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack current = stacks.poll();
|
StackListEntry<ItemStack> currentEntry = stacks.poll();
|
||||||
|
|
||||||
|
ItemStack current = currentEntry != null ? currentEntry.getStack() : null;
|
||||||
|
|
||||||
List<Integer> availableSlots = IntStream.range(0, dest.getSlots()).boxed().collect(Collectors.toList());
|
List<Integer> availableSlots = IntStream.range(0, dest.getSlots()).boxed().collect(Collectors.toList());
|
||||||
|
|
||||||
@@ -803,7 +806,9 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (remainder.isEmpty()) { // If we inserted successfully, get a next stack.
|
if (remainder.isEmpty()) { // If we inserted successfully, get a next stack.
|
||||||
current = stacks.poll();
|
currentEntry = stacks.poll();
|
||||||
|
|
||||||
|
current = currentEntry != null ? currentEntry.getStack() : null;
|
||||||
} else if (current.getCount() == remainder.getCount()) { // If we didn't insert anything over ALL these slots, stop here.
|
} else if (current.getCount() == remainder.getCount()) { // If we didn't insert anything over ALL these slots, stop here.
|
||||||
break;
|
break;
|
||||||
} else { // If we didn't insert all, continue with other slots and use our remainder.
|
} else { // If we didn't insert all, continue with other slots and use our remainder.
|
||||||
@@ -1047,8 +1052,8 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
elements.add(new CraftingMonitorElementItemRender(stack, stack.getCount(), 0, 0, 0, 0));
|
elements.add(new CraftingMonitorElementItemRender(stack, stack.getCount(), 0, 0, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ItemStack missing : this.missing.getStacks()) {
|
for (StackListEntry<ItemStack> missing : this.missing.getStacks()) {
|
||||||
elements.add(new CraftingMonitorElementItemRender(missing, 0, missing.getCount(), 0, 0, 0));
|
elements.add(new CraftingMonitorElementItemRender(missing.getStack(), 0, missing.getStack().getCount(), 0, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Crafting crafting : this.crafting) {
|
for (Crafting crafting : this.crafting) {
|
||||||
@@ -1063,12 +1068,12 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (processing.getState() == ProcessingState.EXTRACTED_ALL) {
|
if (processing.getState() == ProcessingState.EXTRACTED_ALL) {
|
||||||
for (ItemStack put : processing.getItemsToPut().getStacks()) {
|
for (StackListEntry<ItemStack> put : processing.getItemsToPut().getStacks()) {
|
||||||
elements.add(new CraftingMonitorElementItemRender(put, 0, 0, put.getCount(), 0, 0));
|
elements.add(new CraftingMonitorElementItemRender(put.getStack(), 0, 0, put.getStack().getCount(), 0, 0));
|
||||||
}
|
}
|
||||||
} else if (processing.getState() == ProcessingState.READY || processing.getState() == ProcessingState.MACHINE_DOES_NOT_ACCEPT || processing.getState() == ProcessingState.MACHINE_NONE || processing.getState() == ProcessingState.LOCKED) {
|
} else if (processing.getState() == ProcessingState.READY || processing.getState() == ProcessingState.MACHINE_DOES_NOT_ACCEPT || processing.getState() == ProcessingState.MACHINE_NONE || processing.getState() == ProcessingState.LOCKED) {
|
||||||
for (ItemStack receive : processing.getItemsToReceive().getStacks()) {
|
for (StackListEntry<ItemStack> receive : processing.getItemsToReceive().getStacks()) {
|
||||||
ICraftingMonitorElement element = new CraftingMonitorElementItemRender(receive, 0, 0, 0, receive.getCount(), 0);
|
ICraftingMonitorElement element = new CraftingMonitorElementItemRender(receive.getStack(), 0, 0, 0, receive.getStack().getCount(), 0);
|
||||||
|
|
||||||
if (processing.getState() == ProcessingState.MACHINE_DOES_NOT_ACCEPT) {
|
if (processing.getState() == ProcessingState.MACHINE_DOES_NOT_ACCEPT) {
|
||||||
element = new CraftingMonitorElementError(element, "gui.refinedstorage:crafting_monitor.machine_does_not_accept_item");
|
element = new CraftingMonitorElementError(element, "gui.refinedstorage:crafting_monitor.machine_does_not_accept_item");
|
||||||
@@ -1089,8 +1094,8 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
elements.add(new CraftingMonitorElementFluidRender(stack, stack.getAmount(), 0, 0, 0, 0));
|
elements.add(new CraftingMonitorElementFluidRender(stack, stack.getAmount(), 0, 0, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (FluidStack missing : this.missingFluids.getStacks()) {
|
for (StackListEntry<FluidStack> missing : this.missingFluids.getStacks()) {
|
||||||
elements.add(new CraftingMonitorElementFluidRender(missing, 0, missing.getAmount(), 0, 0, 0));
|
elements.add(new CraftingMonitorElementFluidRender(missing.getStack(), 0, missing.getStack().getAmount(), 0, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Processing processing : this.processing) {
|
for (Processing processing : this.processing) {
|
||||||
@@ -1099,12 +1104,12 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (processing.getState() == ProcessingState.EXTRACTED_ALL) {
|
if (processing.getState() == ProcessingState.EXTRACTED_ALL) {
|
||||||
for (FluidStack put : processing.getFluidsToPut().getStacks()) {
|
for (StackListEntry<FluidStack> put : processing.getFluidsToPut().getStacks()) {
|
||||||
elements.add(new CraftingMonitorElementFluidRender(put, 0, 0, put.getAmount(), 0, 0));
|
elements.add(new CraftingMonitorElementFluidRender(put.getStack(), 0, 0, put.getStack().getAmount(), 0, 0));
|
||||||
}
|
}
|
||||||
} else if (processing.getState() == ProcessingState.READY || processing.getState() == ProcessingState.MACHINE_DOES_NOT_ACCEPT || processing.getState() == ProcessingState.MACHINE_NONE) {
|
} else if (processing.getState() == ProcessingState.READY || processing.getState() == ProcessingState.MACHINE_DOES_NOT_ACCEPT || processing.getState() == ProcessingState.MACHINE_NONE) {
|
||||||
for (FluidStack receive : processing.getFluidsToReceive().getStacks()) {
|
for (StackListEntry<FluidStack> receive : processing.getFluidsToReceive().getStacks()) {
|
||||||
ICraftingMonitorElement element = new CraftingMonitorElementFluidRender(receive, 0, 0, 0, receive.getAmount(), 0);
|
ICraftingMonitorElement element = new CraftingMonitorElementFluidRender(receive.getStack(), 0, 0, 0, receive.getStack().getAmount(), 0);
|
||||||
|
|
||||||
if (processing.getState() == ProcessingState.MACHINE_DOES_NOT_ACCEPT) {
|
if (processing.getState() == ProcessingState.MACHINE_DOES_NOT_ACCEPT) {
|
||||||
element = new CraftingMonitorElementError(element, "gui.refinedstorage:crafting_monitor.machine_does_not_accept_fluid");
|
element = new CraftingMonitorElementError(element, "gui.refinedstorage:crafting_monitor.machine_does_not_accept_fluid");
|
||||||
@@ -1127,88 +1132,88 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
Map<Integer, CraftingPreviewElementItemStack> map = new LinkedHashMap<>();
|
Map<Integer, CraftingPreviewElementItemStack> map = new LinkedHashMap<>();
|
||||||
Map<Integer, CraftingPreviewElementFluidStack> mapFluids = new LinkedHashMap<>();
|
Map<Integer, CraftingPreviewElementFluidStack> mapFluids = new LinkedHashMap<>();
|
||||||
|
|
||||||
for (ItemStack stack : toCraft.getStacks()) {
|
for (StackListEntry<ItemStack> stack : toCraft.getStacks()) {
|
||||||
int hash = API.instance().getItemStackHashCode(stack);
|
int hash = API.instance().getItemStackHashCode(stack.getStack());
|
||||||
|
|
||||||
CraftingPreviewElementItemStack previewStack = map.get(hash);
|
CraftingPreviewElementItemStack previewStack = map.get(hash);
|
||||||
|
|
||||||
if (previewStack == null) {
|
if (previewStack == null) {
|
||||||
previewStack = new CraftingPreviewElementItemStack(stack);
|
previewStack = new CraftingPreviewElementItemStack(stack.getStack());
|
||||||
}
|
}
|
||||||
|
|
||||||
previewStack.addToCraft(stack.getCount());
|
previewStack.addToCraft(stack.getStack().getCount());
|
||||||
|
|
||||||
map.put(hash, previewStack);
|
map.put(hash, previewStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (FluidStack stack : toCraftFluids.getStacks()) {
|
for (StackListEntry<FluidStack> stack : toCraftFluids.getStacks()) {
|
||||||
int hash = API.instance().getFluidStackHashCode(stack);
|
int hash = API.instance().getFluidStackHashCode(stack.getStack());
|
||||||
|
|
||||||
CraftingPreviewElementFluidStack previewStack = mapFluids.get(hash);
|
CraftingPreviewElementFluidStack previewStack = mapFluids.get(hash);
|
||||||
|
|
||||||
if (previewStack == null) {
|
if (previewStack == null) {
|
||||||
previewStack = new CraftingPreviewElementFluidStack(stack);
|
previewStack = new CraftingPreviewElementFluidStack(stack.getStack());
|
||||||
}
|
}
|
||||||
|
|
||||||
previewStack.addToCraft(stack.getAmount());
|
previewStack.addToCraft(stack.getStack().getAmount());
|
||||||
|
|
||||||
mapFluids.put(hash, previewStack);
|
mapFluids.put(hash, previewStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ItemStack stack : missing.getStacks()) {
|
for (StackListEntry<ItemStack> stack : missing.getStacks()) {
|
||||||
int hash = API.instance().getItemStackHashCode(stack);
|
int hash = API.instance().getItemStackHashCode(stack.getStack());
|
||||||
|
|
||||||
CraftingPreviewElementItemStack previewStack = map.get(hash);
|
CraftingPreviewElementItemStack previewStack = map.get(hash);
|
||||||
|
|
||||||
if (previewStack == null) {
|
if (previewStack == null) {
|
||||||
previewStack = new CraftingPreviewElementItemStack(stack);
|
previewStack = new CraftingPreviewElementItemStack(stack.getStack());
|
||||||
}
|
}
|
||||||
|
|
||||||
previewStack.setMissing(true);
|
previewStack.setMissing(true);
|
||||||
previewStack.addToCraft(stack.getCount());
|
previewStack.addToCraft(stack.getStack().getCount());
|
||||||
|
|
||||||
map.put(hash, previewStack);
|
map.put(hash, previewStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (FluidStack stack : missingFluids.getStacks()) {
|
for (StackListEntry<FluidStack> stack : missingFluids.getStacks()) {
|
||||||
int hash = API.instance().getFluidStackHashCode(stack);
|
int hash = API.instance().getFluidStackHashCode(stack.getStack());
|
||||||
|
|
||||||
CraftingPreviewElementFluidStack previewStack = mapFluids.get(hash);
|
CraftingPreviewElementFluidStack previewStack = mapFluids.get(hash);
|
||||||
|
|
||||||
if (previewStack == null) {
|
if (previewStack == null) {
|
||||||
previewStack = new CraftingPreviewElementFluidStack(stack);
|
previewStack = new CraftingPreviewElementFluidStack(stack.getStack());
|
||||||
}
|
}
|
||||||
|
|
||||||
previewStack.setMissing(true);
|
previewStack.setMissing(true);
|
||||||
previewStack.addToCraft(stack.getAmount());
|
previewStack.addToCraft(stack.getStack().getAmount());
|
||||||
|
|
||||||
mapFluids.put(hash, previewStack);
|
mapFluids.put(hash, previewStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ItemStack stack : toTake.getStacks()) {
|
for (StackListEntry<ItemStack> stack : toTake.getStacks()) {
|
||||||
int hash = API.instance().getItemStackHashCode(stack);
|
int hash = API.instance().getItemStackHashCode(stack.getStack());
|
||||||
|
|
||||||
CraftingPreviewElementItemStack previewStack = map.get(hash);
|
CraftingPreviewElementItemStack previewStack = map.get(hash);
|
||||||
|
|
||||||
if (previewStack == null) {
|
if (previewStack == null) {
|
||||||
previewStack = new CraftingPreviewElementItemStack(stack);
|
previewStack = new CraftingPreviewElementItemStack(stack.getStack());
|
||||||
}
|
}
|
||||||
|
|
||||||
previewStack.addAvailable(stack.getCount());
|
previewStack.addAvailable(stack.getStack().getCount());
|
||||||
|
|
||||||
map.put(hash, previewStack);
|
map.put(hash, previewStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (FluidStack stack : toTakeFluids.getStacks()) {
|
for (StackListEntry<FluidStack> stack : toTakeFluids.getStacks()) {
|
||||||
int hash = API.instance().getFluidStackHashCode(stack);
|
int hash = API.instance().getFluidStackHashCode(stack.getStack());
|
||||||
|
|
||||||
CraftingPreviewElementFluidStack previewStack = mapFluids.get(hash);
|
CraftingPreviewElementFluidStack previewStack = mapFluids.get(hash);
|
||||||
|
|
||||||
if (previewStack == null) {
|
if (previewStack == null) {
|
||||||
previewStack = new CraftingPreviewElementFluidStack(stack);
|
previewStack = new CraftingPreviewElementFluidStack(stack.getStack());
|
||||||
}
|
}
|
||||||
|
|
||||||
previewStack.addAvailable(stack.getAmount());
|
previewStack.addAvailable(stack.getStack().getAmount());
|
||||||
|
|
||||||
mapFluids.put(hash, previewStack);
|
mapFluids.put(hash, previewStack);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import net.minecraftforge.fluids.capability.IFluidHandler;
|
|||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class FluidGridHandler implements IFluidGridHandler {
|
public class FluidGridHandler implements IFluidGridHandler {
|
||||||
private INetwork network;
|
private INetwork network;
|
||||||
@@ -30,8 +31,8 @@ public class FluidGridHandler implements IFluidGridHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onExtract(ServerPlayerEntity player, int hash, boolean shift) {
|
public void onExtract(ServerPlayerEntity player, UUID id, boolean shift) {
|
||||||
FluidStack stack = network.getFluidStorageCache().getList().get(hash);
|
FluidStack stack = network.getFluidStorageCache().getList().get(id);
|
||||||
|
|
||||||
if (stack == null || stack.getAmount() < FluidAttributes.BUCKET_VOLUME || !network.getSecurityManager().hasPermission(Permission.EXTRACT, player)) {
|
if (stack == null || stack.getAmount() < FluidAttributes.BUCKET_VOLUME || !network.getSecurityManager().hasPermission(Permission.EXTRACT, player)) {
|
||||||
return;
|
return;
|
||||||
@@ -111,7 +112,7 @@ public class FluidGridHandler implements IFluidGridHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCraftingPreviewRequested(ServerPlayerEntity player, int hash, int quantity, boolean noPreview) {
|
public void onCraftingPreviewRequested(ServerPlayerEntity player, UUID id, int quantity, boolean noPreview) {
|
||||||
if (!network.getSecurityManager().hasPermission(Permission.AUTOCRAFTING, player)) {
|
if (!network.getSecurityManager().hasPermission(Permission.AUTOCRAFTING, player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -124,7 +125,7 @@ public class FluidGridHandler implements IFluidGridHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FluidStack stack = cache.get(hash);
|
FluidStack stack = cache.get(id);
|
||||||
|
|
||||||
if (stack != null) {
|
if (stack != null) {
|
||||||
Thread calculationThread = new Thread(() -> {
|
Thread calculationThread = new Thread(() -> {
|
||||||
@@ -151,7 +152,7 @@ public class FluidGridHandler implements IFluidGridHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCraftingRequested(ServerPlayerEntity player, int hash, int quantity) {
|
public void onCraftingRequested(ServerPlayerEntity player, UUID id, int quantity) {
|
||||||
if (quantity <= 0 || !network.getSecurityManager().hasPermission(Permission.AUTOCRAFTING, player)) {
|
if (quantity <= 0 || !network.getSecurityManager().hasPermission(Permission.AUTOCRAFTING, player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -160,7 +161,7 @@ public class FluidGridHandler implements IFluidGridHandler {
|
|||||||
|
|
||||||
for (ICraftingPattern pattern : network.getCraftingManager().getPatterns()) {
|
for (ICraftingPattern pattern : network.getCraftingManager().getPatterns()) {
|
||||||
for (FluidStack output : pattern.getFluidOutputs()) {
|
for (FluidStack output : pattern.getFluidOutputs()) {
|
||||||
if (API.instance().getFluidStackHashCode(output) == hash) {
|
if (/* TODO API.instance().getFluidStackHashCode(output) == hash*/false) {
|
||||||
stack = output;
|
stack = output;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import net.minecraftforge.fluids.capability.IFluidHandler;
|
|||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class FluidGridHandlerPortable implements IFluidGridHandler {
|
public class FluidGridHandlerPortable implements IFluidGridHandler {
|
||||||
private IPortableGrid portableGrid;
|
private IPortableGrid portableGrid;
|
||||||
@@ -26,8 +27,8 @@ public class FluidGridHandlerPortable implements IFluidGridHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onExtract(ServerPlayerEntity player, int hash, boolean shift) {
|
public void onExtract(ServerPlayerEntity player, UUID id, boolean shift) {
|
||||||
FluidStack stack = portableGrid.getFluidCache().getList().get(hash);
|
FluidStack stack = portableGrid.getFluidCache().getList().get(id);
|
||||||
|
|
||||||
if (stack == null || stack.getAmount() < FluidAttributes.BUCKET_VOLUME) {
|
if (stack == null || stack.getAmount() < FluidAttributes.BUCKET_VOLUME) {
|
||||||
return;
|
return;
|
||||||
@@ -99,12 +100,12 @@ public class FluidGridHandlerPortable implements IFluidGridHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCraftingPreviewRequested(ServerPlayerEntity player, int hash, int quantity, boolean noPreview) {
|
public void onCraftingPreviewRequested(ServerPlayerEntity player, UUID id, int quantity, boolean noPreview) {
|
||||||
// NO OP
|
// NO OP
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCraftingRequested(ServerPlayerEntity player, int hash, int quantity) {
|
public void onCraftingRequested(ServerPlayerEntity player, UUID id, int quantity) {
|
||||||
// NO OP
|
// NO OP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ public class ItemGridHandler implements IItemGridHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onExtract(ServerPlayerEntity player, int hash, int flags) {
|
public void onExtract(ServerPlayerEntity player, UUID id, int flags) {
|
||||||
ItemStack item = network.getItemStorageCache().getList().get(hash);
|
ItemStack item = network.getItemStorageCache().getList().get(id);
|
||||||
|
|
||||||
if (item == null || !network.getSecurityManager().hasPermission(Permission.EXTRACT, player)) {
|
if (item == null || !network.getSecurityManager().hasPermission(Permission.EXTRACT, player)) {
|
||||||
return;
|
return;
|
||||||
@@ -157,7 +157,7 @@ public class ItemGridHandler implements IItemGridHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCraftingPreviewRequested(ServerPlayerEntity player, int hash, int quantity, boolean noPreview) {
|
public void onCraftingPreviewRequested(ServerPlayerEntity player, UUID id, int quantity, boolean noPreview) {
|
||||||
if (!network.getSecurityManager().hasPermission(Permission.AUTOCRAFTING, player)) {
|
if (!network.getSecurityManager().hasPermission(Permission.AUTOCRAFTING, player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -170,7 +170,7 @@ public class ItemGridHandler implements IItemGridHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack stack = cache.get(hash);
|
ItemStack stack = cache.get(id);
|
||||||
|
|
||||||
if (stack != null) {
|
if (stack != null) {
|
||||||
Thread calculationThread = new Thread(() -> {
|
Thread calculationThread = new Thread(() -> {
|
||||||
@@ -197,7 +197,7 @@ public class ItemGridHandler implements IItemGridHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCraftingRequested(ServerPlayerEntity player, int hash, int quantity) {
|
public void onCraftingRequested(ServerPlayerEntity player, UUID id, int quantity) {
|
||||||
if (quantity <= 0 || !network.getSecurityManager().hasPermission(Permission.AUTOCRAFTING, player)) {
|
if (quantity <= 0 || !network.getSecurityManager().hasPermission(Permission.AUTOCRAFTING, player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -206,7 +206,7 @@ public class ItemGridHandler implements IItemGridHandler {
|
|||||||
|
|
||||||
for (ICraftingPattern pattern : network.getCraftingManager().getPatterns()) {
|
for (ICraftingPattern pattern : network.getCraftingManager().getPatterns()) {
|
||||||
for (ItemStack output : pattern.getOutputs()) {
|
for (ItemStack output : pattern.getOutputs()) {
|
||||||
if (API.instance().getItemStackHashCode(output) == hash) {
|
if (/* TODO API.instance().getItemStackHashCode(output) == hash*/false) {
|
||||||
stack = output;
|
stack = output;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -28,12 +28,12 @@ public class ItemGridHandlerPortable implements IItemGridHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onExtract(ServerPlayerEntity player, int hash, int flags) {
|
public void onExtract(ServerPlayerEntity player, UUID id, int flags) {
|
||||||
if (portableGrid.getStorage() == null || !grid.isActive()) {
|
if (portableGrid.getStorage() == null || !grid.isActive()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack item = portableGrid.getItemCache().getList().get(hash);
|
ItemStack item = portableGrid.getItemCache().getList().get(id);
|
||||||
|
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
return;
|
return;
|
||||||
@@ -157,12 +157,12 @@ public class ItemGridHandlerPortable implements IItemGridHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCraftingPreviewRequested(ServerPlayerEntity player, int hash, int quantity, boolean noPreview) {
|
public void onCraftingPreviewRequested(ServerPlayerEntity player, UUID id, int quantity, boolean noPreview) {
|
||||||
// NO OP
|
// NO OP
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCraftingRequested(ServerPlayerEntity player, int hash, int quantity) {
|
public void onCraftingRequested(ServerPlayerEntity player, UUID id, int quantity) {
|
||||||
// NO OP
|
// NO OP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public class NetworkNodeDetector extends NetworkNode implements IComparable, ITy
|
|||||||
|
|
||||||
powered = isPowered(stack == null ? null : stack.getCount());
|
powered = isPowered(stack == null ? null : stack.getCount());
|
||||||
} else {
|
} else {
|
||||||
powered = isPowered(network.getItemStorageCache().getList().getStacks().stream().map(ItemStack::getCount).mapToInt(Number::intValue).sum());
|
powered = isPowered(network.getItemStorageCache().getList().getStacks().stream().map(e -> e.getStack().getCount()).mapToInt(Number::intValue).sum());
|
||||||
}
|
}
|
||||||
} else if (type == IType.FLUIDS) {
|
} else if (type == IType.FLUIDS) {
|
||||||
FluidStack slot = fluidFilters.getFluid(0);
|
FluidStack slot = fluidFilters.getFluid(0);
|
||||||
@@ -87,7 +87,7 @@ public class NetworkNodeDetector extends NetworkNode implements IComparable, ITy
|
|||||||
|
|
||||||
powered = isPowered(stack == null ? null : stack.getAmount());
|
powered = isPowered(stack == null ? null : stack.getAmount());
|
||||||
} else {
|
} else {
|
||||||
powered = isPowered(network.getFluidStorageCache().getList().getStacks().stream().map(FluidStack::getAmount).mapToInt(Number::intValue).sum());
|
powered = isPowered(network.getFluidStorageCache().getList().getStacks().stream().map(e -> e.getStack().getAmount()).mapToInt(Number::intValue).sum());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
|
|||||||
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
|
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.Action;
|
import com.raoulvdberge.refinedstorage.api.util.Action;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.util.StackListEntry;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNode;
|
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNode;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive.DiskDriveNetworkNode;
|
import com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive.DiskDriveNetworkNode;
|
||||||
import com.raoulvdberge.refinedstorage.inventory.fluid.FluidInventory;
|
import com.raoulvdberge.refinedstorage.inventory.fluid.FluidInventory;
|
||||||
@@ -34,6 +35,7 @@ import net.minecraftforge.items.wrapper.CombinedInvWrapper;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class NetworkNodeDiskManipulator extends NetworkNode implements IComparable, IWhitelistBlacklist, IType, IStorageDiskContainerContext {
|
public class NetworkNodeDiskManipulator extends NetworkNode implements IComparable, IWhitelistBlacklist, IType, IStorageDiskContainerContext {
|
||||||
public static final String ID = "disk_manipulator";
|
public static final String ID = "disk_manipulator";
|
||||||
@@ -232,7 +234,7 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
|||||||
|
|
||||||
if (itemFilters.isEmpty()) {
|
if (itemFilters.isEmpty()) {
|
||||||
ItemStack toExtract = null;
|
ItemStack toExtract = null;
|
||||||
ArrayList<ItemStack> networkItems = new ArrayList<>(network.getItemStorageCache().getList().getStacks());
|
List<ItemStack> networkItems = network.getItemStorageCache().getList().getStacks().stream().map(StackListEntry::getStack).collect(Collectors.toList());
|
||||||
|
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
|
||||||
@@ -331,7 +333,7 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
|||||||
|
|
||||||
if (fluidFilters.isEmpty()) {
|
if (fluidFilters.isEmpty()) {
|
||||||
FluidStack toExtract = null;
|
FluidStack toExtract = null;
|
||||||
ArrayList<FluidStack> networkFluids = new ArrayList<>(network.getFluidStorageCache().getList().getStacks());
|
List<FluidStack> networkFluids = network.getFluidStorageCache().getList().getStacks().stream().map(StackListEntry::getStack).collect(Collectors.toList());
|
||||||
|
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package com.raoulvdberge.refinedstorage.apiimpl.storage;
|
|||||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.*;
|
import com.raoulvdberge.refinedstorage.api.storage.*;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.util.StackListResult;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -21,7 +21,7 @@ public class StorageCacheFluid implements IStorageCache<FluidStack> {
|
|||||||
private CopyOnWriteArrayList<IStorage<FluidStack>> storages = new CopyOnWriteArrayList<>();
|
private CopyOnWriteArrayList<IStorage<FluidStack>> storages = new CopyOnWriteArrayList<>();
|
||||||
private IStackList<FluidStack> list = API.instance().createFluidStackList();
|
private IStackList<FluidStack> list = API.instance().createFluidStackList();
|
||||||
private List<IStorageCacheListener<FluidStack>> listeners = new LinkedList<>();
|
private List<IStorageCacheListener<FluidStack>> listeners = new LinkedList<>();
|
||||||
private List<Pair<FluidStack, Integer>> batchedChanges = new ArrayList<>();
|
private List<StackListResult<FluidStack>> batchedChanges = new ArrayList<>();
|
||||||
|
|
||||||
public StorageCacheFluid(INetwork network) {
|
public StorageCacheFluid(INetwork network) {
|
||||||
this.network = network;
|
this.network = network;
|
||||||
@@ -54,24 +54,26 @@ public class StorageCacheFluid implements IStorageCache<FluidStack> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(@Nonnull FluidStack stack, int size, boolean rebuilding, boolean batched) {
|
public void add(@Nonnull FluidStack stack, int size, boolean rebuilding, boolean batched) {
|
||||||
list.add(stack, size);
|
StackListResult<FluidStack> result = list.add(stack, size);
|
||||||
|
|
||||||
if (!rebuilding) {
|
if (!rebuilding) {
|
||||||
if (!batched) {
|
if (!batched) {
|
||||||
listeners.forEach(l -> l.onChanged(stack, size));
|
listeners.forEach(l -> l.onChanged(result));
|
||||||
} else {
|
} else {
|
||||||
batchedChanges.add(Pair.of(stack.copy(), size));
|
batchedChanges.add(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove(@Nonnull FluidStack stack, int size, boolean batched) {
|
public void remove(@Nonnull FluidStack stack, int size, boolean batched) {
|
||||||
if (list.remove(stack, size)) {
|
StackListResult<FluidStack> result = list.remove(stack, size);
|
||||||
|
|
||||||
|
if (result != null) {
|
||||||
if (!batched) {
|
if (!batched) {
|
||||||
listeners.forEach(l -> l.onChanged(stack, -size));
|
listeners.forEach(l -> l.onChanged(result));
|
||||||
} else {
|
} else {
|
||||||
batchedChanges.add(Pair.of(stack.copy(), -size));
|
batchedChanges.add(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,7 +81,7 @@ public class StorageCacheFluid implements IStorageCache<FluidStack> {
|
|||||||
@Override
|
@Override
|
||||||
public void flush() {
|
public void flush() {
|
||||||
if (!batchedChanges.isEmpty()) {
|
if (!batchedChanges.isEmpty()) {
|
||||||
batchedChanges.forEach(c -> listeners.forEach(l -> l.onChanged(c.getKey(), c.getValue())));
|
batchedChanges.forEach(change -> listeners.forEach(l -> l.onChanged(change)));
|
||||||
batchedChanges.clear();
|
batchedChanges.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.raoulvdberge.refinedstorage.api.storage.IStorage;
|
|||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageCache;
|
import com.raoulvdberge.refinedstorage.api.storage.IStorageCache;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageCacheListener;
|
import com.raoulvdberge.refinedstorage.api.storage.IStorageCacheListener;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.util.StackListResult;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
import com.raoulvdberge.refinedstorage.tile.grid.portable.IPortableGrid;
|
import com.raoulvdberge.refinedstorage.tile.grid.portable.IPortableGrid;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
@@ -35,17 +36,19 @@ public class StorageCacheFluidPortable implements IStorageCache<FluidStack> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(@Nonnull FluidStack stack, int size, boolean rebuilding, boolean batched) {
|
public void add(@Nonnull FluidStack stack, int size, boolean rebuilding, boolean batched) {
|
||||||
list.add(stack, size);
|
StackListResult<FluidStack> result = list.add(stack, size);
|
||||||
|
|
||||||
if (!rebuilding) {
|
if (!rebuilding) {
|
||||||
listeners.forEach(l -> l.onChanged(stack, size));
|
listeners.forEach(l -> l.onChanged(result));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove(@Nonnull FluidStack stack, int size, boolean batched) {
|
public void remove(@Nonnull FluidStack stack, int size, boolean batched) {
|
||||||
if (list.remove(stack, size)) {
|
StackListResult<FluidStack> result = list.remove(stack, size);
|
||||||
listeners.forEach(l -> l.onChanged(stack, -size));
|
|
||||||
|
if (result != null) {
|
||||||
|
listeners.forEach(l -> l.onChanged(result));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package com.raoulvdberge.refinedstorage.apiimpl.storage;
|
|||||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.*;
|
import com.raoulvdberge.refinedstorage.api.storage.*;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.util.StackListResult;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -21,7 +21,7 @@ public class StorageCacheItem implements IStorageCache<ItemStack> {
|
|||||||
private CopyOnWriteArrayList<IStorage<ItemStack>> storages = new CopyOnWriteArrayList<>();
|
private CopyOnWriteArrayList<IStorage<ItemStack>> storages = new CopyOnWriteArrayList<>();
|
||||||
private IStackList<ItemStack> list = API.instance().createItemStackList();
|
private IStackList<ItemStack> list = API.instance().createItemStackList();
|
||||||
private List<IStorageCacheListener<ItemStack>> listeners = new LinkedList<>();
|
private List<IStorageCacheListener<ItemStack>> listeners = new LinkedList<>();
|
||||||
private List<Pair<ItemStack, Integer>> batchedChanges = new ArrayList<>();
|
private List<StackListResult<ItemStack>> batchedChanges = new ArrayList<>();
|
||||||
|
|
||||||
public StorageCacheItem(INetwork network) {
|
public StorageCacheItem(INetwork network) {
|
||||||
this.network = network;
|
this.network = network;
|
||||||
@@ -56,24 +56,26 @@ public class StorageCacheItem implements IStorageCache<ItemStack> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(@Nonnull ItemStack stack, int size, boolean rebuilding, boolean batched) {
|
public void add(@Nonnull ItemStack stack, int size, boolean rebuilding, boolean batched) {
|
||||||
list.add(stack, size);
|
StackListResult<ItemStack> result = list.add(stack, size);
|
||||||
|
|
||||||
if (!rebuilding) {
|
if (!rebuilding) {
|
||||||
if (!batched) {
|
if (!batched) {
|
||||||
listeners.forEach(l -> l.onChanged(stack, size));
|
listeners.forEach(l -> l.onChanged(result));
|
||||||
} else {
|
} else {
|
||||||
batchedChanges.add(Pair.of(stack.copy(), size));
|
batchedChanges.add(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove(@Nonnull ItemStack stack, int size, boolean batched) {
|
public void remove(@Nonnull ItemStack stack, int size, boolean batched) {
|
||||||
if (list.remove(stack, size)) {
|
StackListResult<ItemStack> result = list.remove(stack, size);
|
||||||
|
|
||||||
|
if (result != null) {
|
||||||
if (!batched) {
|
if (!batched) {
|
||||||
listeners.forEach(l -> l.onChanged(stack, -size));
|
listeners.forEach(l -> l.onChanged(result));
|
||||||
} else {
|
} else {
|
||||||
batchedChanges.add(Pair.of(stack.copy(), -size));
|
batchedChanges.add(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -84,7 +86,7 @@ public class StorageCacheItem implements IStorageCache<ItemStack> {
|
|||||||
if (batchedChanges.size() > 1) {
|
if (batchedChanges.size() > 1) {
|
||||||
listeners.forEach(l -> l.onChangedBulk(batchedChanges));
|
listeners.forEach(l -> l.onChangedBulk(batchedChanges));
|
||||||
} else {
|
} else {
|
||||||
batchedChanges.forEach(c -> listeners.forEach(l -> l.onChanged(c.getKey(), c.getValue())));
|
batchedChanges.forEach(change -> listeners.forEach(l -> l.onChanged(change)));
|
||||||
}
|
}
|
||||||
|
|
||||||
batchedChanges.clear();
|
batchedChanges.clear();
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.raoulvdberge.refinedstorage.api.storage.IStorage;
|
|||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageCache;
|
import com.raoulvdberge.refinedstorage.api.storage.IStorageCache;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageCacheListener;
|
import com.raoulvdberge.refinedstorage.api.storage.IStorageCacheListener;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.util.StackListResult;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
import com.raoulvdberge.refinedstorage.tile.grid.portable.IPortableGrid;
|
import com.raoulvdberge.refinedstorage.tile.grid.portable.IPortableGrid;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
@@ -35,17 +36,19 @@ public class StorageCacheItemPortable implements IStorageCache<ItemStack> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(@Nonnull ItemStack stack, int size, boolean rebuilding, boolean batched) {
|
public void add(@Nonnull ItemStack stack, int size, boolean rebuilding, boolean batched) {
|
||||||
list.add(stack, size);
|
StackListResult<ItemStack> result = list.add(stack, size);
|
||||||
|
|
||||||
if (!rebuilding) {
|
if (!rebuilding) {
|
||||||
listeners.forEach(l -> l.onChanged(stack, size));
|
listeners.forEach(l -> l.onChanged(result));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove(@Nonnull ItemStack stack, int size, boolean batched) {
|
public void remove(@Nonnull ItemStack stack, int size, boolean batched) {
|
||||||
if (list.remove(stack, size)) {
|
StackListResult<ItemStack> result = list.remove(stack, size);
|
||||||
listeners.forEach(l -> l.onChanged(stack, -size));
|
|
||||||
|
if (result != null) {
|
||||||
|
listeners.forEach(l -> l.onChanged(result));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,10 @@ package com.raoulvdberge.refinedstorage.apiimpl.storage;
|
|||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageCacheListener;
|
import com.raoulvdberge.refinedstorage.api.storage.IStorageCacheListener;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.util.StackListResult;
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class StorageCacheListenerGridFluid implements IStorageCacheListener<FluidStack> {
|
public class StorageCacheListenerGridFluid implements IStorageCacheListener<FluidStack> {
|
||||||
@@ -29,14 +28,17 @@ public class StorageCacheListenerGridFluid implements IStorageCacheListener<Flui
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChanged(@Nonnull FluidStack stack, int size) {
|
public void onChanged(StackListResult<FluidStack> delta) {
|
||||||
// TODO RS.INSTANCE.network.sendTo(new MessageGridFluidDelta(network, network.getFluidStorageTracker(), stack, size), player);
|
// TODO: RS.INSTANCE.network.sendTo(new MessageGridFluidUpdate(network, network.getSecurityManager().hasPermission(Permission.AUTOCRAFTING, player)), player);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChangedBulk(@Nonnull List<Pair<FluidStack, Integer>> stacks) {
|
public void onChangedBulk(List<StackListResult<FluidStack>> storageCacheDeltas) {
|
||||||
|
/* TODO
|
||||||
for (Pair<FluidStack, Integer> stack : stacks) {
|
for (Pair<FluidStack, Integer> stack : stacks) {
|
||||||
onChanged(stack.getLeft(), stack.getRight());
|
onChanged(stack.getLeft(), stack.getRight());
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,13 +4,12 @@ import com.raoulvdberge.refinedstorage.RS;
|
|||||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.security.Permission;
|
import com.raoulvdberge.refinedstorage.api.network.security.Permission;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageCacheListener;
|
import com.raoulvdberge.refinedstorage.api.storage.IStorageCacheListener;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.util.StackListResult;
|
||||||
import com.raoulvdberge.refinedstorage.network.grid.GridItemDeltaMessage;
|
import com.raoulvdberge.refinedstorage.network.grid.GridItemDeltaMessage;
|
||||||
import com.raoulvdberge.refinedstorage.network.grid.GridItemUpdateMessage;
|
import com.raoulvdberge.refinedstorage.network.grid.GridItemUpdateMessage;
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -34,16 +33,16 @@ public class StorageCacheListenerGridItem implements IStorageCacheListener<ItemS
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChanged(@Nonnull ItemStack stack, int size) {
|
public void onChanged(StackListResult<ItemStack> delta) {
|
||||||
List<Pair<ItemStack, Integer>> deltas = new ArrayList<>();
|
List<StackListResult<ItemStack>> deltas = new ArrayList<>();
|
||||||
|
|
||||||
deltas.add(Pair.of(stack, size));
|
deltas.add(delta);
|
||||||
|
|
||||||
onChangedBulk(deltas);
|
onChangedBulk(deltas);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChangedBulk(@Nonnull List<Pair<ItemStack, Integer>> stacks) {
|
public void onChangedBulk(List<StackListResult<ItemStack>> deltas) {
|
||||||
RS.NETWORK_HANDLER.sendTo(player, new GridItemDeltaMessage(network, stacks));
|
RS.NETWORK_HANDLER.sendTo(player, new GridItemDeltaMessage(network, deltas));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
package com.raoulvdberge.refinedstorage.apiimpl.storage;
|
package com.raoulvdberge.refinedstorage.apiimpl.storage;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageCacheListener;
|
import com.raoulvdberge.refinedstorage.api.storage.IStorageCacheListener;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.util.StackListResult;
|
||||||
import com.raoulvdberge.refinedstorage.tile.grid.portable.IPortableGrid;
|
import com.raoulvdberge.refinedstorage.tile.grid.portable.IPortableGrid;
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class StorageCacheListenerGridPortable implements IStorageCacheListener<ItemStack> {
|
public class StorageCacheListenerGridPortable implements IStorageCacheListener<ItemStack> {
|
||||||
@@ -42,12 +41,12 @@ public class StorageCacheListenerGridPortable implements IStorageCacheListener<I
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChanged(@Nonnull ItemStack stack, int size) {
|
public void onChanged(StackListResult<ItemStack> delta) {
|
||||||
// TODO RS.INSTANCE.network.sendTo(new MessageGridItemDelta(null, portableGrid.getItemStorageTracker(), stack, size), player);
|
// TODO RS.INSTANCE.network.sendTo(new MessageGridItemDelta(null, portableGrid.getItemStorageTracker(), stack, size), player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChangedBulk(@Nonnull List<Pair<ItemStack, Integer>> stacks) {
|
public void onChangedBulk(List<StackListResult<ItemStack>> storageCacheDeltas) {
|
||||||
// TODO RS.INSTANCE.network.sendTo(new MessageGridItemDelta(null, portableGrid.getItemStorageTracker(), stacks), player);
|
// TODO RS.INSTANCE.network.sendTo(new MessageGridItemDelta(null, portableGrid.getItemStorageTracker(), stacks), player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
package com.raoulvdberge.refinedstorage.apiimpl.storage;
|
package com.raoulvdberge.refinedstorage.apiimpl.storage;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageCacheListener;
|
import com.raoulvdberge.refinedstorage.api.storage.IStorageCacheListener;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.util.StackListResult;
|
||||||
import com.raoulvdberge.refinedstorage.tile.grid.portable.IPortableGrid;
|
import com.raoulvdberge.refinedstorage.tile.grid.portable.IPortableGrid;
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class StorageCacheListenerGridPortableFluid implements IStorageCacheListener<FluidStack> {
|
public class StorageCacheListenerGridPortableFluid implements IStorageCacheListener<FluidStack> {
|
||||||
@@ -47,14 +46,18 @@ public class StorageCacheListenerGridPortableFluid implements IStorageCacheListe
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChanged(@Nonnull FluidStack stack, int size) {
|
public void onChanged(StackListResult<FluidStack> delta) {
|
||||||
// TODO RS.INSTANCE.network.sendTo(new MessageGridFluidDelta(null, portableGrid.getFluidStorageTracker(), stack, size), player);
|
// TODO RS.INSTANCE.network.sendTo(new MessageGridFluidDelta(null, portableGrid.getFluidStorageTracker(), stack, size), player);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChangedBulk(@Nonnull List<Pair<FluidStack, Integer>> stacks) {
|
public void onChangedBulk(List<StackListResult<FluidStack>> storageCacheDeltas) {
|
||||||
|
/* TODO
|
||||||
for (Pair<FluidStack, Integer> stack : stacks) {
|
for (Pair<FluidStack, Integer> stack : stacks) {
|
||||||
onChanged(stack.getLeft(), stack.getRight());
|
onChanged(stack.getLeft(), stack.getRight());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,133 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.apiimpl.util;
|
||||||
|
|
||||||
|
import com.google.common.collect.ArrayListMultimap;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.util.StackListEntry;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.util.StackListResult;
|
||||||
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
|
import net.minecraft.fluid.Fluid;
|
||||||
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class FluidStackList implements IStackList<FluidStack> {
|
||||||
|
private final ArrayListMultimap<Fluid, StackListEntry<FluidStack>> stacks = ArrayListMultimap.create();
|
||||||
|
private final Map<UUID, FluidStack> index = new HashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StackListResult<FluidStack> add(@Nonnull FluidStack stack, int size) {
|
||||||
|
if (size < 0) {
|
||||||
|
throw new IllegalArgumentException("Cannot accept empty stack");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (StackListEntry<FluidStack> entry : stacks.get(stack.getFluid())) {
|
||||||
|
FluidStack otherStack = entry.getStack();
|
||||||
|
|
||||||
|
if (stack.isFluidEqual(otherStack)) {
|
||||||
|
if ((long) otherStack.getAmount() + (long) size > Integer.MAX_VALUE) {
|
||||||
|
otherStack.setAmount(Integer.MAX_VALUE);
|
||||||
|
} else {
|
||||||
|
otherStack.grow(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new StackListResult<>(otherStack, entry.getId(), size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FluidStack newStack = stack.copy();
|
||||||
|
newStack.setAmount(size);
|
||||||
|
|
||||||
|
StackListEntry<FluidStack> newEntry = new StackListEntry<>(newStack);
|
||||||
|
|
||||||
|
stacks.put(newStack.getFluid(), newEntry);
|
||||||
|
index.put(newEntry.getId(), newEntry.getStack());
|
||||||
|
|
||||||
|
return new StackListResult<>(newStack, newEntry.getId(), size);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StackListResult<FluidStack> add(@Nonnull FluidStack stack) {
|
||||||
|
return add(stack, stack.getAmount());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StackListResult<FluidStack> remove(@Nonnull FluidStack stack, int size) {
|
||||||
|
for (StackListEntry<FluidStack> entry : stacks.get(stack.getFluid())) {
|
||||||
|
FluidStack otherStack = entry.getStack();
|
||||||
|
|
||||||
|
if (stack.isFluidEqual(otherStack)) {
|
||||||
|
if (otherStack.getAmount() - size <= 0) {
|
||||||
|
stacks.remove(otherStack.getFluid(), entry);
|
||||||
|
index.remove(entry.getId());
|
||||||
|
|
||||||
|
return new StackListResult<>(otherStack, entry.getId(), -otherStack.getAmount());
|
||||||
|
} else {
|
||||||
|
otherStack.shrink(size);
|
||||||
|
|
||||||
|
return new StackListResult<>(otherStack, entry.getId(), -size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StackListResult<FluidStack> remove(@Nonnull FluidStack stack) {
|
||||||
|
return remove(stack, stack.getAmount());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public FluidStack get(@Nonnull FluidStack stack, int flags) {
|
||||||
|
for (StackListEntry<FluidStack> entry : stacks.get(stack.getFluid())) {
|
||||||
|
FluidStack otherStack = entry.getStack();
|
||||||
|
|
||||||
|
if (API.instance().getComparer().isEqual(otherStack, stack, flags)) {
|
||||||
|
return otherStack;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public FluidStack get(UUID id) {
|
||||||
|
return index.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
stacks.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return stacks.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public Collection<StackListEntry<FluidStack>> getStacks() {
|
||||||
|
return stacks.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nonnull
|
||||||
|
public IStackList<FluidStack> copy() {
|
||||||
|
FluidStackList list = new FluidStackList();
|
||||||
|
|
||||||
|
for (StackListEntry<FluidStack> entry : stacks.values()) {
|
||||||
|
list.stacks.put(entry.getStack().getFluid(), new StackListEntry<>(entry.getId(), entry.getStack().copy()));
|
||||||
|
list.index.put(entry.getId(), entry.getStack());
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,131 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.apiimpl.util;
|
||||||
|
|
||||||
|
import com.google.common.collect.ArrayListMultimap;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.util.StackListEntry;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.util.StackListResult;
|
||||||
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraftforge.items.ItemHandlerHelper;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class ItemStackList implements IStackList<ItemStack> {
|
||||||
|
private final ArrayListMultimap<Item, StackListEntry<ItemStack>> stacks = ArrayListMultimap.create();
|
||||||
|
private final Map<UUID, ItemStack> index = new HashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StackListResult<ItemStack> add(@Nonnull ItemStack stack, int size) {
|
||||||
|
if (stack.isEmpty() || size <= 0) {
|
||||||
|
throw new IllegalArgumentException("Cannot accept empty stack");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (StackListEntry<ItemStack> entry : stacks.get(stack.getItem())) {
|
||||||
|
ItemStack otherStack = entry.getStack();
|
||||||
|
|
||||||
|
if (API.instance().getComparer().isEqualNoQuantity(otherStack, stack)) {
|
||||||
|
if ((long) otherStack.getCount() + (long) size > Integer.MAX_VALUE) {
|
||||||
|
otherStack.setCount(Integer.MAX_VALUE);
|
||||||
|
} else {
|
||||||
|
otherStack.grow(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new StackListResult<>(otherStack, entry.getId(), size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StackListEntry<ItemStack> newEntry = new StackListEntry<>(ItemHandlerHelper.copyStackWithSize(stack, size));
|
||||||
|
|
||||||
|
stacks.put(stack.getItem(), newEntry);
|
||||||
|
index.put(newEntry.getId(), newEntry.getStack());
|
||||||
|
|
||||||
|
return new StackListResult<>(newEntry.getStack(), newEntry.getId(), size);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StackListResult<ItemStack> add(@Nonnull ItemStack stack) {
|
||||||
|
return add(stack, stack.getCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StackListResult<ItemStack> remove(@Nonnull ItemStack stack, int size) {
|
||||||
|
for (StackListEntry<ItemStack> entry : stacks.get(stack.getItem())) {
|
||||||
|
ItemStack otherStack = entry.getStack();
|
||||||
|
|
||||||
|
if (API.instance().getComparer().isEqualNoQuantity(otherStack, stack)) {
|
||||||
|
if (otherStack.getCount() - size <= 0) {
|
||||||
|
stacks.remove(otherStack.getItem(), entry);
|
||||||
|
index.remove(entry.getId());
|
||||||
|
|
||||||
|
return new StackListResult<>(otherStack, entry.getId(), -otherStack.getCount());
|
||||||
|
} else {
|
||||||
|
otherStack.shrink(size);
|
||||||
|
|
||||||
|
return new StackListResult<>(otherStack, entry.getId(), -size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StackListResult<ItemStack> remove(@Nonnull ItemStack stack) {
|
||||||
|
return remove(stack, stack.getCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public ItemStack get(@Nonnull ItemStack stack, int flags) {
|
||||||
|
for (StackListEntry<ItemStack> entry : stacks.get(stack.getItem())) {
|
||||||
|
ItemStack otherStack = entry.getStack();
|
||||||
|
|
||||||
|
if (API.instance().getComparer().isEqual(otherStack, stack, flags)) {
|
||||||
|
return otherStack;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public ItemStack get(UUID id) {
|
||||||
|
return index.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
stacks.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return stacks.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public Collection<StackListEntry<ItemStack>> getStacks() {
|
||||||
|
return stacks.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nonnull
|
||||||
|
public IStackList<ItemStack> copy() {
|
||||||
|
ItemStackList list = new ItemStackList();
|
||||||
|
|
||||||
|
for (StackListEntry<ItemStack> entry : stacks.values()) {
|
||||||
|
list.stacks.put(entry.getStack().getItem(), new StackListEntry<>(entry.getId(), entry.getStack().copy()));
|
||||||
|
list.index.put(entry.getId(), entry.getStack());
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,119 +0,0 @@
|
|||||||
package com.raoulvdberge.refinedstorage.apiimpl.util;
|
|
||||||
|
|
||||||
import com.google.common.collect.ArrayListMultimap;
|
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
|
||||||
import net.minecraft.fluid.Fluid;
|
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
public class StackListFluid implements IStackList<FluidStack> {
|
|
||||||
private ArrayListMultimap<Fluid, FluidStack> stacks = ArrayListMultimap.create();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void add(@Nonnull FluidStack stack, int size) {
|
|
||||||
if (size < 0) {
|
|
||||||
throw new IllegalArgumentException("Cannot accept empty stack");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (FluidStack otherStack : stacks.get(stack.getFluid())) {
|
|
||||||
if (stack.isFluidEqual(otherStack)) {
|
|
||||||
if ((long) otherStack.getAmount() + (long) size > Integer.MAX_VALUE) {
|
|
||||||
otherStack.setAmount(Integer.MAX_VALUE);
|
|
||||||
} else {
|
|
||||||
otherStack.grow(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FluidStack newStack = stack.copy();
|
|
||||||
newStack.setAmount(size);
|
|
||||||
stacks.put(stack.getFluid(), newStack);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void add(@Nonnull FluidStack stack) {
|
|
||||||
add(stack, stack.getAmount());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean remove(@Nonnull FluidStack stack, int size) {
|
|
||||||
for (FluidStack otherStack : stacks.get(stack.getFluid())) {
|
|
||||||
if (stack.isFluidEqual(otherStack)) {
|
|
||||||
otherStack.shrink(size);
|
|
||||||
|
|
||||||
boolean success = otherStack.getAmount() >= 0;
|
|
||||||
|
|
||||||
if (otherStack.getAmount() <= 0) {
|
|
||||||
stacks.remove(otherStack.getFluid(), otherStack);
|
|
||||||
}
|
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean remove(@Nonnull FluidStack stack) {
|
|
||||||
return remove(stack, stack.getAmount());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public FluidStack get(@Nonnull FluidStack stack, int flags) {
|
|
||||||
for (FluidStack otherStack : stacks.get(stack.getFluid())) {
|
|
||||||
if (API.instance().getComparer().isEqual(otherStack, stack, flags)) {
|
|
||||||
return otherStack;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public FluidStack get(int hash) {
|
|
||||||
for (FluidStack stack : this.stacks.values()) {
|
|
||||||
if (API.instance().getFluidStackHashCode(stack) == hash) {
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clear() {
|
|
||||||
stacks.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return stacks.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public Collection<FluidStack> getStacks() {
|
|
||||||
return stacks.values();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nonnull
|
|
||||||
public IStackList<FluidStack> copy() {
|
|
||||||
StackListFluid list = new StackListFluid();
|
|
||||||
|
|
||||||
for (FluidStack stack : stacks.values()) {
|
|
||||||
list.stacks.put(stack.getFluid(), stack.copy());
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,118 +0,0 @@
|
|||||||
package com.raoulvdberge.refinedstorage.apiimpl.util;
|
|
||||||
|
|
||||||
import com.google.common.collect.ArrayListMultimap;
|
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraftforge.items.ItemHandlerHelper;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
public class StackListItem implements IStackList<ItemStack> {
|
|
||||||
private ArrayListMultimap<Item, ItemStack> stacks = ArrayListMultimap.create();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void add(@Nonnull ItemStack stack, int size) {
|
|
||||||
if (stack.isEmpty() || size <= 0) {
|
|
||||||
throw new IllegalArgumentException("Cannot accept empty stack");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ItemStack otherStack : stacks.get(stack.getItem())) {
|
|
||||||
if (API.instance().getComparer().isEqualNoQuantity(otherStack, stack)) {
|
|
||||||
if ((long) otherStack.getCount() + (long) size > Integer.MAX_VALUE) {
|
|
||||||
otherStack.setCount(Integer.MAX_VALUE);
|
|
||||||
} else {
|
|
||||||
otherStack.grow(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stacks.put(stack.getItem(), ItemHandlerHelper.copyStackWithSize(stack, size));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void add(@Nonnull ItemStack stack) {
|
|
||||||
add(stack, stack.getCount());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean remove(@Nonnull ItemStack stack, int size) {
|
|
||||||
for (ItemStack otherStack : stacks.get(stack.getItem())) {
|
|
||||||
if (API.instance().getComparer().isEqualNoQuantity(otherStack, stack)) {
|
|
||||||
boolean success = otherStack.getCount() - size >= 0;
|
|
||||||
|
|
||||||
if (otherStack.getCount() - size <= 0) {
|
|
||||||
stacks.remove(otherStack.getItem(), otherStack);
|
|
||||||
} else {
|
|
||||||
otherStack.shrink(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean remove(@Nonnull ItemStack stack) {
|
|
||||||
return remove(stack, stack.getCount());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public ItemStack get(@Nonnull ItemStack stack, int flags) {
|
|
||||||
for (ItemStack otherStack : stacks.get(stack.getItem())) {
|
|
||||||
if (API.instance().getComparer().isEqual(otherStack, stack, flags)) {
|
|
||||||
return otherStack;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public ItemStack get(int hash) {
|
|
||||||
for (ItemStack stack : this.stacks.values()) {
|
|
||||||
if (API.instance().getItemStackHashCode(stack) == hash) {
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clear() {
|
|
||||||
stacks.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return stacks.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public Collection<ItemStack> getStacks() {
|
|
||||||
return stacks.values();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nonnull
|
|
||||||
public IStackList<ItemStack> copy() {
|
|
||||||
StackListItem list = new StackListItem();
|
|
||||||
|
|
||||||
for (ItemStack stack : stacks.values()) {
|
|
||||||
list.stacks.put(stack.getItem(), stack.copy());
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.raoulvdberge.refinedstorage.network.grid;
|
package com.raoulvdberge.refinedstorage.network.grid;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.util.StackListResult;
|
||||||
import com.raoulvdberge.refinedstorage.screen.BaseScreen;
|
import com.raoulvdberge.refinedstorage.screen.BaseScreen;
|
||||||
import com.raoulvdberge.refinedstorage.screen.grid.GridScreen;
|
import com.raoulvdberge.refinedstorage.screen.grid.GridScreen;
|
||||||
import com.raoulvdberge.refinedstorage.screen.grid.stack.IGridStack;
|
import com.raoulvdberge.refinedstorage.screen.grid.stack.IGridStack;
|
||||||
@@ -18,44 +19,46 @@ import java.util.function.Supplier;
|
|||||||
public class GridItemDeltaMessage {
|
public class GridItemDeltaMessage {
|
||||||
@Nullable
|
@Nullable
|
||||||
private INetwork network;
|
private INetwork network;
|
||||||
private List<Pair<ItemStack, Integer>> deltas;
|
private List<StackListResult<ItemStack>> deltas;
|
||||||
|
|
||||||
private List<Pair<IGridStack, Integer>> gridStacks;
|
private List<Pair<IGridStack, Integer>> clientDeltas;
|
||||||
|
|
||||||
public GridItemDeltaMessage(INetwork network, List<Pair<ItemStack, Integer>> deltas) {
|
public GridItemDeltaMessage(INetwork network, List<StackListResult<ItemStack>> deltas) {
|
||||||
this.network = network;
|
this.network = network;
|
||||||
this.deltas = deltas;
|
this.deltas = deltas;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GridItemDeltaMessage(List<Pair<IGridStack, Integer>> gridStacks) {
|
public GridItemDeltaMessage(List<Pair<IGridStack, Integer>> clientDeltas) {
|
||||||
this.gridStacks = gridStacks;
|
this.clientDeltas = clientDeltas;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GridItemDeltaMessage decode(PacketBuffer buf) {
|
public static GridItemDeltaMessage decode(PacketBuffer buf) {
|
||||||
int size = buf.readInt();
|
int size = buf.readInt();
|
||||||
|
|
||||||
List<Pair<IGridStack, Integer>> gridStacks = new LinkedList<>();
|
List<Pair<IGridStack, Integer>> clientDeltas = new LinkedList<>();
|
||||||
|
|
||||||
for (int i = 0; i < size; ++i) {
|
for (int i = 0; i < size; ++i) {
|
||||||
gridStacks.add(Pair.of(StackUtils.readItemGridStack(buf), buf.readInt()));
|
int delta = buf.readInt();
|
||||||
|
|
||||||
|
clientDeltas.add(Pair.of(StackUtils.readItemGridStack(buf), delta));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new GridItemDeltaMessage(gridStacks);
|
return new GridItemDeltaMessage(clientDeltas);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void encode(GridItemDeltaMessage message, PacketBuffer buf) {
|
public static void encode(GridItemDeltaMessage message, PacketBuffer buf) {
|
||||||
buf.writeInt(message.deltas.size());
|
buf.writeInt(message.deltas.size());
|
||||||
|
|
||||||
for (Pair<ItemStack, Integer> delta : message.deltas) {
|
for (StackListResult<ItemStack> delta : message.deltas) {
|
||||||
StackUtils.writeItemGridStack(buf, delta.getLeft(), message.network, false, message.network.getItemStorageTracker().get(delta.getLeft()));
|
buf.writeInt(delta.getChange());
|
||||||
|
|
||||||
buf.writeInt(delta.getRight());
|
StackUtils.writeItemGridStack(buf, delta.getStack(), delta.getId(), message.network, false, message.network.getItemStorageTracker().get(delta.getStack()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handle(GridItemDeltaMessage message, Supplier<NetworkEvent.Context> ctx) {
|
public static void handle(GridItemDeltaMessage message, Supplier<NetworkEvent.Context> ctx) {
|
||||||
BaseScreen.executeLater(GridScreen.class, grid -> {
|
BaseScreen.executeLater(GridScreen.class, grid -> {
|
||||||
message.gridStacks.forEach(p -> grid.getView().postChange(p.getLeft(), p.getRight()));
|
message.clientDeltas.forEach(p -> grid.getView().postChange(p.getLeft(), p.getRight()));
|
||||||
|
|
||||||
grid.getView().sort();
|
grid.getView().sort();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -7,23 +7,24 @@ import net.minecraft.inventory.container.Container;
|
|||||||
import net.minecraft.network.PacketBuffer;
|
import net.minecraft.network.PacketBuffer;
|
||||||
import net.minecraftforge.fml.network.NetworkEvent;
|
import net.minecraftforge.fml.network.NetworkEvent;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class GridItemPullMessage {
|
public class GridItemPullMessage {
|
||||||
private int hash;
|
private UUID id;
|
||||||
private int flags;
|
private int flags;
|
||||||
|
|
||||||
public GridItemPullMessage(int hash, int flags) {
|
public GridItemPullMessage(UUID id, int flags) {
|
||||||
this.hash = hash;
|
this.id = id;
|
||||||
this.flags = flags;
|
this.flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GridItemPullMessage decode(PacketBuffer buf) {
|
public static GridItemPullMessage decode(PacketBuffer buf) {
|
||||||
return new GridItemPullMessage(buf.readInt(), buf.readInt());
|
return new GridItemPullMessage(buf.readUniqueId(), buf.readInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void encode(GridItemPullMessage message, PacketBuffer buf) {
|
public static void encode(GridItemPullMessage message, PacketBuffer buf) {
|
||||||
buf.writeInt(message.hash);
|
buf.writeUniqueId(message.id);
|
||||||
buf.writeInt(message.flags);
|
buf.writeInt(message.flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +39,7 @@ public class GridItemPullMessage {
|
|||||||
IGrid grid = ((GridContainer) container).getGrid();
|
IGrid grid = ((GridContainer) container).getGrid();
|
||||||
|
|
||||||
if (grid.getItemHandler() != null) {
|
if (grid.getItemHandler() != null) {
|
||||||
grid.getItemHandler().onExtract(player, message.hash, message.flags);
|
grid.getItemHandler().onExtract(player, message.id, message.flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.raoulvdberge.refinedstorage.network.grid;
|
|||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPattern;
|
import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPattern;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.util.StackListEntry;
|
||||||
import com.raoulvdberge.refinedstorage.screen.BaseScreen;
|
import com.raoulvdberge.refinedstorage.screen.BaseScreen;
|
||||||
import com.raoulvdberge.refinedstorage.screen.grid.GridScreen;
|
import com.raoulvdberge.refinedstorage.screen.grid.GridScreen;
|
||||||
import com.raoulvdberge.refinedstorage.screen.grid.stack.IGridStack;
|
import com.raoulvdberge.refinedstorage.screen.grid.stack.IGridStack;
|
||||||
@@ -56,13 +57,13 @@ public class GridItemUpdateMessage {
|
|||||||
|
|
||||||
buf.writeInt(size);
|
buf.writeInt(size);
|
||||||
|
|
||||||
for (ItemStack stack : message.network.getItemStorageCache().getList().getStacks()) {
|
for (StackListEntry<ItemStack> stack : message.network.getItemStorageCache().getList().getStacks()) {
|
||||||
StackUtils.writeItemGridStack(buf, stack, message.network, false, message.network.getItemStorageTracker().get(stack));
|
StackUtils.writeItemGridStack(buf, stack.getStack(), stack.getId(), message.network, false, message.network.getItemStorageTracker().get(stack.getStack()));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ICraftingPattern pattern : message.network.getCraftingManager().getPatterns()) {
|
for (ICraftingPattern pattern : message.network.getCraftingManager().getPatterns()) {
|
||||||
for (ItemStack output : pattern.getOutputs()) {
|
for (ItemStack output : pattern.getOutputs()) {
|
||||||
StackUtils.writeItemGridStack(buf, output, message.network, true, message.network.getItemStorageTracker().get(output));
|
// TODO StackUtils.writeItemGridStack(buf, output, message.network, true, message.network.getItemStorageTracker().get(output));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -478,7 +478,7 @@ public class GridScreen extends BaseScreen<GridContainer> implements IScreenInfo
|
|||||||
flags |= IItemGridHandler.EXTRACT_SINGLE;
|
flags |= IItemGridHandler.EXTRACT_SINGLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
RS.NETWORK_HANDLER.sendToServer(new GridItemPullMessage(stack.getHash(), flags));
|
RS.NETWORK_HANDLER.sendToServer(new GridItemPullMessage(stack.getId(), flags));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
|||||||
import com.raoulvdberge.refinedstorage.screen.grid.stack.IGridStack;
|
import com.raoulvdberge.refinedstorage.screen.grid.stack.IGridStack;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.registry.Registry;
|
||||||
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
|
||||||
public class IdGridSorter implements IGridSorter {
|
public class IdGridSorter implements IGridSorter {
|
||||||
@Override
|
@Override
|
||||||
@@ -13,19 +15,22 @@ public class IdGridSorter implements IGridSorter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(IGridStack left, IGridStack right, SortingDirection sortingDirection) {
|
public int compare(IGridStack left, IGridStack right, SortingDirection sortingDirection) {
|
||||||
int x = left.getHash();
|
int leftId = 0;
|
||||||
int y = right.getHash();
|
int rightId = 0;
|
||||||
|
|
||||||
if (left.getIngredient() instanceof ItemStack && right.getIngredient() instanceof ItemStack) {
|
if (left.getIngredient() instanceof ItemStack && right.getIngredient() instanceof ItemStack) {
|
||||||
x = Item.getIdFromItem(((ItemStack) left.getIngredient()).getItem());
|
leftId = Item.getIdFromItem(((ItemStack) left.getIngredient()).getItem());
|
||||||
y = Item.getIdFromItem(((ItemStack) right.getIngredient()).getItem());
|
rightId = Item.getIdFromItem(((ItemStack) right.getIngredient()).getItem());
|
||||||
|
} else if (left.getIngredient() instanceof FluidStack && right.getIngredient() instanceof FluidStack) {
|
||||||
|
leftId = Registry.FLUID.getId(((FluidStack) left.getIngredient()).getFluid());
|
||||||
|
rightId = Registry.FLUID.getId(((FluidStack) right.getIngredient()).getFluid());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (x != y) {
|
if (leftId != rightId) {
|
||||||
if (sortingDirection == SortingDirection.DESCENDING) {
|
if (sortingDirection == SortingDirection.DESCENDING) {
|
||||||
return Integer.compare(x, y);
|
return Integer.compare(leftId, rightId);
|
||||||
} else if (sortingDirection == SortingDirection.ASCENDING) {
|
} else if (sortingDirection == SortingDirection.ASCENDING) {
|
||||||
return Integer.compare(y, x);
|
return Integer.compare(rightId, leftId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,10 @@ import net.minecraft.client.resources.I18n;
|
|||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class FluidGridStack implements IGridStack {
|
public class FluidGridStack implements IGridStack {
|
||||||
private int hash;
|
private UUID id;
|
||||||
private FluidStack stack;
|
private FluidStack stack;
|
||||||
@Nullable
|
@Nullable
|
||||||
private IStorageTracker.IStorageTrackerEntry entry;
|
private IStorageTracker.IStorageTrackerEntry entry;
|
||||||
@@ -19,8 +20,8 @@ public class FluidGridStack implements IGridStack {
|
|||||||
private String modId;
|
private String modId;
|
||||||
private String modName;
|
private String modName;
|
||||||
|
|
||||||
public FluidGridStack(int hash, FluidStack stack, @Nullable IStorageTracker.IStorageTrackerEntry entry, boolean craftable, boolean displayCraftText) {
|
public FluidGridStack(UUID id, FluidStack stack, @Nullable IStorageTracker.IStorageTrackerEntry entry, boolean craftable, boolean displayCraftText) {
|
||||||
this.hash = hash;
|
this.id = id;
|
||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
this.entry = entry;
|
this.entry = entry;
|
||||||
this.craftable = craftable;
|
this.craftable = craftable;
|
||||||
@@ -47,8 +48,8 @@ public class FluidGridStack implements IGridStack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getHash() {
|
public UUID getId() {
|
||||||
return hash;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -4,9 +4,10 @@ import com.raoulvdberge.refinedstorage.api.storage.IStorageTracker;
|
|||||||
import com.raoulvdberge.refinedstorage.screen.BaseScreen;
|
import com.raoulvdberge.refinedstorage.screen.BaseScreen;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public interface IGridStack {
|
public interface IGridStack {
|
||||||
int getHash();
|
UUID getId();
|
||||||
|
|
||||||
String getName();
|
String getName();
|
||||||
|
|
||||||
|
|||||||
@@ -8,10 +8,11 @@ import net.minecraft.client.resources.I18n;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ItemGridStack implements IGridStack {
|
public class ItemGridStack implements IGridStack {
|
||||||
private int hash;
|
private UUID id;
|
||||||
private ItemStack stack;
|
private ItemStack stack;
|
||||||
private String cachedName;
|
private String cachedName;
|
||||||
private boolean craftable;
|
private boolean craftable;
|
||||||
@@ -27,8 +28,8 @@ public class ItemGridStack implements IGridStack {
|
|||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemGridStack(int hash, ItemStack stack, boolean craftable, boolean displayCraftText, IStorageTracker.IStorageTrackerEntry entry) {
|
public ItemGridStack(UUID id, ItemStack stack, boolean craftable, boolean displayCraftText, IStorageTracker.IStorageTrackerEntry entry) {
|
||||||
this.hash = hash;
|
this.id = id;
|
||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
this.craftable = craftable;
|
this.craftable = craftable;
|
||||||
this.displayCraftText = displayCraftText;
|
this.displayCraftText = displayCraftText;
|
||||||
@@ -70,8 +71,8 @@ public class ItemGridStack implements IGridStack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getHash() {
|
public UUID getId() {
|
||||||
return hash;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public abstract class BaseGridView implements IGridView {
|
|||||||
private List<IGridSorter> sorters;
|
private List<IGridSorter> sorters;
|
||||||
|
|
||||||
private List<IGridStack> stacks = new ArrayList<>();
|
private List<IGridStack> stacks = new ArrayList<>();
|
||||||
protected Map<Integer, IGridStack> map = new HashMap<>();
|
protected Map<UUID, IGridStack> map = new HashMap<>();
|
||||||
|
|
||||||
public BaseGridView(GridScreen screen, IGridSorter defaultSorter, List<IGridSorter> sorters) {
|
public BaseGridView(GridScreen screen, IGridSorter defaultSorter, List<IGridSorter> sorters) {
|
||||||
this.screen = screen;
|
this.screen = screen;
|
||||||
|
|||||||
@@ -18,11 +18,11 @@ public class FluidGridView extends BaseGridView {
|
|||||||
|
|
||||||
for (IGridStack stack : stacks) {
|
for (IGridStack stack : stacks) {
|
||||||
// Don't let a craftable stack override a normal stack
|
// Don't let a craftable stack override a normal stack
|
||||||
if (stack.doesDisplayCraftText() && map.containsKey(stack.getHash())) {
|
if (stack.doesDisplayCraftText() && map.containsKey(stack.getId())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
map.put(stack.getHash(), stack);
|
map.put(stack.getId(), stack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,18 +32,18 @@ public class FluidGridView extends BaseGridView {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FluidGridStack existing = (FluidGridStack) map.get(stack.getHash());
|
FluidGridStack existing = (FluidGridStack) map.get(stack.getId());
|
||||||
|
|
||||||
if (existing == null) {
|
if (existing == null) {
|
||||||
((FluidGridStack) stack).getStack().setAmount(delta);
|
((FluidGridStack) stack).getStack().setAmount(delta);
|
||||||
|
|
||||||
map.put(stack.getHash(), stack);
|
map.put(stack.getId(), stack);
|
||||||
} else {
|
} else {
|
||||||
if (existing.getStack().getAmount() + delta <= 0) {
|
if (existing.getStack().getAmount() + delta <= 0) {
|
||||||
if (existing.isCraftable()) {
|
if (existing.isCraftable()) {
|
||||||
existing.setDisplayCraftText(true);
|
existing.setDisplayCraftText(true);
|
||||||
} else {
|
} else {
|
||||||
map.remove(existing.getHash());
|
map.remove(existing.getId());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (existing.doesDisplayCraftText()) {
|
if (existing.doesDisplayCraftText()) {
|
||||||
|
|||||||
@@ -18,11 +18,11 @@ public class ItemGridView extends BaseGridView {
|
|||||||
|
|
||||||
for (IGridStack stack : stacks) {
|
for (IGridStack stack : stacks) {
|
||||||
// Don't let a craftable stack override a normal stack
|
// Don't let a craftable stack override a normal stack
|
||||||
if (stack.doesDisplayCraftText() && map.containsKey(stack.getHash())) {
|
if (stack.doesDisplayCraftText() && map.containsKey(stack.getId())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
map.put(stack.getHash(), stack);
|
map.put(stack.getId(), stack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,18 +32,18 @@ public class ItemGridView extends BaseGridView {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemGridStack existing = (ItemGridStack) map.get(stack.getHash());
|
ItemGridStack existing = (ItemGridStack) map.get(stack.getId());
|
||||||
|
|
||||||
if (existing == null) {
|
if (existing == null) {
|
||||||
((ItemGridStack) stack).getStack().setCount(delta);
|
((ItemGridStack) stack).getStack().setCount(delta);
|
||||||
|
|
||||||
map.put(stack.getHash(), stack);
|
map.put(stack.getId(), stack);
|
||||||
} else {
|
} else {
|
||||||
if (existing.getStack().getCount() + delta <= 0) {
|
if (existing.getStack().getCount() + delta <= 0) {
|
||||||
if (existing.isCraftable()) {
|
if (existing.isCraftable()) {
|
||||||
existing.setDisplayCraftText(true);
|
existing.setDisplayCraftText(true);
|
||||||
} else {
|
} else {
|
||||||
map.remove(existing.getHash());
|
map.remove(existing.getId());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (existing.doesDisplayCraftText()) {
|
if (existing.doesDisplayCraftText()) {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import org.apache.commons.lang3.tuple.Pair;
|
|||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public final class StackUtils {
|
public final class StackUtils {
|
||||||
@@ -76,10 +77,10 @@ public final class StackUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void writeItemGridStack(PacketBuffer buf, ItemStack stack, @Nullable INetwork network, boolean displayCraftText, @Nullable IStorageTracker.IStorageTrackerEntry entry) {
|
public static void writeItemGridStack(PacketBuffer buf, ItemStack stack, UUID id, @Nullable INetwork network, boolean displayCraftText, @Nullable IStorageTracker.IStorageTrackerEntry entry) {
|
||||||
writeItemStack(buf, stack);
|
writeItemStack(buf, stack);
|
||||||
|
|
||||||
buf.writeInt(API.instance().getItemStackHashCode(stack));
|
buf.writeUniqueId(id);
|
||||||
|
|
||||||
if (network != null) {
|
if (network != null) {
|
||||||
buf.writeBoolean(network.getCraftingManager().getPattern(stack) != null);
|
buf.writeBoolean(network.getCraftingManager().getPattern(stack) != null);
|
||||||
@@ -101,7 +102,7 @@ public final class StackUtils {
|
|||||||
|
|
||||||
public static ItemGridStack readItemGridStack(PacketBuffer buf) {
|
public static ItemGridStack readItemGridStack(PacketBuffer buf) {
|
||||||
ItemStack stack = readItemStack(buf);
|
ItemStack stack = readItemStack(buf);
|
||||||
int hash = buf.readInt();
|
UUID id = buf.readUniqueId();
|
||||||
boolean craftable = buf.readBoolean();
|
boolean craftable = buf.readBoolean();
|
||||||
boolean displayCraftText = buf.readBoolean();
|
boolean displayCraftText = buf.readBoolean();
|
||||||
|
|
||||||
@@ -110,13 +111,13 @@ public final class StackUtils {
|
|||||||
entry = new StorageTrackerEntry(buf.readLong(), buf.readString());
|
entry = new StorageTrackerEntry(buf.readLong(), buf.readString());
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ItemGridStack(hash, stack, craftable, displayCraftText, entry);
|
return new ItemGridStack(id, stack, craftable, displayCraftText, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void writeFluidGridStack(PacketBuffer buf, FluidStack stack, @Nullable INetwork network, boolean displayCraftText, @Nullable IStorageTracker.IStorageTrackerEntry entry) {
|
public static void writeFluidGridStack(PacketBuffer buf, FluidStack stack, UUID id, @Nullable INetwork network, boolean displayCraftText, @Nullable IStorageTracker.IStorageTrackerEntry entry) {
|
||||||
stack.writeToPacket(buf);
|
stack.writeToPacket(buf);
|
||||||
|
|
||||||
buf.writeInt(API.instance().getFluidStackHashCode(stack));
|
buf.writeUniqueId(id);
|
||||||
|
|
||||||
if (network != null) {
|
if (network != null) {
|
||||||
buf.writeBoolean(network.getCraftingManager().getPattern(stack) != null);
|
buf.writeBoolean(network.getCraftingManager().getPattern(stack) != null);
|
||||||
@@ -138,7 +139,7 @@ public final class StackUtils {
|
|||||||
|
|
||||||
public static FluidGridStack readFluidGridStack(PacketBuffer buf) {
|
public static FluidGridStack readFluidGridStack(PacketBuffer buf) {
|
||||||
FluidStack stack = FluidStack.readFromPacket(buf);
|
FluidStack stack = FluidStack.readFromPacket(buf);
|
||||||
int hash = buf.readInt();
|
UUID id = buf.readUniqueId();
|
||||||
boolean craftable = buf.readBoolean();
|
boolean craftable = buf.readBoolean();
|
||||||
boolean displayCraftText = buf.readBoolean();
|
boolean displayCraftText = buf.readBoolean();
|
||||||
|
|
||||||
@@ -147,7 +148,7 @@ public final class StackUtils {
|
|||||||
entry = new StorageTrackerEntry(buf.readLong(), buf.readString());
|
entry = new StorageTrackerEntry(buf.readLong(), buf.readString());
|
||||||
}
|
}
|
||||||
|
|
||||||
return new FluidGridStack(hash, stack, entry, craftable, displayCraftText);
|
return new FluidGridStack(id, stack, entry, craftable, displayCraftText);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack nullToEmpty(@Nullable ItemStack stack) {
|
public static ItemStack nullToEmpty(@Nullable ItemStack stack) {
|
||||||
|
|||||||
Reference in New Issue
Block a user