return;
}
movedItemCart = false;
EntityMinecart cart = CartTools.getMinecartOnSide(worldObj, xCoord, yCoord, zCoord, 0.1f, getOrientation());
if (cart != currentCart) {
setPowered(false);
currentCart = cart;
transferedItems.clear();
cartWasSent();
}
if (cart == null) {
return;
}
IInventory cartInv = null;
if (cart instanceof IInventory) {
cartInv = (IInventory) cart;
}
if (cartInv == null || cartInv.getSizeInventory() <= 0) {
if (CartTools.cartVelocityIsLessThan(cart, STOP_VELOCITY) || cart.isPoweredCart()) {
setPowered(true);
}
return;
}
if (isSendCartGateAction()) {
if (CartTools.cartVelocityIsLessThan(cart, STOP_VELOCITY)) {
setPowered(true);
}
return;
}
ItemStack minecartSlot1 = getCartFilters().getStackInSlot(0);
ItemStack minecartSlot2 = getCartFilters().getStackInSlot(1);
if (minecartSlot1 != null || minecartSlot2 != null) {
if (!CartUtils.doesCartMatchFilter(minecartSlot1, cart) && !CartUtils.doesCartMatchFilter(minecartSlot2, cart)) {
if (CartTools.cartVelocityIsLessThan(cart, STOP_VELOCITY)) {
setPowered(true);
}
return;
}
}
if (isPaused())
return;
LinkedList<IInventory> chests = new LinkedList<IInventory>(invCache.getAdjecentInventories());
chests.addFirst(invBuffer);
checkedItems.clear();
switch (getMode()) {
case TRANSFER: {
boolean hasFilter = false;
for (ItemStack filter : getItemFilters().getContents()) {
if (filter == null) {
continue;
}
if (!checkedItems.add(filter)) {
continue;
}
hasFilter = true;
Short numMoved = transferedItems.get(filter);
if (numMoved == null) {
numMoved = 0;
}
if (numMoved < InvTools.countItems(getItemFilters(), filter)) {
ItemStack moved = InvTools.moveOneItem(chests, cartInv, filter);
if (moved != null) {
movedItemCart = true;
numMoved++;
transferedItems.put(moved, numMoved);
break;
}
}
}
if (!hasFilter) {
ItemStack moved = InvTools.moveOneItem(chests, cartInv);
if (moved != null) {
movedItemCart = true;
break;
}
}
break;
}
case STOCK: {
for (ItemStack filter : getItemFilters().getContents()) {
if (filter == null) {
continue;
}
if (!checkedItems.add(filter)) {
continue;
}
int stocked = InvTools.countItems(cartInv, filter);
if (stocked < InvTools.countItems(getItemFilters(), filter)) {
ItemStack moved = InvTools.moveOneItem(chests, cartInv, filter);
if (moved != null) {
movedItemCart = true;
break;
}
}
}
break;
}
case EXCESS: {
for (ItemStack filter : getItemFilters().getContents()) {
if (filter == null) {
continue;
}
if (!checkedItems.add(filter)) {
continue;
}
int stocked = InvTools.countItems(chests, filter);
if (stocked > InvTools.countItems(getItemFilters(), filter)) {
ItemStack moved = InvTools.moveOneItem(chests, cartInv, filter);
if (moved != null) {
movedItemCart = true;
break;
}
}
}
if (!movedItemCart) {
movedItemCart = InvTools.moveOneItemExcept(chests, cartInv, getItemFilters().getContents()) != null;
}
break;
}
case ALL: {
boolean hasFilter = false;
for (ItemStack filter : getItemFilters().getContents()) {
if (filter == null) {
continue;
}
if (!checkedItems.add(filter)) {
continue;
}
hasFilter = true;
ItemStack moved = InvTools.moveOneItem(chests, cartInv, filter);
if (moved != null) {
movedItemCart = true;
break;
}
}
if (!hasFilter) {
ItemStack moved = InvTools.moveOneItem(chests, cartInv);
if (moved != null) {
movedItemCart = true;
break;
}
}
break;
}
}
if (movedItemCart) {
setPowered(false);
}
EnumRedstoneMode state = getRedstoneModeController().getButtonState();
if (state != EnumRedstoneMode.MANUAL && !isPowered() && (CartTools.cartVelocityIsLessThan(cart, STOP_VELOCITY) || cart.isPoweredCart())) {
if (!movedItemCart && state != EnumRedstoneMode.COMPLETE) {
if (state == EnumRedstoneMode.PARTIAL) {
if (!InvTools.isInventoryEmpty(cartInv)) {
setPowered(true);
}