Fix subtle bugs, todo apiimpl package

This commit is contained in:
Raoul Van den Berge
2016-11-26 22:43:19 +01:00
parent c026f08d58
commit 21754a1240
19 changed files with 69 additions and 59 deletions

View File

@@ -4,6 +4,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.items.ItemStackHandler;
import javax.annotation.Nonnull;
public class ItemHandlerBasic extends ItemStackHandler {
private TileEntity tile;
@@ -21,6 +23,7 @@ public class ItemHandlerBasic extends ItemStackHandler {
}
@Override
@Nonnull
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
if (validators.length > 0) {
for (IItemValidator validator : validators) {
@@ -44,6 +47,7 @@ public class ItemHandlerBasic extends ItemStackHandler {
}
}
@Nonnull
public ItemStack extractItemInternal(int slot, int amount, boolean simulate) {
return super.extractItem(slot, amount, simulate);
}

View File

@@ -71,7 +71,7 @@ public class TileConstructor extends TileNode implements IComparable, IType {
protected void onContentsChanged(int slot) {
super.onContentsChanged(slot);
item = getStackInSlot(slot) == null ? null : getStackInSlot(slot).copy();
item = getStackInSlot(slot).isEmpty() ? null : getStackInSlot(slot).copy();
block = SlotFilter.getBlockState(getWorld(), pos.offset(getDirection()), getStackInSlot(slot));
}
};

View File

@@ -353,14 +353,14 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
}
@Override
public void addCraftingTask(ICraftingTask task) {
public void addCraftingTask(@Nonnull ICraftingTask task) {
craftingTasksToAdd.add(task);
markDirty();
}
@Override
public void cancelCraftingTask(ICraftingTask task) {
public void cancelCraftingTask(@Nonnull ICraftingTask task) {
craftingTasksToCancel.add(task);
markDirty();
@@ -580,7 +580,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
@Override
public ItemStack insertItem(@Nonnull ItemStack stack, int size, boolean simulate) {
if (stack == null || stack.getItem() == null || itemStorage.getStorages().isEmpty()) {
if (stack == null || (stack != null && stack.isEmpty()) || itemStorage.getStorages().isEmpty()) {
return ItemHandlerHelper.copyStackWithSize(stack, size);
}

View File

@@ -81,7 +81,7 @@ public class TileCrafter extends TileNode implements ICraftingPatternContainer {
for (int i = 0; i < patterns.getSlots(); ++i) {
ItemStack patternStack = patterns.getStackInSlot(i);
if (patternStack != null) {
if (!patternStack.isEmpty()) {
ICraftingPattern pattern = ((ICraftingPatternProvider) patternStack.getItem()).create(getWorld(), patternStack, this);
if (pattern.isValid()) {
@@ -96,7 +96,7 @@ public class TileCrafter extends TileNode implements ICraftingPatternContainer {
int usage = RS.INSTANCE.config.crafterUsage + upgrades.getEnergyUsage();
for (int i = 0; i < patterns.getSlots(); ++i) {
if (patterns.getStackInSlot(i) != null) {
if (!patterns.getStackInSlot(i).isEmpty()) {
usage += RS.INSTANCE.config.crafterPerPatternUsage;
}
}

View File

@@ -94,7 +94,6 @@ public class TileDestructor extends TileNode implements IComparable, IFilterable
@Override
public void updateNode() {
if (ticks % upgrades.getSpeed(BASE_SPEED, 4) == 0) {
BlockPos front = pos.offset(getDirection());
if (pickupItem && type == IType.ITEMS) {
@@ -123,7 +122,7 @@ public class TileDestructor extends TileNode implements IComparable, IFilterable
@SuppressWarnings("deprecation")
ItemStack frontStack = frontBlock.getItem(getWorld(), front, frontBlockState);
if (frontStack != null) {
if (!frontStack.isEmpty()) {
if (IFilterable.canTake(itemFilters, mode, compare, frontStack) && frontBlockState.getBlockHardness(getWorld(), front) != -1.0) {
List<ItemStack> drops;
if (upgrades.hasUpgrade(ItemUpgrade.TYPE_SILK_TOUCH) && frontBlock.canSilkHarvest(getWorld(), front, frontBlockState, null)) {

View File

@@ -110,7 +110,7 @@ public class TileDetector extends TileNode implements IComparable, IType {
if (type == IType.ITEMS) {
ItemStack slot = itemFilters.getStackInSlot(0);
if (slot != null) {
if (!slot.isEmpty()) {
if (mode == MODE_AUTOCRAFTING) {
boolean found = false;

View File

@@ -213,7 +213,7 @@ public class TileDiskDrive extends TileNode implements IItemStorageProvider, IFl
int usage = RS.INSTANCE.config.diskDriveUsage;
for (int i = 0; i < disks.getSlots(); ++i) {
if (disks.getStackInSlot(i) != null) {
if (!disks.getStackInSlot(i).isEmpty()) {
usage += RS.INSTANCE.config.diskDrivePerDiskUsage;
}
}
@@ -507,7 +507,7 @@ public class TileDiskDrive extends TileNode implements IItemStorageProvider, IFl
for (int i = 0; i < disks.getSlots(); ++i) {
ItemStack disk = disks.getStackInSlot(i);
if (disk != null) {
if (!disk.isEmpty()) {
stored += disk.getItem() == RSItems.STORAGE_DISK ? ItemStorageNBT.getStoredFromNBT(disk.getTagCompound()) : FluidStorageNBT.getStoredFromNBT(disk.getTagCompound());
}
}
@@ -522,7 +522,7 @@ public class TileDiskDrive extends TileNode implements IItemStorageProvider, IFl
for (int i = 0; i < disks.getSlots(); ++i) {
ItemStack disk = disks.getStackInSlot(i);
if (disk != null) {
if (!disk.isEmpty()) {
int diskCapacity = disk.getItem() == RSItems.STORAGE_DISK ? EnumItemStorageType.getById(disk.getItemDamage()).getCapacity() : EnumFluidStorageType.getById(disk.getItemDamage()).getCapacity();
if (diskCapacity == -1) {

View File

@@ -31,6 +31,7 @@ import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
import javax.annotation.Nonnull;
import java.util.ArrayList;
public class TileDiskManipulator extends TileNode implements IComparable, IFilterable, IType {
@@ -84,6 +85,7 @@ public class TileDiskManipulator extends TileNode implements IComparable, IFilte
}
@Override
@Nonnull
public ItemStack extractItem(int slot, int amount, boolean simulate) {
if (itemStorages[slot] != null) {
itemStorages[slot].writeToNBT();
@@ -427,9 +429,9 @@ public class TileDiskManipulator extends TileNode implements IComparable, IFilte
private void moveDriveToOutput(int slot) {
ItemStack disk = inputDisks.getStackInSlot(slot);
if (disk != null) {
if (!disk.isEmpty()) {
int i = 0;
while (i < 3 && outputDisks.getStackInSlot(i) != null) {
while (i < 3 && !outputDisks.getStackInSlot(i).isEmpty()) {
i++;
}

View File

@@ -56,14 +56,14 @@ public class TileExporter extends TileNode implements IComparable, IType {
for (int i = 0; i < itemFilters.getSlots(); ++i) {
ItemStack slot = itemFilters.getStackInSlot(i);
if (slot != null) {
if (!slot.isEmpty()) {
ItemStack took = network.extractItem(slot, upgrades.getItemInteractCount(), compare, true);
if (took == null) {
if (upgrades.hasUpgrade(ItemUpgrade.TYPE_CRAFTING)) {
network.scheduleCraftingTask(slot, 1, compare);
}
} else if (ItemHandlerHelper.insertItem(handler, took, true) == null) {
} else if (ItemHandlerHelper.insertItem(handler, took, true).isEmpty()) {
took = network.extractItem(slot, upgrades.getItemInteractCount(), compare, false);
ItemHandlerHelper.insertItem(handler, took, false);

View File

@@ -92,7 +92,7 @@ public class TileFluidInterface extends TileNode implements IComparable {
public void updateNode() {
ItemStack container = in.getStackInSlot(0);
if (container != null) {
if (!container.isEmpty()) {
FluidStack fluid = RSUtils.getFluidFromStack(container, true);
if (fluid != null && tankIn.fillInternal(fluid, false) == fluid.amount) {

View File

@@ -68,12 +68,12 @@ public class TileImporter extends TileNode implements IComparable, IFilterable,
if (handler.getSlots() > 0) {
ItemStack stack = handler.getStackInSlot(currentSlot);
if (stack == null || !IFilterable.canTake(itemFilters, mode, compare, stack)) {
if (stack.isEmpty() || !IFilterable.canTake(itemFilters, mode, compare, stack)) {
currentSlot++;
} else if (ticks % upgrades.getSpeed() == 0) {
ItemStack result = handler.extractItem(currentSlot, upgrades.getItemInteractCount(), true);
if (result != null && network.insertItem(result, result.getCount(), true) == null) {
if (!result.isEmpty() && network.insertItem(result, result.getCount(), true) == null) {
network.insertItem(result, result.getCount(), false);
handler.extractItem(currentSlot, upgrades.getItemInteractCount(), false);

View File

@@ -16,6 +16,8 @@ import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
import javax.annotation.Nonnull;
public class TileInterface extends TileNode implements IComparable {
public static final TileDataParameter<Integer> COMPARE = IComparable.createParameter();
@@ -26,6 +28,7 @@ public class TileInterface extends TileNode implements IComparable {
private ItemHandlerBasic exportSpecimenItems = new ItemHandlerBasic(9, this);
private ItemHandlerBasic exportItems = new ItemHandlerBasic(9, this) {
@Override
@Nonnull
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
return stack;
}
@@ -54,7 +57,7 @@ public class TileInterface extends TileNode implements IComparable {
ItemStack slot = importItems.getStackInSlot(currentSlot);
if (slot == null) {
if (slot.isEmpty()) {
currentSlot++;
} else if (ticks % upgrades.getSpeed() == 0) {
int size = Math.min(slot.getCount(), upgrades.getItemInteractCount());
@@ -65,6 +68,7 @@ public class TileInterface extends TileNode implements IComparable {
importItems.extractItemInternal(currentSlot, size, false);
} else {
importItems.extractItemInternal(currentSlot, size - remainder.getCount(), false);
currentSlot++;
}
}
@@ -73,18 +77,18 @@ public class TileInterface extends TileNode implements IComparable {
ItemStack wanted = exportSpecimenItems.getStackInSlot(i);
ItemStack got = exportItems.getStackInSlot(i);
if (wanted == null) {
if (got != null) {
exportItems.setStackInSlot(i, network.insertItem(got, got.getCount(), false));
if (wanted.isEmpty()) {
if (!got.isEmpty()) {
exportItems.setStackInSlot(i, RSUtils.getStack(network.insertItem(got, got.getCount(), false)));
}
} else {
int delta = got == null ? wanted.getCount() : (wanted.getCount() - got.getCount());
int delta = got.isEmpty() ? wanted.getCount() : (wanted.getCount() - got.getCount());
if (delta > 0) {
ItemStack result = network.extractItem(wanted, delta, compare, false);
if (result != null) {
if (exportItems.getStackInSlot(i) == null) {
if (exportItems.getStackInSlot(i).isEmpty()) {
exportItems.setStackInSlot(i, result);
} else {
exportItems.getStackInSlot(i).grow(result.getCount());

View File

@@ -57,7 +57,7 @@ public class TileNetworkTransmitter extends TileNode {
ItemStack card = getStackInSlot(slot);
if (card == null) {
if (card.isEmpty()) {
receiver = null;
} else {
receiver = ItemNetworkCard.getReceiver(card);

View File

@@ -79,7 +79,7 @@ public class TileProcessingPatternEncoder extends TileBase {
ItemPattern.setOredict(pattern, oredictPattern);
for (int i = 0; i < 18; ++i) {
if (configuration.getStackInSlot(i) != null) {
if (!configuration.getStackInSlot(i).isEmpty()) {
if (i >= 9) {
ItemPattern.addOutput(pattern, configuration.getStackInSlot(i));
} else {
@@ -97,18 +97,18 @@ public class TileProcessingPatternEncoder extends TileBase {
int inputsFilled = 0, outputsFilled = 0;
for (int i = 0; i < 9; ++i) {
if (configuration.getStackInSlot(i) != null) {
if (!configuration.getStackInSlot(i).isEmpty()) {
inputsFilled++;
}
}
for (int i = 9; i < 18; ++i) {
if (configuration.getStackInSlot(i) != null) {
if (!configuration.getStackInSlot(i).isEmpty()) {
outputsFilled++;
}
}
return inputsFilled > 0 && outputsFilled > 0 && patterns.getStackInSlot(0) != null && patterns.getStackInSlot(1) == null;
return inputsFilled > 0 && outputsFilled > 0 && !patterns.getStackInSlot(0).isEmpty() && patterns.getStackInSlot(1).isEmpty();
}
public ItemHandlerBasic getPatterns() {

View File

@@ -19,6 +19,8 @@ import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
import javax.annotation.Nonnull;
public class TileSolderer extends TileNode {
public static final TileDataParameter<Integer> DURATION = new TileDataParameter<>(DataSerializers.VARINT, 0, new ITileDataProducer<Integer, TileSolderer>() {
@Override
@@ -46,6 +48,7 @@ public class TileSolderer extends TileNode {
private ItemHandlerBasic items = new ItemHandlerBasic(3, this) {
@Override
@Nonnull
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
for (ISoldererRecipe recipe : API.instance().getSoldererRegistry().getRecipes()) {
if (API.instance().getComparer().isEqualNoQuantity(recipe.getRow(slot), stack) || API.instance().getComparer().isEqualOredict(recipe.getRow(slot), stack)) {
@@ -58,6 +61,7 @@ public class TileSolderer extends TileNode {
};
private ItemHandlerBasic result = new ItemHandlerBasic(1, this) {
@Override
@Nonnull
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
return stack;
}
@@ -82,7 +86,7 @@ public class TileSolderer extends TileNode {
@Override
public void updateNode() {
if (items.getStackInSlot(1) == null && items.getStackInSlot(2) == null && result.getStackInSlot(0) == null) {
if (items.getStackInSlot(1).isEmpty() && items.getStackInSlot(2).isEmpty() && result.getStackInSlot(0).isEmpty()) {
stop();
} else {
ISoldererRecipe newRecipe = API.instance().getSoldererRegistry().getRecipe(items);
@@ -90,9 +94,9 @@ public class TileSolderer extends TileNode {
if (newRecipe == null) {
stop();
} else if (newRecipe != recipe) {
boolean sameItem = result.getStackInSlot(0) != null && API.instance().getComparer().isEqualNoQuantity(result.getStackInSlot(0), newRecipe.getResult());
boolean sameItem = !result.getStackInSlot(0).isEmpty() && API.instance().getComparer().isEqualNoQuantity(result.getStackInSlot(0), newRecipe.getResult());
if (result.getStackInSlot(0) == null || (sameItem && ((result.getStackInSlot(0).getCount() + newRecipe.getResult().getCount()) <= result.getStackInSlot(0).getMaxStackSize()))) {
if (result.getStackInSlot(0).isEmpty() || (sameItem && ((result.getStackInSlot(0).getCount() + newRecipe.getResult().getCount()) <= result.getStackInSlot(0).getMaxStackSize()))) {
recipe = newRecipe;
progress = 0;
working = true;
@@ -103,7 +107,7 @@ public class TileSolderer extends TileNode {
progress += 1 + upgrades.getUpgradeCount(ItemUpgrade.TYPE_SPEED);
if (progress >= recipe.getDuration()) {
if (result.getStackInSlot(0) != null) {
if (!result.getStackInSlot(0).isEmpty()) {
result.getStackInSlot(0).grow(recipe.getResult().getCount());
} else {
result.setStackInSlot(0, recipe.getResult().copy());

View File

@@ -63,10 +63,6 @@ public class ItemStorageDrawer extends ItemStorageExternal {
return Collections.emptyList();
}
public static boolean isVoidable(IDrawer drawer) {
return drawer instanceof IVoidable & ((IVoidable) drawer).isVoid();
}
public static ItemStack insertItem(TileExternalStorage externalStorage, IDrawer drawer, ItemStack stack, int size, boolean simulate) {
if (IFilterable.canTake(externalStorage.getItemFilters(), externalStorage.getMode(), externalStorage.getCompare(), stack) && drawer.canItemBeStored(stack)) {
int stored = drawer.getStoredItemCount();
@@ -88,7 +84,7 @@ public class ItemStorageDrawer extends ItemStorageExternal {
int returnSize = size - inserted;
if (isVoidable(drawer)) {
if (drawer instanceof IVoidable && ((IVoidable) drawer).isVoid()) {
returnSize = -returnSize;
}

View File

@@ -41,14 +41,14 @@ public abstract class ItemStorageExternal implements IItemStorage {
ItemStack cached = cache.get(i);
if (cached != null && actual == null) {
// If the cached is not null but the actual is, we remove this item
if (cached != ItemStack.EMPTY && actual == ItemStack.EMPTY) {
// If the cached is not empty but the actual is, we remove this item
network.getItemStorageCache().remove(cached, cached.getCount());
} else if (cached == null && actual != null) {
// If the cached is null and the actual isn't, we added this item
} else if (cached == ItemStack.EMPTY && actual != ItemStack.EMPTY) {
// If the cached is empty and the actual isn't, we added this item
network.getItemStorageCache().add(actual, actual.getCount(), false);
} else if (cached == null && actual == null) {
// If they're both null, nothing happens
} else if (cached == ItemStack.EMPTY && actual == ItemStack.EMPTY) {
// If they're both empty, nothing happens
} else if (!API.instance().getComparer().isEqualNoQuantity(cached, actual)) {
// If both items mismatch, remove the old and add the new
network.getItemStorageCache().remove(cached, cached.getCount());
@@ -68,7 +68,7 @@ public abstract class ItemStorageExternal implements IItemStorage {
// In that case, we remove the items that have been removed due to the shrinkage
if (cache.size() > newStacks.size()) {
for (int i = newStacks.size(); i < cache.size(); ++i) {
if (cache.get(i) != null) {
if (cache.get(i) != ItemStack.EMPTY) {
network.getItemStorageCache().remove(cache.get(i), cache.get(i).getCount());
}
}

View File

@@ -7,6 +7,7 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemHandlerHelper;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
@@ -34,14 +35,14 @@ public class ItemStorageItemHandler extends ItemStorageExternal {
List<ItemStack> items = new ArrayList<>();
for (int i = 0; i < handler.getSlots(); ++i) {
items.add(handler.getStackInSlot(i) != null ? handler.getStackInSlot(i).copy() : null);
items.add(!handler.getStackInSlot(i).isEmpty() ? handler.getStackInSlot(i).copy() : null);
}
return items;
}
@Override
public ItemStack insertItem(ItemStack stack, int size, boolean simulate) {
public ItemStack insertItem(@Nonnull ItemStack stack, int size, boolean simulate) {
if (IFilterable.canTake(externalStorage.getItemFilters(), externalStorage.getMode(), externalStorage.getCompare(), stack)) {
return ItemHandlerHelper.insertItem(handler, ItemHandlerHelper.copyStackWithSize(stack, size), simulate);
}
@@ -50,7 +51,7 @@ public class ItemStorageItemHandler extends ItemStorageExternal {
}
@Override
public ItemStack extractItem(ItemStack stack, int size, int flags, boolean simulate) {
public ItemStack extractItem(@Nonnull ItemStack stack, int size, int flags, boolean simulate) {
int remaining = size;
ItemStack received = null;
@@ -58,10 +59,10 @@ public class ItemStorageItemHandler extends ItemStorageExternal {
for (int i = 0; i < handler.getSlots(); ++i) {
ItemStack slot = handler.getStackInSlot(i);
if (slot != null && API.instance().getComparer().isEqual(slot, stack, flags)) {
if (!slot.isEmpty() && API.instance().getComparer().isEqual(slot, stack, flags)) {
ItemStack got = handler.extractItem(i, remaining, simulate);
if (got != null) {
if (!got.isEmpty()) {
if (received == null) {
received = got;
} else {
@@ -85,7 +86,7 @@ public class ItemStorageItemHandler extends ItemStorageExternal {
int size = 0;
for (int i = 0; i < handler.getSlots(); ++i) {
if (handler.getStackInSlot(i) != null) {
if (!handler.getStackInSlot(i).isEmpty()) {
size += handler.getStackInSlot(i).getCount();
}
}

View File

@@ -276,7 +276,7 @@ public class TileGrid extends TileNode implements IGrid {
if (i < remainder.size() && !remainder.get(i).isEmpty()) {
// If there is no space for the remainder, dump it in the player inventory
if (slot != null && slot.getCount() > 1) {
if (!slot.isEmpty() && slot.getCount() > 1) {
if (!player.inventory.addItemStackToInventory(remainder.get(i).copy())) {
ItemStack remainderStack = network.insertItem(remainder.get(i).copy(), remainder.get(i).getCount(), false);
@@ -289,7 +289,7 @@ public class TileGrid extends TileNode implements IGrid {
} else {
matrix.setInventorySlotContents(i, remainder.get(i).copy());
}
} else if (slot != null) {
} else if (!slot.isEmpty()) {
if (slot.getCount() == 1 && isConnected()) {
matrix.setInventorySlotContents(i, network.extractItem(slot, 1, false));
} else {
@@ -342,7 +342,7 @@ public class TileGrid extends TileNode implements IGrid {
for (int i = 0; i < 9; ++i) {
ItemStack ingredient = matrix.getStackInSlot(i);
if (ingredient != null) {
if (!ingredient.isEmpty()) {
ItemPattern.setSlot(pattern, i, ingredient);
}
}
@@ -352,7 +352,7 @@ public class TileGrid extends TileNode implements IGrid {
}
public boolean canCreatePattern() {
return result.getStackInSlot(0) != null && patterns.getStackInSlot(1) == null && patterns.getStackInSlot(0) != null;
return !result.getStackInSlot(0).isEmpty() && patterns.getStackInSlot(1).isEmpty() && patterns.getStackInSlot(0) != null;
}
public void onRecipeTransfer(EntityPlayer player, ItemStack[][] recipe) {
@@ -360,7 +360,7 @@ public class TileGrid extends TileNode implements IGrid {
for (int i = 0; i < matrix.getSizeInventory(); ++i) {
ItemStack slot = matrix.getStackInSlot(i);
if (slot != null) {
if (!slot.isEmpty()) {
// Only if we are a crafting grid. Pattern grids can just be emptied.
if (getType() == EnumGridType.CRAFTING) {
// If we are connected, try to insert into network. If it fails, stop.
@@ -378,7 +378,7 @@ public class TileGrid extends TileNode implements IGrid {
}
}
matrix.setInventorySlotContents(i, null);
matrix.setInventorySlotContents(i, ItemStack.EMPTY);
}
}
@@ -397,7 +397,7 @@ public class TileGrid extends TileNode implements IGrid {
ItemStack took = network.extractItem(possibility, 1, false);
if (took != null) {
matrix.setInventorySlotContents(i, took);
matrix.setInventorySlotContents(i, RSUtils.getStack(took));
found = true;