Search in sources :

Example 1 with TileEntityLogisticalSorter

use of mekanism.common.tile.TileEntityLogisticalSorter in project Mekanism by mekanism.

the class BlockLogisticalSorter method use.

@Nonnull
@Override
@Deprecated
public ActionResultType use(@Nonnull BlockState state, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull PlayerEntity player, @Nonnull Hand hand, @Nonnull BlockRayTraceResult hit) {
    TileEntityLogisticalSorter tile = WorldUtils.getTileEntity(TileEntityLogisticalSorter.class, world, pos);
    if (tile == null) {
        return ActionResultType.PASS;
    } else if (world.isClientSide) {
        return genericClientActivated(player, hand);
    }
    // TODO: Make this be moved into the logistical sorter tile
    ItemStack stack = player.getItemInHand(hand);
    if (MekanismUtils.canUseAsWrench(stack)) {
        if (SecurityUtils.canAccess(player, tile)) {
            if (player.isShiftKeyDown()) {
                WorldUtils.dismantleBlock(state, world, pos);
                return ActionResultType.SUCCESS;
            }
            Direction change = tile.getDirection().getClockWise();
            if (!tile.hasConnectedInventory()) {
                for (Direction dir : EnumUtils.DIRECTIONS) {
                    TileEntity tileEntity = WorldUtils.getTileEntity(world, pos.relative(dir));
                    if (InventoryUtils.isItemHandler(tileEntity, dir)) {
                        change = dir.getOpposite();
                        break;
                    }
                }
            }
            tile.setFacing(change);
            world.updateNeighborsAt(pos, this);
        } else {
            SecurityUtils.displayNoAccess(player);
        }
        return ActionResultType.SUCCESS;
    }
    return tile.openGui(player);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityLogisticalSorter(mekanism.common.tile.TileEntityLogisticalSorter) ItemStack(net.minecraft.item.ItemStack) Direction(net.minecraft.util.Direction) Nonnull(javax.annotation.Nonnull)

Example 2 with TileEntityLogisticalSorter

use of mekanism.common.tile.TileEntityLogisticalSorter in project Mekanism by mekanism.

the class TransitRequest method addToInventory.

@Nonnull
public TransitResponse addToInventory(TileEntity tile, Direction side, int min, boolean force) {
    if (force && tile instanceof TileEntityLogisticalSorter) {
        return ((TileEntityLogisticalSorter) tile).sendHome(this);
    }
    if (isEmpty()) {
        return getEmptyResponse();
    }
    Optional<IItemHandler> capability = CapabilityUtils.getCapability(tile, CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side.getOpposite()).resolve();
    if (capability.isPresent()) {
        IItemHandler inventory = capability.get();
        if (min > 1) {
            // If we have a minimum amount of items we are trying to send, we need to start by simulating
            // to see if we actually have enough room to send the minimum amount of our item. We can
            // skip this step if we don't have a minimum amount being sent, as then whatever we are
            // able to insert will be "good enough"
            TransitResponse response = TransporterManager.getPredictedInsert(inventory, this);
            if (response.isEmpty() || response.getSendingAmount() < min) {
                // return that we aren't able to insert the requested amount
                return getEmptyResponse();
            }
        // otherwise, continue on to actually sending items to the inventory
        }
        for (ItemData data : getItemData()) {
            ItemStack origInsert = StackUtils.size(data.getStack(), data.getTotalCount());
            ItemStack toInsert = origInsert.copy();
            for (int i = 0; i < inventory.getSlots(); i++) {
                // Check validation
                if (inventory.isItemValid(i, toInsert)) {
                    // Do insert
                    toInsert = inventory.insertItem(i, toInsert, false);
                    // If empty, end
                    if (toInsert.isEmpty()) {
                        return createResponse(origInsert, data);
                    }
                }
            }
            if (TransporterManager.didEmit(origInsert, toInsert)) {
                return createResponse(TransporterManager.getToUse(origInsert, toInsert), data);
            }
        }
    }
    return getEmptyResponse();
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) TileEntityLogisticalSorter(mekanism.common.tile.TileEntityLogisticalSorter) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 3 with TileEntityLogisticalSorter

use of mekanism.common.tile.TileEntityLogisticalSorter in project Mekanism by mekanism.

the class PacketEditFilter method handle.

@Override
public void handle(NetworkEvent.Context context) {
    PlayerEntity player = context.getSender();
    if (player == null) {
        return;
    }
    TileEntity tile = WorldUtils.getTileEntity(player.level, pos);
    if (tile != null) {
        if (filter instanceof SorterFilter && tile instanceof TileEntityLogisticalSorter) {
            HashList<SorterFilter<?>> filters = ((TileEntityLogisticalSorter) tile).getFilters();
            int index = filters.indexOf(filter);
            if (index != -1) {
                filters.remove(index);
                if (!delete) {
                    filters.add(index, (SorterFilter<?>) edited);
                }
            }
        } else if (filter instanceof MinerFilter && tile instanceof TileEntityDigitalMiner) {
            HashList<MinerFilter<?>> filters = ((TileEntityDigitalMiner) tile).getFilters();
            int index = filters.indexOf(filter);
            if (index != -1) {
                filters.remove(index);
                if (!delete) {
                    filters.add(index, (MinerFilter<?>) edited);
                }
            }
        } else if (filter instanceof OredictionificatorItemFilter && tile instanceof TileEntityOredictionificator) {
            HashList<OredictionificatorItemFilter> filters = ((TileEntityOredictionificator) tile).getFilters();
            int index = filters.indexOf(filter);
            if (index != -1) {
                filters.remove(index);
                if (!delete) {
                    filters.add(index, (OredictionificatorItemFilter) edited);
                }
            }
        } else if (filter instanceof QIOFilter && tile instanceof TileEntityQIOFilterHandler) {
            HashList<QIOFilter<?>> filters = ((TileEntityQIOFilterHandler) tile).getFilters();
            int index = filters.indexOf(filter);
            if (index != -1) {
                filters.remove(index);
                if (!delete) {
                    filters.add(index, (QIOFilter<?>) edited);
                }
            }
        }
        tile.setChanged();
    }
}
Also used : SorterFilter(mekanism.common.content.transporter.SorterFilter) HashList(mekanism.common.lib.collection.HashList) TileEntityLogisticalSorter(mekanism.common.tile.TileEntityLogisticalSorter) MinerFilter(mekanism.common.content.miner.MinerFilter) PlayerEntity(net.minecraft.entity.player.PlayerEntity) TileEntityOredictionificator(mekanism.common.tile.machine.TileEntityOredictionificator) TileEntity(net.minecraft.tileentity.TileEntity) TileEntityDigitalMiner(mekanism.common.tile.machine.TileEntityDigitalMiner) TileEntityQIOFilterHandler(mekanism.common.tile.qio.TileEntityQIOFilterHandler) QIOFilter(mekanism.common.content.qio.filter.QIOFilter) OredictionificatorItemFilter(mekanism.common.content.oredictionificator.OredictionificatorItemFilter)

Example 4 with TileEntityLogisticalSorter

use of mekanism.common.tile.TileEntityLogisticalSorter in project Mekanism by mekanism.

the class BlockLogisticalSorter method updateShape.

@Nonnull
@Override
@Deprecated
public BlockState updateShape(BlockState state, @Nonnull Direction dir, @Nonnull BlockState facingState, @Nonnull IWorld world, @Nonnull BlockPos pos, @Nonnull BlockPos neighborPos) {
    if (!world.isClientSide()) {
        TileEntityLogisticalSorter sorter = WorldUtils.getTileEntity(TileEntityLogisticalSorter.class, world, pos);
        if (sorter != null && !sorter.hasConnectedInventory()) {
            TileEntity tileEntity = WorldUtils.getTileEntity(world, neighborPos);
            if (InventoryUtils.isItemHandler(tileEntity, dir)) {
                sorter.setFacing(dir.getOpposite());
                state = sorter.getBlockState();
            }
        }
    }
    return super.updateShape(state, dir, facingState, world, pos, neighborPos);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityLogisticalSorter(mekanism.common.tile.TileEntityLogisticalSorter) Nonnull(javax.annotation.Nonnull)

Example 5 with TileEntityLogisticalSorter

use of mekanism.common.tile.TileEntityLogisticalSorter in project Mekanism by mekanism.

the class TransporterUtils method canInsert.

public static boolean canInsert(TileEntity tile, EnumColor color, ItemStack itemStack, Direction side, boolean force) {
    if (force && tile instanceof TileEntityLogisticalSorter) {
        return ((TileEntityLogisticalSorter) tile).canSendHome(itemStack);
    }
    if (!force && tile instanceof ISideConfiguration) {
        ISideConfiguration config = (ISideConfiguration) tile;
        if (config.getEjector().hasStrictInput()) {
            Direction tileSide = config.getDirection();
            EnumColor configColor = config.getEjector().getInputColor(RelativeSide.fromDirections(tileSide, side.getOpposite()));
            if (configColor != null && configColor != color) {
                return false;
            }
        }
    }
    Optional<IItemHandler> capability = CapabilityUtils.getCapability(tile, CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side.getOpposite()).resolve();
    if (capability.isPresent()) {
        IItemHandler inventory = capability.get();
        for (int i = 0; i < inventory.getSlots(); i++) {
            // Check validation
            if (inventory.isItemValid(i, itemStack)) {
                // Simulate insert
                ItemStack rejects = inventory.insertItem(i, itemStack, true);
                if (TransporterManager.didEmit(itemStack, rejects)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : EnumColor(mekanism.api.text.EnumColor) IItemHandler(net.minecraftforge.items.IItemHandler) TileEntityLogisticalSorter(mekanism.common.tile.TileEntityLogisticalSorter) ItemStack(net.minecraft.item.ItemStack) Direction(net.minecraft.util.Direction) ISideConfiguration(mekanism.common.tile.interfaces.ISideConfiguration)

Aggregations

TileEntityLogisticalSorter (mekanism.common.tile.TileEntityLogisticalSorter)5 Nonnull (javax.annotation.Nonnull)3 ItemStack (net.minecraft.item.ItemStack)3 TileEntity (net.minecraft.tileentity.TileEntity)3 Direction (net.minecraft.util.Direction)2 IItemHandler (net.minecraftforge.items.IItemHandler)2 EnumColor (mekanism.api.text.EnumColor)1 MinerFilter (mekanism.common.content.miner.MinerFilter)1 OredictionificatorItemFilter (mekanism.common.content.oredictionificator.OredictionificatorItemFilter)1 QIOFilter (mekanism.common.content.qio.filter.QIOFilter)1 SorterFilter (mekanism.common.content.transporter.SorterFilter)1 HashList (mekanism.common.lib.collection.HashList)1 ISideConfiguration (mekanism.common.tile.interfaces.ISideConfiguration)1 TileEntityDigitalMiner (mekanism.common.tile.machine.TileEntityDigitalMiner)1 TileEntityOredictionificator (mekanism.common.tile.machine.TileEntityOredictionificator)1 TileEntityQIOFilterHandler (mekanism.common.tile.qio.TileEntityQIOFilterHandler)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1