Make INetwork insertItem/extractItem return a NonNull ItemStack
This commit is contained in:
@@ -121,7 +121,7 @@ public interface ICraftingManager {
|
|||||||
*
|
*
|
||||||
* @param stack the stack
|
* @param stack the stack
|
||||||
*/
|
*/
|
||||||
int track(ItemStack stack, int size);
|
int track(@Nonnull ItemStack stack, int size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tracks an incoming stack.
|
* Tracks an incoming stack.
|
||||||
|
|||||||
@@ -87,27 +87,27 @@ public interface INetwork {
|
|||||||
/**
|
/**
|
||||||
* Inserts an item in this network.
|
* Inserts an item in this network.
|
||||||
*
|
*
|
||||||
* @param stack the stack prototype to insert, do NOT modify
|
* @param stack the stack prototype to insert, can be empty, do NOT modify
|
||||||
* @param size the amount of that prototype that has to be inserted
|
* @param size the amount of that prototype that has to be inserted
|
||||||
* @param action the action
|
* @param action the action
|
||||||
* @return null if the insert was successful, or a stack with the remainder
|
* @return an empty stack if the insert was successful, or a stack with the remainder
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nonnull
|
||||||
ItemStack insertItem(@Nonnull ItemStack stack, int size, Action action);
|
ItemStack insertItem(@Nonnull ItemStack stack, int size, Action action);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts an item and notifies the crafting manager of the incoming item.
|
* Inserts an item and notifies the crafting manager of the incoming item.
|
||||||
*
|
*
|
||||||
* @param stack the stack prototype to insert, do NOT modify
|
* @param stack the stack prototype to insert, can be empty, do NOT modify
|
||||||
* @param size the amount of that prototype that has to be inserted
|
* @param size the amount of that prototype that has to be inserted
|
||||||
* @return null if the insert was successful, or a stack with the remainder
|
* @return an empty stack if the insert was successful, or a stack with the remainder
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nonnull
|
||||||
default ItemStack insertItemTracked(@Nonnull ItemStack stack, int size) {
|
default ItemStack insertItemTracked(@Nonnull ItemStack stack, int size) {
|
||||||
int remainder = getCraftingManager().track(stack, size);
|
int remainder = getCraftingManager().track(stack, size);
|
||||||
|
|
||||||
if (remainder == 0) {
|
if (remainder == 0) {
|
||||||
return null;
|
return ItemStack.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
return insertItem(stack, remainder, Action.PERFORM);
|
return insertItem(stack, remainder, Action.PERFORM);
|
||||||
@@ -121,9 +121,9 @@ public interface INetwork {
|
|||||||
* @param flags the flags to compare on, see {@link IComparer}
|
* @param flags the flags to compare on, see {@link IComparer}
|
||||||
* @param action the action
|
* @param action the action
|
||||||
* @param filter a filter for the storage
|
* @param filter a filter for the storage
|
||||||
* @return null if we didn't extract anything, or a stack with the result
|
* @return an empty stack if nothing was extracted, or a stack with the result
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nonnull
|
||||||
ItemStack extractItem(@Nonnull ItemStack stack, int size, int flags, Action action, Predicate<IStorage<ItemStack>> filter);
|
ItemStack extractItem(@Nonnull ItemStack stack, int size, int flags, Action action, Predicate<IStorage<ItemStack>> filter);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -133,9 +133,9 @@ public interface INetwork {
|
|||||||
* @param size the amount of that prototype that has to be extracted
|
* @param size the amount of that prototype that has to be extracted
|
||||||
* @param flags the flags to compare on, see {@link IComparer}
|
* @param flags the flags to compare on, see {@link IComparer}
|
||||||
* @param action the action
|
* @param action the action
|
||||||
* @return null if we didn't extract anything, or a stack with the result
|
* @return an empty stack if nothing was extracted, or a stack with the result
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nonnull
|
||||||
default ItemStack extractItem(@Nonnull ItemStack stack, int size, int flags, Action action) {
|
default ItemStack extractItem(@Nonnull ItemStack stack, int size, int flags, Action action) {
|
||||||
return extractItem(stack, size, flags, action, s -> true);
|
return extractItem(stack, size, flags, action, s -> true);
|
||||||
}
|
}
|
||||||
@@ -146,9 +146,9 @@ public interface INetwork {
|
|||||||
* @param stack the prototype of the stack to extract, do NOT modify
|
* @param stack the prototype of the stack to extract, do NOT modify
|
||||||
* @param size the amount of that prototype that has to be extracted
|
* @param size the amount of that prototype that has to be extracted
|
||||||
* @param action the action
|
* @param action the action
|
||||||
* @return null if we didn't extract anything, or a stack with the result
|
* @return an empty stack if nothing was extracted, or a stack with the result
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nonnull
|
||||||
default ItemStack extractItem(@Nonnull ItemStack stack, int size, Action action) {
|
default ItemStack extractItem(@Nonnull ItemStack stack, int size, Action action) {
|
||||||
return extractItem(stack, size, IComparer.COMPARE_NBT, action);
|
return extractItem(stack, size, IComparer.COMPARE_NBT, action);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.raoulvdberge.refinedstorage.api.network.grid;
|
package com.raoulvdberge.refinedstorage.api.network.grid;
|
||||||
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.crafting.ICraftingRecipe;
|
import net.minecraft.item.crafting.ICraftingRecipe;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -8,7 +9,7 @@ import net.minecraft.item.crafting.ICraftingRecipe;
|
|||||||
*/
|
*/
|
||||||
public interface ICraftingGridBehavior {
|
public interface ICraftingGridBehavior {
|
||||||
/**
|
/**
|
||||||
* Default logic for regular crafting.
|
* Logic for regular crafting.
|
||||||
*
|
*
|
||||||
* @param grid the grid
|
* @param grid the grid
|
||||||
* @param recipe the recipe
|
* @param recipe the recipe
|
||||||
@@ -17,10 +18,19 @@ public interface ICraftingGridBehavior {
|
|||||||
void onCrafted(IGridNetworkAware grid, ICraftingRecipe recipe, PlayerEntity player);
|
void onCrafted(IGridNetworkAware grid, ICraftingRecipe recipe, PlayerEntity player);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default logic for crafting with shift click (mass crafting).
|
* Logic for crafting with shift click (mass crafting).
|
||||||
*
|
*
|
||||||
* @param grid the grid
|
* @param grid the grid
|
||||||
* @param player the layer
|
* @param player the player
|
||||||
*/
|
*/
|
||||||
void onCraftedShift(IGridNetworkAware grid, PlayerEntity player);
|
void onCraftedShift(IGridNetworkAware grid, PlayerEntity player);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logic for when a recipe is transferred to the grid.
|
||||||
|
*
|
||||||
|
* @param grid the grid
|
||||||
|
* @param player the player
|
||||||
|
* @param recipe the recipe
|
||||||
|
*/
|
||||||
|
void onRecipeTransfer(IGridNetworkAware grid, PlayerEntity player, ItemStack[][] recipe);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.raoulvdberge.refinedstorage.api.network.grid.handler;
|
|||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,9 +24,9 @@ public interface IFluidGridHandler {
|
|||||||
*
|
*
|
||||||
* @param player the player
|
* @param player the player
|
||||||
* @param container a stack with a fluid container we're trying to insert
|
* @param container a stack with a fluid container we're trying to insert
|
||||||
* @return the remainder, or null if there is no remainder
|
* @return the remainder, or an empty stack if there is no remainder
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nonnull
|
||||||
ItemStack onInsert(ServerPlayerEntity player, ItemStack container);
|
ItemStack onInsert(ServerPlayerEntity player, ItemStack container);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,6 +43,7 @@ public interface IFluidGridHandler {
|
|||||||
* @param container the container
|
* @param container the container
|
||||||
* @return the remainder container
|
* @return the remainder container
|
||||||
*/
|
*/
|
||||||
|
@Nonnull
|
||||||
ItemStack onShiftClick(ServerPlayerEntity player, ItemStack container);
|
ItemStack onShiftClick(ServerPlayerEntity player, ItemStack container);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public interface IItemGridHandler {
|
|||||||
*
|
*
|
||||||
* @param player the player that is attempting the insert
|
* @param player the player that is attempting the insert
|
||||||
* @param stack the item we're trying to insert
|
* @param stack the item we're trying to insert
|
||||||
* @return the remainder, or null if there is no remainder
|
* @return the remainder, or an empty stack if there is no remainder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
ItemStack onInsert(ServerPlayerEntity player, ItemStack stack);
|
ItemStack onInsert(ServerPlayerEntity player, ItemStack stack);
|
||||||
@@ -47,7 +47,7 @@ public interface IItemGridHandler {
|
|||||||
*
|
*
|
||||||
* @param player the player
|
* @param player the player
|
||||||
* @param stack the stack
|
* @param stack the stack
|
||||||
* @return the remainder stack
|
* @return the remainder, or an empty stack if there is no remainder
|
||||||
*/
|
*/
|
||||||
// TODO Maybe remove?
|
// TODO Maybe remove?
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
|||||||
@@ -316,7 +316,11 @@ public class CraftingManager implements ICraftingManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int track(ItemStack stack, int size) {
|
public int track(@Nonnull ItemStack stack, int size) {
|
||||||
|
if (stack.isEmpty()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
for (ICraftingTask task : tasks.values()) {
|
for (ICraftingTask task : tasks.values()) {
|
||||||
size = task.onTrackedInsert(stack, size);
|
size = task.onTrackedInsert(stack, size);
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public class CraftingPattern implements ICraftingPattern {
|
|||||||
for (int i = 0; i < 9; ++i) {
|
for (int i = 0; i < 9; ++i) {
|
||||||
ItemStack input = PatternItem.getInputSlot(stack, i);
|
ItemStack input = PatternItem.getInputSlot(stack, i);
|
||||||
|
|
||||||
if (input == null) {
|
if (input.isEmpty()) {
|
||||||
inputs.add(NonNullList.create());
|
inputs.add(NonNullList.create());
|
||||||
} else if (oredict) {
|
} else if (oredict) {
|
||||||
NonNullList<ItemStack> ores = NonNullList.create();
|
NonNullList<ItemStack> ores = NonNullList.create();
|
||||||
@@ -75,7 +75,7 @@ public class CraftingPattern implements ICraftingPattern {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ItemStack output = PatternItem.getOutputSlot(stack, i);
|
ItemStack output = PatternItem.getOutputSlot(stack, i);
|
||||||
if (output != null) {
|
if (!output.isEmpty()) {
|
||||||
this.valid = true; // As soon as we have one output, we are valid.
|
this.valid = true; // As soon as we have one output, we are valid.
|
||||||
|
|
||||||
outputs.add(output);
|
outputs.add(output);
|
||||||
@@ -101,12 +101,10 @@ public class CraftingPattern implements ICraftingPattern {
|
|||||||
for (int i = 0; i < 9; ++i) {
|
for (int i = 0; i < 9; ++i) {
|
||||||
ItemStack input = PatternItem.getInputSlot(stack, i);
|
ItemStack input = PatternItem.getInputSlot(stack, i);
|
||||||
|
|
||||||
inputs.add(input == null ? NonNullList.create() : NonNullList.from(ItemStack.EMPTY, input));
|
inputs.add(input.isEmpty() ? NonNullList.create() : NonNullList.from(ItemStack.EMPTY, input));
|
||||||
|
|
||||||
if (input != null) {
|
|
||||||
inv.setInventorySlotContents(i, input);
|
inv.setInventorySlotContents(i, input);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Optional<ICraftingRecipe> potentialRecipe = world.getRecipeManager().getRecipe(IRecipeType.CRAFTING, inv, world);
|
Optional<ICraftingRecipe> potentialRecipe = world.getRecipeManager().getRecipe(IRecipeType.CRAFTING, inv, world);
|
||||||
if (potentialRecipe.isPresent()) {
|
if (potentialRecipe.isPresent()) {
|
||||||
|
|||||||
@@ -546,7 +546,7 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
for (StackListEntry<ItemStack> toExtract : toExtractInitial.getStacks()) {
|
for (StackListEntry<ItemStack> toExtract : toExtractInitial.getStacks()) {
|
||||||
ItemStack result = network.extractItem(toExtract.getStack(), toExtract.getStack().getCount(), Action.PERFORM);
|
ItemStack result = network.extractItem(toExtract.getStack(), toExtract.getStack().getCount(), Action.PERFORM);
|
||||||
|
|
||||||
if (result != null) {
|
if (!result.isEmpty()) {
|
||||||
internalStorage.insert(toExtract.getStack(), result.getCount(), Action.PERFORM);
|
internalStorage.insert(toExtract.getStack(), result.getCount(), Action.PERFORM);
|
||||||
|
|
||||||
toRemove.add(result);
|
toRemove.add(result);
|
||||||
@@ -634,10 +634,8 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
} else {
|
} else {
|
||||||
ItemStack remainder = this.network.insertItem(output, output.getCount(), Action.PERFORM);
|
ItemStack remainder = this.network.insertItem(output, output.getCount(), Action.PERFORM);
|
||||||
|
|
||||||
if (remainder != null) {
|
|
||||||
this.internalStorage.insert(remainder, remainder.getCount(), Action.PERFORM);
|
this.internalStorage.insert(remainder, remainder.getCount(), Action.PERFORM);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Byproducts need to always be inserted in the internal storage for later reuse further in the task.
|
// Byproducts need to always be inserted in the internal storage for later reuse further in the task.
|
||||||
// Regular outputs can be inserted into the network *IF* it's a root since it's *NOT* expected to be used later on.
|
// Regular outputs can be inserted into the network *IF* it's a root since it's *NOT* expected to be used later on.
|
||||||
@@ -852,13 +850,7 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
for (ItemStack stack : internalStorage.getStacks()) {
|
for (ItemStack stack : internalStorage.getStacks()) {
|
||||||
ItemStack remainder = network.insertItem(stack, stack.getCount(), Action.PERFORM);
|
ItemStack remainder = network.insertItem(stack, stack.getCount(), Action.PERFORM);
|
||||||
|
|
||||||
toPerform.add(() -> {
|
toPerform.add(() -> internalStorage.extract(stack, stack.getCount() - remainder.getCount(), IComparer.COMPARE_NBT, Action.PERFORM));
|
||||||
if (remainder == null) {
|
|
||||||
internalStorage.extract(stack, stack.getCount(), IComparer.COMPARE_NBT, Action.PERFORM);
|
|
||||||
} else {
|
|
||||||
internalStorage.extract(stack, stack.getCount() - remainder.getCount(), IComparer.COMPARE_NBT, Action.PERFORM);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (FluidStack stack : internalFluidStorage.getStacks()) {
|
for (FluidStack stack : internalFluidStorage.getStacks()) {
|
||||||
@@ -960,9 +952,7 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
} else {
|
} else {
|
||||||
ItemStack remainder = network.insertItem(stack, needed, Action.PERFORM);
|
ItemStack remainder = network.insertItem(stack, needed, Action.PERFORM);
|
||||||
|
|
||||||
if (remainder != null) {
|
internalStorage.insert(remainder, remainder.getCount(), Action.PERFORM);
|
||||||
internalStorage.insert(stack, needed, Action.PERFORM);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
package com.raoulvdberge.refinedstorage.apiimpl.network.grid;
|
package com.raoulvdberge.refinedstorage.apiimpl.network.grid;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.network.grid.GridType;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.grid.ICraftingGridBehavior;
|
import com.raoulvdberge.refinedstorage.api.network.grid.ICraftingGridBehavior;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGridNetworkAware;
|
import com.raoulvdberge.refinedstorage.api.network.grid.IGridNetworkAware;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.network.security.Permission;
|
||||||
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.apiimpl.API;
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.inventory.CraftingInventory;
|
import net.minecraft.inventory.CraftingInventory;
|
||||||
import net.minecraft.inventory.InventoryHelper;
|
import net.minecraft.inventory.InventoryHelper;
|
||||||
@@ -38,7 +40,7 @@ public class CraftingGridBehavior implements ICraftingGridBehavior {
|
|||||||
ItemStack remainderStack = network == null ? remainder.get(i).copy() : network.insertItem(remainder.get(i).copy(), remainder.get(i).getCount(), Action.PERFORM);
|
ItemStack remainderStack = network == null ? remainder.get(i).copy() : network.insertItem(remainder.get(i).copy(), remainder.get(i).getCount(), Action.PERFORM);
|
||||||
|
|
||||||
// If there is no space in the network, just dump it in the world.
|
// If there is no space in the network, just dump it in the world.
|
||||||
if (remainderStack != null) {
|
if (!remainderStack.isEmpty()) {
|
||||||
InventoryHelper.spawnItemStack(player.getEntityWorld(), player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), remainderStack);
|
InventoryHelper.spawnItemStack(player.getEntityWorld(), player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), remainderStack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,7 +51,7 @@ public class CraftingGridBehavior implements ICraftingGridBehavior {
|
|||||||
}
|
}
|
||||||
} else if (!slot.isEmpty()) { // We don't have a remainder, but the slot is not empty.
|
} else if (!slot.isEmpty()) { // We don't have a remainder, but the slot is not empty.
|
||||||
if (slot.getCount() == 1 && network != null) { // Attempt to refill the slot with the same item from the network, only if we have a network and only if it's the last item.
|
if (slot.getCount() == 1 && network != null) { // Attempt to refill the slot with the same item from the network, only if we have a network and only if it's the last item.
|
||||||
ItemStack refill = StackUtils.nullToEmpty(network.extractItem(slot, 1, Action.PERFORM));
|
ItemStack refill = network.extractItem(slot, 1, Action.PERFORM);
|
||||||
|
|
||||||
matrix.setInventorySlotContents(i, refill);
|
matrix.setInventorySlotContents(i, refill);
|
||||||
|
|
||||||
@@ -86,7 +88,7 @@ public class CraftingGridBehavior implements ICraftingGridBehavior {
|
|||||||
if (!player.inventory.addItemStackToInventory(craftedItem.copy())) {
|
if (!player.inventory.addItemStackToInventory(craftedItem.copy())) {
|
||||||
ItemStack remainder = network == null ? craftedItem : network.insertItem(craftedItem, craftedItem.getCount(), Action.PERFORM);
|
ItemStack remainder = network == null ? craftedItem : network.insertItem(craftedItem, craftedItem.getCount(), Action.PERFORM);
|
||||||
|
|
||||||
if (remainder != null) {
|
if (!remainder.isEmpty()) {
|
||||||
InventoryHelper.spawnItemStack(player.getEntityWorld(), player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), remainder);
|
InventoryHelper.spawnItemStack(player.getEntityWorld(), player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), remainder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,4 +100,94 @@ public class CraftingGridBehavior implements ICraftingGridBehavior {
|
|||||||
crafted.onCrafting(player.world, player, amountCrafted);
|
crafted.onCrafting(player.world, player, amountCrafted);
|
||||||
BasicEventHooks.firePlayerCraftingEvent(player, ItemHandlerHelper.copyStackWithSize(crafted, amountCrafted), grid.getCraftingMatrix());
|
BasicEventHooks.firePlayerCraftingEvent(player, ItemHandlerHelper.copyStackWithSize(crafted, amountCrafted), grid.getCraftingMatrix());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRecipeTransfer(IGridNetworkAware grid, PlayerEntity player, ItemStack[][] recipe) {
|
||||||
|
INetwork network = grid.getNetwork();
|
||||||
|
|
||||||
|
if (network != null && grid.getGridType() == GridType.CRAFTING && !network.getSecurityManager().hasPermission(Permission.EXTRACT, player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// First try to empty the crafting matrix
|
||||||
|
for (int i = 0; i < grid.getCraftingMatrix().getSizeInventory(); ++i) {
|
||||||
|
ItemStack slot = grid.getCraftingMatrix().getStackInSlot(i);
|
||||||
|
|
||||||
|
if (!slot.isEmpty()) {
|
||||||
|
// Only if we are a crafting grid. Pattern grids can just be emptied.
|
||||||
|
if (grid.getGridType() == GridType.CRAFTING) {
|
||||||
|
// If we are connected, try to insert into network. If it fails, stop.
|
||||||
|
if (network != null) {
|
||||||
|
if (!network.insertItem(slot, slot.getCount(), Action.SIMULATE).isEmpty()) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
network.insertItem(slot, slot.getCount(), Action.PERFORM);
|
||||||
|
|
||||||
|
network.getItemStorageTracker().changed(player, slot.copy());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// If we aren't connected, try to insert into player inventory. If it fails, stop.
|
||||||
|
if (!player.inventory.addItemStackToInventory(slot.copy())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
grid.getCraftingMatrix().setInventorySlotContents(i, ItemStack.EMPTY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now let's fill the matrix
|
||||||
|
for (int i = 0; i < grid.getCraftingMatrix().getSizeInventory(); ++i) {
|
||||||
|
if (recipe[i] != null) {
|
||||||
|
ItemStack[] possibilities = recipe[i];
|
||||||
|
|
||||||
|
// If we are a crafting grid
|
||||||
|
if (grid.getGridType() == GridType.CRAFTING) {
|
||||||
|
boolean found = false;
|
||||||
|
|
||||||
|
// If we are connected, first try to get the possibilities from the network
|
||||||
|
if (network != null) {
|
||||||
|
for (ItemStack possibility : possibilities) {
|
||||||
|
ItemStack took = network.extractItem(possibility, 1, IComparer.COMPARE_NBT, Action.PERFORM);
|
||||||
|
|
||||||
|
if (!took.isEmpty()) {
|
||||||
|
grid.getCraftingMatrix().setInventorySlotContents(i, took);
|
||||||
|
|
||||||
|
network.getItemStorageTracker().changed(player, took.copy());
|
||||||
|
|
||||||
|
found = true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we haven't found anything in the network (or we are disconnected), go look in the player inventory
|
||||||
|
if (!found) {
|
||||||
|
for (ItemStack possibility : possibilities) {
|
||||||
|
for (int j = 0; j < player.inventory.getSizeInventory(); ++j) {
|
||||||
|
if (API.instance().getComparer().isEqual(possibility, player.inventory.getStackInSlot(j), IComparer.COMPARE_NBT)) {
|
||||||
|
grid.getCraftingMatrix().setInventorySlotContents(i, ItemHandlerHelper.copyStackWithSize(player.inventory.getStackInSlot(j), 1));
|
||||||
|
|
||||||
|
player.inventory.decrStackSize(j, 1);
|
||||||
|
|
||||||
|
found = true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (grid.getGridType() == GridType.PATTERN) {
|
||||||
|
// If we are a pattern grid we can just set the slot
|
||||||
|
grid.getCraftingMatrix().setInventorySlotContents(i, possibilities.length == 0 ? ItemStack.EMPTY : possibilities[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
|||||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
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.Nonnull;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class FluidGridHandler implements IFluidGridHandler {
|
public class FluidGridHandler implements IFluidGridHandler {
|
||||||
@@ -52,7 +52,7 @@ public class FluidGridHandler implements IFluidGridHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (bucket.isEmpty()) {
|
if (bucket.isEmpty()) {
|
||||||
bucket = StackUtils.nullToEmpty(network.extractItem(StackUtils.EMPTY_BUCKET, 1, Action.PERFORM));
|
bucket = network.extractItem(StackUtils.EMPTY_BUCKET, 1, Action.PERFORM);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bucket.isEmpty()) {
|
if (!bucket.isEmpty()) {
|
||||||
@@ -79,8 +79,8 @@ public class FluidGridHandler implements IFluidGridHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nonnull
|
||||||
public ItemStack onInsert(ServerPlayerEntity player, ItemStack container) {
|
public ItemStack onInsert(ServerPlayerEntity player, ItemStack container) {
|
||||||
if (!network.getSecurityManager().hasPermission(Permission.INSERT, player)) {
|
if (!network.getSecurityManager().hasPermission(Permission.INSERT, player)) {
|
||||||
return container;
|
return container;
|
||||||
@@ -105,13 +105,14 @@ public class FluidGridHandler implements IFluidGridHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInsertHeldContainer(ServerPlayerEntity player) {
|
public void onInsertHeldContainer(ServerPlayerEntity player) {
|
||||||
player.inventory.setItemStack(StackUtils.nullToEmpty(onInsert(player, player.inventory.getItemStack())));
|
player.inventory.setItemStack(onInsert(player, player.inventory.getItemStack()));
|
||||||
player.updateHeldItem();
|
player.updateHeldItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nonnull
|
||||||
public ItemStack onShiftClick(ServerPlayerEntity player, ItemStack container) {
|
public ItemStack onShiftClick(ServerPlayerEntity player, ItemStack container) {
|
||||||
return StackUtils.nullToEmpty(onInsert(player, container));
|
return onInsert(player, container);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import com.raoulvdberge.refinedstorage.api.network.security.Permission;
|
|||||||
import com.raoulvdberge.refinedstorage.api.util.Action;
|
import com.raoulvdberge.refinedstorage.api.util.Action;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.Direction;
|
||||||
@@ -78,21 +77,19 @@ public class ItemGridHandler implements IItemGridHandler {
|
|||||||
|
|
||||||
ItemStack took = network.extractItem(item, size, Action.SIMULATE);
|
ItemStack took = network.extractItem(item, size, Action.SIMULATE);
|
||||||
|
|
||||||
if (took != null) {
|
if (!took.isEmpty()) {
|
||||||
if ((flags & EXTRACT_SHIFT) == EXTRACT_SHIFT) {
|
if ((flags & EXTRACT_SHIFT) == EXTRACT_SHIFT) {
|
||||||
IItemHandler playerInventory = player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.UP).orElse(null);
|
IItemHandler playerInventory = player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.UP).orElse(null);
|
||||||
|
|
||||||
if (playerInventory != null && ItemHandlerHelper.insertItem(playerInventory, took, true).isEmpty()) {
|
if (playerInventory != null && ItemHandlerHelper.insertItem(playerInventory, took, true).isEmpty()) {
|
||||||
took = network.extractItem(item, size, Action.PERFORM);
|
took = network.extractItem(item, size, Action.PERFORM);
|
||||||
|
|
||||||
if (took != null) {
|
|
||||||
ItemHandlerHelper.insertItem(playerInventory, took, false);
|
ItemHandlerHelper.insertItem(playerInventory, took, false);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
took = network.extractItem(item, size, Action.PERFORM);
|
took = network.extractItem(item, size, Action.PERFORM);
|
||||||
|
|
||||||
if (took != null) {
|
if (!took.isEmpty()) {
|
||||||
if (single && !held.isEmpty()) {
|
if (single && !held.isEmpty()) {
|
||||||
held.grow(1);
|
held.grow(1);
|
||||||
} else {
|
} else {
|
||||||
@@ -116,7 +113,7 @@ public class ItemGridHandler implements IItemGridHandler {
|
|||||||
|
|
||||||
network.getItemStorageTracker().changed(player, stack.copy());
|
network.getItemStorageTracker().changed(player, stack.copy());
|
||||||
|
|
||||||
ItemStack remainder = StackUtils.nullToEmpty(network.insertItem(stack, stack.getCount(), Action.PERFORM));
|
ItemStack remainder = network.insertItem(stack, stack.getCount(), Action.PERFORM);
|
||||||
|
|
||||||
// TODO network.getNetworkItemHandler().drainEnergy(player, RS.INSTANCE.config.wirelessGridInsertUsage);
|
// TODO network.getNetworkItemHandler().drainEnergy(player, RS.INSTANCE.config.wirelessGridInsertUsage);
|
||||||
|
|
||||||
@@ -135,17 +132,18 @@ public class ItemGridHandler implements IItemGridHandler {
|
|||||||
network.getItemStorageTracker().changed(player, stack.copy());
|
network.getItemStorageTracker().changed(player, stack.copy());
|
||||||
|
|
||||||
if (single) {
|
if (single) {
|
||||||
if (network.insertItem(stack, size, Action.SIMULATE) == null) {
|
if (network.insertItem(stack, size, Action.SIMULATE).isEmpty()) {
|
||||||
network.insertItem(stack, size, Action.PERFORM);
|
network.insertItem(stack, size, Action.PERFORM);
|
||||||
|
|
||||||
stack.shrink(size);
|
stack.shrink(size);
|
||||||
|
|
||||||
if (stack.getCount() == 0) {
|
// TODO Is this still needed?
|
||||||
|
if (stack.isEmpty()) {
|
||||||
player.inventory.setItemStack(ItemStack.EMPTY);
|
player.inventory.setItemStack(ItemStack.EMPTY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
player.inventory.setItemStack(StackUtils.nullToEmpty(network.insertItem(stack, size, Action.PERFORM)));
|
player.inventory.setItemStack(network.insertItem(stack, size, Action.PERFORM));
|
||||||
}
|
}
|
||||||
|
|
||||||
player.updateHeldItem();
|
player.updateHeldItem();
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
|||||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
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.Nonnull;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class PortableFluidGridHandler implements IFluidGridHandler {
|
public class PortableFluidGridHandler implements IFluidGridHandler {
|
||||||
@@ -68,8 +68,8 @@ public class PortableFluidGridHandler implements IFluidGridHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nonnull
|
||||||
public ItemStack onInsert(ServerPlayerEntity player, ItemStack container) {
|
public ItemStack onInsert(ServerPlayerEntity player, ItemStack container) {
|
||||||
Pair<ItemStack, FluidStack> result = StackUtils.getFluid(container, true);
|
Pair<ItemStack, FluidStack> result = StackUtils.getFluid(container, true);
|
||||||
|
|
||||||
@@ -90,13 +90,14 @@ public class PortableFluidGridHandler implements IFluidGridHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInsertHeldContainer(ServerPlayerEntity player) {
|
public void onInsertHeldContainer(ServerPlayerEntity player) {
|
||||||
player.inventory.setItemStack(StackUtils.nullToEmpty(onInsert(player, player.inventory.getItemStack())));
|
player.inventory.setItemStack(onInsert(player, player.inventory.getItemStack()));
|
||||||
player.updateHeldItem();
|
player.updateHeldItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nonnull
|
||||||
public ItemStack onShiftClick(ServerPlayerEntity player, ItemStack container) {
|
public ItemStack onShiftClick(ServerPlayerEntity player, ItemStack container) {
|
||||||
return StackUtils.nullToEmpty(onInsert(player, container));
|
return onInsert(player, container);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ public class PortableItemGridHandler implements IItemGridHandler {
|
|||||||
stack.shrink(size);
|
stack.shrink(size);
|
||||||
|
|
||||||
// TODO ???
|
// TODO ???
|
||||||
if (stack.getCount() == 0) {
|
if (stack.isEmpty()) {
|
||||||
player.inventory.setItemStack(ItemStack.EMPTY);
|
player.inventory.setItemStack(ItemStack.EMPTY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package com.raoulvdberge.refinedstorage.apiimpl.network.node;
|
|||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.RS;
|
import com.raoulvdberge.refinedstorage.RS;
|
||||||
import com.raoulvdberge.refinedstorage.RSItems;
|
import com.raoulvdberge.refinedstorage.RSItems;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
|
||||||
import com.raoulvdberge.refinedstorage.api.network.grid.*;
|
import com.raoulvdberge.refinedstorage.api.network.grid.*;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IFluidGridHandler;
|
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IFluidGridHandler;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IItemGridHandler;
|
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IItemGridHandler;
|
||||||
@@ -10,7 +9,6 @@ import com.raoulvdberge.refinedstorage.api.network.security.Permission;
|
|||||||
import com.raoulvdberge.refinedstorage.api.storage.cache.IStorageCache;
|
import com.raoulvdberge.refinedstorage.api.storage.cache.IStorageCache;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.cache.IStorageCacheListener;
|
import com.raoulvdberge.refinedstorage.api.storage.cache.IStorageCacheListener;
|
||||||
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.IFilter;
|
import com.raoulvdberge.refinedstorage.api.util.IFilter;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.cache.listener.FluidGridStorageCacheListener;
|
import com.raoulvdberge.refinedstorage.apiimpl.storage.cache.listener.FluidGridStorageCacheListener;
|
||||||
@@ -47,7 +45,6 @@ import net.minecraftforge.fluids.FluidAttributes;
|
|||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||||
import net.minecraftforge.items.ItemHandlerHelper;
|
|
||||||
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
|
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
|
||||||
import net.minecraftforge.items.wrapper.InvWrapper;
|
import net.minecraftforge.items.wrapper.InvWrapper;
|
||||||
|
|
||||||
@@ -110,17 +107,17 @@ public class GridNetworkNode extends NetworkNode implements IGridNetworkAware, I
|
|||||||
|
|
||||||
if (isPatternProcessing && isProcessingPattern()) {
|
if (isPatternProcessing && isProcessingPattern()) {
|
||||||
for (int i = 0; i < 9; ++i) {
|
for (int i = 0; i < 9; ++i) {
|
||||||
processingMatrix.setStackInSlot(i, StackUtils.nullToEmpty(PatternItem.getInputSlot(pattern, i)));
|
processingMatrix.setStackInSlot(i, PatternItem.getInputSlot(pattern, i));
|
||||||
processingMatrixFluids.setFluid(i, PatternItem.getFluidInputSlot(pattern, i));
|
processingMatrixFluids.setFluid(i, PatternItem.getFluidInputSlot(pattern, i));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 9; ++i) {
|
for (int i = 0; i < 9; ++i) {
|
||||||
processingMatrix.setStackInSlot(9 + i, StackUtils.nullToEmpty(PatternItem.getOutputSlot(pattern, i)));
|
processingMatrix.setStackInSlot(9 + i, PatternItem.getOutputSlot(pattern, i));
|
||||||
processingMatrixFluids.setFluid(9 + i, PatternItem.getFluidOutputSlot(pattern, i));
|
processingMatrixFluids.setFluid(9 + i, PatternItem.getFluidOutputSlot(pattern, i));
|
||||||
}
|
}
|
||||||
} else if (!isPatternProcessing && !isProcessingPattern()) {
|
} else if (!isPatternProcessing && !isProcessingPattern()) {
|
||||||
for (int i = 0; i < 9; ++i) {
|
for (int i = 0; i < 9; ++i) {
|
||||||
matrix.setInventorySlotContents(i, StackUtils.nullToEmpty(PatternItem.getInputSlot(pattern, i)));
|
matrix.setInventorySlotContents(i, PatternItem.getInputSlot(pattern, i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -341,96 +338,7 @@ public class GridNetworkNode extends NetworkNode implements IGridNetworkAware, I
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRecipeTransfer(PlayerEntity player, ItemStack[][] recipe) {
|
public void onRecipeTransfer(PlayerEntity player, ItemStack[][] recipe) {
|
||||||
onRecipeTransfer(this, player, recipe);
|
API.instance().getCraftingGridBehavior().onRecipeTransfer(this, player, recipe);
|
||||||
}
|
|
||||||
|
|
||||||
public static void onRecipeTransfer(IGridNetworkAware grid, PlayerEntity player, ItemStack[][] recipe) {
|
|
||||||
INetwork network = grid.getNetwork();
|
|
||||||
|
|
||||||
if (network != null && grid.getGridType() == GridType.CRAFTING && !network.getSecurityManager().hasPermission(Permission.EXTRACT, player)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// First try to empty the crafting matrix
|
|
||||||
for (int i = 0; i < grid.getCraftingMatrix().getSizeInventory(); ++i) {
|
|
||||||
ItemStack slot = grid.getCraftingMatrix().getStackInSlot(i);
|
|
||||||
|
|
||||||
if (!slot.isEmpty()) {
|
|
||||||
// Only if we are a crafting grid. Pattern grids can just be emptied.
|
|
||||||
if (grid.getGridType() == GridType.CRAFTING) {
|
|
||||||
// If we are connected, try to insert into network. If it fails, stop.
|
|
||||||
if (network != null) {
|
|
||||||
if (network.insertItem(slot, slot.getCount(), Action.SIMULATE) != null) {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
network.insertItem(slot, slot.getCount(), Action.PERFORM);
|
|
||||||
|
|
||||||
network.getItemStorageTracker().changed(player, slot.copy());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// If we aren't connected, try to insert into player inventory. If it fails, stop.
|
|
||||||
if (!player.inventory.addItemStackToInventory(slot.copy())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
grid.getCraftingMatrix().setInventorySlotContents(i, ItemStack.EMPTY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now let's fill the matrix
|
|
||||||
for (int i = 0; i < grid.getCraftingMatrix().getSizeInventory(); ++i) {
|
|
||||||
if (recipe[i] != null) {
|
|
||||||
ItemStack[] possibilities = recipe[i];
|
|
||||||
|
|
||||||
// If we are a crafting grid
|
|
||||||
if (grid.getGridType() == GridType.CRAFTING) {
|
|
||||||
boolean found = false;
|
|
||||||
|
|
||||||
// If we are connected, first try to get the possibilities from the network
|
|
||||||
if (network != null) {
|
|
||||||
for (ItemStack possibility : possibilities) {
|
|
||||||
ItemStack took = network.extractItem(possibility, 1, IComparer.COMPARE_NBT, Action.PERFORM);
|
|
||||||
|
|
||||||
if (took != null) {
|
|
||||||
grid.getCraftingMatrix().setInventorySlotContents(i, StackUtils.nullToEmpty(took));
|
|
||||||
|
|
||||||
network.getItemStorageTracker().changed(player, took.copy());
|
|
||||||
|
|
||||||
found = true;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we haven't found anything in the network (or we are disconnected), go look in the player inventory
|
|
||||||
if (!found) {
|
|
||||||
for (ItemStack possibility : possibilities) {
|
|
||||||
for (int j = 0; j < player.inventory.getSizeInventory(); ++j) {
|
|
||||||
if (API.instance().getComparer().isEqual(possibility, player.inventory.getStackInSlot(j), IComparer.COMPARE_NBT)) {
|
|
||||||
grid.getCraftingMatrix().setInventorySlotContents(i, ItemHandlerHelper.copyStackWithSize(player.inventory.getStackInSlot(j), 1));
|
|
||||||
|
|
||||||
player.inventory.decrStackSize(j, 1);
|
|
||||||
|
|
||||||
found = true;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (found) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (grid.getGridType() == GridType.PATTERN) {
|
|
||||||
// If we are a pattern grid we can just set the slot
|
|
||||||
grid.getCraftingMatrix().setInventorySlotContents(i, possibilities.length == 0 ? ItemStack.EMPTY : possibilities[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearMatrix() {
|
public void clearMatrix() {
|
||||||
@@ -469,7 +377,7 @@ public class GridNetworkNode extends NetworkNode implements IGridNetworkAware, I
|
|||||||
ItemStack slot = matrix.getStackInSlot(i);
|
ItemStack slot = matrix.getStackInSlot(i);
|
||||||
|
|
||||||
if (!slot.isEmpty()) {
|
if (!slot.isEmpty()) {
|
||||||
matrix.setInventorySlotContents(i, StackUtils.nullToEmpty(network.insertItem(slot, slot.getCount(), Action.PERFORM)));
|
matrix.setInventorySlotContents(i, network.insertItem(slot, slot.getCount(), Action.PERFORM));
|
||||||
|
|
||||||
network.getItemStorageTracker().changed(player, slot.copy());
|
network.getItemStorageTracker().changed(player, slot.copy());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ public class NetworkNodeConstructor extends NetworkNode implements IComparable,
|
|||||||
if (item.getItem() == Items.FIREWORK_ROCKET && !drop) {
|
if (item.getItem() == Items.FIREWORK_ROCKET && !drop) {
|
||||||
ItemStack took = network.extractItem(item, 1, Action.PERFORM);
|
ItemStack took = network.extractItem(item, 1, Action.PERFORM);
|
||||||
|
|
||||||
if (took != null) {
|
if (!took.isEmpty()) {
|
||||||
world.addEntity(new FireworkRocketEntity(world, getDispensePositionX(), getDispensePositionY(), getDispensePositionZ(), took));
|
world.addEntity(new FireworkRocketEntity(world, getDispensePositionX(), getDispensePositionY(), getDispensePositionZ(), took));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -164,7 +164,7 @@ public class NetworkNodeConstructor extends NetworkNode implements IComparable,
|
|||||||
|
|
||||||
ItemStack took = network.extractItem(item, 1, compare, Action.SIMULATE);
|
ItemStack took = network.extractItem(item, 1, compare, Action.SIMULATE);
|
||||||
|
|
||||||
if (took != null) {
|
if (!took.isEmpty()) {
|
||||||
BlockState state = FilterSlot.getBlockState(world, front, took);
|
BlockState state = FilterSlot.getBlockState(world, front, took);
|
||||||
|
|
||||||
// TODO if (state != null && world.isAirBlock(front) && state.getBlock().canPlaceBlockAt(world, front)) {
|
// TODO if (state != null && world.isAirBlock(front) && state.getBlock().canPlaceBlockAt(world, front)) {
|
||||||
@@ -177,7 +177,7 @@ public class NetworkNodeConstructor extends NetworkNode implements IComparable,
|
|||||||
|
|
||||||
took = network.extractItem(item, 1, compare, Action.PERFORM);
|
took = network.extractItem(item, 1, compare, Action.PERFORM);
|
||||||
|
|
||||||
if (took != null) {
|
if (!took.isEmpty()) {
|
||||||
if (item.getItem() instanceof BlockItem) {
|
if (item.getItem() instanceof BlockItem) {
|
||||||
/*((BlockItem) item.getItem()).tryPlace(new BlockItemUseContext(
|
/*((BlockItem) item.getItem()).tryPlace(new BlockItemUseContext(
|
||||||
took,
|
took,
|
||||||
@@ -242,7 +242,7 @@ public class NetworkNodeConstructor extends NetworkNode implements IComparable,
|
|||||||
private void dropItem() {
|
private void dropItem() {
|
||||||
ItemStack took = network.extractItem(itemFilters.getStackInSlot(0), upgrades.getItemInteractCount(), Action.PERFORM);
|
ItemStack took = network.extractItem(itemFilters.getStackInSlot(0), upgrades.getItemInteractCount(), Action.PERFORM);
|
||||||
|
|
||||||
if (took != null) {
|
if (!took.isEmpty()) {
|
||||||
DefaultDispenseItemBehavior.doDispense(world, took, 6, getDirection(), new Position(getDispensePositionX(), getDispensePositionY(), getDispensePositionZ()));
|
DefaultDispenseItemBehavior.doDispense(world, took, 6, getDirection(), new Position(getDispensePositionX(), getDispensePositionY(), getDispensePositionZ()));
|
||||||
} else if (upgrades.hasUpgrade(UpgradeItem.Type.CRAFTING)) {
|
} else if (upgrades.hasUpgrade(UpgradeItem.Type.CRAFTING)) {
|
||||||
ItemStack craft = itemFilters.getStackInSlot(0);
|
ItemStack craft = itemFilters.getStackInSlot(0);
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ public class NetworkNodeDestructor extends NetworkNode implements IComparable, I
|
|||||||
if (entity instanceof ItemEntity) {
|
if (entity instanceof ItemEntity) {
|
||||||
ItemStack droppedItem = ((ItemEntity) entity).getItem();
|
ItemStack droppedItem = ((ItemEntity) entity).getItem();
|
||||||
|
|
||||||
if (IWhitelistBlacklist.acceptsItem(itemFilters, mode, compare, droppedItem) && network.insertItem(droppedItem, droppedItem.getCount(), Action.SIMULATE) == null) {
|
if (IWhitelistBlacklist.acceptsItem(itemFilters, mode, compare, droppedItem) && network.insertItem(droppedItem, droppedItem.getCount(), Action.SIMULATE).isEmpty()) {
|
||||||
network.insertItemTracked(droppedItem.copy(), droppedItem.getCount());
|
network.insertItemTracked(droppedItem.copy(), droppedItem.getCount());
|
||||||
|
|
||||||
// TODO world.removeEntity(entity);
|
// TODO world.removeEntity(entity);
|
||||||
@@ -148,7 +148,7 @@ public class NetworkNodeDestructor extends NetworkNode implements IComparable, I
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
for (ItemStack drop : drops) {
|
for (ItemStack drop : drops) {
|
||||||
if (network.insertItem(drop, drop.getCount(), Action.SIMULATE) != null) {
|
if (!network.insertItem(drop, drop.getCount(), Action.SIMULATE).isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,18 +79,16 @@ public class NetworkNodeExporter extends NetworkNode implements IComparable, ITy
|
|||||||
|
|
||||||
ItemStack took = network.extractItem(slot, Math.min(slot.getMaxStackSize(), stackSize), compare, Action.SIMULATE);
|
ItemStack took = network.extractItem(slot, Math.min(slot.getMaxStackSize(), stackSize), compare, Action.SIMULATE);
|
||||||
|
|
||||||
if (took == null) {
|
if (took.isEmpty()) {
|
||||||
if (upgrades.hasUpgrade(UpgradeItem.Type.CRAFTING)) {
|
if (upgrades.hasUpgrade(UpgradeItem.Type.CRAFTING)) {
|
||||||
network.getCraftingManager().request(new SlottedCraftingRequest(this, filterSlot), slot, stackSize);
|
network.getCraftingManager().request(new SlottedCraftingRequest(this, filterSlot), slot, stackSize);
|
||||||
}
|
}
|
||||||
} else if (ItemHandlerHelper.insertItem(handler, took, true).isEmpty()) {
|
} else if (ItemHandlerHelper.insertItem(handler, took, true).isEmpty()) {
|
||||||
took = network.extractItem(slot, Math.min(slot.getMaxStackSize(), stackSize), compare, Action.PERFORM);
|
took = network.extractItem(slot, Math.min(slot.getMaxStackSize(), stackSize), compare, Action.PERFORM);
|
||||||
|
|
||||||
if (took != null) {
|
|
||||||
ItemHandlerHelper.insertItem(handler, took, false);
|
ItemHandlerHelper.insertItem(handler, took, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
filterSlot++;
|
filterSlot++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,12 +86,10 @@ public class NetworkNodeImporter extends NetworkNode implements IComparable, IWh
|
|||||||
} else if (ticks % upgrades.getSpeed() == 0) {
|
} else if (ticks % upgrades.getSpeed() == 0) {
|
||||||
ItemStack result = handler.extractItem(currentSlot, upgrades.getItemInteractCount(), true);
|
ItemStack result = handler.extractItem(currentSlot, upgrades.getItemInteractCount(), true);
|
||||||
|
|
||||||
if (!result.isEmpty() && network.insertItem(result, result.getCount(), Action.SIMULATE) == null) {
|
if (!result.isEmpty() && network.insertItem(result, result.getCount(), Action.SIMULATE).isEmpty()) {
|
||||||
result = handler.extractItem(currentSlot, upgrades.getItemInteractCount(), false);
|
result = handler.extractItem(currentSlot, upgrades.getItemInteractCount(), false);
|
||||||
|
|
||||||
if (!result.isEmpty()) {
|
|
||||||
network.insertItemTracked(result, result.getCount());
|
network.insertItemTracked(result, result.getCount());
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
currentSlot++;
|
currentSlot++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,14 +72,10 @@ public class NetworkNodeInterface extends NetworkNode implements IComparable {
|
|||||||
|
|
||||||
ItemStack remainder = network.insertItemTracked(slot, size);
|
ItemStack remainder = network.insertItemTracked(slot, size);
|
||||||
|
|
||||||
if (remainder == null) {
|
|
||||||
importItems.extractItem(currentSlot, size, false);
|
|
||||||
} else if (size - remainder.getCount() > 0) {
|
|
||||||
importItems.extractItem(currentSlot, size - remainder.getCount(), false);
|
importItems.extractItem(currentSlot, size - remainder.getCount(), false);
|
||||||
|
|
||||||
currentSlot++;
|
currentSlot++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < 9; ++i) {
|
for (int i = 0; i < 9; ++i) {
|
||||||
ItemStack wanted = exportFilterItems.getStackInSlot(i);
|
ItemStack wanted = exportFilterItems.getStackInSlot(i);
|
||||||
@@ -87,10 +83,10 @@ public class NetworkNodeInterface extends NetworkNode implements IComparable {
|
|||||||
|
|
||||||
if (wanted.isEmpty()) {
|
if (wanted.isEmpty()) {
|
||||||
if (!got.isEmpty()) {
|
if (!got.isEmpty()) {
|
||||||
exportItems.setStackInSlot(i, StackUtils.nullToEmpty(network.insertItemTracked(got, got.getCount())));
|
exportItems.setStackInSlot(i, network.insertItemTracked(got, got.getCount()));
|
||||||
}
|
}
|
||||||
} else if (!got.isEmpty() && !API.instance().getComparer().isEqual(wanted, got, getCompare())) {
|
} else if (!got.isEmpty() && !API.instance().getComparer().isEqual(wanted, got, getCompare())) {
|
||||||
exportItems.setStackInSlot(i, StackUtils.nullToEmpty(network.insertItemTracked(got, got.getCount())));
|
exportItems.setStackInSlot(i, network.insertItemTracked(got, got.getCount()));
|
||||||
} else {
|
} else {
|
||||||
int delta = got.isEmpty() ? wanted.getCount() : (wanted.getCount() - got.getCount());
|
int delta = got.isEmpty() ? wanted.getCount() : (wanted.getCount() - got.getCount());
|
||||||
|
|
||||||
@@ -108,7 +104,7 @@ public class NetworkNodeInterface extends NetworkNode implements IComparable {
|
|||||||
return !(s instanceof ItemExternalStorage) || !((ItemExternalStorage) s).isConnectedToInterface();
|
return !(s instanceof ItemExternalStorage) || !((ItemExternalStorage) s).isConnectedToInterface();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result != null) {
|
if (!result.isEmpty()) {
|
||||||
if (exportItems.getStackInSlot(i).isEmpty()) {
|
if (exportItems.getStackInSlot(i).isEmpty()) {
|
||||||
exportItems.setStackInSlot(i, result);
|
exportItems.setStackInSlot(i, result);
|
||||||
} else {
|
} else {
|
||||||
@@ -118,7 +114,7 @@ public class NetworkNodeInterface extends NetworkNode implements IComparable {
|
|||||||
|
|
||||||
// Example: our delta is 5, we extracted 3 items.
|
// Example: our delta is 5, we extracted 3 items.
|
||||||
// That means we still have to autocraft 2 items.
|
// That means we still have to autocraft 2 items.
|
||||||
delta -= result == null ? 0 : result.getCount();
|
delta -= result.isEmpty() ? 0 : result.getCount();
|
||||||
|
|
||||||
if (delta > 0 && upgrades.hasUpgrade(UpgradeItem.Type.CRAFTING)) {
|
if (delta > 0 && upgrades.hasUpgrade(UpgradeItem.Type.CRAFTING)) {
|
||||||
network.getCraftingManager().request(new SlottedCraftingRequest(this, i), wanted, delta);
|
network.getCraftingManager().request(new SlottedCraftingRequest(this, i), wanted, delta);
|
||||||
@@ -126,15 +122,11 @@ public class NetworkNodeInterface extends NetworkNode implements IComparable {
|
|||||||
} else if (delta < 0) {
|
} else if (delta < 0) {
|
||||||
ItemStack remainder = network.insertItemTracked(got, Math.abs(delta));
|
ItemStack remainder = network.insertItemTracked(got, Math.abs(delta));
|
||||||
|
|
||||||
if (remainder == null) {
|
|
||||||
exportItems.extractItem(i, Math.abs(delta), false);
|
|
||||||
} else {
|
|
||||||
exportItems.extractItem(i, Math.abs(delta) - remainder.getCount(), false);
|
exportItems.extractItem(i, Math.abs(delta) - remainder.getCount(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isActingAsStorage() {
|
private boolean isActingAsStorage() {
|
||||||
for (Direction facing : Direction.values()) {
|
for (Direction facing : Direction.values()) {
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ public class NetworkNodeStorageMonitor extends NetworkNode implements IComparabl
|
|||||||
ItemStack toInsert = player.inventory.getStackInSlot(i);
|
ItemStack toInsert = player.inventory.getStackInSlot(i);
|
||||||
|
|
||||||
if (API.instance().getComparer().isEqual(inserted, toInsert, compare)) {
|
if (API.instance().getComparer().isEqual(inserted, toInsert, compare)) {
|
||||||
player.inventory.setInventorySlotContents(i, StackUtils.nullToEmpty(network.insertItemTracked(toInsert, toInsert.getCount())));
|
player.inventory.setInventorySlotContents(i, network.insertItemTracked(toInsert, toInsert.getCount()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,7 +108,7 @@ public class NetworkNodeStorageMonitor extends NetworkNode implements IComparabl
|
|||||||
ItemStack filter = itemFilter.getStackInSlot(0);
|
ItemStack filter = itemFilter.getStackInSlot(0);
|
||||||
|
|
||||||
if (!filter.isEmpty() && API.instance().getComparer().isEqual(filter, toInsert, compare)) {
|
if (!filter.isEmpty() && API.instance().getComparer().isEqual(filter, toInsert, compare)) {
|
||||||
player.inventory.setInventorySlotContents(player.inventory.currentItem, StackUtils.nullToEmpty(network.insertItemTracked(toInsert, toInsert.getCount())));
|
player.inventory.setInventorySlotContents(player.inventory.currentItem, network.insertItemTracked(toInsert, toInsert.getCount()));
|
||||||
|
|
||||||
deposits.put(player.getGameProfile().getName(), Pair.of(toInsert, System.currentTimeMillis()));
|
deposits.put(player.getGameProfile().getName(), Pair.of(toInsert, System.currentTimeMillis()));
|
||||||
}
|
}
|
||||||
@@ -132,13 +132,11 @@ public class NetworkNodeStorageMonitor extends NetworkNode implements IComparabl
|
|||||||
if (!filter.isEmpty()) {
|
if (!filter.isEmpty()) {
|
||||||
ItemStack result = network.extractItem(filter, toExtract, compare, Action.PERFORM);
|
ItemStack result = network.extractItem(filter, toExtract, compare, Action.PERFORM);
|
||||||
|
|
||||||
if (result != null) {
|
if (!result.isEmpty() && !player.inventory.addItemStackToInventory(result.copy())) {
|
||||||
if (!player.inventory.addItemStackToInventory(result.copy())) {
|
|
||||||
InventoryHelper.spawnItemStack(world, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), result);
|
InventoryHelper.spawnItemStack(world, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getEnergyUsage() {
|
public int getEnergyUsage() {
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
|||||||
}
|
}
|
||||||
|
|
||||||
ItemStack remainder = network.insertItem(extracted, extracted.getCount(), Action.PERFORM);
|
ItemStack remainder = network.insertItem(extracted, extracted.getCount(), Action.PERFORM);
|
||||||
if (remainder == null) {
|
if (remainder.isEmpty()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,7 +222,7 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
|||||||
}
|
}
|
||||||
|
|
||||||
ItemStack remainder = network.insertItem(extracted, extracted.getCount(), Action.SIMULATE);
|
ItemStack remainder = network.insertItem(extracted, extracted.getCount(), Action.SIMULATE);
|
||||||
if (remainder == null) { //An item could be inserted (no remainders when trying to). This disk isn't done.
|
if (remainder.isEmpty()) { // An item could be inserted (no remainders when trying to). This disk isn't done.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -230,7 +230,7 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void extractItemFromNetwork(IStorageDisk<ItemStack> storage, int slot) {
|
private void extractItemFromNetwork(IStorageDisk<ItemStack> storage, int slot) {
|
||||||
ItemStack extracted = null;
|
ItemStack extracted = ItemStack.EMPTY;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if (itemFilters.isEmpty()) {
|
if (itemFilters.isEmpty()) {
|
||||||
@@ -260,17 +260,15 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extracted == null) {
|
if (extracted.isEmpty()) {
|
||||||
moveDriveToOutput(slot);
|
moveDriveToOutput(slot);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack remainder = storage.insert(extracted, extracted.getCount(), Action.PERFORM);
|
ItemStack remainder = storage.insert(extracted, extracted.getCount(), Action.PERFORM);
|
||||||
|
|
||||||
if (!remainder.isEmpty()) {
|
|
||||||
network.insertItem(remainder, remainder.getCount(), Action.PERFORM);
|
network.insertItem(remainder, remainder.getCount(), Action.PERFORM);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void insertFluidIntoNetwork(IStorageDisk<FluidStack> storage, int slot) {
|
private void insertFluidIntoNetwork(IStorageDisk<FluidStack> storage, int slot) {
|
||||||
List<FluidStack> stacks = new ArrayList<>(storage.getStacks());
|
List<FluidStack> stacks = new ArrayList<>(storage.getStacks());
|
||||||
|
|||||||
@@ -120,20 +120,15 @@ public class PatternItem extends Item implements ICraftingPatternProvider {
|
|||||||
pattern.getTag().put(String.format(NBT_INPUT_SLOT, slot), stack.serializeNBT());
|
pattern.getTag().put(String.format(NBT_INPUT_SLOT, slot), stack.serializeNBT());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nonnull
|
||||||
public static ItemStack getInputSlot(ItemStack pattern, int slot) {
|
public static ItemStack getInputSlot(ItemStack pattern, int slot) {
|
||||||
String id = String.format(NBT_INPUT_SLOT, slot);
|
String id = String.format(NBT_INPUT_SLOT, slot);
|
||||||
|
|
||||||
if (!pattern.hasTag() || !pattern.getTag().contains(id)) {
|
if (!pattern.hasTag() || !pattern.getTag().contains(id)) {
|
||||||
return null;
|
return ItemStack.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack stack = ItemStack.read(pattern.getTag().getCompound(id));
|
return ItemStack.read(pattern.getTag().getCompound(id));
|
||||||
if (stack.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return stack;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setOutputSlot(ItemStack pattern, int slot, ItemStack stack) {
|
public static void setOutputSlot(ItemStack pattern, int slot, ItemStack stack) {
|
||||||
@@ -144,20 +139,15 @@ public class PatternItem extends Item implements ICraftingPatternProvider {
|
|||||||
pattern.getTag().put(String.format(NBT_OUTPUT_SLOT, slot), stack.serializeNBT());
|
pattern.getTag().put(String.format(NBT_OUTPUT_SLOT, slot), stack.serializeNBT());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nonnull
|
||||||
public static ItemStack getOutputSlot(ItemStack pattern, int slot) {
|
public static ItemStack getOutputSlot(ItemStack pattern, int slot) {
|
||||||
String id = String.format(NBT_OUTPUT_SLOT, slot);
|
String id = String.format(NBT_OUTPUT_SLOT, slot);
|
||||||
|
|
||||||
if (!pattern.hasTag() || !pattern.getTag().contains(id)) {
|
if (!pattern.hasTag() || !pattern.getTag().contains(id)) {
|
||||||
return null;
|
return ItemStack.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack stack = ItemStack.read(pattern.getTag().getCompound(id));
|
return ItemStack.read(pattern.getTag().getCompound(id));
|
||||||
if (stack.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return stack;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setFluidInputSlot(ItemStack pattern, int slot, FluidStack stack) {
|
public static void setFluidInputSlot(ItemStack pattern, int slot, FluidStack stack) {
|
||||||
|
|||||||
@@ -292,8 +292,13 @@ public class ControllerTile extends BaseTile implements ITickableTileEntity, INe
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nonnull
|
||||||
public ItemStack insertItem(@Nonnull ItemStack stack, int size, Action action) {
|
public ItemStack insertItem(@Nonnull ItemStack stack, int size, Action action) {
|
||||||
if (stack.isEmpty() || itemStorage.getStorages().isEmpty()) {
|
if (stack.isEmpty()) {
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (itemStorage.getStorages().isEmpty()) {
|
||||||
return ItemHandlerHelper.copyStackWithSize(stack, size);
|
return ItemHandlerHelper.copyStackWithSize(stack, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,16 +345,16 @@ public class ControllerTile extends BaseTile implements ITickableTileEntity, INe
|
|||||||
itemStorage.add(stack, inserted - insertedExternally, false, false);
|
itemStorage.add(stack, inserted - insertedExternally, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Remove.
|
|
||||||
if (remainder.isEmpty()) {
|
|
||||||
remainder = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return remainder;
|
return remainder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nonnull
|
||||||
public ItemStack extractItem(@Nonnull ItemStack stack, int size, int flags, Action action, Predicate<IStorage<ItemStack>> filter) {
|
public ItemStack extractItem(@Nonnull ItemStack stack, int size, int flags, Action action, Predicate<IStorage<ItemStack>> filter) {
|
||||||
|
if (stack.isEmpty()) {
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
int requested = size;
|
int requested = size;
|
||||||
int received = 0;
|
int received = 0;
|
||||||
|
|
||||||
@@ -390,11 +395,6 @@ public class ControllerTile extends BaseTile implements ITickableTileEntity, INe
|
|||||||
itemStorage.remove(newStack, newStack.getCount() - extractedExternally, false);
|
itemStorage.remove(newStack, newStack.getCount() - extractedExternally, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Remove.
|
|
||||||
if (newStack.isEmpty()) {
|
|
||||||
newStack = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return newStack;
|
return newStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -150,15 +150,6 @@ public final class StackUtils {
|
|||||||
return new FluidGridStack(id, stack, entry, craftable, displayCraftText);
|
return new FluidGridStack(id, stack, entry, craftable, displayCraftText);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack nullToEmpty(@Nullable ItemStack stack) {
|
|
||||||
return stack == null ? ItemStack.EMPTY : stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static ItemStack emptyToNull(@Nonnull ItemStack stack) {
|
|
||||||
return stack.isEmpty() ? null : stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static void createStorages(ServerWorld world, ItemStack diskStack, int slot, IStorageDisk<ItemStack>[] itemDisks, IStorageDisk<FluidStack>[] fluidDisks, Function<IStorageDisk<ItemStack>, IStorageDisk> itemDiskWrapper, Function<IStorageDisk<FluidStack>, IStorageDisk> fluidDiskWrapper) {
|
public static void createStorages(ServerWorld world, ItemStack diskStack, int slot, IStorageDisk<ItemStack>[] itemDisks, IStorageDisk<FluidStack>[] fluidDisks, Function<IStorageDisk<ItemStack>, IStorageDisk> itemDiskWrapper, Function<IStorageDisk<FluidStack>, IStorageDisk> fluidDiskWrapper) {
|
||||||
if (diskStack.isEmpty()) {
|
if (diskStack.isEmpty()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user