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);
}
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();
}
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();
}
}
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);
}
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;
}
Aggregations